Browse Source
* CLDC-2895 Add squish to the names of locations, schemes, users, and institutions * CLDC-2895 Add rake task to squish the names of all locations, schemes, users, and organisations * CLDC-2895 Add tests to squish_names rake tasksdemo-branch
David May-Miller
1 year ago
committed by
GitHub
6 changed files with 88 additions and 4 deletions
@ -0,0 +1,19 @@
|
||||
desc "Squish names of locations, schemes, users, and organisations" |
||||
task squish_names: :environment do |
||||
Location.find_each do |location| |
||||
location.name.squish! |
||||
location.save! |
||||
end |
||||
Scheme.find_each do |scheme| |
||||
scheme.service_name.squish! |
||||
scheme.save! |
||||
end |
||||
User.find_each do |user| |
||||
user.name.squish! |
||||
user.save! |
||||
end |
||||
Organisation.find_each do |organisation| |
||||
organisation.name.squish! |
||||
organisation.save! |
||||
end |
||||
end |
@ -0,0 +1,65 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "squish_names" do |
||||
describe ":squish_names", type: :task do |
||||
subject(:task) { Rake::Task["squish_names"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/squish_names") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the rake task is run" do |
||||
let!(:scheme) { create(:scheme) } |
||||
let!(:location) { create(:location) } |
||||
let!(:user) { create(:user) } |
||||
let!(:organisation) { create(:organisation) } |
||||
|
||||
it "updates names with multiple spaces to only have one" do |
||||
scheme.service_name = "test test" |
||||
location.name = "test test test" |
||||
user.name = "test test" |
||||
organisation.name = "test test test" |
||||
|
||||
scheme.save!(validate: false) |
||||
location.save!(validate: false) |
||||
user.save!(validate: false) |
||||
organisation.save!(validate: false) |
||||
|
||||
task.invoke |
||||
scheme.reload |
||||
location.reload |
||||
user.reload |
||||
organisation.reload |
||||
expect(scheme.service_name).to eq("test test") |
||||
expect(location.name).to eq("test test test") |
||||
expect(user.name).to eq("test test") |
||||
expect(organisation.name).to eq("test test test") |
||||
end |
||||
|
||||
it "does not update names without multiple spaces" do |
||||
scheme.service_name = "test test" |
||||
location.name = "test test test" |
||||
user.name = "test test" |
||||
organisation.name = "test test test" |
||||
|
||||
scheme.save!(validate: false) |
||||
location.save!(validate: false) |
||||
user.save!(validate: false) |
||||
organisation.save!(validate: false) |
||||
|
||||
task.invoke |
||||
scheme.reload |
||||
location.reload |
||||
user.reload |
||||
organisation.reload |
||||
expect(scheme.service_name).to eq("test test") |
||||
expect(location.name).to eq("test test test") |
||||
expect(user.name).to eq("test test") |
||||
expect(organisation.name).to eq("test test test") |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue