team_user_spec.rb revision 6514d548e755dd1067259c3eea6b7c05859a84d1
1117N/Arequire 'spec_helper'
1379N/A
1117N/Adescribe TeamUser do
1117N/A context 'Associations' do
1117N/A %i(team user creator).each do |association|
1117N/A it { should belong_to(association) }
1117N/A end
1117N/A end
1117N/A
1117N/A context 'team with admin and user' do
1117N/A let(:team_admin) { create :user } # admin in team
1117N/A let(:team_user) { create :user } # non-admin in team
1117N/A let(:admin_user) { create :team_user, user: team_admin }
1117N/A let(:team) { admin_user.team }
1117N/A let(:non_admim_user) { team.team_users.non_admin.first }
1117N/A before { team.users << team_user }
1117N/A
1117N/A it 'have 2 members' do
1117N/A expect(team.team_users.count).to eq(2)
1117N/A end
1117N/A
1117N/A it 'have a admin' do
1117N/A expect(team.team_users.admin.first.user).to eq(team_admin)
1117N/A end
1117N/A
1117N/A it 'have a non-admin' do
1117N/A expect(team.team_users.non_admin.first.user).to eq(team_user)
1117N/A end
1117N/A
1117N/A it 'remove non-admin' do
1117N/A expect(non_admim_user.destroy).to be_truthy
1117N/A end
1117N/A
1117N/A it 'not destroy the last admin' do
1117N/A expect { admin_user.destroy }.
1117N/A to raise_error(Permission::PowerVaccuumError)
1117N/A end
1117N/A
1117N/A it 'not remove the last admin flag' do
1117N/A expect { admin_user.update_attribute :admin, false }.
1117N/A to raise_error(Permission::PowerVaccuumError)
1117N/A end
1117N/A end
1117N/Aend
1117N/A