From 9f87b34f667582c0df82b0a79b07ad2a0c1931bb Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Mon, 26 Jun 2017 16:23:46 +0200
Subject: [PATCH] Combine group leave feature specs in one file

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 .../last_owner_cannot_leave_group_spec.rb     | 16 -----
 .../groups/members/leave_group_spec.rb        | 62 +++++++++++++++++++
 .../members/member_leaves_group_spec.rb       | 21 -------
 3 files changed, 62 insertions(+), 37 deletions(-)
 delete mode 100644 spec/features/groups/members/last_owner_cannot_leave_group_spec.rb
 create mode 100644 spec/features/groups/members/leave_group_spec.rb
 delete mode 100644 spec/features/groups/members/member_leaves_group_spec.rb

diff --git a/spec/features/groups/members/last_owner_cannot_leave_group_spec.rb b/spec/features/groups/members/last_owner_cannot_leave_group_spec.rb
deleted file mode 100644
index 5af94e4069b..00000000000
--- a/spec/features/groups/members/last_owner_cannot_leave_group_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require 'spec_helper'
-
-feature 'Groups > Members > Last owner cannot leave group', feature: true do
-  let(:owner) { create(:user) }
-  let(:group) { create(:group) }
-
-  background do
-    group.add_owner(owner)
-    gitlab_sign_in(owner)
-    visit group_path(group)
-  end
-
-  scenario 'user does not see a "Leave group" link' do
-    expect(page).not_to have_content 'Leave group'
-  end
-end
diff --git a/spec/features/groups/members/leave_group_spec.rb b/spec/features/groups/members/leave_group_spec.rb
new file mode 100644
index 00000000000..5b812891281
--- /dev/null
+++ b/spec/features/groups/members/leave_group_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper'
+
+feature 'Groups > Members > Leave group', feature: true do
+  let(:user) { create(:user) }
+  let(:other_user) { create(:user) }
+  let(:group) { create(:group) }
+
+  background do
+    gitlab_sign_in(user)
+  end
+
+  scenario 'guest leaves the group' do
+    group.add_guest(user)
+    group.add_owner(other_user)
+
+    visit group_path(group)
+    click_link 'Leave group'
+
+    expect(current_path).to eq(dashboard_groups_path)
+    expect(page).to have_content left_group_message(group)
+    expect(group.members).not_to include(user)
+  end
+
+  scenario 'guest leaves the group as last member' do
+    group.add_guest(user)
+
+    visit group_path(group)
+    click_link 'Leave group'
+
+    expect(current_path).to eq(dashboard_groups_path)
+    expect(page).to have_content left_group_message(group)
+    expect(group.members).not_to include(user)
+  end
+
+  scenario 'owner leaves the group if they is not the last owner' do
+    group.add_owner(user)
+    group.add_owner(other_user)
+
+    visit group_path(group)
+    click_link 'Leave group'
+
+    expect(current_path).to eq(dashboard_groups_path)
+    expect(page).to have_content left_group_message(group)
+    expect(group.members).not_to include(user)
+  end
+
+  scenario 'owner can not leave the group if they is a last owner' do
+    group.add_owner(user)
+
+    visit group_path(group)
+
+    expect(page).not_to have_content 'Leave group'
+
+    visit group_group_members_path(group)
+
+    expect(find(:css, '.project-members-page li', text: user.name)).not_to have_selector(:css, 'a.btn-remove')
+  end
+
+  def left_group_message(group)
+    "You left the \"#{group.name}\""
+  end
+end
diff --git a/spec/features/groups/members/member_leaves_group_spec.rb b/spec/features/groups/members/member_leaves_group_spec.rb
deleted file mode 100644
index 40f3b166e74..00000000000
--- a/spec/features/groups/members/member_leaves_group_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'spec_helper'
-
-feature 'Groups > Members > Member leaves group', feature: true do
-  let(:user) { create(:user) }
-  let(:owner) { create(:user) }
-  let(:group) { create(:group, :public) }
-
-  background do
-    group.add_owner(owner)
-    group.add_developer(user)
-    gitlab_sign_in(user)
-    visit group_path(group)
-  end
-
-  scenario 'user leaves group' do
-    click_link 'Leave group'
-
-    expect(current_path).to eq(dashboard_groups_path)
-    expect(group.users.exists?(user.id)).to be_falsey
-  end
-end
-- 
2.30.9