#coding: utf-8
#提醒controller测试
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 NoticesController do
  login_admin
  render_views

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

    it "should be success" do
      get :index
      response.should be_success
    end
  end

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

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

  describe "POST create" do
    describe "with valid params" do
      it "the notice should success create" do
        Rails.logger.info("notice count : #{Notice.count}")
        lambda do
          post :create,:notice => {:org_id => Factory(:zz),:load_list_id => Factory(:load_list)}
          Rails.logger.info("notice count : #{Notice.count}")
        end.should change(Notice,:count).by(1)
        Rails.logger.info("notice count : #{Notice.count}")
      end

      it "redirects to the created load_list" do
        post :create,:notice => {:org_id => Factory(:zz),:load_list_id => 1}
        response.should redirect_to(assigns[:notice])
      end
    end

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


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

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

    it "redirects to the load_lists list" do
      delete :destroy ,:id => @notice
      response.should redirect_to(notices_url)
    end
  end
end
