Sha256: 4614f086e814b72dee6d585b6d747cea0d01833ddfc2f41e6987c238c0333c5b

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

require 'rails_helper'

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

    describe "#index" do
      it "should redirect to activity" do
        get :index
        expect(response).to redirect_to people_activity_path
      end
    end

    describe '#list' do
      describe 'sorting' do
        let!(:alice)       { create(:individual, first_name: 'Alice', last_name: 'Zarston') }
        let!(:bob)         { create(:individual, first_name: 'Bob', last_name: 'Tilan')     }
        let!(:corporation) { create(:corporation, name: 'Zorg Corp')                        }

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

      end

      describe "search" do
        it "search should ignore filters" do
          corporation1 = create(:corporation, tag_list: "abc", name: "aaa")
          corporation2 = create(:corporation, tag_list: "xyz", name: "bbb")
          @request.cookies["filters"] = {tags: ["abc"]}.to_json
          get :list, q: "bbb"
          expect(assigns(:people)).to eq [corporation2]
        end
      end
    end

    describe "activity" do
      before do
        @person = create(:customer_vault_corporation)
        @comment1 = @person.comments.create!(text: "ABC", created_at: Time.now - 3.days)
        @comment2 = @person.comments.create!(text: "DEF", created_at: Time.now - 2.days)
        @comment3 = @person.comments.create!(text: "DEF", created_at: Time.now - 9.days)
      end

      it "should assigns all comments ordered by created_at DESC" do
        get :activity
        expect(assigns(:comments)).to eq [@comment2, @comment1, @comment3]
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
customer_vault-1.3.2 spec/controllers/customer_vault/people_controller_spec.rb
customer_vault-1.3.1 spec/controllers/customer_vault/people_controller_spec.rb