]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2267'
authorTom Hughes <tom@compton.nu>
Thu, 20 Jun 2019 18:02:31 +0000 (19:02 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 20 Jun 2019 18:02:31 +0000 (19:02 +0100)
17 files changed:
Gemfile.lock
app/abilities/ability.rb
app/controllers/changesets_controller.rb
app/controllers/diary_entries_controller.rb
app/controllers/users_controller.rb
app/models/friendship.rb [moved from app/models/friend.rb with 89% similarity]
app/models/user.rb
app/views/diary_entries/_diary_comment.html.erb
app/views/diary_entries/_diary_entry.html.erb
app/views/users/show.html.erb
config/locales/en.yml
test/abilities/abilities_test.rb
test/controllers/changesets_controller_test.rb
test/controllers/diary_entries_controller_test.rb
test/controllers/users_controller_test.rb
test/factories/friendships.rb [moved from test/factories/friends.rb with 83% similarity]
test/models/user_test.rb

index 80f946845823a7a0449bfc99e4373e27db5f682d..23022ad5bd9720cca65dc9d49e1f0ebd2f4aa7c0 100644 (file)
@@ -104,10 +104,10 @@ GEM
     composite_primary_keys (11.1.0)
       activerecord (~> 5.2.1)
     concurrent-ruby (1.1.5)
-    config (1.7.1)
+    config (1.7.2)
       activesupport (>= 3.0)
-      deep_merge (~> 1.2.1)
-      dry-validation (>= 0.12.2)
+      deep_merge (~> 1.2, >= 1.2.1)
+      dry-validation (~> 0.12, >= 0.12.2, < 1.0.0)
     coveralls (0.8.23)
       json (>= 1.8, < 3)
       simplecov (~> 0.16.1)
@@ -125,11 +125,11 @@ GEM
     delayed_job_active_record (4.1.3)
       activerecord (>= 3.0, < 5.3)
       delayed_job (>= 3.0, < 5)
-    docile (1.3.1)
+    docile (1.3.2)
     dry-configurable (0.8.3)
       concurrent-ruby (~> 1.0)
       dry-core (~> 0.4, >= 0.4.7)
-    dry-container (0.7.0)
+    dry-container (0.7.1)
       concurrent-ruby (~> 1.0)
       dry-configurable (~> 0.1, >= 0.1.3)
     dry-core (0.4.7)
@@ -189,7 +189,7 @@ GEM
     http_accept_language (2.0.5)
     i18n (0.9.5)
       concurrent-ruby (~> 1.0)
-    i18n-js (3.2.3)
+    i18n-js (3.3.0)
       i18n (>= 0.6.6)
     image_optim (0.26.4)
       exifr (~> 1.2, >= 1.2.2)
@@ -203,8 +203,8 @@ GEM
       sprockets
     image_size (2.0.1)
     in_threads (1.5.2)
-    jaro_winkler (1.5.2)
-    jquery-rails (4.3.3)
+    jaro_winkler (1.5.3)
+    jquery-rails (4.3.5)
       rails-dom-testing (>= 1, < 3)
       railties (>= 4.2.0)
       thor (>= 0.14, < 2.0)
@@ -371,8 +371,8 @@ GEM
       unicode-display_width (>= 1.4.0, < 1.7)
     rubocop-performance (1.3.0)
       rubocop (>= 0.68.0)
-    rubocop-rails (2.0.0)
-      rack (>= 2.0)
+    rubocop-rails (2.0.1)
+      rack (>= 1.1)
       rubocop (>= 0.70.0)
     ruby-openid (2.7.0)
     ruby-progressbar (1.10.1)
@@ -385,7 +385,7 @@ GEM
     sassc (2.0.1)
       ffi (~> 1.9)
       rake
-    sassc-rails (2.1.1)
+    sassc-rails (2.1.2)
       railties (>= 4.0.0)
       sassc (>= 2.0)
       sprockets (> 3.0)
@@ -427,9 +427,9 @@ GEM
       addressable (>= 2.3.6)
       crack (>= 0.3.2)
       hashdiff (>= 0.4.0, < 2.0.0)
-    websocket-driver (0.7.0)
+    websocket-driver (0.7.1)
       websocket-extensions (>= 0.1.0)
-    websocket-extensions (0.1.3)
+    websocket-extensions (0.1.4)
     xpath (3.2.0)
       nokogiri (~> 1.8)
 
index 28380392df1aaaba9500b1724e047e8c71f70826..c34f357a97a41b2febfbdb7fa1b0a505ded8e3aa 100644 (file)
@@ -44,6 +44,7 @@ class Ability
         can [:account, :go_public, :make_friend, :remove_friend], User
 
         if user.moderator?
+          can [:hide, :hidecomment], DiaryEntry
           can [:index, :show, :resolve, :ignore, :reopen], Issue
           can :create, IssueComment
           can [:new, :create, :edit, :update, :destroy], Redaction
@@ -51,7 +52,7 @@ class Ability
         end
 
         if user.administrator?
-          can [:hide, :unhide, :hidecomment, :unhidecomment], [DiaryEntry, DiaryComment]
+          can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
           can [:index, :show, :resolve, :ignore, :reopen], Issue
           can :create, IssueComment
           can [:set_status, :delete, :index], User
index 3b20130d00829eb29a4ae71e1aa3b8f011c23281..82966a353437d1d0a0837b527d1583c9798f11ca 100644 (file)
@@ -53,7 +53,7 @@ class ChangesetsController < ApplicationController
       elsif @params[:bbox]
         changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
       elsif @params[:friends] && current_user
-        changesets = changesets.where(:user_id => current_user.friend_users.identifiable)
+        changesets = changesets.where(:user_id => current_user.friends.identifiable)
       elsif @params[:nearby] && current_user
         changesets = changesets.where(:user_id => current_user.nearby)
       end
index f827bac3f165a00d1f94313975c291fbcf329979..d4a32efb212c8b9cfbf45e0b88a5ae0b80276fa6 100644 (file)
@@ -129,7 +129,7 @@ class DiaryEntriesController < ApplicationController
     elsif params[:friends]
       if current_user
         @title = t "diary_entries.index.title_friends"
-        @entries = DiaryEntry.where(:user_id => current_user.friend_users)
+        @entries = DiaryEntry.where(:user_id => current_user.friends)
       else
         require_user
         return
index e41330c4b40306e808423796c70bf6ef5053a93f..1ec9ab8d8573412fdaf533a27bbd0b35597061a6 100644 (file)
@@ -388,16 +388,16 @@ class UsersController < ApplicationController
 
     if @new_friend
       if request.post?
-        friend = Friend.new
-        friend.befriender = current_user
-        friend.befriendee = @new_friend
+        friendship = Friendship.new
+        friendship.befriender = current_user
+        friendship.befriendee = @new_friend
         if current_user.is_friends_with?(@new_friend)
           flash[:warning] = t "users.make_friend.already_a_friend", :name => @new_friend.display_name
-        elsif friend.save
+        elsif friendship.save
           flash[:notice] = t "users.make_friend.success", :name => @new_friend.display_name
-          Notifier.friend_notification(friend).deliver_later
+          Notifier.friend_notification(friendship).deliver_later
         else
-          friend.add_error(t("users.make_friend.failed", :name => @new_friend.display_name))
+          friendship.add_error(t("users.make_friend.failed", :name => @new_friend.display_name))
         end
 
         if params[:referer]
@@ -417,7 +417,7 @@ class UsersController < ApplicationController
     if @friend
       if request.post?
         if current_user.is_friends_with?(@friend)
-          Friend.where(:user_id => current_user.id, :friend_user_id => @friend.id).delete_all
+          Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all
           flash[:notice] = t "users.remove_friend.success", :name => @friend.display_name
         else
           flash[:error] = t "users.remove_friend.not_a_friend", :name => @friend.display_name
similarity index 89%
rename from app/models/friend.rb
rename to app/models/friendship.rb
index 615da10767c1a9c08bf9e2895b8859df195ae239..27b25aee1b31313674db1d1578701873c921f160 100644 (file)
@@ -17,7 +17,9 @@
 #  friends_user_id_fkey         (user_id => users.id)
 #
 
-class Friend < ActiveRecord::Base
+class Friendship < ActiveRecord::Base
+  self.table_name = "friends"
+
   belongs_to :befriender, :class_name => "User", :foreign_key => :user_id
   belongs_to :befriendee, :class_name => "User", :foreign_key => :friend_user_id
 end
index 2979b13d75309cb89a392db02df4fdef3fa6dcb0..1d008959905e85a50428c0433c04dbe16799d8a8 100644 (file)
@@ -57,8 +57,8 @@ class User < ActiveRecord::Base
   has_many :messages, -> { where(:to_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :foreign_key => :to_user_id
   has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id
   has_many :sent_messages, -> { where(:from_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :class_name => "Message", :foreign_key => :from_user_id
-  has_many :friends, -> { joins(:befriendee).where(:users => { :status => %w[active confirmed] }) }
-  has_many :friend_users, :through => :friends, :source => :befriendee
+  has_many :friendships, -> { joins(:befriendee).where(:users => { :status => %w[active confirmed] }) }
+  has_many :friends, :through => :friendships, :source => :befriendee
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
   has_many :changesets, -> { order(:created_at => :desc) }
@@ -224,7 +224,7 @@ class User < ActiveRecord::Base
   end
 
   def is_friends_with?(new_friend)
-    friends.where(:friend_user_id => new_friend.id).exists?
+    friendships.where(:befriendee => new_friend).exists?
   end
 
   ##
index 301739eef9cf3ffe19d4b5fd0d0868198772c840..639ac9a191f170e055db979142739c8f179dbb07 100644 (file)
@@ -7,7 +7,7 @@
   </p>
 
   <div class="richtext"><%= diary_comment.body.to_html %></div>
-  <% if current_user && current_user.administrator? %>
+  <% if can? :hidecomment, DiaryEntry %>
     <span>
       <% if diary_comment.visible? %>
         <%= link_to t(".hide_link"), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data => { :confirm => t(".confirm") } %>
index 5674a37b7c4d70f9b0041de822baf5b6ea92fce9..c7dbec38616f8a623382905127af877b0cb67250 100644 (file)
@@ -37,7 +37,7 @@
       </li>
     <% end %>
 
-    <% if current_user && current_user.administrator? %>
+    <% if can? :hide, DiaryEntry %>
       <li>
         <% if diary_entry.visible %>
           <%= link_to t(".hide_link"), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t(".confirm") } %>
index 87eb9b45feb1c44027c7317e679820d79e8334c5..aee000a97b001571d78f45603082afbd08443f7d 100644 (file)
       <%= content_tag "div", "", :id => "map", :class => "content_map", :data => { :user => user_data } %>
     <% end %>
 
-    <% friends = @user.friends.collect(&:befriendee) %>
+    <% friends = @user.friends %>
     <% nearby = @user.nearby - friends %>
 
   <div class="activity-block column-1">
index d7127a4e9321601fc9e25b4000624728de06c871..0281703ab73178bcf4583dabd4bafdeece119600 100644 (file)
@@ -103,6 +103,45 @@ en:
         description: "Description"
         languages: "Languages"
         pass_crypt: "Password"
+  datetime:
+    distance_in_words_ago:
+      about_x_hours:
+        one: about 1 hour ago
+        other: about %{count} hours ago
+      about_x_months:
+        one: about 1 month ago
+        other: about %{count} months ago
+      about_x_years:
+        one: about 1 year ago
+        other: about %{count} years ago
+      almost_x_years:
+        one: almost 1 year ago
+        other: almost %{count} years ago
+      half_a_minute: half a minute ago
+      less_than_x_seconds:
+        one: less than 1 second ago
+        other: less than %{count} seconds ago
+      less_than_x_minutes:
+        one: less than a minute ago
+        other: less than %{count} minutes ago
+      over_x_years:
+        one: over 1 year ago
+        other: over %{count} years ago
+      x_seconds:
+        one: 1 second ago
+        other: "%{count} seconds ago"
+      x_minutes:
+        one: 1 minute ago
+        other: "%{count} minutes ago"
+      x_days:
+        one: 1 day ago
+        other: "%{count} days ago"
+      x_months:
+        one: 1 month ago
+        other: "%{count} months ago"
+      x_years:
+        one: 1 year ago
+        other: "%{count} years ago"
   printable_name:
     with_id: "%{id}"
     with_version: "%{id}, v%{version}"
index f43b6bf50de811b2f5b5fcc66fdca7d82e99b299..99154b4b72cfaeb79ef35019ed4bdb0293f6c174 100644 (file)
@@ -23,7 +23,6 @@ class GuestAbilityTest < AbilityTest
 
     [:create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
       assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
-      assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
     end
   end
 
@@ -54,7 +53,6 @@ class UserAbilityTest < AbilityTest
 
     [:hide, :hidecomment].each do |action|
       assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
-      assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
     end
 
     [:index, :show, :resolve, :ignore, :reopen].each do |action|
@@ -78,6 +76,10 @@ class ModeratorAbilityTest < AbilityTest
     [:grant, :revoke].each do |action|
       assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
     end
+
+    [:hide, :hidecomment].each do |action|
+      assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
+    end
   end
 end
 
@@ -87,10 +89,6 @@ class AdministratorAbilityTest < AbilityTest
     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
     end
-
-    [:hide, :hidecomment].each do |action|
-      assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
-    end
   end
 
   test "User Roles permissions for an administrator" do
index fad7a97d8387d5e5cc6977fea0f59779accc89f0..caf7721cd4ab425e483e7720f9147fc62cc41450 100644 (file)
@@ -130,8 +130,8 @@ class ChangesetsControllerTest < ActionController::TestCase
   # Checks the display of the friends changesets listing
   def test_index_friends
     private_user = create(:user, :data_public => true)
-    friend = create(:friend, :befriender => private_user)
-    create(:changeset, :user => friend.befriendee)
+    friendship = create(:friendship, :befriender => private_user)
+    create(:changeset, :user => friendship.befriendee)
 
     get :index, :params => { :friends => true }
     assert_response :redirect
@@ -147,7 +147,7 @@ class ChangesetsControllerTest < ActionController::TestCase
     assert_response :success
     assert_template "index"
 
-    check_index_result(Changeset.where(:user => private_user.friend_users.identifiable))
+    check_index_result(Changeset.where(:user => private_user.friends.identifiable))
   end
 
   ##
index 2b4230db7a41cfbfdf92cb4a6bcd73fcc611900c..8414e18a704883272a74027021cb799b0b975879 100644 (file)
@@ -528,8 +528,8 @@ class DiaryEntriesControllerTest < ActionController::TestCase
   def test_index_friends
     user = create(:user)
     other_user = create(:user)
-    friend = create(:friend, :befriender => user)
-    diary_entry = create(:diary_entry, :user => friend.befriendee)
+    friendship = create(:friendship, :befriender => user)
+    diary_entry = create(:diary_entry, :user => friendship.befriendee)
     _other_entry = create(:diary_entry, :user => other_user)
 
     # Try a list of diary entries for your friends when not logged in
@@ -733,9 +733,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase
 
   def test_hide
     user = create(:user)
+    diary_entry = create(:diary_entry, :user => user)
 
     # Try without logging in
-    diary_entry = create(:diary_entry, :user => user)
     post :hide,
          :params => { :display_name => user.display_name, :id => diary_entry.id }
     assert_response :forbidden
@@ -749,6 +749,17 @@ class DiaryEntriesControllerTest < ActionController::TestCase
     assert_redirected_to :controller => :errors, :action => :forbidden
     assert_equal true, DiaryEntry.find(diary_entry.id).visible
 
+    # Now try as a moderator
+    post :hide,
+         :params => { :display_name => user.display_name, :id => diary_entry.id },
+         :session => { :user => create(:moderator_user) }
+    assert_response :redirect
+    assert_redirected_to :action => :index, :display_name => user.display_name
+    assert_equal false, DiaryEntry.find(diary_entry.id).visible
+
+    # Reset
+    diary_entry.reload.update(:visible => true)
+
     # Finally try as an administrator
     post :hide,
          :params => { :display_name => user.display_name, :id => diary_entry.id },
@@ -787,9 +798,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase
 
   def test_hidecomment
     user = create(:user)
-    administrator_user = create(:administrator_user)
     diary_entry = create(:diary_entry, :user => user)
     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
+
     # Try without logging in
     post :hidecomment,
          :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }
@@ -804,10 +815,21 @@ class DiaryEntriesControllerTest < ActionController::TestCase
     assert_redirected_to :controller => :errors, :action => :forbidden
     assert_equal true, DiaryComment.find(diary_comment.id).visible
 
+    # Try as a moderator
+    post :hidecomment,
+         :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
+         :session => { :user => create(:moderator_user) }
+    assert_response :redirect
+    assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
+    assert_equal false, DiaryComment.find(diary_comment.id).visible
+
+    # Reset
+    diary_comment.reload.update(:visible => true)
+
     # Finally try as an administrator
     post :hidecomment,
          :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
-         :session => { :user => administrator_user }
+         :session => { :user => create(:administrator_user) }
     assert_response :redirect
     assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
     assert_equal false, DiaryComment.find(diary_comment.id).visible
index 5dbd866a960f6fb74ec423f8bae97822b67c05b5..984ea8d46cce6bfc3fa49a3c1ec752fe2f87c337 100644 (file)
@@ -988,7 +988,7 @@ class UsersControllerTest < ActionController::TestCase
     # Test a normal user
     user = create(:user, :home_lon => 1.1, :home_lat => 1.1)
     friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2)
-    create(:friend, :befriender => user, :befriendee => friend_user)
+    create(:friendship, :befriender => user, :befriendee => friend_user)
     create(:changeset, :user => friend_user)
 
     get :show, :params => { :display_name => user.display_name }
@@ -1113,7 +1113,7 @@ class UsersControllerTest < ActionController::TestCase
     friend = create(:user)
 
     # Check that the users aren't already friends
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When not logged in a GET should ask us to login
     get :make_friend, :params => { :display_name => friend.display_name }
@@ -1122,7 +1122,7 @@ class UsersControllerTest < ActionController::TestCase
     # When not logged in a POST should error
     post :make_friend, :params => { :display_name => friend.display_name }
     assert_response :forbidden
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When logged in a GET should get a confirmation page
     get :make_friend, :params => { :display_name => friend.display_name }, :session => { :user => user }
@@ -1132,7 +1132,7 @@ class UsersControllerTest < ActionController::TestCase
       assert_select "input[type='hidden'][name='referer']", 0
       assert_select "input[type='submit']", 1
     end
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When logged in a POST should add the friendship
     assert_difference "ActionMailer::Base.deliveries.size", 1 do
@@ -1142,7 +1142,7 @@ class UsersControllerTest < ActionController::TestCase
     end
     assert_redirected_to user_path(friend)
     assert_match(/is now your friend/, flash[:notice])
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
     email = ActionMailer::Base.deliveries.first
     assert_equal 1, email.to.count
     assert_equal friend.email, email.to.first
@@ -1156,7 +1156,7 @@ class UsersControllerTest < ActionController::TestCase
     end
     assert_redirected_to user_path(friend)
     assert_match(/You are already friends with/, flash[:warning])
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
   end
 
   def test_make_friend_with_referer
@@ -1165,7 +1165,7 @@ class UsersControllerTest < ActionController::TestCase
     friend = create(:user)
 
     # Check that the users aren't already friends
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
 
     # The GET should preserve any referer
     get :make_friend, :params => { :display_name => friend.display_name, :referer => "/test" }, :session => { :user => user }
@@ -1175,7 +1175,7 @@ class UsersControllerTest < ActionController::TestCase
       assert_select "input[type='hidden'][name='referer'][value='/test']", 1
       assert_select "input[type='submit']", 1
     end
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When logged in a POST should add the friendship and refer us
     assert_difference "ActionMailer::Base.deliveries.size", 1 do
@@ -1185,7 +1185,7 @@ class UsersControllerTest < ActionController::TestCase
     end
     assert_redirected_to "/test"
     assert_match(/is now your friend/, flash[:notice])
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
     email = ActionMailer::Base.deliveries.first
     assert_equal 1, email.to.count
     assert_equal friend.email, email.to.first
@@ -1203,10 +1203,10 @@ class UsersControllerTest < ActionController::TestCase
     # Get users to work with
     user = create(:user)
     friend = create(:user)
-    create(:friend, :befriender => user, :befriendee => friend)
+    create(:friendship, :befriender => user, :befriendee => friend)
 
     # Check that the users are friends
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When not logged in a GET should ask us to login
     get :remove_friend, :params => { :display_name => friend.display_name }
@@ -1215,7 +1215,7 @@ class UsersControllerTest < ActionController::TestCase
     # When not logged in a POST should error
     post :remove_friend, :params => { :display_name => friend.display_name }
     assert_response :forbidden
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When logged in a GET should get a confirmation page
     get :remove_friend, :params => { :display_name => friend.display_name }, :session => { :user => user }
@@ -1225,29 +1225,29 @@ class UsersControllerTest < ActionController::TestCase
       assert_select "input[type='hidden'][name='referer']", 0
       assert_select "input[type='submit']", 1
     end
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When logged in a POST should remove the friendship
     post :remove_friend, :params => { :display_name => friend.display_name }, :session => { :user => user }
     assert_redirected_to user_path(friend)
     assert_match(/was removed from your friends/, flash[:notice])
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
 
     # A second POST should report that the friendship does not exist
     post :remove_friend, :params => { :display_name => friend.display_name }, :session => { :user => user }
     assert_redirected_to user_path(friend)
     assert_match(/is not one of your friends/, flash[:error])
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
   end
 
   def test_remove_friend_with_referer
     # Get users to work with
     user = create(:user)
     friend = create(:user)
-    create(:friend, :user_id => user.id, :friend_user_id => friend.id)
+    create(:friendship, :befriender => user, :befriendee => friend)
 
     # Check that the users are friends
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
 
     # The GET should preserve any referer
     get :remove_friend, :params => { :display_name => friend.display_name, :referer => "/test" }, :session => { :user => user }
@@ -1257,13 +1257,13 @@ class UsersControllerTest < ActionController::TestCase
       assert_select "input[type='hidden'][name='referer'][value='/test']", 1
       assert_select "input[type='submit']", 1
     end
-    assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert Friendship.where(:befriender => user, :befriendee => friend).first
 
     # When logged in a POST should remove the friendship and refer
     post :remove_friend, :params => { :display_name => friend.display_name, :referer => "/test" }, :session => { :user => user }
     assert_redirected_to "/test"
     assert_match(/was removed from your friends/, flash[:notice])
-    assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+    assert_nil Friendship.where(:befriender => user, :befriendee => friend).first
   end
 
   def test_remove_friend_unkown_user
similarity index 83%
rename from test/factories/friends.rb
rename to test/factories/friendships.rb
index 15317ee0cb51e863b66b7cc21ee98d6d13c117e4..4879373a8de63ee47dd042d145a124e079dfede4 100644 (file)
@@ -1,5 +1,5 @@
 FactoryBot.define do
-  factory :friend do
+  factory :friendship do
     association :befriender, :factory => :user
     association :befriendee, :factory => :user
   end
index a17c30deb5eded5191d4e99ff872696d3efc97da..96c6632ffcbcac8e9b85aadac8f91d2901d4cea7 100644 (file)
@@ -105,7 +105,7 @@ class UserTest < ActiveSupport::TestCase
     alice = create(:user, :active)
     bob = create(:user, :active)
     charlie = create(:user, :active)
-    create(:friend, :befriender => alice, :befriendee => bob)
+    create(:friendship, :befriender => alice, :befriendee => bob)
 
     assert alice.is_friends_with?(bob)
     assert_not alice.is_friends_with?(charlie)
@@ -136,16 +136,16 @@ class UserTest < ActiveSupport::TestCase
     assert_equal [], vagrant_user.nearby
   end
 
-  def test_friend_users
+  def test_friends
     norm = create(:user, :active)
     sec = create(:user, :active)
-    create(:friend, :befriender => norm, :befriendee => sec)
+    create(:friendship, :befriender => norm, :befriendee => sec)
 
-    assert_equal [sec], norm.friend_users
-    assert_equal 1, norm.friend_users.size
+    assert_equal [sec], norm.friends
+    assert_equal 1, norm.friends.size
 
-    assert_equal [], sec.friend_users
-    assert_equal 0, sec.friend_users.size
+    assert_equal [], sec.friends
+    assert_equal 0, sec.friends.size
   end
 
   def test_user_preferred_editor