BigW Consortium Gitlab

project_member_spec.rb 2.6 KB
Newer Older
Dmitriy Zaporozhets committed
1 2
# == Schema Information
#
Valery Sizov committed
3
# Table name: members
Dmitriy Zaporozhets committed
4
#
5
#  id                 :integer          not null, primary key
Valery Sizov committed
6 7 8
#  access_level       :integer          not null
#  source_id          :integer          not null
#  source_type        :string(255)      not null
Stan Hu committed
9
#  user_id            :integer
Valery Sizov committed
10 11
#  notification_level :integer          not null
#  type               :string(255)
Dmitriy Zaporozhets committed
12 13
#  created_at         :datetime
#  updated_at         :datetime
Stan Hu committed
14 15 16 17
#  created_by_id      :integer
#  invite_email       :string(255)
#  invite_token       :string(255)
#  invite_accepted_at :datetime
Dmitriy Zaporozhets committed
18 19
#

gitlabhq committed
20 21
require 'spec_helper'

22
describe ProjectMember do
23 24 25 26 27 28 29 30 31 32 33
  describe :import_team do
    before do
      @abilities = Six.new
      @abilities << Ability

      @project_1 = create :project
      @project_2 = create :project

      @user_1 = create :user
      @user_2 = create :user

34 35
      @project_1.team << [ @user_1, :developer ]
      @project_2.team << [ @user_2, :reporter ]
36

37
      @status = @project_2.team.import(@project_1)
38 39
    end

40
    it { expect(@status).to be_truthy }
41 42

    describe 'project 2 should get user 1 as developer. user_2 should not be changed' do
43 44
      it { expect(@project_2.users).to include(@user_1) }
      it { expect(@project_2.users).to include(@user_2) }
45

46
      it { expect(@abilities.allowed?(@user_1, :create_project, @project_2)).to be_truthy }
47
      it { expect(@abilities.allowed?(@user_2, :read_project, @project_2)).to be_truthy }
48 49 50
    end

    describe 'project 1 should not be changed' do
51 52
      it { expect(@project_1.users).to include(@user_1) }
      it { expect(@project_1.users).not_to include(@user_2) }
53 54
    end
  end
55 56 57 58 59 60 61 62 63

  describe :add_users_into_projects do
    before do
      @project_1 = create :project
      @project_2 = create :project

      @user_1 = create :user
      @user_2 = create :user

64
      ProjectMember.add_users_into_projects(
65 66
        [@project_1.id, @project_2.id],
        [@user_1.id, @user_2.id],
67
        ProjectMember::MASTER
68 69 70
      )
    end

71 72
    it { expect(@project_1.users).to include(@user_1) }
    it { expect(@project_1.users).to include(@user_2) }
73 74


75 76
    it { expect(@project_2.users).to include(@user_1) }
    it { expect(@project_2.users).to include(@user_2) }
77 78 79 80 81 82 83 84 85 86
  end

  describe :truncate_teams do
    before do
      @project_1 = create :project
      @project_2 = create :project

      @user_1 = create :user
      @user_2 = create :user

87 88
      @project_1.team << [ @user_1, :developer]
      @project_2.team << [ @user_2, :reporter]
89

90
      ProjectMember.truncate_teams([@project_1.id, @project_2.id])
91 92
    end

93 94
    it { expect(@project_1.users).to be_empty }
    it { expect(@project_2.users).to be_empty }
95
  end
gitlabhq committed
96
end