-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update / test remove MP letters task
There were a few edge cases which came up when I ran this task last night: 1) MySQL LIKE statements are case insensitive, so the query found things like "Francis Implementation Team" (as it's got a lower case mp in). 2) Even if it was case sensitive, %MP% would match people with MPhil degrees. 3) The `puts` statement being outside of the if statement caused some confusion - it would log things as updated that matched the query, but not the ruby gsub, even though they hadn't been updated. I considered making the MySQL query stricter, but then we might actually miss things (like someone with MP in their letters, but separated with a comma, or lower case). Instead, I've just made it clear which ones are being skipped in the logs. While writing tests for this, I also noticed an edge case where it would replace letters like "CBE MP VC" with "CBEVC" (i.e. it would remove both surrounding spaces from MP). Better to do it with split / join to avoid this I think.
- Loading branch information
1 parent
315cc64
commit 0568dce
Showing
2 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "test_helper" | ||
require "rake" | ||
|
||
class RemoveMpLettersRake < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
teardown { task.reenable } | ||
|
||
describe "#remove_mp_letters" do | ||
let(:task) { Rake::Task["election:remove_mp_letters"] } | ||
|
||
it "removes the letters MP from people names" do | ||
member_a = create(:person, forename: "A", surname: "Member", letters: "MP") | ||
member_b = create(:person, forename: "B", surname: "Member", letters: "CBE MP") | ||
member_c = create(:person, forename: "C", surname: "Member", letters: "MP MEng") | ||
member_d = create(:person, forename: "D", surname: "Member", letters: "CBE MP MPhil") | ||
non_member_a = create(:person, forename: "A", surname: "Non-Member", letters: "CBE MPhil VC") | ||
|
||
out, _err = capture_io { task.invoke } | ||
|
||
assert_match /updated A Member MP to A Member/, out | ||
Check failure on line 21 in test/unit/lib/tasks/election_remove_mp_letters_test.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
assert_match /updated B Member CBE MP to B Member CBE/, out | ||
Check failure on line 22 in test/unit/lib/tasks/election_remove_mp_letters_test.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
assert_match /updated C Member MP MEng to C Member MEng/, out | ||
Check failure on line 23 in test/unit/lib/tasks/election_remove_mp_letters_test.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
assert_match /updated D Member CBE MP MPhil to D Member CBE MPhil/, out | ||
Check failure on line 24 in test/unit/lib/tasks/election_remove_mp_letters_test.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
assert_match /skipped A Non-Member/, out | ||
Check failure on line 25 in test/unit/lib/tasks/election_remove_mp_letters_test.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
|
||
assert_equal "A Member", member_a.reload.name | ||
assert_equal "B Member CBE", member_b.reload.name | ||
assert_equal "C Member MEng", member_c.reload.name | ||
assert_equal "D Member CBE MPhil", member_d.reload.name | ||
assert_equal "A Non-Member CBE MPhil VC", non_member_a.reload.name | ||
end | ||
end | ||
end |