summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-15 10:48:28 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-15 10:48:28 +0000
commite3d818a4e8f51c00aaba1924690f728aa468d7f2 (patch)
tree2893b6d4528cbb0580d42de94725ff00fcfd5786 /spec
parentb75866120b2391d0f2f01d03601a19baa9fa9b4e (diff)
parent3d0c0bd922dadbf09c46f2b8acb58d44565394ce (diff)
downloadgitlab-ce-e3d818a4e8f51c00aaba1924690f728aa468d7f2.tar.gz
Merge branch 'invitation' into 'master'
Allow users to be invited. Addresses private issue https://dev.gitlab.org/gitlab/gitlabhq/issues/2058. The "Add members" panes for both Group Members and Project Members have gained a line of text by the People field. ![Screen_Shot_2015-04-10_at_14.14.32](https://gitlab.com/gitlab-org/gitlab-ce/uploads/fe990e65eccd9203d7324b492941362b/Screen_Shot_2015-04-10_at_14.14.32.png) Entering an email address that is not already a member will give you the option to invite them. ![Screen_Shot_2015-04-10_at_14.14.48](https://gitlab.com/gitlab-org/gitlab-ce/uploads/d6b0d4571ea90f2a2e4af8f5b336e8e1/Screen_Shot_2015-04-10_at_14.14.48.png) Choosing the option will add them to the People field. This works the right way (TM) in combination with adding existing users as members. ![Screen_Shot_2015-04-10_at_14.15.09](https://gitlab.com/gitlab-org/gitlab-ce/uploads/a618e5ec292d79578b16400dca6d4cfe/Screen_Shot_2015-04-10_at_14.15.09.png) The invited member will be shown in the members list as such. The access level can be changed, and the invite can be revoked by deleting the member. ![Screen_Shot_2015-04-10_at_14.15.19](https://gitlab.com/gitlab-org/gitlab-ce/uploads/3695b9a6778d367b275115747579b46e/Screen_Shot_2015-04-10_at_14.15.19.png) The invited user will receive an email with an "Accept invitation" link. ![Screen_Shot_2015-04-10_at_14.17.52](https://gitlab.com/gitlab-org/gitlab-ce/uploads/730121888153117d83c3cd0e4f5c90f6/Screen_Shot_2015-04-10_at_14.17.52.png) If they're not already logged in, clicking this link will redirect them to the sign in/up page with a helpful notice. ![Screen_Shot_2015-04-10_at_14.18.12](https://gitlab.com/gitlab-org/gitlab-ce/uploads/1a26a5fa13321e7ef77ed8b538c8557d/Screen_Shot_2015-04-10_at_14.18.12.png) Signing in or signing up will redirect them back to the invite detail page, where they can actually accept the invitation, which will update the member record in question to point to the user in question. ![Screen_Shot_2015-04-10_at_14.18.48](https://gitlab.com/gitlab-org/gitlab-ce/uploads/7ac33085463a99b8cfa6baa13bfa1235/Screen_Shot_2015-04-10_at_14.18.48.png) Accepting the invitation will redirect them to the group (or project) with an appropriate notice. ![Screen_Shot_2015-04-10_at_14.18.58](https://gitlab.com/gitlab-org/gitlab-ce/uploads/7bf02a2e3bea589a11df401c23e68648/Screen_Shot_2015-04-10_at_14.18.58.png) As currently, they will also receive this information by email. ![Screen_Shot_2015-04-10_at_14.24.00](https://gitlab.com/gitlab-org/gitlab-ce/uploads/b44a342068433a268c0a06ed9e791ffa/Screen_Shot_2015-04-10_at_14.24.00.png) At the same time, the person who initially invited the email address is sent a notification as well, so they know of the new member and to tell them what name the user signed up with. ![Screen_Shot_2015-04-10_at_14.19.07](https://gitlab.com/gitlab-org/gitlab-ce/uploads/b29fea128186f938ec76bd7dec016b83/Screen_Shot_2015-04-10_at_14.19.07.png) The member row on the Members page will now have been updated with the new user account. ![Screen_Shot_2015-04-10_at_14.19.23](https://gitlab.com/gitlab-org/gitlab-ce/uploads/cf503d3d1679614e03acec2e946a28c3/Screen_Shot_2015-04-10_at_14.19.23.png) See merge request !500
Diffstat (limited to 'spec')
-rw-r--r--spec/models/member_spec.rb148
-rw-r--r--spec/models/members_spec.rb20
-rw-r--r--spec/requests/api/repositories_spec.rb2
3 files changed, 148 insertions, 22 deletions
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb
new file mode 100644
index 00000000000..56d030a03b3
--- /dev/null
+++ b/spec/models/member_spec.rb
@@ -0,0 +1,148 @@
+require 'spec_helper'
+
+describe Member do
+ describe "Associations" do
+ it { is_expected.to belong_to(:user) }
+ end
+
+ describe "Validation" do
+ subject { Member.new(access_level: Member::GUEST) }
+
+ it { is_expected.to validate_presence_of(:user) }
+ it { is_expected.to validate_presence_of(:source) }
+ it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
+
+ context "when an invite email is provided" do
+ let(:member) { build(:project_member, invite_email: "user@example.com", user: nil) }
+
+ it "doesn't require a user" do
+ expect(member).to be_valid
+ end
+
+ it "requires a valid invite email" do
+ member.invite_email = "nope"
+
+ expect(member).not_to be_valid
+ end
+
+ it "requires a unique invite email scoped to this source" do
+ create(:project_member, source: member.source, invite_email: member.invite_email)
+
+ expect(member).not_to be_valid
+ end
+
+ it "is valid otherwise" do
+ expect(member).to be_valid
+ end
+ end
+
+ context "when an invite email is not provided" do
+ let(:member) { build(:project_member) }
+
+ it "requires a user" do
+ member.user = nil
+
+ expect(member).not_to be_valid
+ end
+
+ it "is valid otherwise" do
+ expect(member).to be_valid
+ end
+ end
+ end
+
+ describe "Delegate methods" do
+ it { is_expected.to respond_to(:user_name) }
+ it { is_expected.to respond_to(:user_email) }
+ end
+
+ describe ".add_user" do
+ let!(:user) { create(:user) }
+ let(:project) { create(:project) }
+
+ context "when called with a user id" do
+ it "adds the user as a member" do
+ Member.add_user(project.project_members, user.id, ProjectMember::MASTER)
+
+ expect(project.users).to include(user)
+ end
+ end
+
+ context "when called with a user object" do
+ it "adds the user as a member" do
+ Member.add_user(project.project_members, user, ProjectMember::MASTER)
+
+ expect(project.users).to include(user)
+ end
+ end
+
+ context "when called with a known user email" do
+ it "adds the user as a member" do
+ Member.add_user(project.project_members, user.email, ProjectMember::MASTER)
+
+ expect(project.users).to include(user)
+ end
+ end
+
+ context "when called with an unknown user email" do
+ it "adds a member invite" do
+ Member.add_user(project.project_members, "user@example.com", ProjectMember::MASTER)
+
+ expect(project.project_members.invite.pluck(:invite_email)).to include("user@example.com")
+ end
+ end
+ end
+
+ describe "#accept_invite!" do
+ let!(:member) { create(:project_member, invite_email: "user@example.com", user: nil) }
+ let(:user) { create(:user) }
+
+ it "resets the invite token" do
+ member.accept_invite!(user)
+
+ expect(member.invite_token).to be_nil
+ end
+
+ it "sets the invite accepted timestamp" do
+ member.accept_invite!(user)
+
+ expect(member.invite_accepted_at).not_to be_nil
+ end
+
+ it "sets the user" do
+ member.accept_invite!(user)
+
+ expect(member.user).to eq(user)
+ end
+
+ it "calls #after_accept_invite" do
+ expect(member).to receive(:after_accept_invite)
+
+ member.accept_invite!(user)
+ end
+ end
+
+ describe "#decline_invite!" do
+ let!(:member) { create(:project_member, invite_email: "user@example.com", user: nil) }
+
+ it "destroys the member" do
+ member.decline_invite!
+
+ expect(member).to be_destroyed
+ end
+
+ it "calls #after_decline_invite" do
+ expect(member).to receive(:after_decline_invite)
+
+ member.decline_invite!
+ end
+ end
+
+ describe "#generate_invite_token" do
+ let!(:member) { create(:project_member, invite_email: "user@example.com", user: nil) }
+
+ it "sets the invite token" do
+ expect { member.generate_invite_token }.to change { member.invite_token}
+ end
+ end
+end
diff --git a/spec/models/members_spec.rb b/spec/models/members_spec.rb
deleted file mode 100644
index dfd3f7feb6b..00000000000
--- a/spec/models/members_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe Member do
- describe "Associations" do
- it { is_expected.to belong_to(:user) }
- end
-
- describe "Validation" do
- subject { Member.new(access_level: Member::GUEST) }
-
- it { is_expected.to validate_presence_of(:user) }
- it { is_expected.to validate_presence_of(:source) }
- it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
- end
-
- describe "Delegate methods" do
- it { is_expected.to respond_to(:user_name) }
- it { is_expected.to respond_to(:user_email) }
- end
-end
diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb
index 729970153d1..09a79553f72 100644
--- a/spec/requests/api/repositories_spec.rb
+++ b/spec/requests/api/repositories_spec.rb
@@ -11,8 +11,6 @@ describe API::API, api: true do
let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) }
- before { project.team << [user, :reporter] }
-
describe "GET /projects/:id/repository/tags" do
it "should return an array of project tags" do
get api("/projects/#{project.id}/repository/tags", user)