diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-01-02 18:06:44 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-01-02 18:06:44 +0300 |
commit | 2665aea6275cc82888ed3e3ab3dbe384028d663c (patch) | |
tree | c293f8e3033667aa992b53f38d2e135093529242 /spec/migrations/clean_up_for_members_spec.rb | |
parent | 3f44c4cedbbd9b72fdf28e83caaec345934e1d8d (diff) |
Fix user membership destroy relation
Diffstat (limited to 'spec/migrations/clean_up_for_members_spec.rb')
-rw-r--r-- | spec/migrations/clean_up_for_members_spec.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/migrations/clean_up_for_members_spec.rb b/spec/migrations/clean_up_for_members_spec.rb new file mode 100644 index 00000000000..0258860d169 --- /dev/null +++ b/spec/migrations/clean_up_for_members_spec.rb @@ -0,0 +1,78 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20171216111734_clean_up_for_members.rb') + +describe CleanUpForMembers, :migration do + let(:migration) { described_class.new } + let!(:group_member) { create_group_member } + let!(:unbinded_group_member) { create_group_member } + let!(:invited_group_member) { create_group_member(true) } + let!(:not_valid_group_member) { create_group_member } + let!(:project_member) { create_project_member } + let!(:invited_project_member) { create_project_member(true) } + let!(:unbinded_project_member) { create_project_member } + let!(:not_valid_project_member) { create_project_member } + + it 'removes members without proper user_id' do + unbinded_group_member.update_column(:user_id, nil) + not_valid_group_member.update_column(:user_id, 9999) + unbinded_project_member.update_column(:user_id, nil) + not_valid_project_member.update_column(:user_id, 9999) + + migrate! + + expect(Member.all).not_to include(unbinded_group_member, not_valid_group_member, unbinded_project_member, not_valid_project_member) + expect(Member.all).to include(group_member, invited_group_member, project_member, invited_project_member) + end + + def create_group_member(invited = false) + fill_member(GroupMember.new(group: create_group), invited) + end + + def create_project_member(invited = false) + fill_member(ProjectMember.new(project: create_project), invited) + end + + def fill_member(member_object, invited) + member_object.tap do |m| + m.access_level = 40 + m.notification_level = 3 + + if invited + m.user_id = nil + m.invite_token = 'xxx' + m.invite_email = 'email@email.com' + else + m.user_id = create_user.id + end + + m.save + end + + member_object + end + + def create_group + name = FFaker::Lorem.characters(10) + + Group.create(name: name, path: name.downcase.gsub(/\s/, '_')) + end + + def create_project + name = FFaker::Lorem.characters(10) + creator = create_user + + Project.create(name: name, + path: name.downcase.gsub(/\s/, '_'), + namespace: creator.namespace, + creator: creator) + end + + def create_user + User.create(email: FFaker::Internet.email, + password: '12345678', + name: FFaker::Name.name, + username: FFaker::Internet.user_name, + confirmed_at: Time.now, + confirmation_token: nil) + end +end |