From 71f1cf470bdb9984539a329c1243d66da08fe1e6 Mon Sep 17 00:00:00 2001 From: Andre Leoni Date: Sat, 4 Sep 2021 11:33:00 -0300 Subject: [PATCH] fix the possessive call when calling twice with another method --- README.md | 4 ++++ lib/name_of_person/person_name.rb | 10 +++++----- test/person_name_test.rb | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 89d90d0..65e6dbb 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ require 'active_record' require 'active_model' ``` +## Run tests with + +`bundle exec rake test` + ## No further development is going to happen This gem is essentially frozen, as the developers have decided to only deal with full names going forward in their applications. Feel free to fork this work, brand it under a new name, and continue development. diff --git a/lib/name_of_person/person_name.rb b/lib/name_of_person/person_name.rb index b475ef7..e5f836a 100644 --- a/lib/name_of_person/person_name.rb +++ b/lib/name_of_person/person_name.rb @@ -35,17 +35,17 @@ def sorted @sorted ||= last.present? ? "#{last}, #{first}" : first end - # Returns full name with with trailing 's or ' if name ends in s. + # Returns full name with trailing 's or ' if name ends in s. def possessive(method = :full) - whitelist = %i[full first last abbreviated sorted initials] + allowed_method_names = %i[full first last abbreviated sorted initials] - unless whitelist.include?(method.to_sym) + unless allowed_method_names.include?(method.to_sym) raise ArgumentError, 'Please provide a valid method' end name = public_send(method) - @possessive ||= "#{name}'#{'s' unless name.downcase.end_with?('s')}" + "#{name}'#{'s' unless name.downcase.end_with?('s')}" end # Returns just the initials. @@ -53,7 +53,7 @@ def initials @initials ||= remove(/(\(|\[).*(\)|\])/).scan(/([[:word:]])[[:word:]]*/i).join end - # Returns a mentionable version of the familiar name + # Returns a mentionable version of the familiar name. def mentionable @mentionable ||= familiar.chop.delete(' ').downcase end diff --git a/test/person_name_test.rb b/test/person_name_test.rb index 96dec8f..dc44a82 100644 --- a/test/person_name_test.rb +++ b/test/person_name_test.rb @@ -52,6 +52,7 @@ class PersonNameTest < ActiveSupport::TestCase test "possessive" do assert_equal "#{@name.full}'s", @name.possessive + assert_equal "#{@name.initials}'s", @name.possessive(:initials) assert_equal "#{@first.full}'s", @first.possessive assert_equal "Foo Bars'", PersonName.new('Foo', 'Bars').possessive end @@ -71,7 +72,7 @@ class PersonNameTest < ActiveSupport::TestCase test "possessive initials" do assert_equal "#{@name.initials}'s", @name.possessive(:initials) end - + test "possessive abbreviated" do assert_equal "#{@name.abbreviated}'s", @name.possessive(:abbreviated) end