Guest User

Untitled

a guest
Mar 11th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. require File.dirname(__FILE__) + '/../spec_helper'
  2.  
  3. describe BooksController do
  4. describe "handling POST /books" do
  5.  
  6. before(:each) do
  7. @book = mock_model(Book, :to_param => "42")
  8. @user = mock_model(User, :to_param => "13")
  9. User.stub!(:find).and_return(@user)
  10. controller.stub!(:current_user).and_return(@user)
  11. @book_finder = mock("book_finder")
  12. @book_finder.stub!(:build).and_return(@book)
  13. @user.stub!(:books).and_return(@book_finder)
  14. end
  15.  
  16. describe "with isbn number" do
  17. it "should get book with known_book isbn from the database and add it to the users list" do
  18. debugger
  19. user = User.create!(:login => "jane", :password => "test", :password_confirmation => "test", :email => "jane@test.com")
  20. controller.stub!(:current_user).and_return(user)
  21.  
  22. isbn = "1234567890"
  23. known_book = Book.create!(:isbn => isbn)
  24. Book.should_receive(:find_by_isbn).with(isbn).and_return(known_book)
  25. Book.should_not_receive(:fetch_for_isbn)
  26. lambda {
  27. post :create, :book => { :isbn => isbn }, :user_id => user
  28. }.should change{ @user.books.count }.by(1)
  29. end
  30. end
  31. end
  32. end
Add Comment
Please, Sign In to add comment