require File.dirname(__FILE__) + '/../test_helper'
require 'books_controller'

# Re-raise errors caught by the controller.
class BooksController; def rescue_action(e) raise e end; end

class BooksControllerTest < Test::Unit::TestCase
  fixtures :books

  def setup
    @controller = BooksController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_search_book
    get :search, :isbn => '0596002815'
    assert_not_nil assigns(:book)
    assert_equal books(:learning_python_book).isbn, assigns(:book).isbn
    assert_valid assigns(:book)
    assert_redirected_to :action => 'show'
  end

  def test_search_invalid_book
    get :search, :isbn => 'x123x' # invalid ISBN
    assert_redirected_to :action => 'list'
    assert_equal 'No books found.', flash[:error]
  end
end