start fixing deprecation warnings

This commit is contained in:
Reinier Balt 2013-05-11 23:13:32 +02:00
parent 0bc9b0397a
commit ebff4cfc0c
9 changed files with 74 additions and 79 deletions

View file

@ -18,9 +18,9 @@ class DataController < ApplicationController
def yaml_export
all_tables = {}
all_tables['todos'] = current_user.todos.includes(:tags).all
all_tables['contexts'] = current_user.contexts.all
all_tables['projects'] = current_user.projects.all
all_tables['todos'] = current_user.todos.includes(:tags)
all_tables['contexts'] = current_user.contexts
all_tables['projects'] = current_user.projects
todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+
@ -37,10 +37,10 @@ class DataController < ApplicationController
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
all_tables['tags'] = tags.all
all_tables['taggings'] = taggings.all
all_tables['notes'] = current_user.notes.all
all_tables['recurring_todos'] = current_user.recurring_todos.all
all_tables['tags'] = tags
all_tables['taggings'] = taggings
all_tables['notes'] = current_user.notes
all_tables['recurring_todos'] = current_user.recurring_todos
result = all_tables.to_yaml
result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings

View file

@ -3,7 +3,7 @@ class NotesController < ApplicationController
before_filter :set_source_view
def index
@all_notes = current_user.notes.all
@all_notes = current_user.notes
@count = @all_notes.size
@page_title = "TRACKS::All notes"
@source_view = 'note_list'

View file

@ -18,7 +18,7 @@ class ProjectsController < ApplicationController
if params[:only_active_with_no_next_actions]
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
else
@projects = current_user.projects.all
@projects = current_user.projects
end
@new_project = current_user.projects.build
@active_projects = current_user.projects.active

View file

@ -11,14 +11,14 @@ class UsersController < ApplicationController
respond_to do |format|
format.html do
@page_title = "TRACKS::Manage Users"
@users = User.paginate :page => params[:page], :order => 'login ASC'
@users = User.order('login ASC').paginate :page => params[:page]
@total_users = User.count
# When we call users/signup from the admin page we store the URL so that
# we get returned here when signup is successful
store_location
end
format.xml do
@users = User.order('login').all
@users = User.order('login')
render :xml => @users.to_xml(:except => [ :password ])
end
end
@ -138,7 +138,7 @@ class UsersController < ApplicationController
def destroy
@deleted_user = User.find(params[:id])
@saved = @deleted_user.destroy
@total_users = User.all.size
@total_users = User.size
respond_to do |format|
format.html do

View file

@ -1,13 +1,13 @@
class Context < ActiveRecord::Base
has_many :todos, :dependent => :delete_all, :include => :project,
:order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC'
has_many :todos, -> { order("todos.due IS NULL, todos.due ASC, todos.created_at ASC").includes(:project) }, :dependent => :delete_all
has_many :recurring_todos, :dependent => :delete_all
belongs_to :user
scope :active, :conditions => { :state => :active }
scope :hidden, :conditions => { :state => :hidden }
scope :closed, :conditions => { :state => :closed }
scope :active, -> { where state: :active }
scope :hidden, -> { where state: :hidden }
scope :closed, -> { where state: :closed }
scope :with_name, lambda { |name| where("name LIKE ?", name) }
acts_as_list :scope => :user, :top_of_list => 0

View file

@ -1,15 +1,15 @@
class Project < ActiveRecord::Base
has_many :todos, :dependent => :delete_all, :order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC'
has_many :notes, :dependent => :delete_all, :order => "created_at DESC"
has_many :todos, -> {order("todos.due IS NULL, todos.due ASC, todos.created_at ASC")}, dependent: :delete_all
has_many :notes, -> {order "created_at DESC"}, dependent: :delete_all
has_many :recurring_todos
belongs_to :default_context, :class_name => "Context", :foreign_key => "default_context_id"
belongs_to :user
scope :active, :conditions => { :state => 'active' }
scope :hidden, :conditions => { :state => 'hidden' }
scope :completed, :conditions => { :state => 'completed'}
scope :uncompleted, :conditions => ["NOT(state = ?)", 'completed']
scope :active, -> { where state: 'active' }
scope :hidden, -> { where state: 'hidden' }
scope :completed, -> { where state: 'completed' }
scope :uncompleted, -> { where("NOT(state = ?)", 'completed') }
scope :with_name_or_description, lambda { |body| where("name LIKE ? OR description LIKE ?", body, body) }

