74 lines
2.8 KiB
Ruby
Executable File
74 lines
2.8 KiB
Ruby
Executable File
# == Schema Information
|
|
#
|
|
# Table name: teams
|
|
#
|
|
# id :bigint not null, primary key
|
|
# allow_auto_assign :boolean default(TRUE)
|
|
# description :text
|
|
# name :string not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# account_id :bigint not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_teams_on_account_id (account_id)
|
|
# index_teams_on_name_and_account_id (name,account_id) UNIQUE
|
|
#
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Team do
|
|
describe 'associations' do
|
|
it { is_expected.to belong_to(:account) }
|
|
it { is_expected.to have_many(:conversations) }
|
|
it { is_expected.to have_many(:team_members) }
|
|
end
|
|
|
|
describe '#add_members' do
|
|
let(:team) { FactoryBot.create(:team) }
|
|
|
|
before do
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
|
end
|
|
|
|
it 'handles adds all members and resets cache keys' do
|
|
users = FactoryBot.create_list(:user, 3)
|
|
team.add_members(users.map(&:id))
|
|
expect(team.reload.team_members.size).to eq(3)
|
|
|
|
expect(Rails.configuration.dispatcher).to have_received(:dispatch).at_least(:once)
|
|
.with(
|
|
'account.cache_invalidated',
|
|
kind_of(Time),
|
|
account: team.account,
|
|
cache_keys: team.account.cache_keys
|
|
)
|
|
end
|
|
end
|
|
|
|
describe '#remove_members' do
|
|
let(:team) { FactoryBot.create(:team) }
|
|
let(:users) { FactoryBot.create_list(:user, 3) }
|
|
|
|
before do
|
|
team.add_members(users.map(&:id))
|
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
|
end
|
|
|
|
it 'removes the members and resets cache keys' do
|
|
expect(team.reload.team_members.size).to eq(3)
|
|
|
|
team.remove_members(users.map(&:id))
|
|
expect(team.reload.team_members.size).to eq(0)
|
|
|
|
expect(Rails.configuration.dispatcher).to have_received(:dispatch).at_least(:once)
|
|
.with(
|
|
'account.cache_invalidated',
|
|
kind_of(Time),
|
|
account: team.account,
|
|
cache_keys: team.account.cache_keys
|
|
)
|
|
end
|
|
end
|
|
end
|