Skip to content

Instantly share code, notes, and snippets.

@phantomwhale
Created August 2, 2012 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phantomwhale/3234264 to your computer and use it in GitHub Desktop.
Save phantomwhale/3234264 to your computer and use it in GitHub Desktop.
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
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment