diff options
Diffstat (limited to 'rubocop/cop/migration/add_limit_to_text_columns.rb')
-rw-r--r-- | rubocop/cop/migration/add_limit_to_text_columns.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/rubocop/cop/migration/add_limit_to_text_columns.rb b/rubocop/cop/migration/add_limit_to_text_columns.rb index b578e73f19e..b2e37ad5137 100644 --- a/rubocop/cop/migration/add_limit_to_text_columns.rb +++ b/rubocop/cop/migration/add_limit_to_text_columns.rb @@ -6,6 +6,10 @@ module RuboCop module Cop module Migration # Cop that enforces always adding a limit on text columns + # + # Text columns starting with `encrypted_` are very likely used + # by `attr_encrypted` which controls the text length. Those columns + # should not add a text limit. class AddLimitToTextColumns < RuboCop::Cop::Cop include MigrationHelpers @@ -102,6 +106,8 @@ module RuboCop # Check if there is an `add_text_limit` call for the provided # table and attribute name def text_limit_missing?(node, table_name, attribute_name) + return false if encrypted_attribute_name?(attribute_name) + limit_found = false node.each_descendant(:send) do |send_node| @@ -118,6 +124,10 @@ module RuboCop !limit_found end + + def encrypted_attribute_name?(attribute_name) + attribute_name.to_s.start_with?('encrypted_') + end end end end |