Help with controllers specs

I had some doubts while specing the action edit for User Model

My controller

def edit
@user = User.find(get_param(:id, :integer))
@user = current_user if !is_admin?
end


My spec

describe “GET edit” do
##############################################################
should_require_login :get, :edit

 ##############################################################
 describe "authenticated user" do
   ##############################################################
   before(:each) do
     login_as_user
     @user = mock_model(User)
     User.stub!(:find).and_return(@user)
   end
   ##############################################################
   it "should find user and return object" do
     User.should_receive(:find_by_id_and_role).with(1,

“SJ”).and_return(@user)
get :edit, :id => 1, :role => ‘SJ’
end
end
end


The method is_admin in Application Controller

def is_admin?
logged_in? && current_user.role == Role.find(Role::ADMINISTRATOR)
end


The error I have is

Spec::Mocks::MockExpectationError in ‘UsersController GET edit
authenticated user should find user and return object’
Mock ‘User_1015’ received unexpected message :role with (no args)

How should I verify the method is_admin?

Thank you

EM

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