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

describe JournalsController do
  login_admin
  render_views

  before(:each) do
    @journal = Factory(:journal)
  end


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

  describe "GET show" do

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

    it "assigns the requested journal as @journal" do
      get :show, :id => @journal
      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 "GET edit" do
    it "assigns the requested journal as @journal" do
      get :edit, :id => @journal
      response.should render_template('edit')
    end
  end

  describe "POST create" do
    before(:each) do
      @attr = Factory.build(:journal).attributes
    end
    describe "success" do
      it "能够成功保存票据信息" do
        lambda do
          post :create, :journal => @attr
        end.should change(Journal,:count).by(1)
      end

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

    describe "with invalid params" do

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

  end

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

    it "redirects to the journals list" do
      delete :destroy, :id => @journal 
      response.should redirect_to(journals_url)
    end
  end
  describe "GET search" do
    it "should be success" do 
      get :search
      response.should be_success
    end
    it "should render 'search'" do
      get :search
      response.should render_template('search')
    end
  end
end

