9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholastarequire 'spec_helper'
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholastadescribe User do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'associations' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta %i(comments ontology_versions team_users teams permissions keys
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta authored_commits committed_commits pushed_commits).
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta each do |association|
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it { should have_many(association) }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it { should strip_attribute :name }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it { should strip_attribute :email }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it { should_not strip_attribute :password }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'when there are only two users, one admin and one not' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let!(:admin) { create :admin }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let!(:user) { create :user }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'should raise no error when deleting the user' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect { user.destroy }.not_to raise_error
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'should raise an error when trying to delete the admin' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect { admin.destroy }.to raise_error(Permission::PowerVaccuumError)
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'User instance' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let(:mails_sent) { ActionMailer::Base.deliveries.size }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let(:user) { create :user }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'not send email to *@example.com' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(ActionMailer::Base.deliveries.size).to eq(mails_sent)
748ba184db97b7534254f97018fa04e8aa458faeJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
748ba184db97b7534254f97018fa04e8aa458faeJan Cholasta it 'have email' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(user.email).not_to be(nil)
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta it 'have name' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect(user.name).not_to be(nil)
d0a8981bce0c462bcd4b5db2900c0f29a40a41f0Jan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'not have deleted_at' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect(user.deleted_at).to be(nil)
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta context 'after deletion' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta before { user.delete }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'have blank email' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(user.email).to be(nil)
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'have deleted_at' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(user.deleted_at).not_to be(nil)
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'Another user instance' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let!(:mails_sent) { ActionMailer::Base.deliveries.size }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let!(:user) { create :user, email: 'user@noexample.com' }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta it 'send email' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(ActionMailer::Base.deliveries.size).to eq(mails_sent+1)
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
d0a8981bce0c462bcd4b5db2900c0f29a40a41f0Jan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'Admin instance' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let(:admins) { 2.times.map { create :admin } }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'destroy one admin' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect(admins.first.destroy).to be_truthy
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'destroy not destroy all admins' do
d0a8981bce0c462bcd4b5db2900c0f29a40a41f0Jan Cholasta expect { admins.each(&:destroy) }.
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta to raise_error(Permission::PowerVaccuumError)
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta context 'considering commits' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let(:author) { create :user }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let(:committer) { create :user }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let(:pusher) { create :user }
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta let!(:commit) do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta create :commit, author: author, committer: committer, pusher: pusher
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'the author' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta it 'has correct authored_commits' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(author.authored_commits).to match_array([commit])
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'has correct committed_commits' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(author.committed_commits).to match_array([])
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta it 'has correct pushed_commits' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(author.pushed_commits).to match_array([])
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta context 'the committer' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta it 'has correct authored_commits' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(committer.authored_commits).to match_array([])
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'has correct committed_commits' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect(committer.committed_commits).to match_array([commit])
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'has correct pushed_commits' do
e5359baeac6e2d49769aceddbdbc606833b1ec69Jan Cholasta expect(committer.pushed_commits).to match_array([])
e5359baeac6e2d49769aceddbdbc606833b1ec69Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta context 'the pusher' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'has correct authored_commits' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect(pusher.authored_commits).to match_array([])
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta it 'has correct committed_commits' do
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta expect(pusher.committed_commits).to match_array([])
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta it 'has correct pushed_commits' do
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta expect(pusher.pushed_commits).to match_array([commit])
e5359baeac6e2d49769aceddbdbc606833b1ec69Jan Cholasta end
e5359baeac6e2d49769aceddbdbc606833b1ec69Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholasta end
1e68ae21e7ae46744700753ccf28bcbcaedbe017Jan Cholastaend
5ca493af3e24e2cf7299289364cf23ccec9e5d35Jan Cholasta