# 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.
# 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,
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"
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
# 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
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)
@bbox ||= BoundingBox.new(min_lon, min_lat, max_lon, max_lat)
end
- def has_valid_bbox?
+ def bbox_valid?
bbox.complete?
end
# 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
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
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
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
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
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
# 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
# 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
# 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
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
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
<% 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>
<% 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,
end
end
- if changeset.has_valid_bbox?
+ if changeset.bbox_valid?
bbox = changeset.bbox.to_unscaled
# See http://georss.org/Encodings#Geometry
<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 %>
<%= 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 %>
<%= 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 -%>
<%= 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 %>
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.
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
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
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
# 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
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
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