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
|
# MethodDefinitionMacros: define_method, define_singleton_method
|
||||||
Naming/PredicateName:
|
Naming/PredicateName:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/models/changeset.rb'
|
|
||||||
- 'app/models/old_node.rb'
|
|
||||||
- 'app/models/old_relation.rb'
|
|
||||||
- 'app/models/old_way.rb'
|
|
||||||
- 'app/models/user.rb'
|
- 'app/models/user.rb'
|
||||||
- 'lib/classic_pagination/pagination.rb'
|
|
||||||
|
|
||||||
# Offense count: 5
|
# Offense count: 5
|
||||||
# Configuration parameters: Database, Include.
|
# Configuration parameters: Database, Include.
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Api
|
||||||
|
|
||||||
# Find the changeset and check it is valid
|
# Find the changeset and check it is valid
|
||||||
changeset = Changeset.find(id)
|
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
|
# Add a comment to the changeset
|
||||||
comment = changeset.comments.create(:changeset => changeset,
|
comment = changeset.comments.create(:changeset => changeset,
|
||||||
|
|
|
@ -17,7 +17,7 @@ class FriendshipsController < ApplicationController
|
||||||
friendship = Friendship.new
|
friendship = Friendship.new
|
||||||
friendship.befriender = current_user
|
friendship.befriender = current_user
|
||||||
friendship.befriendee = @new_friend
|
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
|
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
|
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"
|
flash.now[:error] = t "friendships.make_friend.limit_exceeded"
|
||||||
|
@ -42,7 +42,7 @@ class FriendshipsController < ApplicationController
|
||||||
|
|
||||||
if @friend
|
if @friend
|
||||||
if request.post?
|
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
|
Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all
|
||||||
flash[:notice] = t "friendships.remove_friend.success", :name => @friend.display_name
|
flash[:notice] = t "friendships.remove_friend.success", :name => @friend.display_name
|
||||||
else
|
else
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Changeset < ApplicationRecord
|
||||||
# Use a method like this, so that we can easily change how we
|
# Use a method like this, so that we can easily change how we
|
||||||
# determine whether a changeset is open, without breaking code in at
|
# determine whether a changeset is open, without breaking code in at
|
||||||
# least 6 controllers
|
# least 6 controllers
|
||||||
def is_open?
|
def open?
|
||||||
# a changeset is open (that is, it will accept further changes) when
|
# 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.
|
# 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
|
# note that this may not be a hard limit - due to timing changes and
|
||||||
|
@ -75,7 +75,7 @@ class Changeset < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_closed_time_now
|
def set_closed_time_now
|
||||||
self.closed_at = Time.now.utc if is_open?
|
self.closed_at = Time.now.utc if open?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_xml(xml, create: false)
|
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)
|
@bbox ||= BoundingBox.new(min_lon, min_lat, max_lon, max_lat)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_valid_bbox?
|
def bbox_valid?
|
||||||
bbox.complete?
|
bbox.complete?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ class Changeset < ApplicationRecord
|
||||||
# that would make it more than 24h long, in which case clip to
|
# that would make it more than 24h long, in which case clip to
|
||||||
# 24h, as this has been decided is a reasonable time limit.
|
# 24h, as this has been decided is a reasonable time limit.
|
||||||
def update_closed_at
|
def update_closed_at
|
||||||
if is_open?
|
if open?
|
||||||
self.closed_at = if (closed_at - created_at) > (MAX_TIME_OPEN - IDLE_TIMEOUT)
|
self.closed_at = if (closed_at - created_at) > (MAX_TIME_OPEN - IDLE_TIMEOUT)
|
||||||
created_at + MAX_TIME_OPEN
|
created_at + MAX_TIME_OPEN
|
||||||
else
|
else
|
||||||
|
@ -205,7 +205,7 @@ class Changeset < ApplicationRecord
|
||||||
raise OSM::APIUserChangesetMismatchError unless user.id == user_id
|
raise OSM::APIUserChangesetMismatchError unless user.id == user_id
|
||||||
|
|
||||||
# can't change a closed changeset
|
# can't change a closed changeset
|
||||||
raise OSM::APIChangesetAlreadyClosedError, self unless is_open?
|
raise OSM::APIChangesetAlreadyClosedError, self unless open?
|
||||||
|
|
||||||
# copy the other's tags
|
# copy the other's tags
|
||||||
self.tags = other.tags
|
self.tags = other.tags
|
||||||
|
|
|
@ -16,7 +16,7 @@ module ConsistencyValidations
|
||||||
raise OSM::APIChangesetMissingError
|
raise OSM::APIChangesetMissingError
|
||||||
elsif new.changeset.user_id != user.id
|
elsif new.changeset.user_id != user.id
|
||||||
raise OSM::APIUserChangesetMismatchError
|
raise OSM::APIUserChangesetMismatchError
|
||||||
elsif !new.changeset.is_open?
|
elsif !new.changeset.open?
|
||||||
raise OSM::APIChangesetAlreadyClosedError, new.changeset
|
raise OSM::APIChangesetAlreadyClosedError, new.changeset
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ module ConsistencyValidations
|
||||||
raise OSM::APIChangesetMissingError
|
raise OSM::APIChangesetMissingError
|
||||||
elsif new.changeset.user_id != user.id
|
elsif new.changeset.user_id != user.id
|
||||||
raise OSM::APIUserChangesetMismatchError
|
raise OSM::APIUserChangesetMismatchError
|
||||||
elsif !new.changeset.is_open?
|
elsif !new.changeset.open?
|
||||||
raise OSM::APIChangesetAlreadyClosedError, new.changeset
|
raise OSM::APIChangesetAlreadyClosedError, new.changeset
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,7 @@ module ConsistencyValidations
|
||||||
raise OSM::APIChangesetMissingError
|
raise OSM::APIChangesetMissingError
|
||||||
elsif user.id != changeset.user_id
|
elsif user.id != changeset.user_id
|
||||||
raise OSM::APIUserChangesetMismatchError
|
raise OSM::APIUserChangesetMismatchError
|
||||||
elsif !changeset.is_open?
|
elsif !changeset.open?
|
||||||
raise OSM::APIChangesetAlreadyClosedError, changeset
|
raise OSM::APIChangesetAlreadyClosedError, changeset
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Redactable
|
||||||
|
|
||||||
def redact!(redaction)
|
def redact!(redaction)
|
||||||
# check that this version isn't the current version
|
# 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
|
# make the change
|
||||||
self.redaction = redaction
|
self.redaction = redaction
|
||||||
|
|
|
@ -103,7 +103,7 @@ class OldNode < ApplicationRecord
|
||||||
|
|
||||||
# check whether this element is the latest version - that is,
|
# check whether this element is the latest version - that is,
|
||||||
# has the same version as its "current" counterpart.
|
# has the same version as its "current" counterpart.
|
||||||
def is_latest_version?
|
def latest_version?
|
||||||
current_node.version == version
|
current_node.version == version
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,7 +99,7 @@ class OldRelation < ApplicationRecord
|
||||||
|
|
||||||
# check whether this element is the latest version - that is,
|
# check whether this element is the latest version - that is,
|
||||||
# has the same version as its "current" counterpart.
|
# has the same version as its "current" counterpart.
|
||||||
def is_latest_version?
|
def latest_version?
|
||||||
current_relation.version == version
|
current_relation.version == version
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,7 +97,7 @@ class OldWay < ApplicationRecord
|
||||||
|
|
||||||
# check whether this element is the latest version - that is,
|
# check whether this element is the latest version - that is,
|
||||||
# has the same version as its "current" counterpart.
|
# has the same version as its "current" counterpart.
|
||||||
def is_latest_version?
|
def latest_version?
|
||||||
current_way.version == version
|
current_way.version == version
|
||||||
end
|
end
|
||||||
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)
|
OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon)
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_friends_with?(new_friend)
|
def friends_with?(new_friend)
|
||||||
friendships.exists?(:befriendee => new_friend)
|
friendships.exists?(:befriendee => new_friend)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
attrs = {
|
attrs = {
|
||||||
"id" => changeset.id,
|
"id" => changeset.id,
|
||||||
"created_at" => changeset.created_at.xmlschema,
|
"created_at" => changeset.created_at.xmlschema,
|
||||||
"open" => changeset.is_open?,
|
"open" => changeset.open?,
|
||||||
"comments_count" => changeset.comments.length,
|
"comments_count" => changeset.comments.length,
|
||||||
"changes_count" => changeset.num_changes
|
"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?
|
changeset.bbox.to_unscaled.add_bounds_to(attrs, "_") if changeset.bbox.complete?
|
||||||
|
|
||||||
# user attributes
|
# user attributes
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
<% unless @changeset.is_open? %>
|
<% unless @changeset.open? %>
|
||||||
<form action="#" class="mb-3">
|
<form action="#" class="mb-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<textarea class="form-control" name="text" cols="40" rows="5"></textarea>
|
<textarea class="form-control" name="text" cols="40" rows="5"></textarea>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<% changeset_data = { :id => changeset.id }
|
<% changeset_data = { :id => changeset.id }
|
||||||
|
|
||||||
if changeset.has_valid_bbox?
|
if changeset.bbox_valid?
|
||||||
bbox = changeset.bbox.to_unscaled
|
bbox = changeset.bbox.to_unscaled
|
||||||
changeset_data[:bbox] = {
|
changeset_data[:bbox] = {
|
||||||
:minlon => bbox.min_lon,
|
:minlon => bbox.min_lon,
|
||||||
|
|
|
@ -72,7 +72,7 @@ atom_feed(:language => I18n.locale, :schema_date => 2009,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if changeset.has_valid_bbox?
|
if changeset.bbox_valid?
|
||||||
bbox = changeset.bbox.to_unscaled
|
bbox = changeset.bbox.to_unscaled
|
||||||
|
|
||||||
# See http://georss.org/Encodings#Geometry
|
# See http://georss.org/Encodings#Geometry
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<ul class='clearfix text-muted'>
|
<ul class='clearfix text-muted'>
|
||||||
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
||||||
<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 %>
|
<%= link_to t("users.show.remove as friend"), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t("users.show.add as friend"), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
<%= 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 %>
|
<%= message_body do %>
|
||||||
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>
|
<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>
|
<p><%= t ".befriend_them_html", :befriendurl => link_to(@friendurl, @friendurl) %></p>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
<%= t '.see_their_profile', :userurl => @viewurl %>
|
<%= 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 %>
|
<%= t '.befriend_them', :befriendurl => @friendurl %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
<%= link_to t(".comments"), diary_comments_path(@user) %>
|
<%= link_to t(".comments"), diary_comments_path(@user) %>
|
||||||
</li>
|
</li>
|
||||||
<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 %>
|
<%= link_to t(".remove as friend"), remove_friend_path(:display_name => @user.display_name), :method => :post %>
|
||||||
<% elsif current_user %>
|
<% elsif current_user %>
|
||||||
<%= link_to t(".add as friend"), make_friend_path(:display_name => @user.display_name), :method => :post %>
|
<%= 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
|
raise ArgumentError, "Page/Paginator mismatch" if page.is_a?(Page) && page.paginator != self
|
||||||
|
|
||||||
page = page.to_i
|
page = page.to_i
|
||||||
@current_page_number = has_page_number?(page) ? page : 1
|
@current_page_number = contains_page?(page) ? page : 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a Page object representing this paginator's current page.
|
# Returns a Page object representing this paginator's current page.
|
||||||
|
@ -277,7 +277,7 @@ module ActionController
|
||||||
alias length page_count
|
alias length page_count
|
||||||
|
|
||||||
# Returns true if this paginator contains the page of index +number+.
|
# 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
|
number >= 1 && number <= page_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ module ActionController
|
||||||
def initialize(paginator, number)
|
def initialize(paginator, number)
|
||||||
@paginator = paginator
|
@paginator = paginator
|
||||||
@number = number.to_i
|
@number = number.to_i
|
||||||
@number = 1 unless @paginator.has_page_number? @number
|
@number = 1 unless @paginator.contains_page? @number
|
||||||
end
|
end
|
||||||
attr_reader :paginator, :number
|
attr_reader :paginator, :number
|
||||||
|
|
||||||
|
@ -399,12 +399,12 @@ module ActionController
|
||||||
def padding=(padding)
|
def padding=(padding)
|
||||||
@padding = padding.negative? ? 0 : padding
|
@padding = padding.negative? ? 0 : padding
|
||||||
# Find the beginning and end pages of the window
|
# 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]
|
@paginator[@page.number - @padding]
|
||||||
else
|
else
|
||||||
@paginator.first
|
@paginator.first
|
||||||
end
|
end
|
||||||
@last = if @paginator.has_page_number?(@page.number + @padding)
|
@last = if @paginator.contains_page?(@page.number + @padding)
|
||||||
@paginator[@page.number + @padding]
|
@paginator[@page.number + @padding]
|
||||||
else
|
else
|
||||||
@paginator.last
|
@paginator.last
|
||||||
|
|
|
@ -205,7 +205,7 @@ module Api
|
||||||
|
|
||||||
# test that it really is closed now
|
# test that it really is closed now
|
||||||
cs = Changeset.find(changeset.id)
|
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}.")
|
"changeset should be closed now (#{cs.closed_at} > #{Time.now.utc}.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1743,7 +1743,7 @@ module Api
|
||||||
assert_equal Changeset::MAX_ELEMENTS + 1, changeset.num_changes
|
assert_equal Changeset::MAX_ELEMENTS + 1, changeset.num_changes
|
||||||
|
|
||||||
# check that the changeset is now closed as well
|
# 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 " \
|
"changeset should have been auto-closed by exceeding " \
|
||||||
"element limit.")
|
"element limit.")
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,12 +97,12 @@ class UserTest < ActiveSupport::TestCase
|
||||||
charlie = create(:user, :active)
|
charlie = create(:user, :active)
|
||||||
create(:friendship, :befriender => alice, :befriendee => bob)
|
create(:friendship, :befriender => alice, :befriendee => bob)
|
||||||
|
|
||||||
assert alice.is_friends_with?(bob)
|
assert alice.friends_with?(bob)
|
||||||
assert_not alice.is_friends_with?(charlie)
|
assert_not alice.friends_with?(charlie)
|
||||||
assert_not bob.is_friends_with?(alice)
|
assert_not bob.friends_with?(alice)
|
||||||
assert_not bob.is_friends_with?(charlie)
|
assert_not bob.friends_with?(charlie)
|
||||||
assert_not charlie.is_friends_with?(bob)
|
assert_not charlie.friends_with?(bob)
|
||||||
assert_not charlie.is_friends_with?(alice)
|
assert_not charlie.friends_with?(alice)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_users_nearby
|
def test_users_nearby
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue