# -*- encoding : 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 the Rails when you ran the scaffold generator.

describe GoodsErrorsController do

  login_admin
  render_views

  before(:each) do
    @goods_error = Factory(:goods_error)
    @bill = Factory(:computer_bill)
  end


  describe "GET index" do
    it "assigns all goods_errors as @goods_errors" do
      get :index
      response.should be_success
    end
  end

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

    it "assigns the requested goods_error as @goods_error" do
      get :show, :id => @goods_error
      response.should be_success
    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(:goods_error).attributes
    end
    describe "success" do
      it "能够成功保存多货少货信息" do
        lambda do
          post :create, :goods_error => @attr,:bill_ids => [@bill.id]
        end.should change(GoodsError,:count).by(1)
      end
    end

    describe "with invalid params" do
      it "re-renders the 'new' template" do
        post :create, :goods_error => {},:bill_ids => [@bill.id]
        response.should render_template("new")
      end
    end
  end

  describe "PUT update" do
    before :each do
      @attr = {:note => 'updated goods_exception'}
    end

    describe "with valid params" do
      it "updates the requested goods_exception" do
        put :update, :id => @goods_error, :goods_error => @attr
        @goods_error.reload
        @goods_error.note.should == @attr[:note]
      end

    end

    describe "with invalid params" do
      it "re-renders the 'edit' template" do
        put :update, :id => @goods_error,:goods_error => {:org_id => nil}
        response.should render_template("edit")
      end
    end

  end

  describe "DELETE destroy" do
    it "destroys the requested goods_exception" do
      lambda do
        delete :destroy, :id => @goods_error
      end.should change(GoodsError,:count).by(-1)
    end

    it "redirects to the goods_exceptions list" do
      delete :destroy, :id => @goods_error
      response.should redirect_to(goods_errors_url)
    end
  end
end