View file

@ -7,8 +7,8 @@ class RecurringTodo < ActiveRecord::Base
has_many :todos
scope :active, :conditions => { :state => 'active'}
scope :completed, :conditions => { :state => 'completed'}
scope :active, -> { where state: 'active'}
scope :completed, -> { where state: 'completed'}
include IsTaggable

View file

@ -17,41 +17,37 @@ class Todo < ActiveRecord::Base
has_many :successor_dependencies, :foreign_key => 'successor_id', :class_name => 'Dependency', :dependent => :destroy
has_many :predecessors, :through => :successor_dependencies
has_many :successors, :through => :predecessor_dependencies
has_many :uncompleted_predecessors, :through => :successor_dependencies,
:source => :predecessor, :conditions => ['NOT (todos.state = ?)', 'completed']
has_many :pending_successors, :through => :predecessor_dependencies,
:source => :successor, :conditions => ['todos.state = ?', 'pending']
has_many :uncompleted_predecessors, -> {where('NOT (todos.state = ?)', 'completed')}, :through => :successor_dependencies,
:source => :predecessor
has_many :pending_successors, -> {where('todos.state = ?', 'pending')}, :through => :predecessor_dependencies,
:source => :successor
# scopes for states of this todo
scope :active, :conditions => { :state => 'active' }
scope :active_or_hidden, :conditions => ["todos.state = ? OR todos.state = ?", 'active', 'project_hidden']
scope :not_completed, :conditions => ['NOT (todos.state = ?)', 'completed']
scope :completed, :conditions => ["todos.state = ?", 'completed']
scope :deferred, :conditions => ["todos.state = ?", 'deferred']
scope :blocked, :conditions => ['todos.state = ?', 'pending']
scope :pending, :conditions => ['todos.state = ?', 'pending']
scope :deferred_or_blocked, :conditions => ["(todos.state = ?) OR (todos.state = ?)", "deferred", "pending"]
scope :not_deferred_or_blocked, :conditions => ["(NOT todos.state=?) AND (NOT todos.state = ?)", "deferred", "pending"]
scope :hidden,
:joins => "INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id",
:conditions => ["todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))",
'project_hidden', 'hidden', 'active', 'deferred', 'pending']
scope :not_hidden,
:joins => "INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id",
:conditions => ['NOT(todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))',
'project_hidden', 'hidden', 'active', 'deferred', 'pending']
scope :active, -> { where state: 'active' }
scope :active_or_hidden, -> { where "todos.state = ? OR todos.state = ?", 'active', 'project_hidden' }
scope :not_completed, -> { where 'NOT (todos.state = ?)', 'completed' }
scope :completed, -> { where "todos.state = ?", 'completed' }
scope :deferred, -> { where "todos.state = ?", 'deferred' }
scope :blocked, -> {where 'todos.state = ?', 'pending' }
scope :pending, -> {where 'todos.state = ?', 'pending' }
scope :deferred_or_blocked, -> { where "(todos.state = ?) OR (todos.state = ?)", "deferred", "pending" }
scope :not_deferred_or_blocked, -> { where "(NOT todos.state=?) AND (NOT todos.state = ?)", "deferred", "pending" }
scope :hidden, -> {
joins("INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id").
where("todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))", 'project_hidden', 'hidden', 'active', 'deferred', 'pending') }
scope :not_hidden, -> {
joins("INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id").
where('NOT(todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))','project_hidden', 'hidden', 'active', 'deferred', 'pending') }
# other scopes
scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
scope :with_tag, lambda { |tag_id| joins("INNER JOIN taggings ON todos.id = taggings.taggable_id").where("taggings.tag_id = ? ", tag_id) }
scope :with_tags, lambda { |tag_ids| where("EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids) }
# scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
scope :completed_after, lambda { |date| where("todos.completed_at > ?", date) }
scope :completed_before, lambda { |date| where("todos.completed_at < ?", date) }
scope :created_after, lambda { |date| where("todos.created_at > ?", date) }
scope :created_before, lambda { |date| where("todos.created_at < ?", date) }
scope :due_today, lambda { where("todos.due <= ?", Time.zone.now) }
scope :are_due, -> { where 'NOT (todos.due IS NULL)' }
scope :due_today, -> { where("todos.due <= ?", Time.zone.now) }
scope :with_tag, lambda { |tag_id| joins("INNER JOIN taggings ON todos.id = taggings.taggable_id").where("taggings.tag_id = ? ", tag_id) }
scope :with_tags, lambda { |tag_ids| where("EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids) }
scope :completed_after, lambda { |date| where("todos.completed_at > ?", date) }
scope :completed_before, lambda { |date| where("todos.completed_at < ?", date) }
scope :created_after, lambda { |date| where("todos.created_at > ?", date) }
scope :created_before, lambda { |date| where("todos.created_at < ?", date) }
def self.due_after(date)
where('todos.due > ?', date)
@ -151,7 +147,7 @@ class Todo < ActiveRecord::Base
end
def uncompleted_predecessors?
return !uncompleted_predecessors.all.empty?
return !uncompleted_predecessors.empty?
end
def should_be_blocked?

View file

@ -11,9 +11,7 @@ class User < ActiveRecord::Base
cattr_accessor :per_page
@@per_page = 5
has_many :contexts,
:order => 'position ASC',
:dependent => :delete_all do
has_many(:contexts, -> { order 'position ASC' }, dependent: :delete_all) do
def find_by_params(params)
find(params['id'] || params['context_id']) || nil
end
@ -25,9 +23,8 @@ class User < ActiveRecord::Base
}
end
end
has_many :projects,
:order => 'projects.position ASC',
:dependent => :delete_all do
has_many(:projects, -> {order 'projects.position ASC'}, dependent: :delete_all) do
def find_by_params(params)
find(params['id'] || params['project_id'])
end
@ -79,34 +76,36 @@ class User < ActiveRecord::Base
return where(scope_conditions)
end
end
has_many :todos,
:order => 'todos.completed_at DESC, todos.created_at DESC',
:dependent => :delete_all do
has_many(:todos, -> { order 'todos.completed_at DESC, todos.created_at DESC' }, dependent: :delete_all) do
def count_by_group(g)
except(:order).group(g).count
end
end
has_many :recurring_todos,
:order => 'recurring_todos.completed_at DESC, recurring_todos.created_at DESC',
:dependent => :delete_all
has_many :deferred_todos,
:class_name => 'Todo',
:conditions => [ 'state = ?', 'deferred' ],
:order => 'show_from ASC, todos.created_at DESC' do
-> {order 'recurring_todos.completed_at DESC, recurring_todos.created_at DESC'},
dependent: :delete_all
has_many(:deferred_todos,
-> { where('state = ?', 'deferred').
order('show_from ASC, todos.created_at DESC')},
:class_name => 'Todo') do
def find_and_activate_ready
where('show_from <= ?', Time.zone.now).collect { |t| t.activate! }
end
end
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
has_one :preference, :dependent => :destroy
has_many :notes, -> { order "created_at DESC" }, dependent: :delete_all
has_one :preference, dependent: :destroy
validates_presence_of :login
validates_presence_of :password, :if => :password_required?
validates_length_of :password, :within => 5..40, :if => :password_required?
validates_presence_of :password_confirmation, :if => :password_required?
validates_presence_of :password, if: :password_required?
validates_length_of :password, within: 5..40, if: :password_required?
validates_presence_of :password_confirmation, if: :password_required?
validates_confirmation_of :password
validates_length_of :login, :within => 3..80
validates_uniqueness_of :login, :on => :create
validates_length_of :login, within: 3..80
validates_uniqueness_of :login, on: :create
validate :validate_auth_type
before_create :crypt_password, :generate_token