Browse Source

introduce visible flag to lettings logs

bulk-upload-resume
Phil Lee 2 years ago
parent
commit
f207c00500
  1. 5
      app/models/lettings_log.rb
  2. 7
      db/migrate/20230329091101_add_visible_to_lettings_logs.rb
  3. 4
      db/schema.rb
  4. 13
      spec/models/lettings_log_spec.rb

5
app/models/lettings_log.rb

@ -21,6 +21,8 @@ class LettingsLog < Log
include Validations::DateValidations
include Validations::FinancialValidations
default_scope { where(visible: true) }
has_paper_trail
validates_with LettingsLogValidator
@ -38,6 +40,9 @@ class LettingsLog < Log
belongs_to :location, optional: true
belongs_to :managing_organisation, class_name: "Organisation", optional: true
scope :visible, -> { where(visible: true) }
scope :invisible, -> { where(visible: false) }
scope :filter_by_year, ->(year) { where(startdate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") }
scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") }

7
db/migrate/20230329091101_add_visible_to_lettings_logs.rb

@ -0,0 +1,7 @@
class AddVisibleToLettingsLogs < ActiveRecord::Migration[7.0]
def change
add_column :lettings_logs, :visible, :boolean, null: false, default: true
add_index :lettings_logs, :visible
end
end

4
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_22_112117) do
ActiveRecord::Schema[7.0].define(version: 2023_03_29_091101) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -289,6 +289,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_22_112117) do
t.string "town_or_city"
t.string "county"
t.integer "carehome_charges_value_check"
t.boolean "visible", default: true, null: false
t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"
t.index ["location_id"], name: "index_lettings_logs_on_location_id"
@ -297,6 +298,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_22_112117) do
t.index ["owning_organisation_id"], name: "index_lettings_logs_on_owning_organisation_id"
t.index ["scheme_id"], name: "index_lettings_logs_on_scheme_id"
t.index ["updated_by_id"], name: "index_lettings_logs_on_updated_by_id"
t.index ["visible"], name: "index_lettings_logs_on_visible"
end
create_table "local_authorities", force: :cascade do |t|

13
spec/models/lettings_log_spec.rb

@ -39,6 +39,19 @@ RSpec.describe LettingsLog do
expect(lettings_log).to be_lettings
end
describe "default_scope" do
let!(:visible_log) { create(:lettings_log) }
let!(:invisible_log) { create(:lettings_log, visible: false) }
it "includes visible logs" do
expect(described_class.all).to include(visible_log)
end
it "excludes non visible logs" do
expect(described_class.all).not_to include(invisible_log)
end
end
describe "#form" do
let(:lettings_log) { build(:lettings_log, created_by: created_by_user) }
let(:lettings_log_2) { build(:lettings_log, startdate: Time.zone.local(2022, 1, 1), created_by: created_by_user) }

Loading…
Cancel
Save