I need some help to stub this method of my controller
@users =
User.accessible_by(current_user).paginate(
:conditions => conditions.to_sql,
:include => :user_channels,
:order => build_sort_conditions(:name, true),
:page => get_param(:page, :integer),
:per_page => 10
)
end
My rspec is
describe ‘GET /index’ do
##############################################################
should_require_login :get, :index
##############################################################
describe “authenticated user” do
##############################################################
before do
login_as_user
check_session_expiration
@user = mock_model(User)
@users = [@user]
User.stub_chain(:accessible_by, :paginate).and_return(@users)
end
##############################################################
it 'should load the users' do
User.should_receive(:paginate).with(
:conditions => ['active = ?', true],
:order => :name,
:page => nil,
:per_page => 10
).and_return(@users)
do_get
assigns[:users].should == @users
end
end
end
##############################################################
The error I get is
Spec::Mocks::MockExpectationError in ‘UsersController GET /index
authenticated user should load the users’
<User(id: integer, name: string, email: string, crypted_password:
string, password_salt: string, persistence_token: string, role:
string, active: boolean, password_last_changed_at: datetime,
created_at: datetime, updated_at: datetime)
(class)> expected :paginate with
({:per_page=>10, :conditions=>[“active = ?”,
true], :order=>:name, :page=>nil}) once, but received it 0 times
./spec/controllers/users_controller_spec.rb:269:
How should I stub a named_scope with
params(accessible_by(current_user)), following a stub to
paginate.with(…).
I can not change my controller
Thank you
EM