team_user_spec.rb revision 15263a1fe962b15de60448a4d3eaa271d7a7affc
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksarequire 'spec_helper'
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksadescribe TeamUser do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa context 'Associations' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa %i(team user creator).each do |association|
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it { should belong_to(association) }
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa context 'team with admin and user' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa let(:team_admin) { FactoryGirl.create :user } # admin in team
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa let(:team_user) { FactoryGirl.create :user } # non-admin in team
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa let(:admin_user) { FactoryGirl.create :team_user, user: team_admin }
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa let(:team) { admin_user.team }
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa let(:non_admim_user) { team.team_users.non_admin.first }
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa before { team.users << team_user }
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it 'have 2 members' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa expect(team.team_users.count).to eq(2)
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it 'have a admin' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa expect(team.team_users.admin.first.user).to eq(team_admin)
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it 'have a non-admin' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa expect(team.team_users.non_admin.first.user).to eq(team_user)
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it 'remove non-admin' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa expect(non_admim_user.destroy).to be_truthy
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it 'not destroy the last admin' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa expect { assert admin_user.destroy }.
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa to raise_error(Permission::PowerVaccuumError)
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa it 'not remove the last admin flag' do
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa expect { admin_user.update_attribute :admin, false }.
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa to raise_error(Permission::PowerVaccuumError)
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksa end
15263a1fe962b15de60448a4d3eaa271d7a7affcEugen Kuksaend