summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-07-21 22:09:02 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-07-22 00:01:17 -0400
commita2ecfdc5859c1703dbbad6dde888f7a0eb5817c8 (patch)
tree6141d33a0c24cbf3bf6fdb5321bf29dfd6b27e8f /spec
parent1fee24a36143e8057d495e8a7e0f2d4b93d83f2a (diff)
downloadgitlab-ce-a2ecfdc5859c1703dbbad6dde888f7a0eb5817c8.tar.gz
Move access-related matchers to their own module
Diffstat (limited to 'spec')
-rw-r--r--spec/features/security/dashboard_access_spec.rb2
-rw-r--r--spec/features/security/group/group_access_spec.rb2
-rw-r--r--spec/features/security/group/internal_group_access_spec.rb2
-rw-r--r--spec/features/security/group/mixed_group_access_spec.rb2
-rw-r--r--spec/features/security/group/public_group_access_spec.rb2
-rw-r--r--spec/features/security/profile_access_spec.rb2
-rw-r--r--spec/features/security/project/internal_access_spec.rb2
-rw-r--r--spec/features/security/project/private_access_spec.rb2
-rw-r--r--spec/features/security/project/public_access_spec.rb3
-rw-r--r--spec/support/matchers.rb34
-rw-r--r--spec/support/matchers/access_matchers.rb54
11 files changed, 72 insertions, 35 deletions
diff --git a/spec/features/security/dashboard_access_spec.rb b/spec/features/security/dashboard_access_spec.rb
index 67238e3ab76..c38cddbb904 100644
--- a/spec/features/security/dashboard_access_spec.rb
+++ b/spec/features/security/dashboard_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Dashboard access", feature: true do
+ include AccessMatchers
+
describe "GET /dashboard" do
subject { dashboard_path }
diff --git a/spec/features/security/group/group_access_spec.rb b/spec/features/security/group/group_access_spec.rb
index 63793149459..e42b7b8d8a0 100644
--- a/spec/features/security/group/group_access_spec.rb
+++ b/spec/features/security/group/group_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Group access", feature: true do
+ include AccessMatchers
+
describe "GET /projects/new" do
it { expect(new_group_path).to be_allowed_for :admin }
it { expect(new_group_path).to be_allowed_for :user }
diff --git a/spec/features/security/group/internal_group_access_spec.rb b/spec/features/security/group/internal_group_access_spec.rb
index d17a7412e43..28673a3ab2f 100644
--- a/spec/features/security/group/internal_group_access_spec.rb
+++ b/spec/features/security/group/internal_group_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Group with internal project access", feature: true do
+ include AccessMatchers
+
describe "Group" do
let(:group) { create(:group) }
diff --git a/spec/features/security/group/mixed_group_access_spec.rb b/spec/features/security/group/mixed_group_access_spec.rb
index b3db7b5dea4..f7f0213737e 100644
--- a/spec/features/security/group/mixed_group_access_spec.rb
+++ b/spec/features/security/group/mixed_group_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Group access", feature: true do
+ include AccessMatchers
+
describe "Group" do
let(:group) { create(:group) }
diff --git a/spec/features/security/group/public_group_access_spec.rb b/spec/features/security/group/public_group_access_spec.rb
index c16f0c0d1e1..03cafad8d7e 100644
--- a/spec/features/security/group/public_group_access_spec.rb
+++ b/spec/features/security/group/public_group_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Group with public project access", feature: true do
+ include AccessMatchers
+
describe "Group" do
let(:group) { create(:group) }
diff --git a/spec/features/security/profile_access_spec.rb b/spec/features/security/profile_access_spec.rb
index bcabc2d53ac..847566d0de9 100644
--- a/spec/features/security/profile_access_spec.rb
+++ b/spec/features/security/profile_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Profile access", feature: true do
+ include AccessMatchers
+
before do
@u1 = create(:user)
end
diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb
index 4649e58cb1a..57563add74c 100644
--- a/spec/features/security/project/internal_access_spec.rb
+++ b/spec/features/security/project/internal_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Internal Project Access", feature: true do
+ include AccessMatchers
+
let(:project) { create(:project, :internal) }
let(:master) { create(:user) }
diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb
index 2866bf0355b..a1e111c6cab 100644
--- a/spec/features/security/project/private_access_spec.rb
+++ b/spec/features/security/project/private_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Private Project Access", feature: true do
+ include AccessMatchers
+
let(:project) { create(:project) }
let(:master) { create(:user) }
diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb
index 554c96bcdc5..655d2c8b7d9 100644
--- a/spec/features/security/project/public_access_spec.rb
+++ b/spec/features/security/project/public_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Public Project Access", feature: true do
+ include AccessMatchers
+
let(:project) { create(:project) }
let(:master) { create(:user) }
@@ -17,7 +19,6 @@ describe "Public Project Access", feature: true do
# readonly
project.team << [reporter, :reporter]
-
end
describe "Project should be public" do
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
index 87a034cca3b..d9b27ab08d8 100644
--- a/spec/support/matchers.rb
+++ b/spec/support/matchers.rb
@@ -1,37 +1,3 @@
-def emulate_user(user)
- user = case user
- when :user then create(:user)
- when :visitor then nil
- when :admin then create(:admin)
- else user
- end
- login_with(user) if user
-end
-
-RSpec::Matchers.define :be_allowed_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code != 404 && current_path != new_user_session_path
- end
-end
-
-RSpec::Matchers.define :be_denied_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code == 404 || current_path == new_user_session_path
- end
-end
-
-RSpec::Matchers.define :be_not_found_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code == 404
- end
-end
-
RSpec::Matchers.define :include_module do |expected|
match do
described_class.included_modules.include?(expected)
diff --git a/spec/support/matchers/access_matchers.rb b/spec/support/matchers/access_matchers.rb
new file mode 100644
index 00000000000..558e8b1612f
--- /dev/null
+++ b/spec/support/matchers/access_matchers.rb
@@ -0,0 +1,54 @@
+# AccessMatchers
+#
+# The custom matchers contained in this module are used to test a user's access
+# to a URL by emulating a specific user or type of user account, visiting the
+# URL, and then checking the response status code and resulting path.
+module AccessMatchers
+ extend RSpec::Matchers::DSL
+ include Warden::Test::Helpers
+
+ def emulate_user(user)
+ case user
+ when :user
+ login_as(create(:user))
+ when :visitor
+ logout
+ when :admin
+ login_as(create(:admin))
+ when User
+ login_as(user)
+ else
+ raise ArgumentError, "cannot emulate user #{user}"
+ end
+ end
+
+ def description_for(user, type)
+ if user.kind_of?(User)
+ # User#inspect displays too much information for RSpec's description
+ # messages
+ "be #{type} for supplied User"
+ else
+ "be #{type} for #{user}"
+ end
+ end
+
+ matcher :be_allowed_for do |user|
+ match do |url|
+ emulate_user(user)
+ visit url
+ status_code != 404 && current_path != new_user_session_path
+ end
+
+ description { description_for(user, 'allowed') }
+ end
+
+ matcher :be_denied_for do |user|
+ match do |url|
+ emulate_user(user)
+ visit url
+ status_code == 404 || current_path == new_user_session_path
+ end
+
+ description { description_for(user, 'denied') }
+ end
+end