Browse Source
* Refactor exports to have years * Update existing exports * Fix flaky test * Remove a commentpull/2850/head
kosiakkatrina
2 months ago
committed by
GitHub
14 changed files with 111 additions and 57 deletions
@ -1,2 +1,5 @@
|
||||
class Export < ApplicationRecord |
||||
scope :lettings, -> { where(collection: "lettings") } |
||||
scope :organisations, -> { where(collection: "organisations") } |
||||
scope :users, -> { where(collection: "users") } |
||||
end |
||||
|
@ -0,0 +1,5 @@
|
||||
class AddYearToExport < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :exports, :year, :integer |
||||
end |
||||
end |
@ -0,0 +1,8 @@
|
||||
desc "Set export collection years for lettings exports" |
||||
task set_export_collection_years: :environment do |
||||
Export.where(collection: %w[2022 2023 2024 2025]).find_each do |export| |
||||
export.year = export.collection.to_i |
||||
export.collection = "lettings" |
||||
export.save! |
||||
end |
||||
end |
@ -0,0 +1,41 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "set_export_collection_years" do |
||||
describe ":set_export_collection_years", type: :task do |
||||
subject(:task) { Rake::Task["set_export_collection_years"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/set_export_collection_years") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the rake task is run" do |
||||
let!(:lettings_export_2023) { Export.create(collection: "2023", year: nil, started_at: Time.zone.now) } |
||||
let!(:lettings_export_2024) { Export.create(collection: "2024", year: nil, started_at: Time.zone.now) } |
||||
let!(:updated_lettings_export) { Export.create(collection: "lettings", year: 2023, started_at: Time.zone.now) } |
||||
let!(:organisations_export) { Export.create(collection: "organisations", year: nil, started_at: Time.zone.now) } |
||||
let!(:users_export) { Export.create(collection: "users", year: nil, started_at: Time.zone.now) } |
||||
|
||||
it "correctly updates collection years" do |
||||
task.invoke |
||||
|
||||
expect(lettings_export_2023.reload.collection).to eq("lettings") |
||||
expect(lettings_export_2023.year).to eq(2023) |
||||
|
||||
expect(lettings_export_2024.reload.collection).to eq("lettings") |
||||
expect(lettings_export_2024.year).to eq(2024) |
||||
|
||||
expect(updated_lettings_export.reload.collection).to eq("lettings") |
||||
expect(updated_lettings_export.year).to eq(2023) |
||||
|
||||
expect(organisations_export.reload.collection).to eq("organisations") |
||||
expect(organisations_export.year).to eq(nil) |
||||
|
||||
expect(users_export.reload.collection).to eq("users") |
||||
expect(users_export.year).to eq(nil) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue