Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.