gitlabhq/spec/support/matchers.rb

60 lines
1.2 KiB
Ruby
Raw Normal View History

2011-10-08 23:36:38 +02:00
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
end
end
RSpec::Matchers.define :be_allowed_for do |user|
match do |url|
include UrlAccess
url_allowed?(user, url)
end
end
RSpec::Matchers.define :be_denied_for do |user|
match do |url|
include UrlAccess
url_denied?(user, url)
end
end
2011-10-17 12:39:03 +02:00
RSpec::Matchers.define :be_404_for do |user|
match do |url|
include UrlAccess
url_404?(user, url)
end
end
2011-10-08 23:36:38 +02:00
module UrlAccess
def url_allowed?(user, url)
emulate_user(user)
visit url
2011-10-17 12:39:03 +02:00
(page.status_code != 404 && current_path != new_user_session_path)
2011-10-08 23:36:38 +02:00
end
def url_denied?(user, url)
emulate_user(user)
visit url
2011-10-17 12:39:03 +02:00
(page.status_code == 404 || current_path == new_user_session_path)
end
def url_404?(user, url)
emulate_user(user)
visit url
page.status_code == 404
2011-10-08 23:36:38 +02:00
end
def emulate_user(user)
user = case user
when :user then Factory(:user)
when :visitor then nil
when :admin then Factory(:admin)
else user
end
login_with(user) if user
end
end