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 GoodsCatsController do
  login_admin
  render_views
  describe "GET index" do
    it "should be success" do
      @goods_cat ||= Factory(:goods_cat)
      get :index
      response.should be_success
    end
  end

  describe "GET show" do

    it "should render 'show'" do
      @goods_cat ||= Factory(:goods_cat)
      get :show, :id => @goods_cat
      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 goods_cat should success create" do
        lambda do
          post :create,:goods_cat => {:name => "goods_cat" }
        end.should change(GoodsCat,:count).by(1)
      end

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

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


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

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

    it "redirects to the goods_cats list" do
      delete :destroy, :id => @goods_cat
      response.should redirect_to(goods_cats_url)
    end
  end
end
