Replace deprecated finder methods
This commit is contained in:
parent
d8399d3e18
commit
6c51b3cc0a
7 changed files with 32 additions and 19 deletions
|
@ -151,9 +151,9 @@ class ApiController < ApplicationController
|
|||
# find which ways are needed
|
||||
ways = Array.new
|
||||
if node_ids.length > 0
|
||||
way_nodes = WayNode.find_all_by_node_id(node_ids)
|
||||
way_nodes = WayNode.where(:node_id => node_ids)
|
||||
way_ids = way_nodes.collect { |way_node| way_node.id[0] }
|
||||
ways = Way.find(way_ids, :include => [:way_nodes, :way_tags])
|
||||
ways = Way.preload(:way_nodes, :way_tags).find(way_ids)
|
||||
|
||||
list_of_way_nodes = ways.collect { |way|
|
||||
way.way_nodes.collect { |way_node| way_node.node_id }
|
||||
|
|
|
@ -27,7 +27,7 @@ class BrowseController < ApplicationController
|
|||
|
||||
def way
|
||||
@type = "way"
|
||||
@way = Way.find(params[:id], :include => [:way_tags, {:changeset => :user}, {:nodes => [:node_tags, {:ways => :way_tags}]}, :containing_relation_members])
|
||||
@way = Way.preload(:way_tags, :containing_relation_members, :changeset => :user, :nodes => [:node_tags, :ways => :way_tags]).find(params[:id])
|
||||
@next = Way.visible.where("id > ?", @way.id).order("id ASC").first
|
||||
@prev = Way.visible.where("id < ?", @way.id).order("id DESC").first
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
|
@ -36,7 +36,7 @@ class BrowseController < ApplicationController
|
|||
|
||||
def way_history
|
||||
@type = "way"
|
||||
@way = Way.find(params[:id], :include => [:way_tags, {:old_ways => {:changeset => :user}}])
|
||||
@way = Way.preload(:way_tags, :old_ways => { :changeset => :user }).find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :action => "not_found", :status => :not_found
|
||||
end
|
||||
|
|
|
@ -279,7 +279,7 @@ class NotesController < ApplicationController
|
|||
@description = t 'note.mine.subheading', :user => render_to_string(:partial => "user", :object => @this_user)
|
||||
@page = (params[:page] || 1).to_i
|
||||
@page_size = 10
|
||||
@notes = @this_user.notes.order("updated_at DESC, id").uniq.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author).all
|
||||
@notes = @this_user.notes.order("updated_at DESC, id").uniq.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author).to_a
|
||||
else
|
||||
@title = t 'user.no_such_user.title'
|
||||
@not_found_user = params[:display_name]
|
||||
|
|
|
@ -173,21 +173,34 @@ module ActionController
|
|||
# the +model+ and given +conditions+. Override this method to implement a
|
||||
# custom counter.
|
||||
def count_collection_for_pagination(model, options)
|
||||
model.count(:conditions => options[:conditions],
|
||||
:joins => options[:join] || options[:joins],
|
||||
:include => options[:include],
|
||||
:select => (options[:group] ? "DISTINCT #{options[:group]}" : options[:count]))
|
||||
collection = model.joins(options[:join] || options[:joins])
|
||||
collection = collection.where(options[:conditions])
|
||||
collection = collection.includes(options[:include])
|
||||
|
||||
if options[:group]
|
||||
collection = collection.select(options[:group]).distinct
|
||||
elsif options[:count]
|
||||
collection = collection.select(options[:count])
|
||||
end
|
||||
|
||||
collection.count
|
||||
end
|
||||
|
||||
# Returns a collection of items for the given +model+ and +options[conditions]+,
|
||||
# ordered by +options[order]+, for the current page in the given +paginator+.
|
||||
# Override this method to implement a custom finder.
|
||||
def find_collection_for_pagination(model, options, paginator)
|
||||
model.find(:all, :conditions => options[:conditions],
|
||||
:order => options[:order_by] || options[:order],
|
||||
:joins => options[:join] || options[:joins], :include => options[:include],
|
||||
:select => options[:select], :limit => options[:per_page],
|
||||
:group => options[:group], :offset => paginator.current.offset)
|
||||
collection = model.joins(options[:join] || options[:joins])
|
||||
collection = collection.where(options[:conditions])
|
||||
collection = collection.order(options[:order_by] || options[:order])
|
||||
collection = collection.includes(options[:include])
|
||||
collection = collection.group(options[:group])
|
||||
|
||||
if options[:select]
|
||||
collection = collection.select(options[:select])
|
||||
end
|
||||
|
||||
collection.offset(paginator.current.offset).limit(options[:per_page])
|
||||
end
|
||||
|
||||
protected :create_paginators_and_retrieve_collections,
|
||||
|
|
|
@ -416,7 +416,7 @@ class AmfControllerTest < ActionController::TestCase
|
|||
assert_equal 0, current_node.tags.size, "There seems to be a tag that has been added to the node"
|
||||
assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
|
||||
# Now check the history table
|
||||
historic_nodes = Node.find(:all, :conditions => { :id => result[3] })
|
||||
historic_nodes = Node.where(:id => result[3])
|
||||
assert_equal 1, historic_nodes.size, "There should only be one historic node created"
|
||||
first_historic_node = historic_nodes.first
|
||||
assert_in_delta lat, first_historic_node.lat, 0.00001, "The latitude was not retreived correctly"
|
||||
|
@ -456,7 +456,7 @@ class AmfControllerTest < ActionController::TestCase
|
|||
assert_equal({ "key" => "value", "ping" => "pong" }, current_node.tags, "tags are different")
|
||||
assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
|
||||
# Now check the history table
|
||||
historic_nodes = Node.find(:all, :conditions => { :id => result[3] })
|
||||
historic_nodes = Node.where(:id => result[3])
|
||||
assert_equal 1, historic_nodes.size, "There should only be one historic node created"
|
||||
first_historic_node = historic_nodes.first
|
||||
assert_in_delta lat, first_historic_node.lat, 0.00001, "The latitude was not retreived correctly"
|
||||
|
|
|
@ -1728,7 +1728,7 @@ EOF
|
|||
##
|
||||
# This should display the last 20 changesets closed.
|
||||
def test_list
|
||||
changesets = Changeset.find(:all, :order => "created_at DESC", :conditions => ['num_changes > 0'], :limit=> 20)
|
||||
changesets = Changeset.where("num_changes > 0").order(:created_at => :desc).limit(20)
|
||||
assert changesets.size <= 20
|
||||
get :list, {:format => "html"}
|
||||
assert_response :success
|
||||
|
@ -1762,7 +1762,7 @@ EOF
|
|||
##
|
||||
# This should display the last 20 changesets closed.
|
||||
def test_feed
|
||||
changesets = Changeset.find(:all, :order => "created_at DESC", :conditions => ['num_changes > 0'], :limit=> 20)
|
||||
changesets = Changeset.where("num_changes > 0").order(:created_at => :desc).limit(20)
|
||||
assert changesets.size <= 20
|
||||
get :feed, {:format => "atom"}
|
||||
assert_response :success
|
||||
|
|
|
@ -54,7 +54,7 @@ class WayControllerTest < ActionController::TestCase
|
|||
##
|
||||
# check the "full" mode
|
||||
def test_full
|
||||
Way.find(:all).each do |way|
|
||||
Way.all.each do |way|
|
||||
get :full, :id => way.id
|
||||
|
||||
# full call should say "gone" for non-visible ways...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue