public

Two Rspec before blocks to stub out some behaviour in a controller.First block works, but is verbose. Second block fails, but unsure why. Last chunk of code is the code being tested.Worth noting that changing the method to 'telect' makes it pass

  • Download Gist
responses_controller_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# This works, but a bit verbose
 
before do
@invitation1, @invitation2 = stub_model(Invitation), stub_model(Invitation)
stubbed_scope = stub
Invitation.stub(:accessible_by => stubbed_scope)
stubbed_scope.stub_chain(:select, :where => [@invitation1, @invitation2])
end
 
# This fails with :
# NoMethodError: private method `select' called for #<Object:0x7f5b31904988>
 
before do
@invitation1, @invitation2 = stub_model(Invitation), stub_model(Invitation)
Invitation.stub_chain(:accessible_by, :select, :where => [@invitation1, @invitation2])
Response.stub(:create_proxy_responses! => 1)
end
 
# code under test
def find_authorized_invitation_ids
secured_invitations = Invitation.accessible_by(current_ability, :create_quote).select('invitations.id').where('invitations.id' => params[:selected_invitations])
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.