-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Section 7.2.2: Lock down specific projects controller actions for adm…
…ins only
- Loading branch information
Ryan Bigg
committed
Nov 16, 2014
1 parent
ae9e195
commit 0a24688
Showing
6 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ def title(*parts) | |
end | ||
end | ||
end | ||
|
||
def admins_only(&block) | ||
block.call if current_user.try(:admin?) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "rails_helper" | ||
|
||
feature "hidden links" do | ||
let(:user) { FactoryGirl.create(:user) } | ||
let(:admin) { FactoryGirl.create(:admin_user) } | ||
let(:project) { FactoryGirl.create(:project) } | ||
|
||
context "anonymous users" do | ||
scenario "cannot see the New Project link" do | ||
visit "/" | ||
assert_no_link_for "New Project" | ||
end | ||
|
||
scenario "cannot see the Edit Project link" do | ||
visit project_path(project) | ||
assert_no_link_for "Edit Project" | ||
end | ||
|
||
scenario "cannot see the Delete Project link" do | ||
visit project_path(project) | ||
assert_no_link_for "Delete Project" | ||
end | ||
end | ||
|
||
context "regular users" do | ||
before { login_as(user) } | ||
scenario "cannot see the New Project link" do | ||
visit "/" | ||
assert_no_link_for "New Project" | ||
end | ||
|
||
scenario "cannot see the Edit Project link" do | ||
visit project_path(project) | ||
assert_no_link_for "Edit Project" | ||
end | ||
|
||
scenario "cannot see the Delete Project link" do | ||
visit project_path(project) | ||
assert_no_link_for "Delete Project" | ||
end | ||
end | ||
|
||
context "admin users" do | ||
before { login_as(admin) } | ||
scenario "can see the New Project link" do | ||
visit "/" | ||
assert_link_for "New Project" | ||
end | ||
|
||
scenario "can see the Edit Project link" do | ||
visit project_path(project) | ||
assert_link_for "Edit Project" | ||
end | ||
|
||
scenario "can see the Delete Project link" do | ||
visit project_path(project) | ||
assert_link_for "Delete Project" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module CapybaraHelpers | ||
def assert_no_link_for(text) | ||
expect(page).to_not(have_css("a", :text => text), | ||
"Expected not to see the #{text.inspect} link, but did.") | ||
end | ||
|
||
def assert_link_for(text) | ||
expect(page).to(have_css("a", :text => text), | ||
"Expected to see the #{text.inspect} link, but did not.") | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include CapybaraHelpers, :type => :feature | ||
end |