#coding: utf-8
require 'spec_helper'
require 'will_paginate/array'

# 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 InStockBillsController do
  login_admin
  render_views


  # This should return the minimal set of attributes required to create a valid
  # InStockBill. As you add validations to InStockBill, be sure to
  # update the return value of this method accordingly.
  def valid_attributes
    Factory.build(:in_stock_bill).attributes.delete_if {|k,v| [:id,:created_at,:updated_at].include? k.to_sym}
  end
  
  # This should return the minimal set of values that should be in the session
  # in order to pass any filters (e.g. authentication) defined in
  # InStockBillsController. Be sure to keep this updated too.
  def valid_session
    {}
  end

  describe "GET index" do
    it "assigns all in_stock_bills as @in_stock_bills" do
      in_stock_bill = Factory(:in_stock_bill)
      get :index
      #assigns(:in_stock_bills).should eq([in_stock_bill])
    end
  end

  describe "GET show" do
    it "assigns the requested in_stock_bill as @in_stock_bill" do
      in_stock_bill = Factory(:in_stock_bill)
      get :show, :id => in_stock_bill
      assigns(:in_stock_bill).should eq(in_stock_bill)
    end
  end

  describe "GET new" do
    it "assigns a new in_stock_bill as @in_stock_bill" do
      get :new
      assigns(:in_stock_bill).should be_a_new(InStockBill)
    end
  end

  describe "GET edit" do
    it "assigns the requested in_stock_bill as @in_stock_bill" do
      in_stock_bill = Factory(:in_stock_bill)
      get :edit, :id => in_stock_bill
      assigns(:in_stock_bill).should eq(in_stock_bill)
    end
  end

  describe "POST create" do
    describe "with valid params" do
      it "creates a new InStockBill" do
        expect {
          post :create, :in_stock_bill => valid_attributes,:bill_ids => [1]
        }.to change(InStockBill, :count).by(1)
      end

      it "assigns a newly created in_stock_bill as @in_stock_bill" do
        post :create,:in_stock_bill => valid_attributes,:bill_ids => [1]
        assigns(:in_stock_bill).should be_a(InStockBill)
        assigns(:in_stock_bill).should be_persisted
      end

      it "redirects to the created in_stock_bill" do
        post :create, :in_stock_bill => valid_attributes,:bill_ids => [1]

        response.should redirect_to(InStockBill.last)
      end
    end

    describe "with invalid params" do
      it "assigns a newly created but unsaved in_stock_bill as @in_stock_bill" do
        # Trigger the behavior that occurs when invalid params are submitted
        #InStockBill.any_instance.stub(:save).and_return(false)
        post :create, :in_stock_bill => {:bill_date => '2013-11-11'},:bill_ids => [1]

        assigns(:in_stock_bill).should be_a_new(InStockBill)
      end

      it "re-renders the 'new' template" do
        # Trigger the behavior that occurs when invalid params are submitted
        #InStockBill.any_instance.stub(:save).and_return(false)
        post :create, :in_stock_bill => {:bill_date => '2013-11-11'},:bill_ids => [1]

        response.should render_template("new")
      end
    end
  end

  describe "PUT update" do
    before :each do
      @in_stock_bill = Factory(:in_stock_bill)
    end
    describe "with valid params" do
      it "updates the requested in_stock_bill" do
        # Assuming there are no other in_stock_bills in the database, this
        # specifies that the InStockBill created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.
        put :update, :id => @in_stock_bill, :in_stock_bill => valid_attributes
      end

      it "assigns the requested in_stock_bill as @in_stock_bill" do
        put :update, :id => @in_stock_bill, :in_stock_bill => valid_attributes
        assigns(:in_stock_bill).should eq(@in_stock_bill)
      end

      it "redirects to the in_stock_bill" do
        put :update, :id => @in_stock_bill, :in_stock_bill => valid_attributes
        response.should redirect_to(@in_stock_bill)
      end
    end

    describe "with invalid params" do
      it "assigns the in_stock_bill as @in_stock_bill" do
        # Trigger the behavior that occurs when invalid params are submitted
        put :update, :id => @in_stock_bill, :in_stock_bill => {}
        assigns(:in_stock_bill).should eq(@in_stock_bill)
      end

      it "re-renders the 'edit' template" do
        # Trigger the behavior that occurs when invalid params are submitted
        put :update, :id => @in_stock_bill, :in_stock_bill => {:org_id => ""}
        response.should render_template("edit")
      end
    end
  end

  describe "DELETE destroy" do
    before :each do
      @in_stock_bill = Factory(:in_stock_bill)
    end
    it "destroys the requested in_stock_bill" do
      expect {
        delete :destroy, :id => @in_stock_bill
      }.to change(InStockBill, :count).by(-1)
    end

    it "redirects to the in_stock_bills list" do
      delete :destroy, :id => @in_stock_bill
      response.should redirect_to(in_stock_bills_url)
    end
  end
end
