Browse Source
* Add managing_organisation_id to sales * Set sales managing org id to owning org idpull/2081/head
kosiakkatrina
1 year ago
committed by
GitHub
5 changed files with 64 additions and 1 deletions
@ -0,0 +1,7 @@ |
|||||||
|
class AddSalesManagingOrganisation < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
change_table :sales_logs, bulk: true do |t| |
||||||
|
t.references :managing_organisation, class_name: "Organisation" |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,4 @@ |
|||||||
|
desc "Set sales managing organisation id to owning organisation id" |
||||||
|
task set_sales_managing_organisation: :environment do |
||||||
|
SalesLog.where.not(owning_organisation_id: nil).update_all("managing_organisation_id = owning_organisation_id") |
||||||
|
end |
@ -0,0 +1,48 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
RSpec.describe "set_sales_managing_organisation" do |
||||||
|
describe ":set_sales_managing_organisation", type: :task do |
||||||
|
subject(:task) { Rake::Task["set_sales_managing_organisation"] } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/set_sales_managing_organisation") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
end |
||||||
|
|
||||||
|
context "when the rake task is run" do |
||||||
|
let!(:sales_log) { create(:sales_log, :completed, managing_organisation_id: nil) } |
||||||
|
|
||||||
|
it "updates sales log managing_organisation_id with owning_organisation_id" do |
||||||
|
expect(sales_log.managing_organisation_id).to eq(nil) |
||||||
|
expect(sales_log.status).to eq("completed") |
||||||
|
task.invoke |
||||||
|
sales_log.reload |
||||||
|
expect(sales_log.managing_organisation_id).to eq(sales_log.owning_organisation_id) |
||||||
|
expect(sales_log.status).to eq("completed") |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update sales log managing_organisation_id if owning_organisation_id is nil" do |
||||||
|
sales_log.update!(owning_organisation_id: nil) |
||||||
|
expect(sales_log.status).to eq("in_progress") |
||||||
|
expect(sales_log.managing_organisation_id).to eq(nil) |
||||||
|
task.invoke |
||||||
|
sales_log.reload |
||||||
|
expect(sales_log.managing_organisation_id).to eq(nil) |
||||||
|
expect(sales_log.status).to eq("in_progress") |
||||||
|
end |
||||||
|
|
||||||
|
it "skips validations" do |
||||||
|
sales_log.saledate = Time.zone.local(2021, 3, 3) |
||||||
|
sales_log.save!(validate: false) |
||||||
|
expect(sales_log.managing_organisation_id).to eq(nil) |
||||||
|
expect(sales_log.status).to eq("in_progress") |
||||||
|
task.invoke |
||||||
|
sales_log.reload |
||||||
|
expect(sales_log.managing_organisation_id).to eq(sales_log.owning_organisation_id) |
||||||
|
expect(sales_log.status).to eq("in_progress") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue