Created
April 5, 2014 16:16
-
-
Save alexparker/9993912 to your computer and use it in GitHub Desktop.
Strange `undefined method model_url` error. Am I missing something with decent exposure? Is the namespace on the controller causing an issue?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::PreordersController < ApplicationController | |
respond_to :json | |
expose :preorder, attributes: :preorder_params | |
def create | |
preorder.save | |
respond_with preorder # does not work | |
# respond_with preorder, location: api_preorder_url(preorder) # works | |
end | |
private | |
def preorder_params | |
params.permit(:email) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Api::PreordersController do | |
describe '#create' do | |
let(:params) { {email: '[email protected]', format: :json} } | |
it 'creates a new preorder' do | |
expect{ | |
post :create, params | |
}.to change{ | |
Preorder.count | |
}.by(1) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :api do | |
resources :preorders, only: [:create, :show] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ spring rspec spec/controllers/api/preorders_controller_spec.rb | |
1) Api::PreordersController#create creates a new preorder | |
Failure/Error: post :create, params: params, format: :json | |
NoMethodError: | |
undefined method `preorder_url' for #<Api::PreordersController:0x007facf46198f8> | |
# ./app/controllers/api/preorders_controller.rb:8:in `create' | |
# ./spec/controllers/api/preorders_controller_spec.rb:9:in `block (4 levels) in <top (required)>' | |
# ./spec/controllers/api/preorders_controller_spec.rb:8:in `block (3 levels) in <top (required)>' | |
# -e:1:in `<main>' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"post :create, params" should be "post :create, params, format: :json" since your action respond_to json