Skip to content

Commit 66abf70

Browse files
committed
Update rake task to create an MouSignature to accept agreement_type
MouSignatures now have an agreement_type of "crown" or "non_crown". Update the rake task to require specifying the agreement_type.
1 parent 379edf8 commit 66abf70

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

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)