Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thoughtbot/shoulda-matchers
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 28f06fea0ee5b68250c088d7ea81b424b9d35229
Choose a base ref
..
head repository: thoughtbot/shoulda-matchers
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e8e1303b3dd32a7bf4a21b925c44f12400c989a6
Choose a head ref
Showing with 11 additions and 7 deletions.
  1. +11 −7 lib/shoulda/matchers/active_model/validate_length_of_matcher.rb
18 changes: 11 additions & 7 deletions lib/shoulda/matchers/active_model/validate_length_of_matcher.rb
Original file line number Diff line number Diff line change
@@ -492,8 +492,8 @@ def disallows_length_of?(length, message)
def value_of_length(length)
if array_column?
['x'] * length
elsif association?
Array.new(length) { association.klass.new }
elsif collection_association?
Array.new(length) { association_reflection.klass.new }
else
'x' * length
end
@@ -503,14 +503,18 @@ def array_column?
@options[:array] || super
end

def association?
return false unless @subject.class.respond_to?(:reflect_on_association)
def collection_association?
association? && [:has_many, :has_and_belongs_to_many].include?(
association_reflection.macro,
)
end

association
def association?
association_reflection.present?
end

def association
@subject.class.reflect_on_association(@attribute)
def association_reflection
model.try(:reflect_on_association, @attribute)
end

def translated_short_message