Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.dirname(__FILE__) + '/../spec_helper'
- describe BooksController do
- describe "handling POST /books" do
- before(:each) do
- @book = mock_model(Book, :to_param => "42")
- @user = mock_model(User, :to_param => "13")
- User.stub!(:find).and_return(@user)
- controller.stub!(:current_user).and_return(@user)
- @book_finder = mock("book_finder")
- @book_finder.stub!(:build).and_return(@book)
- @user.stub!(:books).and_return(@book_finder)
- end
- describe "with isbn number" do
- it "should get book with known_book isbn from the database and add it to the users list" do
- debugger
- user = User.create!(:login => "jane", :password => "test", :password_confirmation => "test", :email => "jane@test.com")
- controller.stub!(:current_user).and_return(user)
- isbn = "1234567890"
- known_book = Book.create!(:isbn => isbn)
- Book.should_receive(:find_by_isbn).with(isbn).and_return(known_book)
- Book.should_not_receive(:fetch_for_isbn)
- lambda {
- post :create, :book => { :isbn => isbn }, :user_id => user
- }.should change{ @user.books.count }.by(1)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment