# -*- 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 RemittancesController do
  login_admin
  render_views

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


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

  describe "GET show" do

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

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

  describe "GET edit" do
    it "assigns the requested remittance as @remittance" do
      get :edit, :id => @remittance
      response.should render_template('edit')
    end
  end

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

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


      it "redirects to the remittance" do
        put :update, :id => @remittance,:remittance => @attr
        response.should redirect_to(remittance_path(@remittance))
      end
    end

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

  end

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

    it "redirects to the remittances list" do
      delete :destroy, :id => @remittance 
      response.should redirect_to(remittances_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

