summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-23 17:32:39 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-06-14 23:06:17 -0400
commit7b7ba11218dab0a75b5715ff697ca020bb12f5d8 (patch)
tree3a66f7fe6d923b21a9c5a618c8ce926b808ea305
parent59604f8a421aa4b1622e90baef78b805abba2538 (diff)
downloadgitlab-ce-7b7ba11218dab0a75b5715ff697ca020bb12f5d8.tar.gz
Update spec/features/security specs
-rw-r--r--spec/features/security/profile_access_spec.rb2
-rw-r--r--spec/support/matchers.rb67
2 files changed, 26 insertions, 43 deletions
diff --git a/spec/features/security/profile_access_spec.rb b/spec/features/security/profile_access_spec.rb
index 2512a9c0e3d..dfccc355218 100644
--- a/spec/features/security/profile_access_spec.rb
+++ b/spec/features/security/profile_access_spec.rb
@@ -6,7 +6,7 @@ describe "Profile access", feature: true do
end
describe "GET /login" do
- it { expect(new_user_session_path).not_to be_404_for :visitor }
+ it { expect(new_user_session_path).not_to be_not_found_for :visitor }
end
describe "GET /profile/keys" do
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
index 35d0bae7085..e5ebc6e7ec8 100644
--- a/spec/support/matchers.rb
+++ b/spec/support/matchers.rb
@@ -1,30 +1,43 @@
RSpec::Matchers.define :be_valid_commit do
match do |actual|
- actual != nil
- actual.id == ValidCommit::ID
- actual.message == ValidCommit::MESSAGE
- actual.author_name == ValidCommit::AUTHOR_FULL_NAME
+ actual &&
+ actual.id == ValidCommit::ID &&
+ actual.message == ValidCommit::MESSAGE &&
+ actual.author_name == ValidCommit::AUTHOR_FULL_NAME
end
end
+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|
- include UrlAccess
- url_allowed?(user, 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|
- include UrlAccess
- url_denied?(user, url)
+ emulate_user(user)
+ visit url
+ status_code == 404 || current_path == new_user_session_path
end
end
-RSpec::Matchers.define :be_404_for do |user|
+RSpec::Matchers.define :be_not_found_for do |user|
match do |url|
- include UrlAccess
- url_404?(user, url)
+ emulate_user(user)
+ visit url
+ status_code == 404
end
end
@@ -34,7 +47,7 @@ RSpec::Matchers.define :include_module do |expected|
end
description do
- "include the #{expected} module"
+ "includes the #{expected} module"
end
failure_message do
@@ -42,36 +55,6 @@ RSpec::Matchers.define :include_module do |expected|
end
end
-module UrlAccess
- def url_allowed?(user, url)
- emulate_user(user)
- visit url
- (status_code != 404 && current_path != new_user_session_path)
- end
-
- def url_denied?(user, url)
- emulate_user(user)
- visit url
- (status_code == 404 || current_path == new_user_session_path)
- end
-
- def url_404?(user, url)
- emulate_user(user)
- visit url
- status_code == 404
- end
-
- 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
-end
-
# Extend shoulda-matchers
module Shoulda::Matchers::ActiveModel
class ValidateLengthOfMatcher