Created
February 8, 2016 16:50
-
-
Save a-leung/c960d220a3528f4c7c7b to your computer and use it in GitHub Desktop.
rspec mocking issue
This file contains 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
def refund | |
self.items | |
ActiveRecord::Base.transaction do | |
self.items.each { |i| i.update!(refund: true) } | |
end | |
end | |
def refund_v2 | |
refundable_items = self.items.where(refund: false) | |
ActiveRecord::Base.transaction do | |
refundable_items.each { |i| i.update!(refund: true) } | |
end | |
end |
This file contains 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
self.items.first.stub(:create_or_update).and_return false | |
expect(refund).to eq false # passes | |
expect(refund_v2).to eq false # fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment