Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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])
# 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)
# code under test
def find_authorized_invitation_ids
secured_invitations = Invitation.accessible_by(current_ability, :create_quote).select('').where('' => params[:selected_invitations])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.