Browse Source
* write helper method to support having the correct rent period checkboxes checked * update new and create in organisations controller and view to enable creation of relevant organisation rent periods write tests for this * small changes to models * enable editing rent period in the UI display change button on org details page display rent periods question on edit page * enable updating org rent periods update logic in #update related tests * alter redirect after support user creates an organisation * adjust various UI elements: ordering of rows, copy changes, label size and associated tests * rework the #rent_period_labels method to return All under the correct conditions, rework tests related to that. + fix assorted tests that were either flakey or breaking due to addition of rent periods logic to create and update * amend failing tests and resolve linting complaints * changes following review * disable checkboxes for rent periods if they are in use so that users are not able to make existing logs invalid hint text added to the question to explain this I have also added all rent periods to a hidden field to remove the need to fetch them again form the db in the update method * update validation to reflect the fact that an org having no associated rent periods no longer means they accept all rent periods update tests adding both cases and removing unnecessary additional db additions * rake task to create rent period associations for orgs that have none * revert mistaken copy changes in designs * create rent periods in factories as default, with an option to skip. skip automatic creation in tests specifically related to rent periods * stub api call for factory value, update csv tests and fixtures accordingly * extract a good chunk of tests out of lettings_log_spec and into a dedicated derived fields spec file. in many cases refactor tests * remove before(:context) and associated patterns. use assign_attributes in various places for cleaner code * escape . in regex for API call stubs to satisfy codeQL remove destroy_all call at the start of a test that was dealing with leftover modesl in the test db * further refactoring of various tests to reduce database interactions and improve speed * remove outdated distinction between unitletas mappings from before 23/24 * remove tests that seem to be testing active record and/or ruby Date classpull/2444/head^2
Arthur Campbell
7 months ago
committed by
GitHub
33 changed files with 1684 additions and 1899 deletions
@ -1,3 +1,5 @@
|
||||
class OrganisationRentPeriod < ApplicationRecord |
||||
belongs_to :organisation |
||||
|
||||
validates :organisation_id, uniqueness: { scope: :rent_period } # rubocop:disable Rails/UniqueValidationWithoutIndex |
||||
end |
||||
|
|
|
|
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,119 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe OrganisationsController, type: :request do |
||||
let(:user) { create(:user, :support) } |
||||
let(:headers) { { "Accept" => "text/html" } } |
||||
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||
|
||||
before do |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
end |
||||
|
||||
describe "#new" do |
||||
before do |
||||
get new_organisation_path |
||||
end |
||||
|
||||
it "displays the rent periods question" do |
||||
expect(page).to have_content "What are the rent periods for the organisation?" |
||||
end |
||||
|
||||
it "the checkboxes for each rent period are checked by default" do |
||||
checkboxes = page.all "input[type='checkbox'][name='organisation[rent_periods][]']" |
||||
expect(checkboxes.count).to be > 5 |
||||
expect(checkboxes.all? { |box| box[:checked] }).to be true |
||||
end |
||||
end |
||||
|
||||
describe "#create" do |
||||
let(:org_name) { "abode team" } |
||||
let(:expected_rent_periods) { [1, 2, 3] } |
||||
let(:params) do |
||||
{ |
||||
"organisation": { |
||||
name: org_name, |
||||
provider_type: "LA", |
||||
rent_periods: expected_rent_periods, |
||||
}, |
||||
} |
||||
end |
||||
|
||||
before do |
||||
post organisations_path headers:, params: |
||||
end |
||||
|
||||
it "creates organisation rent periods with the correct rent period and organisation id" do |
||||
org = Organisation.includes(:organisation_rent_periods).find_by_name(org_name) |
||||
org_rent_periods = org.organisation_rent_periods |
||||
expect(org_rent_periods.count).to be expected_rent_periods.count |
||||
expect(org_rent_periods.map(&:rent_period)).to match_array expected_rent_periods |
||||
expect(org_rent_periods.map(&:organisation_id)).to all be org.id |
||||
end |
||||
end |
||||
|
||||
describe "#edit" do |
||||
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } |
||||
let(:fake_rent_periods) do |
||||
{ |
||||
"1" => { "value" => "Every minute" }, |
||||
"2" => { "value" => "Every decade" }, |
||||
} |
||||
end |
||||
let(:checked_rent_period_id) { "1" } |
||||
|
||||
before do |
||||
allow(RentPeriod).to receive(:rent_period_mappings).and_return fake_rent_periods |
||||
create(:organisation_rent_period, organisation:, rent_period: checked_rent_period_id) |
||||
get edit_organisation_path organisation |
||||
end |
||||
|
||||
it "displays the rent periods question" do |
||||
expect(page).to have_content "What are the rent periods for the organisation?" |
||||
end |
||||
|
||||
it "the checkboxes for each rent period are checked where appropriate" do |
||||
checkboxes = page.all "input[type='checkbox']" |
||||
expect(checkboxes.count).to be 2 |
||||
expected_checked_checkbox = checkboxes.find { |cb| cb[:value] == checked_rent_period_id } |
||||
expect(expected_checked_checkbox[:checked]).to be true |
||||
expected_not_checked_checkbox = checkboxes.find { |cb| cb[:value] != checked_rent_period_id } |
||||
expect(expected_not_checked_checkbox[:checked]).to be false |
||||
end |
||||
end |
||||
|
||||
describe "#update" do |
||||
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } |
||||
let(:initially_checked_rent_period_id) { "1" } |
||||
let(:initially_unchecked_rent_period_id) { "2" } |
||||
let(:params) do |
||||
{ |
||||
"organisation": { |
||||
name: organisation.name, |
||||
rent_periods: [initially_unchecked_rent_period_id], |
||||
all_rent_periods: [initially_unchecked_rent_period_id, initially_checked_rent_period_id], |
||||
}, |
||||
} |
||||
end |
||||
|
||||
before do |
||||
create(:organisation_rent_period, organisation:, rent_period: initially_checked_rent_period_id) |
||||
end |
||||
|
||||
it "creates and destroys organisation rent periods as appropriate" do |
||||
rent_periods = Organisation.includes(:organisation_rent_periods) |
||||
.find(organisation.id) |
||||
.organisation_rent_periods |
||||
expect(rent_periods.count).to be 1 |
||||
expect(rent_periods.first.rent_period.to_s).to eq initially_checked_rent_period_id |
||||
|
||||
patch organisation_path(organisation, headers:, params:) |
||||
|
||||
rent_periods = Organisation.includes(:organisation_rent_periods) |
||||
.find(organisation.id) |
||||
.organisation_rent_periods |
||||
expect(rent_periods.count).to be 1 |
||||
expect(rent_periods.first.rent_period.to_s).to eq initially_unchecked_rent_period_id |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue