project_member_spec.rb 2.38 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
2
# == Schema Information
#
3
# Table name: project_members
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
#
5
6
7
#  id                 :integer          not null, primary key
#  user_id            :integer          not null
#  project_id         :integer          not null
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8
9
#  created_at         :datetime
#  updated_at         :datetime
10
11
#  project_access     :integer          default(0), not null
#  notification_level :integer          default(3), not null
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
12
13
#

gitlabhq's avatar
gitlabhq committed
14
15
require 'spec_helper'

16
describe ProjectMember do
17
18
19
20
21
22
23
24
25
26
27
  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

28
29
      @project_1.team << [ @user_1, :developer ]
      @project_2.team << [ @user_2, :reporter ]
30

31
      @status = @project_2.team.import(@project_1)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    end

    it { @status.should be_true }

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

      it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true }
      it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true }
    end

    describe 'project 1 should not be changed' do
      it { @project_1.users.should include(@user_1) }
      it { @project_1.users.should_not include(@user_2) }
    end
  end
49
50
51
52
53
54
55
56
57

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

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

58
      ProjectMember.add_users_into_projects(
59
60
        [@project_1.id, @project_2.id],
        [@user_1.id, @user_2.id],
61
        ProjectMember::MASTER
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
      )
    end

    it { @project_1.users.should include(@user_1) }
    it { @project_1.users.should include(@user_2) }


    it { @project_2.users.should include(@user_1) }
    it { @project_2.users.should include(@user_2) }
  end

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

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

81
82
      @project_1.team << [ @user_1, :developer]
      @project_2.team << [ @user_2, :reporter]
83

84
      ProjectMember.truncate_teams([@project_1.id, @project_2.id])
85
86
87
88
89
    end

    it { @project_1.users.should be_empty }
    it { @project_2.users.should be_empty }
  end
gitlabhq's avatar
gitlabhq committed
90
end