Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RemoveDefaultValueForMouSignatureAgreementType < ActiveRecord::Migration[8.1]
def up
change_column_default :mou_signatures, :agreement_type, nil
end

def down
change_column_default :mou_signatures, :agreement_type, "crown"
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
research_contact_status: :consented,
user_research_opted_in_at: Time.zone.now })

MouSignature.create! user: default_user, organisation: gds
MouSignature.create! user: default_user, organisation: gds, agreement_type: "crown"

# create extra organisations
test_org = Organisation.create! slug: "test-org", name: "Test Org", abbreviation: "TO"
Expand Down
9 changes: 5 additions & 4 deletions lib/tasks/mou_signatures.rake
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
namespace :mou_signatures do
desc "Add MOU signature that was done offline"
task :create, %i[user_email organisation_name agreed_at_date] => :environment do |_, args|
usage_message = "usage: rake mou_signatures:create[<user_email>, <organisation_name>, <agreed_at_date>]".freeze
abort usage_message if args[:user_email].blank? || args[:organisation_name].blank? || args[:agreed_at_date].blank?
task :create, %i[user_email organisation_name agreed_at_date agreement_type] => :environment do |_, args|
usage_message = "usage: rake mou_signatures:create[<user_email>, <organisation_name>, <agreed_at_date>, <agreement_type>]".freeze
abort usage_message if args[:user_email].blank? || args[:organisation_name].blank? || args[:agreed_at_date].blank? ||
args[:agreement_type].blank?

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

mou_signature = MouSignature.create!(user:, organisation:, created_at: agreed_at_date)
mou_signature = MouSignature.create!(user:, organisation:, created_at: agreed_at_date, agreement_type: args[:agreement_type])

puts "Added MOU signature for User: #{mou_signature.user.name} and Organisation: #{mou_signature.organisation.name} signed at: #{mou_signature.created_at}"
end
Expand Down
32 changes: 27 additions & 5 deletions spec/lib/tasks/mou_signatures.rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,49 @@
let(:date) { Date.iso8601 "2020-01-01T00:00" }

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

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

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

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

expect(MouSignature.last).to have_attributes(user:, organisation:, created_at: date, updated_at: Time.zone.now)
expect(MouSignature.last).to have_attributes(
user:,
organisation:,
created_at: date,
updated_at: Time.zone.now,
agreement_type: "crown",
)
end
end

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

expect(MouSignature.last).to have_attributes(
user:,
organisation:,
created_at: date,
updated_at: Time.zone.now,
agreement_type: "non_crown",
)
end
end
end
Expand Down
Loading