require 'spec_helper'

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator.  If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails.  There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec.  Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.

describe AddressBooksController do
  login_admin
  render_views
  describe "GET index" do
    it "should be success" do
      @address_book ||= Factory(:address_book)
      get :index
      response.should be_success
    end
  end

  describe "GET show" do

    it "should render 'show'" do
      @address_book ||= Factory(:address_book)
      get :show, :id => @address_book
      response.should render_template('show')
    end
  end

  describe "GET new" do
    it "should be sucesss" do
      get :new
      response.should be_success
    end
    it "should render template 'new'" do
      get :new
      response.should render_template('_form')
    end
  end

  describe "POST create" do
    describe "with valid params" do
      it "the address_book should success create" do
        lambda do
          post :create,:address_book => {:name => "address_book",:phone => "phone",:address => "address" }
        end.should change(AddressBook,:count).by(1)
      end

      it "redirects to the created address_book" do
        post :create,:address_book => {:name => 'address_book',:phone => "phone",:address => "address"}
        response.should redirect_to(assigns[:address_book])
      end
    end

    describe "with invalid params" do
      it "re-renders the 'new' template" do
        post :create, :address_book => {}
        response.should render_template('new')
      end
    end
  end


  describe "DELETE destroy" do
    before(:each) do
      @address_book ||= Factory(:address_book)
    end

    it "destroys the requested address_book" do
      lambda do
        delete :destroy ,:id => @address_book
      end.should change(AddressBook,:count).by(-1)
    end

    it "redirects to the address_books list" do
      delete :destroy, :id => @address_book
      response.should redirect_to(address_books_url)
    end
  end
end
