Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor spec configuration option assignment #8152

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions spec/controllers/admin_public_body_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -753,21 +753,18 @@

describe "when administering public bodies and paying attention to authentication" do
before do
config = MySociety::Config.load_default
config['SKIP_ADMIN_AUTH'] = false
allow(AlaveteliConfiguration).to receive(:skip_admin_auth).
and_return(false)
basic_auth_login @request
end

after do
config = MySociety::Config.load_default
config['SKIP_ADMIN_AUTH'] = true
end

def setup_emergency_credentials(username, password)
config = MySociety::Config.load_default
config['SKIP_ADMIN_AUTH'] = false
config['ADMIN_USERNAME'] = username
config['ADMIN_PASSWORD'] = password
allow(AlaveteliConfiguration).to receive(:skip_admin_auth).
and_return(false)
allow(AlaveteliConfiguration).to receive(:admin_username).
and_return(username)
allow(AlaveteliConfiguration).to receive(:admin_password).
and_return(password)
@request.env["HTTP_AUTHORIZATION"] = ""
end

Expand All @@ -782,8 +779,8 @@ def setup_emergency_credentials(username, password)
end

it "skips admin authorisation when SKIP_ADMIN_AUTH set" do
config = MySociety::Config.load_default
config['SKIP_ADMIN_AUTH'] = true
allow(AlaveteliConfiguration).to receive(:skip_admin_auth).
and_return(true)
@request.env["HTTP_AUTHORIZATION"] = ""
n = PublicBody.count
post :destroy, params: { id: public_bodies(:forlorn_public_body).id }
Expand Down Expand Up @@ -871,8 +868,8 @@ def setup_emergency_credentials(username, password)
end

it 'returns the REMOTE_USER value from the request environment when skipping admin auth' do
config = MySociety::Config.load_default
config['SKIP_ADMIN_AUTH'] = true
allow(AlaveteliConfiguration).to receive(:skip_admin_auth).
and_return(true)
@request.env["HTTP_AUTHORIZATION"] = ""
@request.env["REMOTE_USER"] = "i_am_admin"
post :show, params: { id: public_bodies(:humpadink_public_body).id }
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/general_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
end

it "should render the front page with default language and ignore the browser setting" do
config = MySociety::Config.load_default
config['USE_DEFAULT_BROWSER_LANGUAGE'] = false
allow(AlaveteliConfiguration).to receive(:use_default_browser_language).
and_return(false)
accept_language = "en-GB,en-US;q=0.8,en;q=0.6"
request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
with_default_locale("es") do
Expand All @@ -126,8 +126,8 @@
end

it "should render the front page with browser-selected language when there's no default set" do
config = MySociety::Config.load_default
config['USE_DEFAULT_BROWSER_LANGUAGE'] = true
allow(AlaveteliConfiguration).to receive(:use_default_browser_language).
and_return(true)
accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6"
request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
get :frontpage
Expand Down
7 changes: 4 additions & 3 deletions spec/integration/statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

RSpec.describe "Site statistics" do
before :each do
config = MySociety::Config.load_default
config['MINIMUM_REQUESTS_FOR_STATISTICS'] = 1
config['PUBLIC_BODY_STATISTICS_PAGE'] = true
allow(AlaveteliConfiguration).to receive(:minimum_requests_for_statistics).
and_return(1)
allow(AlaveteliConfiguration).to receive(:public_body_statistics_page).
and_return(true)
end

describe "for public bodies" do
Expand Down
6 changes: 2 additions & 4 deletions spec/lib/alaveteli_text_masker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@

context 'applying masks to PDF' do
def pdf_replacement_test(use_ghostscript_compression)
config = MySociety::Config.load_default
previous = config['USE_GHOSTSCRIPT_COMPRESSION']
config['USE_GHOSTSCRIPT_COMPRESSION'] = use_ghostscript_compression
allow(AlaveteliConfiguration).to receive(:use_ghostscript_compression).
and_return(use_ghostscript_compression)
orig_pdf = load_file_fixture('tfl.pdf')
pdf = orig_pdf.dup

Expand All @@ -100,7 +99,6 @@ def pdf_replacement_test(use_ghostscript_compression)
masked_text = MailHandler.get_attachment_text_one_file('application/pdf', result)
expect(masked_text).not_to match(/foi@tfl.gov.uk/)
expect(masked_text).to match(/xxx@xxx.xxx.xx/)
config['USE_GHOSTSCRIPT_COMPRESSION'] = previous
end

it "replaces everything in PDF files using pdftk" do
Expand Down
Loading