Created
August 2, 2012 06:03
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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