Sha256: 48ce3f6d815e4cf5a52580573638a98a064d887066a68cc9048b047ff240155d

Contents?: true

Size: 1.6 KB

Versions: 11

Compression:

Stored size: 1.6 KB

Contents

require 'rails_helper'

module CustomerVault
  RSpec.describe PeopleController, :type => :controller do      
    routes { CustomerVault::Engine.routes }

    describe 'index' do 
      describe 'sorting' do
        let!(:alice) {FactoryGirl.create(:individual, first_name: 'Alice', last_name: 'Zarston')}  
        let!(:bob) {FactoryGirl.create(:individual, first_name: 'Bob', last_name: 'Tilan')}  
        let!(:corporation) {FactoryGirl.create(:corporation, name: 'Zorg Corp')}  
        
        it 'should sort people by name by default' do
          get :index
          expect(assigns(:people)).to eq([bob, alice, corporation])
        end

        it 'should sort people by name' do
          get :index, sort: 'name'
          expect(assigns(:people)).to eq([bob, alice, corporation])
        end
        it 'should sort people by reverse name' do
          get :index, sort: '-name'
          expect(assigns(:people)).to eq([corporation, alice, bob])
        end

        context 'sort by zip code' do
          before :each do
            alice.address.update_attribute(:zip, 'c123')
            bob.address.update_attribute(:zip, 'b123')
            corporation.address.update_attribute(:zip, 'a123')
            
          end
          it 'should sort buildings by zip code' do
            get :index, sort: 'zip'
            expect(assigns(:people)).to eq([corporation, bob, alice])
          end
          it 'should sort buildings by reverse zip code' do
            get :index, sort: '-zip'
            expect(assigns(:people)).to eq([alice, bob, corporation])
          end
        end

      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
customer_vault-1.2.5 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.2.4 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.2.3 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.2.2 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.2.1 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.2.0 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.1.0 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.0.4 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.0.3 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.0.2 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.0.1 spec/controllers/customer_vault/people_controller_spec.rb