Created
March 4, 2012 22:01
-
-
Save vsavkin/1975016 to your computer and use it in GitHub Desktop.
Refactored sell_book
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 sell_book | |
@book = Book.find(params[:id]) | |
BookSellingService.sell_book(@book) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for writing here but comments under the post are disabled.
You wrote comment to this snippet:
How test for this action would look like? Do you just assert that BookSellingService received
sell_book
message with proper book?Is that sufficient enough? (assuming you have unit tests for
BookSellingService
).Other scenario I'm thinking of is writing:
receive(:sell_book).with(book).and_call_original
?. But in that case I would have stub any dependencies ofBookSellingService
, is that right?Let's say that
BookSellingService
uses courier (e.g. FedEx) API and needs to call it.In that case would we have to add
before { allow(FedEx).to receive(:ship!).and_return (true) }
to this test case? IMHO controller test for this action shouldn't have any idea of internalBookSellingService
implementation but I'm not highly concerned about it.How would you write test for it?