Fix some rubocop Naming/PredicateName warnings
This commit is contained in:
parent
aef7439c56
commit
cbcc7dc49f
21 changed files with 38 additions and 43 deletions
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
<% end %>
|
||||
|
||||
<% if current_user %>
|
||||
<% unless @changeset.is_open? %>
|
||||
<% unless @changeset.open? %>
|
||||
<form action="#" class="mb-3">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" name="text" cols="40" rows="5"></textarea>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<ul class='clearfix text-muted'>
|
||||
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
||||
<li>
|
||||
<% 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 %>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<%= message_body do %>
|
||||
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>
|
||||
|
||||
<% unless @friendship.befriendee.is_friends_with?(@friendship.befriender) -%>
|
||||
<% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%>
|
||||
<p><%= t ".befriend_them_html", :befriendurl => link_to(@friendurl, @friendurl) %></p>
|
||||
<% end -%>
|
||||
<% end %>
|
||||
|
|
|
@ -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 -%>
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<%= link_to t(".comments"), diary_comments_path(@user) %>
|
||||
</li>
|
||||
<li>
|
||||
<% 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 %>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue