I'm trying to test a nested controller with Rspec and mocked models but i'm getting these errors:
Failure/Error: it { assigns[:store].should equal(mock_store) }
expected #<Store:2198414660> => #<Store:0x83092544 @name="Store_1008">
got #<User:2198383140> => #<User:0x8308aa24 @name="User_1009">
and i can't find why this is happening.
routes.rb
namespace :api do
namespace :v1 do
devise_for :users, :controllers => { :sessions => "devise/sessions",
:passwords => "devise/passwords",
:registrations => "devise/registrations" }
resources :categories, :only => [ :index, :show ]
resources :users, :only => [ :index, :show ] do
resources :stores
end
resources :stores do
resources :products
end
resources :products
end
end
app/controllers/api/v1/stores_controller.rb
class Api::V1::StoresController < Api::ApiController
belongs_to :user
actions :all
end
app/controllers/api/api_controller.rb
class Api::ApiController < InheritedResources::Base
respond_to :json
end
My spec/controllers/api/v1/stores_controller_spec.rb -> http://www.pastie.org/2118818 throws me these strange errors -> http://www.pastie.org/2118825.
Why do i always get the mocked User instead the Store.
If I remove the belongs_to :user line from app/controllers/api/v1/stores_controller.rb all my test pass, but i'm interested in testing "users/:user_id/stores/*" routes.
How can i test them correctly, and why i'm getting a Mocked User instead the Store.
I'm using
* inherited_resources (1.2.2)
* rails (3.0.7)
* rspec (2.5.0)
* rspec-core (2.5.2)
* rspec-expectations (2.5.0)
* rspec-mocks (2.5.0)
* rspec-rails (2.5.0)
Thanks for your time.