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