Browse Source

Remove redundant test, lint

pull/557/head
Kat 3 years ago
parent
commit
13915260de
  1. 4
      app/controllers/helpers/filter.rb
  2. 2
      app/controllers/organisations_controller.rb
  3. 2
      app/models/user.rb
  4. 2
      spec/features/organisation_spec.rb
  5. 44
      spec/features/user_spec.rb

4
app/controllers/helpers/filter.rb

@ -13,9 +13,9 @@ module Helpers::Filter
current_user.support? ? logs.all.includes(:owning_organisation, :managing_organisation) : logs
end
def set_session_filters(specific_org = false)
def set_session_filters(specific_org: false)
new_filters = session[:case_logs_filters].present? ? JSON.parse(session[:case_logs_filters]) : {}
current_user.case_logs_filters(specific_org).each { |filter| new_filters[filter] = params[filter] if params[filter].present? }
current_user.case_logs_filters(specific_org:).each { |filter| new_filters[filter] = params[filter] if params[filter].present? }
new_filters = new_filters.except("organisation") if params["organisation_select"] == "all"
session[:case_logs_filters] = new_filters.to_json

2
app/controllers/organisations_controller.rb

@ -45,7 +45,7 @@ class OrganisationsController < ApplicationController
end
def logs
set_session_filters(true)
set_session_filters(specific_org: true)
if current_user.support?
organisation_logs = CaseLog.all.where(owning_organisation_id: @organisation.id)

2
app/models/user.rb

@ -108,7 +108,7 @@ class User < ApplicationRecord
ROLES.except(:support)
end
def case_logs_filters(specific_org = false)
def case_logs_filters(specific_org: false)
if support? && !specific_org
%w[status years user organisation]
else

2
spec/features/organisation_spec.rb

@ -106,7 +106,7 @@ RSpec.describe "User Features" do
end
check("years-2021-field")
click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/logs?years[]=&years[]=2021&status[]=&user=all&organisation_select=all&organisation=")
expect(page).to have_current_path("/organisations/#{org_id}/logs?years[]=&years[]=2021&status[]=&user=all")
expect(page).not_to have_link first_log.id.to_s, href: "/logs/#{first_log.id}"
end
end

44
spec/features/user_spec.rb

@ -549,49 +549,5 @@ RSpec.describe "User Features" do
end
end
end
context "when the user is logged in as a support user" do
let!(:support_user) { FactoryBot.create(:user, :support) }
let!(:test_org_1) { FactoryBot.create(:organisation, name: "Test1") }
let!(:test_org_2) { FactoryBot.create(:organisation, name: "Test2") }
let!(:test_org_3) { FactoryBot.create(:organisation, name: "Test3") }
let!(:test_org_4) { FactoryBot.create(:organisation, name: "Test4") }
let!(:test_org_5) { FactoryBot.create(:organisation, name: "Test5") }
let!(:case_log) { FactoryBot.create(:case_log, owning_organisation_id: test_org_3.id, managing_organisation_id: test_org_3.id) }
before do
FactoryBot.create_list(:organisation, 50)
allow(SecureRandom).to receive(:random_number).and_return(otp)
visit("/logs")
fill_in("user[email]", with: support_user.email)
fill_in("user[password]", with: "pAssword1")
click_button("Sign in")
fill_in("code", with: otp)
click_button("Submit")
end
it "they should see organisations instead of your organisations in the navigation bar" do
visit("/organisations")
expect(page).to have_selector("h1", text: "Organisations")
end
it "they should see all organisations listed in the organisations page, with pagination" do
visit("/organisations")
expect(page).to have_css("#all-organisations-table")
expect(page).to have_css(".app-pagination__link")
end
context "when the support user is on the organisations list page" do
it "they can click on an organisation to see their logs page" do
visit("/organisations")
click_link("Test3")
expect(page).to have_content("1 total logs")
expect(page).to have_selector("a", text: case_log.id.to_s)
visit("/organisations")
click_link("Test5")
expect(page).not_to have_selector("a", text: case_log.id.to_s)
end
end
end
end
end

Loading…
Cancel
Save