fix all upgrade warnings from the rails_upgrade plugin

This commit is contained in:
Reinier Balt 2012-04-18 14:22:58 +02:00
parent fd4fb6df9e
commit fd433d76d8
47 changed files with 288 additions and 2284 deletions

View file

@ -10,7 +10,7 @@ class User < ActiveRecord::Base
:order => 'position ASC',
:dependent => :delete_all do
def find_by_params(params)
find(params['id'] || params['context_id']) || nil
find_by_id(params['id'] || params['context_id']) || nil
end
def update_positions(context_ids)
context_ids.each_with_index {|id, position|
@ -24,7 +24,7 @@ class User < ActiveRecord::Base
:order => 'projects.position ASC',
:dependent => :delete_all do
def find_by_params(params)
find(params['id'] || params['project_id'])
find_by_id(params['id'] || params['project_id'])
end
def update_positions(project_ids)
project_ids.each_with_index {|id, position|
@ -34,7 +34,7 @@ class User < ActiveRecord::Base
}
end
def projects_in_state_by_position(state)
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
end
def next_from(project)
self.offset_from(project, 1)
@ -49,29 +49,29 @@ class User < ActiveRecord::Base
projects.at( position + offset)
end
def cache_note_counts
project_note_counts = Note.count(:group => 'project_id')
project_note_counts = Note.group(:project_id).count
self.each do |project|
project.cached_note_count = project_note_counts[project.id] || 0
end
end
def alphabetize(scope_conditions = {})
projects = find(:all, :conditions => scope_conditions)
projects = where(scope_conditions)
projects.sort!{ |x,y| x.name.downcase <=> y.name.downcase }
self.update_positions(projects.map{ |p| p.id })
return projects
end
def actionize(scope_conditions = {})
todos_in_project = find(:all, :conditions => scope_conditions, :include => [:todos])
todos_in_project = where(scope_conditions).includes(:todos)
todos_in_project.sort!{ |x, y| -(x.todos.active.count <=> y.todos.active.count) }
todos_in_project.reject{ |p| p.todos.active.count > 0 }
sorted_project_ids = todos_in_project.map {|p| p.id}
all_project_ids = find(:all).map {|p| p.id}
all_project_ids = all.map {|p| p.id}
other_project_ids = all_project_ids - sorted_project_ids
update_positions(sorted_project_ids + other_project_ids)
return find(:all, :conditions => scope_conditions)
return where(scope_conditions)
end
end
has_many :todos,
@ -85,7 +85,7 @@ class User < ActiveRecord::Base
:conditions => [ 'state = ?', 'deferred' ],
:order => 'show_from ASC, todos.created_at DESC' do
def find_and_activate_ready
find(:all, :conditions => ['show_from <= ?', Time.zone.now ]).collect { |t| t.activate! }
where('show_from <= ?', Time.zone.now).collect { |t| t.activate! }
end
end
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
@ -119,7 +119,7 @@ class User < ActiveRecord::Base
def self.authenticate(login, pass)
return nil if login.blank?
candidate = find(:first, :conditions => ["login = ?", login])
candidate = where("login = ?", login).first
return nil if candidate.nil?
if Tracks::Config.auth_schemes.include?('database')