Skip to content

Commit

Permalink
Correctly handle duplicate new friends/locations when editing
Browse files Browse the repository at this point in the history
Fixes #199
  • Loading branch information
JacobEvelyn committed Aug 2, 2018
1 parent f067be8 commit 29023f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/friends/introvert.rb
Expand Up @@ -43,11 +43,17 @@ def clean(clean_command:)
# locations.
(@activities + @notes).each do |event|
event.friend_names.each do |name|
add_friend(name: name) unless friend_names.include? name
unless friend_names.include? name
add_friend(name: name)
friend_names << name
end
end

event.location_names.each do |name|
add_location(name: name) unless location_names.include? name
unless location_names.include? name
add_location(name: name)
location_names << name
end
end
end

Expand Down
1 change: 1 addition & 0 deletions test/commands/edit_spec.rb
Expand Up @@ -81,6 +81,7 @@
- 2015-11-01: **Grace Hopper** and I went to _Marie's Diner_. George had to cancel at the last minute. @food
- 2015-01-04: Got lunch with **Grace Hopper** and **George Washington Carver**. @food
- 2014-12-31: Celebrated the new year in _Paris_ with **Marie Curie**. @partying
- 2014-12-16: Okay, yep, I definitely just saw **Bigfoot** in the _Mysterious Mountains_!
- 2014-12-15: I just had a possible **Bigfoot** sighting! I think I may have seen **Bigfoot** in the _Mysterious Mountains_.
- 2014-11-15: Talked to **George Washington Carver** on the phone for an hour.
Expand Down
6 changes: 6 additions & 0 deletions test/editor
Expand Up @@ -9,7 +9,13 @@ filename = ARGV[0]
current_file_contents = File.read(filename).split("\n")
File.open(filename, "w") do |file|
file.puts current_file_contents[0]

# We add two activities that contain the same new friend and new
# location, to test that this doesn't crash `friends edit` as
# previously happened.
file.puts "- 2014-12-15: I just had a possible **Bigfoot** sighting! "\
"I think I may have seen **Bigfoot** in the _Mysterious Mountains_."
file.puts "- 2014-12-16: Okay, yep, I definitely just saw **Bigfoot** in "\
"the _Mysterious Mountains_!"
file.puts current_file_contents.drop(1)
end

0 comments on commit 29023f3

Please sign in to comment.