Skip to content

Commit

Permalink
Fix tests that fail locally
Browse files Browse the repository at this point in the history
Believe the issue is that locally I have the grace window set, but in travis its set to 0. Hence tests that expect a registration that is expired to not renew work in travis, but not for me locally.

These changes should ensure we are consistent across all environments.
  • Loading branch information
Cruikshanks committed Nov 6, 2018
1 parent 87a8223 commit e306b3a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
26 changes: 18 additions & 8 deletions spec/models/waste_carriers_engine/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,22 @@ module WasteCarriersEngine
end

context "when the registration expiration date is today" do
let(:registration) { build(:registration, :is_active, expires_on: Date.today) }
context "and the 'grace' window is 3 days" do
before { allow(Rails.configuration).to receive(:grace_window).and_return(3) }

it "cannot be renewed" do
expect(registration.metaData).to_not allow_event :renew
let(:registration) { build(:registration, :is_active, expires_on: Date.today) }

it "cannot be renewed in 3 days time" do
Timecop.freeze(registration.expires_on + 3.days) do
expect(registration.metaData).to_not allow_event :renew
end
end
end
end

context "when the registration was created in BST and expires in GMT" do
before { allow(Rails.configuration).to receive(:grace_window).and_return(3) }

let(:registration) { create(:registration, :has_required_data, :is_active, expires_on: 3.years.from_now) }
# Registration is made during British Summer Time (BST)
# UK local time is 00:30 on 28 March 2017
Expand All @@ -485,16 +493,18 @@ module WasteCarriersEngine
expect(registration.metaData).to allow_event :renew
end

it "expires when it reaches the expiry date in the UK" do
it "expires when it reaches the expiry date plus 'grace window' in the UK" do
# Skip ahead to the start of the day a reg should expire
Timecop.freeze(Time.find_zone("London").local(2020, 3, 28, 0, 1))
Timecop.freeze(Time.find_zone("London").local(2020, 3, 31, 0, 1))
# GMT is now in effect (not BST)
# UK local time & UTC are both 00:01 on 28 March 2020
expect(registration.metaData).to_not allow_event :renew
end
end

context "when the registration was created in GMT and expires in BST" do
before { allow(Rails.configuration).to receive(:grace_window).and_return(3) }

let(:registration) { create(:registration, :has_required_data, :is_active, expires_on: 3.years.from_now) }
# Registration is made in during Greenwich Mean Time (GMT)
# UK local time & UTC are both 23:30 on 27 October 2015
Expand All @@ -520,9 +530,9 @@ module WasteCarriersEngine
expect(registration.metaData).to allow_event :renew
end

it "expires when it reaches the expiry date in the UK" do
# Skip ahead to the start of the day a reg should expire
Timecop.freeze(Time.find_zone("London").local(2018, 10, 27, 0, 1))
it "expires when it reaches the expiry date plus 'grace window' in the UK" do
# Skip ahead to the start of the day a reg should expire, plus the
Timecop.freeze(Time.find_zone("London").local(2018, 10, 30, 0, 1))
# BST is now in effect (not GMT)
# UK local time is 00:01 on 27 October 2018
# UTC time is 23:01 on 26 October 2018
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module WasteCarriersEngine
end

context "when the registration cannot be renewed" do
before(:each) { registration.update_attributes(expires_on: Date.today + Rails.configuration.grace_window) }
before(:each) { registration.update_attributes(expires_on: Date.today - Rails.configuration.grace_window) }

it "redirects to the unrenewable error page" do
get new_renewal_start_form_path(registration[:reg_identifier])
Expand Down Expand Up @@ -208,7 +208,7 @@ module WasteCarriersEngine
end

context "when the registration cannot be renewed" do
before(:each) { registration.update_attributes(expires_on: Date.today + Rails.configuration.grace_window) }
before(:each) { registration.update_attributes(expires_on: Date.today - Rails.configuration.grace_window) }

it "redirects to the unrenewable error page" do
get new_renewal_start_form_path(registration[:reg_identifier])
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/request_post_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
valid_params[:reg_identifier] = transient_registration.reg_identifier
# But the registration is now expired
registration = WasteCarriersEngine::Registration.where(reg_identifier: transient_registration.reg_identifier).first
registration.update_attributes(expires_on: Date.today + Rails.configuration.grace_window)
registration.update_attributes(expires_on: Date.today - Rails.configuration.grace_window)
end

it "does not update the transient registration, including workflow_state" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
before do
# Params are otherwise valid, but the registration is now expired
registration = WasteCarriersEngine::Registration.where(reg_identifier: transient_registration.reg_identifier).first
registration.update_attributes(expires_on: Date.today + Rails.configuration.grace_window)
registration.update_attributes(expires_on: Date.today - Rails.configuration.grace_window)
end

it "does not update the transient registration, including workflow_state" do
Expand Down

0 comments on commit e306b3a

Please sign in to comment.