Browse Source

review changes

pull/683/head
Dushan Despotovic 3 years ago
parent
commit
38f384ae8b
  1. 4
      config/initializers/feature_toggle.rb
  2. 14
      spec/models/case_log_spec.rb
  3. 6
      spec/models/validations/date_validations_spec.rb
  4. 16
      spec/requests/case_logs_controller_spec.rb
  5. 23
      spec/requests/form_controller_spec.rb

4
config/initializers/feature_toggle.rb

@ -6,8 +6,6 @@ class FeatureToggle
end end
def self.startdate_two_week_validation_enabled? def self.startdate_two_week_validation_enabled?
return true if Rails.env.production? true
false
end end
end end

14
spec/models/case_log_spec.rb

@ -1981,6 +1981,14 @@ RSpec.describe CaseLog do
end end
context "when filtering by year" do context "when filtering by year" do
before do
Timecop.freeze(Time.utc(2021, 5, 3))
end
after do
Timecop.unfreeze
end
it "allows filtering on a single year" do it "allows filtering on a single year" do
expect(described_class.filter_by_years(%w[2021]).count).to eq(2) expect(described_class.filter_by_years(%w[2021]).count).to eq(2)
end end
@ -1994,8 +2002,10 @@ RSpec.describe CaseLog do
end end
it "filters based on date boundaries correctly" do it "filters based on date boundaries correctly" do
case_log_1.update!(startdate: Time.zone.local(2022, 4, 1)) case_log_1.startdate = Time.zone.local(2022, 4, 1)
case_log_2.update!(startdate: Time.zone.local(2022, 3, 31)) case_log_1.save!(validate: false)
case_log_2.startdate = Time.zone.local(2022, 3, 31)
case_log_2.save!(validate: false)
expect(described_class.filter_by_years(%w[2021]).count).to eq(1) expect(described_class.filter_by_years(%w[2021]).count).to eq(1)
expect(described_class.filter_by_years(%w[2022]).count).to eq(2) expect(described_class.filter_by_years(%w[2022]).count).to eq(2)

6
spec/models/validations/date_validations_spec.rb

@ -55,11 +55,6 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
end end
context "when in the production environment" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "validates that the tenancy start date is not later than 14 days from the current date" do it "validates that the tenancy start date is not later than 14 days from the current date" do
record.startdate = Time.zone.today + 15.days record.startdate = Time.zone.today + 15.days
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
@ -73,7 +68,6 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
end end
end end
end
describe "major repairs date" do describe "major repairs date" do
it "cannot be after the tenancy start date" do it "cannot be after the tenancy start date" do

16
spec/requests/case_logs_controller_spec.rb

@ -249,12 +249,14 @@ RSpec.describe CaseLogsController, type: :request do
managing_organisation: organisation) managing_organisation: organisation)
end end
let!(:case_log_2022) do let!(:case_log_2022) do
FactoryBot.create(:case_log, :completed, case_log = FactoryBot.build(:case_log, :completed,
owning_organisation: organisation, owning_organisation: organisation,
mrcdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2022, 2, 1),
startdate: Time.zone.local(2022, 12, 1), startdate: Time.zone.local(2022, 12, 1),
tenancy: 6, tenancy: 6,
managing_organisation: organisation) managing_organisation: organisation)
case_log.save!(validate: false)
case_log
end end
it "shows case logs for multiple selected years" do it "shows case logs for multiple selected years" do
@ -279,23 +281,27 @@ RSpec.describe CaseLogsController, type: :request do
created_by: user) created_by: user)
end end
let!(:case_log_2022) do let!(:case_log_2022) do
FactoryBot.create(:case_log, :completed, case_log = FactoryBot.build(:case_log, :completed,
owning_organisation: organisation, owning_organisation: organisation,
mrcdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2022, 2, 1),
startdate: Time.zone.local(2022, 12, 1), startdate: Time.zone.local(2022, 12, 1),
tenancy: 6, tenancy: 6,
managing_organisation: organisation, managing_organisation: organisation
created_by: user) created_by: user)
case_log.save!(validate: false)
case_log
end end
let!(:case_log_2022_in_progress) do let!(:case_log_2022_in_progress) do
FactoryBot.create(:case_log, :in_progress, case_log = FactoryBot.build(:case_log, :in_progress,
owning_organisation: organisation, owning_organisation: organisation,
mrcdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2022, 2, 1),
startdate: Time.zone.local(2022, 12, 1), startdate: Time.zone.local(2022, 12, 1),
tenancy: 6, tenancy: 6,
managing_organisation: organisation, managing_organisation: organisation,
tenancycode: nil, tenancycode: nil
created_by: user) created_by: user)
case_log.save!(validate: false)
case_log
end end
it "shows case logs for multiple selected statuses and years" do it "shows case logs for multiple selected statuses and years" do

23
spec/requests/form_controller_spec.rb

@ -37,14 +37,6 @@ RSpec.describe FormController, type: :request do
managing_organisation: organisation, managing_organisation: organisation,
) )
end end
let(:case_log_2022) do
FactoryBot.create(
:case_log,
startdate: Time.zone.local(2022, 12, 1),
owning_organisation: organisation,
managing_organisation: organisation,
)
end
let(:headers) { { "Accept" => "text/html" } } let(:headers) { { "Accept" => "text/html" } }
context "when a user is not signed in" do context "when a user is not signed in" do
@ -112,10 +104,25 @@ RSpec.describe FormController, type: :request do
end end
context "when no other sections are enabled" do context "when no other sections are enabled" do
let(:case_log_2022) do
FactoryBot.create(
:case_log,
startdate: Time.zone.local(2022, 12, 1),
owning_organisation: organisation,
managing_organisation: organisation,
)
end
let(:headers) { { "Accept" => "text/html" } }
before do before do
Timecop.freeze(Time.zone.local(2022, 12, 1))
get "/logs/#{case_log_2022.id}/setup/check-answers", headers: headers, params: {} get "/logs/#{case_log_2022.id}/setup/check-answers", headers: headers, params: {}
end end
after do
Timecop.unfreeze
end
it "does not show Save and go to next incomplete section button" do it "does not show Save and go to next incomplete section button" do
expect(page).not_to have_content("Save and go to next incomplete section") expect(page).not_to have_content("Save and go to next incomplete section")
end end

Loading…
Cancel
Save