Need some help with a simple

I can’t figure out why this is failing. It seems to have a hard time
assigning the @account. I have spent way too long trying to figure this
out.

Thanks for any help.


NoMethodError in ‘StaffMembersController GET index should allow
anonymous users’
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.staff_members

++++++++++++++++
describe StaffMembersController do

describe “GET index” do

before :each do
  @account = mock_model(Account, :staff_members =>

[mock_model(StaffMember)])
controller.stub!(:find_account_by_subdomain_or_url).and_return(@account)
end

# Authorization
it "should allow anonymous users" do
  get :index
  response.should render_template(:index)
end

end
end
++++++++++++++++

StaffMembersController
++++++++++++++++
class StaffMembersController < ApplicationController
before_filter :find_account_by_subdomain_or_url

def index
@staff_members = @account.staff_members
end

end
+++++++++++++++

I’m guessing the key is inside “find_account_by_subdomain_or_url”. Do
you have that defined somewhere? It probably calls something like:

@account = Account.find_by_subdomain(blah) or Account.find_by_url(blah)

In which case that’s probably what you need to stub. Nothing is
actually checking for the return value of the controller method or
assigning it to @account. In other words, you probably should do
Account.stub! instead of controller.stub! Check what’s in that method
and see if that gets you closer to the solution.

Good luck!
Glenn

Glenn F. wrote:

I’m guessing the key is inside “find_account_by_subdomain_or_url”. Do
you have that defined somewhere? It probably calls something like:

@account = Account.find_by_subdomain(blah) or Account.find_by_url(blah)

In which case that’s probably what you need to stub. Nothing is
actually checking for the return value of the controller method or
assigning it to @account. In other words, you probably should do
Account.stub! instead of controller.stub! Check what’s in that method
and see if that gets you closer to the solution.

Good luck!
Glenn

That worked.

I was under the impression that there would be no subdomain available
when testing, which is why I was stubbing the controller method. After
it working I actually checked what the request.domain was and saw that
it is test.host :slight_smile:

Thanks Glenn

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs