Skip to content

Commit 9c03f44

Browse files
committed
spec: model/datafixup linter fix, fixes SD-2020
correctly whitelist things that chain off of whitelisted methods, e.g. connection Change-Id: I38ec4699b324d0e5d26de6bde36d841fa696d7e5 Reviewed-on: https://gerrit.instructure.com/100186 Tested-by: Jenkins Reviewed-by: Cody Cutrer <cody@instructure.com> Product-Review: Jon Jensen <jon@instructure.com> QA-Review: Jon Jensen <jon@instructure.com>
1 parent 1b1dd7b commit 9c03f44

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

gems/rubocop-canvas/lib/rubocop_canvas/cops/migration/model_behavior.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def on_send(node)
3232
parts = receiver + methods
3333
return true if whitelist.any? do |whitelist_parts|
3434
if whitelist_parts[0] == :*
35-
methods.last == whitelist_parts.last
35+
methods.any? { |m| m == whitelist_parts.last }
3636
else
3737
parts[0, whitelist_parts.length] == whitelist_parts
3838
end

gems/rubocop-canvas/spec/rubocop/cop/migration/model_behavior_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"Whitelist" => [
88
"Migrations::FooFix",
99
"*.update_all",
10-
"*.delete_all"
10+
"*.delete_all",
11+
"*.connection"
1112
]
1213
}
1314
)
@@ -26,6 +27,17 @@ def up
2627
expect(subject.offenses.size).to eq(0)
2728
end
2829

30+
it "should find no offenses when calling methods on whitelisted classes/methods" do
31+
inspect_source(subject, %{
32+
class Foo < ActiveRecord::Migration
33+
def up
34+
User.connection.execute "YOLO"
35+
end
36+
end
37+
})
38+
expect(subject.offenses.size).to eq(0)
39+
end
40+
2941
it "should find no offenses when calling whitelisted methods" do
3042
inspect_source(subject, %{
3143
class Foo < ActiveRecord::Migration

0 commit comments

Comments
 (0)