Add sdg manager section to admin
Allow a user to become an sdg manager
This commit is contained in:
96
spec/system/admin/sdg/managers_spec.rb
Normal file
96
spec/system/admin/sdg/managers_spec.rb
Normal file
@@ -0,0 +1,96 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Admin SDG managers", :js do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:sdg_manager) { create(:sdg_manager) }
|
||||
|
||||
before do
|
||||
login_as(create(:administrator).user)
|
||||
visit admin_sdg_managers_path
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
expect(page).to have_content sdg_manager.name
|
||||
expect(page).to have_content sdg_manager.email
|
||||
expect(page).not_to have_content user.name
|
||||
end
|
||||
|
||||
scenario "Create SDG Manager" do
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content user.name
|
||||
|
||||
click_link "Add"
|
||||
|
||||
within("#sdg_managers") do
|
||||
expect(page).to have_content user.name
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Delete SDG Manager" do
|
||||
accept_confirm { click_link "Delete" }
|
||||
|
||||
within("#sdg_managers") do
|
||||
expect(page).not_to have_content sdg_manager.name
|
||||
end
|
||||
end
|
||||
|
||||
context "Search" do
|
||||
let(:user) { create(:user, username: "Taylor Swift", email: "taylor@swift.com") }
|
||||
let(:user2) { create(:user, username: "Stephanie Corneliussen", email: "steph@mrrobot.com") }
|
||||
let!(:sdg_manager1) { create(:sdg_manager, user: user) }
|
||||
let!(:sdg_manager2) { create(:sdg_manager, user: user2) }
|
||||
|
||||
before do
|
||||
visit admin_sdg_managers_path
|
||||
end
|
||||
|
||||
scenario "returns no results if search term is empty" do
|
||||
expect(page).to have_content(sdg_manager1.name)
|
||||
expect(page).to have_content(sdg_manager2.name)
|
||||
|
||||
fill_in "search", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("SDG managers")
|
||||
expect(page).to have_content("There are no users.")
|
||||
expect(page).not_to have_content(sdg_manager1.name)
|
||||
expect(page).not_to have_content(sdg_manager2.name)
|
||||
end
|
||||
|
||||
scenario "search by name" do
|
||||
expect(page).to have_content(sdg_manager1.name)
|
||||
expect(page).to have_content(sdg_manager2.name)
|
||||
|
||||
fill_in "search", with: "Taylor"
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("SDG managers")
|
||||
expect(page).to have_content(sdg_manager1.name)
|
||||
expect(page).not_to have_content(sdg_manager2.name)
|
||||
end
|
||||
|
||||
scenario "search by email" do
|
||||
expect(page).to have_content(sdg_manager1.email)
|
||||
expect(page).to have_content(sdg_manager2.email)
|
||||
|
||||
fill_in "search", with: sdg_manager2.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("SDG managers")
|
||||
expect(page).to have_content(sdg_manager2.email)
|
||||
expect(page).not_to have_content(sdg_manager1.email)
|
||||
end
|
||||
|
||||
scenario "Delete after searching" do
|
||||
fill_in "Search user by name or email", with: sdg_manager2.email
|
||||
click_button "Search"
|
||||
|
||||
accept_confirm { click_link "Delete" }
|
||||
|
||||
expect(page).to have_content(sdg_manager1.email)
|
||||
expect(page).not_to have_content(sdg_manager2.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,6 +42,16 @@ describe "Admin" do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as SDG manager is not authorized", :js do
|
||||
create(:sdg_manager, user: user)
|
||||
login_as(user)
|
||||
visit admin_root_path
|
||||
|
||||
expect(page).not_to have_current_path(admin_root_path)
|
||||
expect(page).to have_current_path(root_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as poll officer is not authorized" do
|
||||
login_as(create(:poll_officer).user)
|
||||
visit admin_root_path
|
||||
@@ -59,12 +69,15 @@ describe "Admin" do
|
||||
end
|
||||
|
||||
scenario "Admin access links", :admin do
|
||||
Setting["feature.sdg"] = true
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Administration")
|
||||
expect(page).to have_link("Moderation")
|
||||
expect(page).to have_link("Valuation")
|
||||
expect(page).to have_link("Management")
|
||||
expect(page).to have_link("SDG content")
|
||||
end
|
||||
|
||||
scenario "Admin dashboard", :admin do
|
||||
|
||||
@@ -43,6 +43,21 @@ describe "Moderation" do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as SDG manager is not authorized", :js do
|
||||
create(:sdg_manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
expect(page).to have_current_path(root_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as poll officer is not authorized" do
|
||||
create(:poll_officer, user: user)
|
||||
|
||||
|
||||
@@ -42,6 +42,20 @@ describe "Poll Officing" do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as SDG manager is not authorized", :js do
|
||||
create(:sdg_manager, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Polling officers")
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
expect(page).not_to have_current_path(officing_root_path)
|
||||
expect(page).to have_current_path(root_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as a valuator is not authorized" do
|
||||
create(:valuator, user: user)
|
||||
login_as(user)
|
||||
|
||||
@@ -42,6 +42,19 @@ describe "Valuation" do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as SDG manager is not authorized" do
|
||||
create(:sdg_manager, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
expect(page).to have_current_path(root_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as poll officer is not authorized" do
|
||||
create(:poll_officer, user: user)
|
||||
login_as(user)
|
||||
|
||||
Reference in New Issue
Block a user