Skip to content

Commit 037d9bc

Browse files
authored
Merge pull request #2634 from alphagov/add-agreement-type-to-mou-signature-rake-task
Ensure agreement_type is specified for MouSignatures added using rake tasks
2 parents 9348cdc + aa886b7 commit 037d9bc

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class RemoveDefaultValueForMouSignatureAgreementType < ActiveRecord::Migration[8.1]
2+
def up
3+
change_column_default :mou_signatures, :agreement_type, nil
4+
end
5+
6+
def down
7+
change_column_default :mou_signatures, :agreement_type, "crown"
8+
end
9+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/seeds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
research_contact_status: :consented,
2929
user_research_opted_in_at: Time.zone.now })
3030

31-
MouSignature.create! user: default_user, organisation: gds
31+
MouSignature.create! user: default_user, organisation: gds, agreement_type: "crown"
3232

3333
# create extra organisations
3434
test_org = Organisation.create! slug: "test-org", name: "Test Org", abbreviation: "TO"

lib/tasks/mou_signatures.rake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
namespace :mou_signatures do
22
desc "Add MOU signature that was done offline"
3-
task :create, %i[user_email organisation_name agreed_at_date] => :environment do |_, args|
4-
usage_message = "usage: rake mou_signatures:create[<user_email>, <organisation_name>, <agreed_at_date>]".freeze
5-
abort usage_message if args[:user_email].blank? || args[:organisation_name].blank? || args[:agreed_at_date].blank?
3+
task :create, %i[user_email organisation_name agreed_at_date agreement_type] => :environment do |_, args|
4+
usage_message = "usage: rake mou_signatures:create[<user_email>, <organisation_name>, <agreed_at_date>, <agreement_type>]".freeze
5+
abort usage_message if args[:user_email].blank? || args[:organisation_name].blank? || args[:agreed_at_date].blank? ||
6+
args[:agreement_type].blank?
67

78
user = User.find_by!(email: args[:user_email])
89
organisation = Organisation.find_by!(name: args[:organisation_name])
910
agreed_at_date = Date.iso8601(args[:agreed_at_date])
1011

11-
mou_signature = MouSignature.create!(user:, organisation:, created_at: agreed_at_date)
12+
mou_signature = MouSignature.create!(user:, organisation:, created_at: agreed_at_date, agreement_type: args[:agreement_type])
1213

1314
puts "Added MOU signature for User: #{mou_signature.user.name} and Organisation: #{mou_signature.organisation.name} signed at: #{mou_signature.created_at}"
1415
end

spec/lib/tasks/mou_signatures.rake_spec.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,49 @@
1919
let(:date) { Date.iso8601 "2020-01-01T00:00" }
2020

2121
it "aborts when the user is not found" do
22-
expect { task.invoke("John Doe", organisation.name, date.iso8601) }
22+
expect { task.invoke("John Doe", organisation.name, date.iso8601, "crown") }
2323
.to raise_error(ActiveRecord::RecordNotFound, /Couldn't find User/)
2424
end
2525

2626
it "aborts when the organisation is not found" do
27-
expect { task.invoke(user.email, "GDS", date.iso8601) }
27+
expect { task.invoke(user.email, "GDS", date.iso8601, "crown") }
2828
.to raise_error(ActiveRecord::RecordNotFound, /Couldn't find Organisation/)
2929
end
3030

3131
it "aborts when the agreed at date is not a valid date" do
32-
expect { task.invoke(user.email, organisation.name, "not a date") }
32+
expect { task.invoke(user.email, organisation.name, "not a date", "crown") }
3333
.to raise_error(Date::Error, /invalid date/)
3434
end
3535

3636
it "creates an MOU signature" do
3737
freeze_time do
38-
expect { task.invoke(user.email, organisation.name, date.iso8601) }
38+
expect { task.invoke(user.email, organisation.name, date.iso8601, "crown") }
3939
.to change(MouSignature, :count).by(1)
4040
.and output(/Added MOU signature for User: A Person and Organisation: Government Digital Service signed at: 2020-01-01 00:00/).to_stdout
4141

42-
expect(MouSignature.last).to have_attributes(user:, organisation:, created_at: date, updated_at: Time.zone.now)
42+
expect(MouSignature.last).to have_attributes(
43+
user:,
44+
organisation:,
45+
created_at: date,
46+
updated_at: Time.zone.now,
47+
agreement_type: "crown",
48+
)
49+
end
50+
end
51+
52+
it "creates a non-crown MOU signature" do
53+
freeze_time do
54+
expect { task.invoke(user.email, organisation.name, date.iso8601, "non_crown") }
55+
.to change(MouSignature, :count).by(1)
56+
.and output(/Added MOU signature for User: A Person and Organisation: Government Digital Service signed at: 2020-01-01 00:00/).to_stdout
57+
58+
expect(MouSignature.last).to have_attributes(
59+
user:,
60+
organisation:,
61+
created_at: date,
62+
updated_at: Time.zone.now,
63+
agreement_type: "non_crown",
64+
)
4365
end
4466
end
4567
end

0 commit comments

Comments
 (0)