Skip to content

Commit

Permalink
Detect correct digestible attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Apr 28, 2019
1 parent 4434400 commit 73c59f7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/shoulda/matchers/rails_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,13 @@ def has_secure_password?(record, attribute_name)
end

def digestible_attributes_in(record)
record.methods.inject([]) do |array, method_name|
match = method_name.to_s.match(
/\A(\w+)_(?:confirmation|digest)=\Z/,
)
writer_methods = record.public_methods.grep(/\A(\w+).*=\Z/)
reader_methods = writer_methods.map { |method_name| method_name.to_s.remove(/=\Z/).to_sym }

if match
array.concat([match[1].to_sym])
else
array
end
reader_methods.select do |reader_method_name|
record.respond_to?("#{reader_method_name}_digest") &&
record.respond_to?("#{reader_method_name}_confirmation=") &&
record.respond_to?("authenticate_#{reader_method_name}")
end
end

Expand Down

0 comments on commit 73c59f7

Please sign in to comment.