#coding: utf-8
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 AdjustFeeInfosController do
  login_admin
  render_views


  describe "GET index" do
    before(:each) do
      @adjust_fee_info = Factory(:adjust_fee_info)
    end


    it "assigns all adjust_fee_infos as @adjust_fee_infos" do
      get :index
      response.should be_success
    end
  end

  describe "GET show" do
    before(:each) do
      @adjust_fee_info = Factory(:adjust_fee_info)
    end


    it "should be success" do
      get :show, :id => @adjust_fee_info
      response.should be_success
    end

    it "assigns the requested adjust_fee_info as @adjust_fee_info" do
      get :show, :id => @adjust_fee_info
      response.should render_template('show')
    end
  end

  describe "GET new" do
    it "should be success" do
      get :new
      response.should be_success
    end
  end

  describe "POST create" do

    before(:each) do
      @attr = Factory.build(:adjust_fee_info).attributes
      @attr.delete(:id);@attr.delete(:created_at);@attr.delete(:updated_at)
    end
    describe "success" do
      it "能够成功保存票据信息" do
        lambda do
          post :create, :adjust_fee_info => @attr
        end.should change(AdjustFeeInfo,:count).by(1)
      end

      it "redirects to the created adjust_fee_info" do
        post :create, :adjust_fee_info => @attr
        response.should redirect_to(adjust_fee_info_path(assigns(:adjust_fee_info)))
      end
    end

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

  end

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

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

    it "redirects to the adjust_fee_infos list" do
      delete :destroy, :id => @adjust_fee_info
      response.should redirect_to(adjust_fee_infos_url)
    end
  end

  #审批通过
  describe "PUT authorize" do
    before(:each) do
      @adjust_fee_info = Factory(:adjust_fee_info)
      @attrs = @adjust_fee_info.attributes
      @attrs.delete(:id);@attrs.delete(:created_at);@attrs.delete(:updated_at)
      @attrs["adjust_fee"] = 11
    end
    it "能够成功审批运费调整申请" do
      put :pass,:id => @adjust_fee_info,:adjust_fee_info => @attrs
      response.should redirect_to(assigns[:adjust_fee_info])
    end

    it "能够成功驳回运费调整申请" do
      put :deny,:id => @adjust_fee_info
      response.should redirect_to(assigns[:adjust_fee_info])
    end
  end

end
