From cbcc7dc49f83f60489fde04b0750cf081e7439fb Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 3 Mar 2022 22:47:55 +0000 Subject: [PATCH] Fix some rubocop Naming/PredicateName warnings --- .rubocop_todo.yml | 5 ----- app/controllers/api/changeset_comments_controller.rb | 2 +- app/controllers/friendships_controller.rb | 4 ++-- app/models/changeset.rb | 10 +++++----- app/models/concerns/consistency_validations.rb | 6 +++--- app/models/concerns/redactable.rb | 2 +- app/models/old_node.rb | 2 +- app/models/old_relation.rb | 2 +- app/models/old_way.rb | 2 +- app/models/user.rb | 2 +- app/views/api/changesets/_changeset.builder | 4 ++-- app/views/browse/changeset.html.erb | 2 +- app/views/changesets/_changeset.html.erb | 2 +- app/views/changesets/index.atom.builder | 2 +- app/views/dashboards/_contact.html.erb | 2 +- .../user_mailer/friendship_notification.html.erb | 2 +- .../user_mailer/friendship_notification.text.erb | 2 +- app/views/users/show.html.erb | 2 +- lib/classic_pagination/pagination.rb | 10 +++++----- test/controllers/api/changesets_controller_test.rb | 4 ++-- test/models/user_test.rb | 12 ++++++------ 21 files changed, 38 insertions(+), 43 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b8e782553..95e3be8fe 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -123,12 +123,7 @@ Naming/AccessorMethodName: # MethodDefinitionMacros: define_method, define_singleton_method Naming/PredicateName: Exclude: - - 'app/models/changeset.rb' - - 'app/models/old_node.rb' - - 'app/models/old_relation.rb' - - 'app/models/old_way.rb' - 'app/models/user.rb' - - 'lib/classic_pagination/pagination.rb' # Offense count: 5 # Configuration parameters: Database, Include. diff --git a/app/controllers/api/changeset_comments_controller.rb b/app/controllers/api/changeset_comments_controller.rb index a3a13b926..4cd33a92b 100644 --- a/app/controllers/api/changeset_comments_controller.rb +++ b/app/controllers/api/changeset_comments_controller.rb @@ -23,7 +23,7 @@ module Api # Find the changeset and check it is valid changeset = Changeset.find(id) - raise OSM::APIChangesetNotYetClosedError, changeset if changeset.is_open? + raise OSM::APIChangesetNotYetClosedError, changeset if changeset.open? # Add a comment to the changeset comment = changeset.comments.create(:changeset => changeset, diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index a08ce0b69..5bfce7f0b 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -17,7 +17,7 @@ class FriendshipsController < ApplicationController friendship = Friendship.new friendship.befriender = current_user friendship.befriendee = @new_friend - if current_user.is_friends_with?(@new_friend) + if current_user.friends_with?(@new_friend) flash[:warning] = t "friendships.make_friend.already_a_friend", :name => @new_friend.display_name elsif current_user.friendships.where("created_at >= ?", Time.now.utc - 1.hour).count >= current_user.max_friends_per_hour flash.now[:error] = t "friendships.make_friend.limit_exceeded" @@ -42,7 +42,7 @@ class FriendshipsController < ApplicationController if @friend if request.post? - if current_user.is_friends_with?(@friend) + if current_user.friends_with?(@friend) Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all flash[:notice] = t "friendships.remove_friend.success", :name => @friend.display_name else diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 2659eaeea..f23a4e356 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -65,7 +65,7 @@ class Changeset < ApplicationRecord # Use a method like this, so that we can easily change how we # determine whether a changeset is open, without breaking code in at # least 6 controllers - def is_open? + def open? # a changeset is open (that is, it will accept further changes) when # it has not yet run out of time and its capacity is small enough. # note that this may not be a hard limit - due to timing changes and @@ -75,7 +75,7 @@ class Changeset < ApplicationRecord end def set_closed_time_now - self.closed_at = Time.now.utc if is_open? + self.closed_at = Time.now.utc if open? end def self.from_xml(xml, create: false) @@ -120,7 +120,7 @@ class Changeset < ApplicationRecord @bbox ||= BoundingBox.new(min_lon, min_lat, max_lon, max_lat) end - def has_valid_bbox? + def bbox_valid? bbox.complete? end @@ -187,7 +187,7 @@ class Changeset < ApplicationRecord # that would make it more than 24h long, in which case clip to # 24h, as this has been decided is a reasonable time limit. def update_closed_at - if is_open? + if open? self.closed_at = if (closed_at - created_at) > (MAX_TIME_OPEN - IDLE_TIMEOUT) created_at + MAX_TIME_OPEN else @@ -205,7 +205,7 @@ class Changeset < ApplicationRecord raise OSM::APIUserChangesetMismatchError unless user.id == user_id # can't change a closed changeset - raise OSM::APIChangesetAlreadyClosedError, self unless is_open? + raise OSM::APIChangesetAlreadyClosedError, self unless open? # copy the other's tags self.tags = other.tags diff --git a/app/models/concerns/consistency_validations.rb b/app/models/concerns/consistency_validations.rb index 8c89f61de..101fd4310 100644 --- a/app/models/concerns/consistency_validations.rb +++ b/app/models/concerns/consistency_validations.rb @@ -16,7 +16,7 @@ module ConsistencyValidations raise OSM::APIChangesetMissingError elsif new.changeset.user_id != user.id raise OSM::APIUserChangesetMismatchError - elsif !new.changeset.is_open? + elsif !new.changeset.open? raise OSM::APIChangesetAlreadyClosedError, new.changeset end end @@ -27,7 +27,7 @@ module ConsistencyValidations raise OSM::APIChangesetMissingError elsif new.changeset.user_id != user.id raise OSM::APIUserChangesetMismatchError - elsif !new.changeset.is_open? + elsif !new.changeset.open? raise OSM::APIChangesetAlreadyClosedError, new.changeset end end @@ -42,7 +42,7 @@ module ConsistencyValidations raise OSM::APIChangesetMissingError elsif user.id != changeset.user_id raise OSM::APIUserChangesetMismatchError - elsif !changeset.is_open? + elsif !changeset.open? raise OSM::APIChangesetAlreadyClosedError, changeset end end diff --git a/app/models/concerns/redactable.rb b/app/models/concerns/redactable.rb index ccf04907f..3a1ccf8b7 100644 --- a/app/models/concerns/redactable.rb +++ b/app/models/concerns/redactable.rb @@ -11,7 +11,7 @@ module Redactable def redact!(redaction) # check that this version isn't the current version - raise OSM::APICannotRedactError if is_latest_version? + raise OSM::APICannotRedactError if latest_version? # make the change self.redaction = redaction diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 4f5f074ab..077039ac3 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -103,7 +103,7 @@ class OldNode < ApplicationRecord # check whether this element is the latest version - that is, # has the same version as its "current" counterpart. - def is_latest_version? + def latest_version? current_node.version == version end end diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 7f9a747e6..c36d64572 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -99,7 +99,7 @@ class OldRelation < ApplicationRecord # check whether this element is the latest version - that is, # has the same version as its "current" counterpart. - def is_latest_version? + def latest_version? current_relation.version == version end end diff --git a/app/models/old_way.rb b/app/models/old_way.rb index acf88ddcf..fcff84ede 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -97,7 +97,7 @@ class OldWay < ApplicationRecord # check whether this element is the latest version - that is, # has the same version as its "current" counterpart. - def is_latest_version? + def latest_version? current_way.version == version end end diff --git a/app/models/user.rb b/app/models/user.rb index e7e077a9b..d357dc4f5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -258,7 +258,7 @@ class User < ApplicationRecord OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon) end - def is_friends_with?(new_friend) + def friends_with?(new_friend) friendships.exists?(:befriendee => new_friend) end diff --git a/app/views/api/changesets/_changeset.builder b/app/views/api/changesets/_changeset.builder index 292184196..e0188a10e 100644 --- a/app/views/api/changesets/_changeset.builder +++ b/app/views/api/changesets/_changeset.builder @@ -3,11 +3,11 @@ attrs = { "id" => changeset.id, "created_at" => changeset.created_at.xmlschema, - "open" => changeset.is_open?, + "open" => changeset.open?, "comments_count" => changeset.comments.length, "changes_count" => changeset.num_changes } -attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.is_open? +attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.open? changeset.bbox.to_unscaled.add_bounds_to(attrs, "_") if changeset.bbox.complete? # user attributes diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index 6aa0f11fb..ca27862c8 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -73,7 +73,7 @@ <% end %> <% if current_user %> - <% unless @changeset.is_open? %> + <% unless @changeset.open? %>
diff --git a/app/views/changesets/_changeset.html.erb b/app/views/changesets/_changeset.html.erb index 714cd14b5..a47a99d33 100644 --- a/app/views/changesets/_changeset.html.erb +++ b/app/views/changesets/_changeset.html.erb @@ -1,6 +1,6 @@ <% changeset_data = { :id => changeset.id } - if changeset.has_valid_bbox? + if changeset.bbox_valid? bbox = changeset.bbox.to_unscaled changeset_data[:bbox] = { :minlon => bbox.min_lon, diff --git a/app/views/changesets/index.atom.builder b/app/views/changesets/index.atom.builder index 7fd9b5dd2..3ab438b59 100644 --- a/app/views/changesets/index.atom.builder +++ b/app/views/changesets/index.atom.builder @@ -72,7 +72,7 @@ atom_feed(:language => I18n.locale, :schema_date => 2009, end end - if changeset.has_valid_bbox? + if changeset.bbox_valid? bbox = changeset.bbox.to_unscaled # See http://georss.org/Encodings#Geometry diff --git a/app/views/dashboards/_contact.html.erb b/app/views/dashboards/_contact.html.erb index 77363dbdb..7785c0552 100644 --- a/app/views/dashboards/_contact.html.erb +++ b/app/views/dashboards/_contact.html.erb @@ -37,7 +37,7 @@
  • <%= link_to t("users.show.send message"), new_message_path(contact) %>
  • - <% if current_user.is_friends_with?(contact) %> + <% if current_user.friends_with?(contact) %> <%= link_to t("users.show.remove as friend"), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %> <% else %> <%= link_to t("users.show.add as friend"), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %> diff --git a/app/views/user_mailer/friendship_notification.html.erb b/app/views/user_mailer/friendship_notification.html.erb index 0f2353150..ee2dea2eb 100644 --- a/app/views/user_mailer/friendship_notification.html.erb +++ b/app/views/user_mailer/friendship_notification.html.erb @@ -3,7 +3,7 @@ <%= message_body do %>

    <%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %>

    - <% unless @friendship.befriendee.is_friends_with?(@friendship.befriender) -%> + <% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%>

    <%= t ".befriend_them_html", :befriendurl => link_to(@friendurl, @friendurl) %>

    <% end -%> <% end %> diff --git a/app/views/user_mailer/friendship_notification.text.erb b/app/views/user_mailer/friendship_notification.text.erb index da859d31c..22c2bbfe7 100644 --- a/app/views/user_mailer/friendship_notification.text.erb +++ b/app/views/user_mailer/friendship_notification.text.erb @@ -2,6 +2,6 @@ <%= t '.see_their_profile', :userurl => @viewurl %> -<% unless @friendship.befriendee.is_friends_with?(@friendship.befriender) -%> +<% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%> <%= t '.befriend_them', :befriendurl => @friendurl %> <% end -%> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 8987785da..4dcc9ab05 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -78,7 +78,7 @@ <%= link_to t(".comments"), diary_comments_path(@user) %>
  • - <% if current_user and current_user.is_friends_with?(@user) %> + <% if current_user and current_user.friends_with?(@user) %> <%= link_to t(".remove as friend"), remove_friend_path(:display_name => @user.display_name), :method => :post %> <% elsif current_user %> <%= link_to t(".add as friend"), make_friend_path(:display_name => @user.display_name), :method => :post %> diff --git a/lib/classic_pagination/pagination.rb b/lib/classic_pagination/pagination.rb index 511228636..c7022e0b0 100644 --- a/lib/classic_pagination/pagination.rb +++ b/lib/classic_pagination/pagination.rb @@ -243,7 +243,7 @@ module ActionController raise ArgumentError, "Page/Paginator mismatch" if page.is_a?(Page) && page.paginator != self page = page.to_i - @current_page_number = has_page_number?(page) ? page : 1 + @current_page_number = contains_page?(page) ? page : 1 end # Returns a Page object representing this paginator's current page. @@ -277,7 +277,7 @@ module ActionController alias length page_count # Returns true if this paginator contains the page of index +number+. - def has_page_number?(number) + def contains_page?(number) number >= 1 && number <= page_count end @@ -304,7 +304,7 @@ module ActionController def initialize(paginator, number) @paginator = paginator @number = number.to_i - @number = 1 unless @paginator.has_page_number? @number + @number = 1 unless @paginator.contains_page? @number end attr_reader :paginator, :number @@ -399,12 +399,12 @@ module ActionController def padding=(padding) @padding = padding.negative? ? 0 : padding # Find the beginning and end pages of the window - @first = if @paginator.has_page_number?(@page.number - @padding) + @first = if @paginator.contains_page?(@page.number - @padding) @paginator[@page.number - @padding] else @paginator.first end - @last = if @paginator.has_page_number?(@page.number + @padding) + @last = if @paginator.contains_page?(@page.number + @padding) @paginator[@page.number + @padding] else @paginator.last diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index e61831fbd..3b4eef25a 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -205,7 +205,7 @@ module Api # test that it really is closed now cs = Changeset.find(changeset.id) - assert_not(cs.is_open?, + assert_not(cs.open?, "changeset should be closed now (#{cs.closed_at} > #{Time.now.utc}.") end @@ -1743,7 +1743,7 @@ module Api assert_equal Changeset::MAX_ELEMENTS + 1, changeset.num_changes # check that the changeset is now closed as well - assert_not(changeset.is_open?, + assert_not(changeset.open?, "changeset should have been auto-closed by exceeding " \ "element limit.") end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index f35cdd23f..644283e84 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -97,12 +97,12 @@ class UserTest < ActiveSupport::TestCase charlie = create(:user, :active) create(:friendship, :befriender => alice, :befriendee => bob) - assert alice.is_friends_with?(bob) - assert_not alice.is_friends_with?(charlie) - assert_not bob.is_friends_with?(alice) - assert_not bob.is_friends_with?(charlie) - assert_not charlie.is_friends_with?(bob) - assert_not charlie.is_friends_with?(alice) + assert alice.friends_with?(bob) + assert_not alice.friends_with?(charlie) + assert_not bob.friends_with?(alice) + assert_not bob.friends_with?(charlie) + assert_not charlie.friends_with?(bob) + assert_not charlie.friends_with?(alice) end def test_users_nearby -- 2.39.5