7 changed files with 54 additions and 27 deletions
@ -0,0 +1,5 @@
|
||||
class AddCollectionYear < ActiveRecord::Migration[7.2] |
||||
def change |
||||
add_column :log_validations, :collection_year, :string |
||||
end |
||||
end |
@ -0,0 +1,6 @@
|
||||
desc "Sets value for collection_year log validations depending on the from value" |
||||
task set_log_validation_collection_year: :environment do |
||||
LogValidation.all.each do |log_validation| |
||||
log_validation.update(collection_year: "#{log_validation.from.year}/#{log_validation.from.year + 1}") |
||||
end |
||||
end |
@ -0,0 +1,29 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "set_log_validation_collection_year" do |
||||
describe ":set_log_validation_collection_year", type: :task do |
||||
subject(:task) { Rake::Task["set_log_validation_collection_year"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/set_log_validation_collection_year") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the rake task is run" do |
||||
let(:user) { create(:user) } |
||||
|
||||
context "and version whodunnit exists for create" do |
||||
let!(:log_validation_2023) { LogValidation.create(from: Time.zone.local(2023, 4, 1), to: Time.zone.local(2024, 4, 1)) } |
||||
let!(:log_validation_2024) { LogValidation.create(from: Time.zone.local(2024, 4, 1), to: Time.zone.local(2025, 4, 1)) } |
||||
|
||||
it "sets collection_year" do |
||||
task.invoke |
||||
expect(log_validation_2023.reload.collection_year).to eq("2023/2024") |
||||
expect(log_validation_2024.reload.collection_year).to eq("2024/2025") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue