mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
remove some dynamic finders (they are deprecated for rails4) and add test for untested method of context.rb
This commit is contained in:
parent
402b078c02
commit
583664be36
4 changed files with 65 additions and 59 deletions
|
|
@ -193,7 +193,7 @@ class ApplicationController < ActionController::Base
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def admin_login_required
|
def admin_login_required
|
||||||
unless User.find_by_id_and_is_admin(session['user_id'], true)
|
unless User.find(session['user_id']).is_admin
|
||||||
render :text => t('errors.user_unauthorized'), :status => 401
|
render :text => t('errors.user_unauthorized'), :status => 401
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class RecurringTodosController < ApplicationController
|
||||||
if params['project_name'] == 'None'
|
if params['project_name'] == 'None'
|
||||||
project = Project.null_object
|
project = Project.null_object
|
||||||
else
|
else
|
||||||
project = current_user.projects.find_by_name(params['project_name'].strip)
|
project = current_user.projects.where(:name => params['project_name'].strip)
|
||||||
unless project
|
unless project
|
||||||
project = current_user.projects.build
|
project = current_user.projects.build
|
||||||
project.name = params['project_name'].strip
|
project.name = params['project_name'].strip
|
||||||
|
|
@ -73,7 +73,7 @@ class RecurringTodosController < ApplicationController
|
||||||
|
|
||||||
# update context
|
# update context
|
||||||
if params['recurring_todo']['context_id'].blank? && !params['context_name'].blank?
|
if params['recurring_todo']['context_id'].blank? && !params['context_name'].blank?
|
||||||
context = current_user.contexts.find_by_name(params['context_name'].strip)
|
context = current_user.contexts.where(:name => params['context_name'].strip)
|
||||||
unless context
|
unless context
|
||||||
context = current_user.contexts.build
|
context = current_user.contexts.build
|
||||||
context.name = params['context_name'].strip
|
context.name = params['context_name'].strip
|
||||||
|
|
@ -105,13 +105,13 @@ class RecurringTodosController < ApplicationController
|
||||||
@recurring_todo.update_attributes(p.attributes)
|
@recurring_todo.update_attributes(p.attributes)
|
||||||
|
|
||||||
if p.project_specified_by_name?
|
if p.project_specified_by_name?
|
||||||
project = current_user.projects.find_or_create_by_name(p.project_name)
|
project = current_user.projects.where(:name => p.project_name).first_or_create
|
||||||
@new_project_created = project.new_record_before_save?
|
@new_project_created = project.new_record_before_save?
|
||||||
@recurring_todo.project_id = project.id
|
@recurring_todo.project_id = project.id
|
||||||
end
|
end
|
||||||
|
|
||||||
if p.context_specified_by_name?
|
if p.context_specified_by_name?
|
||||||
context = current_user.contexts.find_or_create_by_name(p.context_name)
|
context = current_user.contexts.where(:name => p.context_name).first_or_create
|
||||||
@new_context_created = context.new_record_before_save?
|
@new_context_created = context.new_record_before_save?
|
||||||
@recurring_todo.context_id = context.id
|
@recurring_todo.context_id = context.id
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:tag]
|
if params[:tag]
|
||||||
tag = Tag.find_by_name(params['tag'])
|
tag = Tag.where(:name => params['tag'])
|
||||||
@not_done_todos = @not_done_todos.where('taggings.tag_id = ?', tag.id)
|
@not_done_todos = @not_done_todos.where('taggings.tag_id = ?', tag.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -91,8 +91,8 @@ class TodosController < ApplicationController
|
||||||
format.m {
|
format.m {
|
||||||
@new_mobile = true
|
@new_mobile = true
|
||||||
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
||||||
@mobile_from_context = current_user.contexts.find_by_id(params[:from_context]) if params[:from_context]
|
@mobile_from_context = current_user.contexts.find(params[:from_context]) if params[:from_context]
|
||||||
@mobile_from_project = current_user.projects.find_by_id(params[:from_project]) if params[:from_project]
|
@mobile_from_project = current_user.projects.find(params[:from_project]) if params[:from_project]
|
||||||
if params[:from_project] && !params[:from_context]
|
if params[:from_project] && !params[:from_context]
|
||||||
# we have a project but not a context -> use the default context
|
# we have a project but not a context -> use the default context
|
||||||
@mobile_from_context = @mobile_from_project.default_context
|
@mobile_from_context = @mobile_from_project.default_context
|
||||||
|
|
@ -103,8 +103,8 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
@default_context = current_user.contexts.find_by_name(params['default_context_name'])
|
@default_context = current_user.contexts.where(:name => params['default_context_name'])
|
||||||
@default_project = current_user.projects.find_by_name(params['default_project_name']) unless params['default_project_name'].blank?
|
@default_project = current_user.projects.where(:name => params['default_project_name']) unless params['default_project_name'].blank?
|
||||||
|
|
||||||
@tag_name = params['_tag_name']
|
@tag_name = params['_tag_name']
|
||||||
|
|
||||||
|
|
@ -120,21 +120,21 @@ class TodosController < ApplicationController
|
||||||
@todo = current_user.todos.build(p.attributes)
|
@todo = current_user.todos.build(p.attributes)
|
||||||
|
|
||||||
if p.project_specified_by_name?
|
if p.project_specified_by_name?
|
||||||
project = current_user.projects.find_or_create_by_name(p.project_name)
|
project = current_user.projects.where(:name => p.project_name).first_or_create
|
||||||
@new_project_created = project.new_record_before_save?
|
@new_project_created = project.new_record_before_save?
|
||||||
@todo.project_id = project.id
|
@todo.project_id = project.id
|
||||||
elsif !(p.project_id.nil? || p.project_id.blank?)
|
elsif !(p.project_id.nil? || p.project_id.blank?)
|
||||||
project = current_user.projects.find_by_id(p.project_id)
|
project = current_user.projects.where(:id => p.project_id).first
|
||||||
@todo.errors[:project] << "unknown" if project.nil?
|
@todo.errors[:project] << "unknown" if project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
if p.context_specified_by_name?
|
if p.context_specified_by_name?
|
||||||
context = current_user.contexts.find_or_create_by_name(p.context_name)
|
context = current_user.contexts.where(:name => p.context_name).first_or_create
|
||||||
@new_context_created = context.new_record_before_save?
|
@new_context_created = context.new_record_before_save?
|
||||||
@not_done_todos = [@todo] if @new_context_created
|
@not_done_todos = [@todo] if @new_context_created
|
||||||
@todo.context_id = context.id
|
@todo.context_id = context.id
|
||||||
elsif !(p.context_id.nil? || p.context_id.blank?)
|
elsif !(p.context_id.nil? || p.context_id.blank?)
|
||||||
context = current_user.contexts.find_by_id(p.context_id)
|
context = current_user.contexts.where(:id=>p.context_id).first
|
||||||
@todo.errors[:context] << "unknown" if context.nil?
|
@todo.errors[:context] << "unknown" if context.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -203,13 +203,13 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def create_multiple
|
def create_multiple
|
||||||
if project_specified_by_name(params[:project_name])
|
if project_specified_by_name(params[:project_name])
|
||||||
project = current_user.projects.find_or_create_by_name(params[:project_name])
|
project = current_user.projects.where(:name => params[:project_name]).first_or_create
|
||||||
@new_project_created = project.new_record_before_save?
|
@new_project_created = project.new_record_before_save?
|
||||||
@project_id = project.id
|
@project_id = project.id
|
||||||
end
|
end
|
||||||
|
|
||||||
if context_specified_by_name(params[:context_name])
|
if context_specified_by_name(params[:context_name])
|
||||||
context = current_user.contexts.find_or_create_by_name(params[:context_name])
|
context = current_user.contexts.where(:name => params[:context_name]).first_or_create
|
||||||
@new_context_created = context.new_record_before_save?
|
@new_context_created = context.new_record_before_save?
|
||||||
@not_done_todos = [] if @new_context_created
|
@not_done_todos = [] if @new_context_created
|
||||||
@context_id = context.id
|
@context_id = context.id
|
||||||
|
|
@ -277,7 +277,7 @@ class TodosController < ApplicationController
|
||||||
else
|
else
|
||||||
@multiple_error = @todos.size > 0 ? "" : t('todos.next_action_needed')
|
@multiple_error = @todos.size > 0 ? "" : t('todos.next_action_needed')
|
||||||
@saved = false
|
@saved = false
|
||||||
@default_tags = current_user.projects.find_by_name(@initial_project_name).default_tags unless @initial_project_name.blank?
|
@default_tags = current_user.projects.where(:name => @initial_project_name).default_tags unless @initial_project_name.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
@status_message = @todos.size > 1 ? t('todos.added_new_next_action_plural') : t('todos.added_new_next_action_singular')
|
@status_message = @todos.size > 1 ? t('todos.added_new_next_action_plural') : t('todos.added_new_next_action_singular')
|
||||||
|
|
@ -312,7 +312,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@todo = current_user.todos.find_by_id(params['id'])
|
@todo = current_user.todos.find(params['id'])
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.m { render :action => 'show' }
|
format.m { render :action => 'show' }
|
||||||
format.xml { render :xml => @todo.to_xml( *to_xml_params ) }
|
format.xml { render :xml => @todo.to_xml( *to_xml_params ) }
|
||||||
|
|
@ -321,9 +321,9 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def add_predecessor
|
def add_predecessor
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
@predecessor = current_user.todos.find_by_id(params['predecessor'])
|
@predecessor = current_user.todos.find(params['predecessor'])
|
||||||
@predecessors = @predecessor.predecessors
|
@predecessors = @predecessor.predecessors
|
||||||
@todo = current_user.todos.includes(Todo::DEFAULT_INCLUDES).find_by_id(params['successor'])
|
@todo = current_user.todos.includes(Todo::DEFAULT_INCLUDES).find(params['successor'])
|
||||||
@original_state = @todo.state
|
@original_state = @todo.state
|
||||||
unless @predecessor.completed?
|
unless @predecessor.completed?
|
||||||
@todo.add_predecessor(@predecessor)
|
@todo.add_predecessor(@predecessor)
|
||||||
|
|
@ -342,8 +342,8 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def remove_predecessor
|
def remove_predecessor
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
@todo = current_user.todos.includes(Todo::DEFAULT_INCLUDES).find_by_id(params['id'])
|
@todo = current_user.todos.includes(Todo::DEFAULT_INCLUDES).find(params['id'])
|
||||||
@predecessor = current_user.todos.find_by_id(params['predecessor'])
|
@predecessor = current_user.todos.find(params['predecessor'])
|
||||||
@predecessors = @predecessor.predecessors
|
@predecessors = @predecessor.predecessors
|
||||||
@successor = @todo
|
@successor = @todo
|
||||||
@removed = @successor.remove_predecessor(@predecessor)
|
@removed = @successor.remove_predecessor(@predecessor)
|
||||||
|
|
@ -426,7 +426,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_star
|
def toggle_star
|
||||||
@todo = current_user.todos.find_by_id(params['id'])
|
@todo = current_user.todos.find(params['id'])
|
||||||
@todo.toggle_star!
|
@todo.toggle_star!
|
||||||
@saved = true # cannot determine error
|
@saved = true # cannot determine error
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
@ -449,9 +449,9 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def change_context
|
def change_context
|
||||||
# change context if you drag a todo to another context
|
# change context if you drag a todo to another context
|
||||||
@todo = current_user.todos.find_by_id(params[:id])
|
@todo = current_user.todos.find(params[:id])
|
||||||
@original_item_context_id = @todo.context_id
|
@original_item_context_id = @todo.context_id
|
||||||
@context = current_user.contexts.find_by_id(params[:todo][:context_id])
|
@context = current_user.contexts.find(params[:todo][:context_id])
|
||||||
@todo.context = @context
|
@todo.context = @context
|
||||||
@saved = @todo.save
|
@saved = @todo.save
|
||||||
|
|
||||||
|
|
@ -467,7 +467,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@todo = current_user.todos.find_by_id(params['id'])
|
@todo = current_user.todos.find(params['id'])
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
# init_data_for_sidebar unless mobile?
|
# init_data_for_sidebar unless mobile?
|
||||||
|
|
||||||
|
|
@ -517,7 +517,7 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
@todo = current_user.todos.find_by_id(params['id'])
|
@todo = current_user.todos.find(params['id'])
|
||||||
@original_item_due = @todo.due
|
@original_item_due = @todo.due
|
||||||
@context_id = @todo.context_id
|
@context_id = @todo.context_id
|
||||||
@project_id = @todo.project_id
|
@project_id = @todo.project_id
|
||||||
|
|
@ -642,12 +642,12 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_to_context
|
def filter_to_context
|
||||||
context = current_user.contexts.find_by_id(params['context']['id'])
|
context = current_user.contexts.find(params['context']['id'])
|
||||||
redirect_to context_todos_path(context, :format => 'm')
|
redirect_to context_todos_path(context, :format => 'm')
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_to_project
|
def filter_to_project
|
||||||
project = current_user.projects.find_by_id(params['project']['id'])
|
project = current_user.projects.find(params['project']['id'])
|
||||||
redirect_to project_todos_path(project, :format => 'm')
|
redirect_to project_todos_path(project, :format => 'm')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -719,7 +719,7 @@ class TodosController < ApplicationController
|
||||||
@source_view = params['_source_view'] || 'tag'
|
@source_view = params['_source_view'] || 'tag'
|
||||||
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
|
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
|
||||||
@page_title = t('todos.completed_tagged_page_title', :tag_name => @tag_name)
|
@page_title = t('todos.completed_tagged_page_title', :tag_name => @tag_name)
|
||||||
@tag = Tag.find_by_name(@tag_name)
|
@tag = Tag.where(:name => @tag_name)
|
||||||
@tag = Tag.new(:name => @tag_name) if @tag.nil?
|
@tag = Tag.new(:name => @tag_name) if @tag.nil?
|
||||||
|
|
||||||
completed_todos = current_user.todos.completed.with_tag(@tag.id)
|
completed_todos = current_user.todos.completed.with_tag(@tag.id)
|
||||||
|
|
@ -736,7 +736,7 @@ class TodosController < ApplicationController
|
||||||
@source_view = params['_source_view'] || 'tag'
|
@source_view = params['_source_view'] || 'tag'
|
||||||
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
|
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
|
||||||
@page_title = t('todos.all_completed_tagged_page_title', :tag_name => @tag_name)
|
@page_title = t('todos.all_completed_tagged_page_title', :tag_name => @tag_name)
|
||||||
@tag = Tag.find_by_name(@tag_name)
|
@tag = Tag.where(:name => @tag_name)
|
||||||
@tag = Tag.new(:name => @tag_name) if @tag.nil?
|
@tag = Tag.new(:name => @tag_name) if @tag.nil?
|
||||||
|
|
||||||
@done = current_user.todos.completed.with_tag(@tag.id).reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES).paginate :page => params[:page], :per_page => 20
|
@done = current_user.todos.completed.with_tag(@tag.id).reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES).paginate :page => params[:page], :per_page => 20
|
||||||
|
|
@ -759,7 +759,7 @@ class TodosController < ApplicationController
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
numdays = params['days'].to_i
|
numdays = params['days'].to_i
|
||||||
|
|
||||||
@todo = current_user.todos.find_by_id(params[:id])
|
@todo = current_user.todos.find(params[:id])
|
||||||
@original_item_context_id = @todo.context_id
|
@original_item_context_id = @todo.context_id
|
||||||
@todo_deferred_state_changed = true
|
@todo_deferred_state_changed = true
|
||||||
@new_context_created = false
|
@new_context_created = false
|
||||||
|
|
@ -776,7 +776,7 @@ class TodosController < ApplicationController
|
||||||
determine_remaining_in_context_count(@todo.context_id)
|
determine_remaining_in_context_count(@todo.context_id)
|
||||||
source_view do |page|
|
source_view do |page|
|
||||||
page.project {
|
page.project {
|
||||||
@remaining_undone_in_project = current_user.projects.find_by_id(@todo.project_id).todos.not_completed.count
|
@remaining_undone_in_project = current_user.projects.find(@todo.project_id).todos.not_completed.count
|
||||||
@original_item_project_id = @todo.project_id
|
@original_item_project_id = @todo.project_id
|
||||||
}
|
}
|
||||||
page.tag {
|
page.tag {
|
||||||
|
|
@ -884,7 +884,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_to_project
|
def convert_to_project
|
||||||
todo = current_user.todos.find_by_id(params[:id])
|
todo = current_user.todos.find(params[:id])
|
||||||
@project = Project.create_from_todo(todo)
|
@project = Project.create_from_todo(todo)
|
||||||
|
|
||||||
if @project.valid?
|
if @project.valid?
|
||||||
|
|
@ -896,7 +896,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_notes
|
def show_notes
|
||||||
@todo = current_user.todos.find_by_id(params['id'])
|
@todo = current_user.todos.find(params['id'])
|
||||||
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
|
|
@ -931,7 +931,7 @@ class TodosController < ApplicationController
|
||||||
def get_todo_from_params
|
def get_todo_from_params
|
||||||
# TODO: this was a :append_before but was removed to tune performance per
|
# TODO: this was a :append_before but was removed to tune performance per
|
||||||
# method. Reconsider re-enabling it
|
# method. Reconsider re-enabling it
|
||||||
@todo = current_user.todos.find_by_id(params['id'])
|
@todo = current_user.todos.find(params['id'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_and_activate_ready
|
def find_and_activate_ready
|
||||||
|
|
@ -966,7 +966,7 @@ class TodosController < ApplicationController
|
||||||
tag_expr.each do |tag_list|
|
tag_expr.each do |tag_list|
|
||||||
id_list = []
|
id_list = []
|
||||||
tag_list.each do |tag|
|
tag_list.each do |tag|
|
||||||
tag = Tag.find_by_name(tag)
|
tag = Tag.where(:name => tag).first
|
||||||
id_list << tag.id if tag
|
id_list << tag.id if tag
|
||||||
end
|
end
|
||||||
ids << id_list
|
ids << id_list
|
||||||
|
|
@ -977,7 +977,7 @@ class TodosController < ApplicationController
|
||||||
def find_todos_with_tag_expr(tag_expr)
|
def find_todos_with_tag_expr(tag_expr)
|
||||||
# optimize for the common case: selecting only one tag
|
# optimize for the common case: selecting only one tag
|
||||||
if @single_tag
|
if @single_tag
|
||||||
tag = Tag.find_by_name(@tag_name)
|
tag = Tag.where(:name => @tag_name).first
|
||||||
tag_id = tag.nil? ? -1 : tag.id
|
tag_id = tag.nil? ? -1 : tag.id
|
||||||
return current_user.todos.with_tag(tag_id)
|
return current_user.todos.with_tag(tag_id)
|
||||||
end
|
end
|
||||||
|
|
@ -997,7 +997,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
from.context do
|
from.context do
|
||||||
context_id = @original_item_context_id || @todo.context_id
|
context_id = @original_item_context_id || @todo.context_id
|
||||||
todos = current_user.contexts.find_by_id(context_id).todos.not_completed
|
todos = current_user.contexts.find(context_id).todos.not_completed
|
||||||
|
|
||||||
if @todo.context.hide?
|
if @todo.context.hide?
|
||||||
# include hidden todos
|
# include hidden todos
|
||||||
|
|
@ -1009,7 +1009,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
from.project do
|
from.project do
|
||||||
unless @todo.project_id == nil
|
unless @todo.project_id == nil
|
||||||
@down_count = current_user.projects.find_by_id(@todo.project_id).todos.active_or_hidden.count
|
@down_count = current_user.projects.find(@todo.project_id).todos.active_or_hidden.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
from.deferred do
|
from.deferred do
|
||||||
|
|
@ -1017,7 +1017,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
from.tag do
|
from.tag do
|
||||||
@tag_name = params['_tag_name']
|
@tag_name = params['_tag_name']
|
||||||
@tag = Tag.find_by_name(@tag_name)
|
@tag = Tag.where(:name => @tag_name)
|
||||||
if @tag.nil?
|
if @tag.nil?
|
||||||
@tag = Tag.new(:name => @tag_name)
|
@tag = Tag.new(:name => @tag_name)
|
||||||
end
|
end
|
||||||
|
|
@ -1030,36 +1030,36 @@ class TodosController < ApplicationController
|
||||||
source_view do |from|
|
source_view do |from|
|
||||||
from.deferred {
|
from.deferred {
|
||||||
# force reload to todos to get correct count and not a cached one
|
# force reload to todos to get correct count and not a cached one
|
||||||
@remaining_in_context = current_user.contexts.find_by_id(context_id).todos.deferred_or_blocked.count
|
@remaining_in_context = current_user.contexts.find(context_id).todos.deferred_or_blocked.count
|
||||||
@target_context_count = current_user.contexts.find_by_id(@todo.context_id).todos.deferred_or_blocked.count
|
@target_context_count = current_user.contexts.find(@todo.context_id).todos.deferred_or_blocked.count
|
||||||
}
|
}
|
||||||
from.tag {
|
from.tag {
|
||||||
tag = Tag.find_by_name(params['_tag_name'])
|
tag = Tag.where(:name => params['_tag_name'])
|
||||||
if tag.nil?
|
if tag.nil?
|
||||||
tag = Tag.new(:name => params['tag'])
|
tag = Tag.new(:name => params['tag'])
|
||||||
end
|
end
|
||||||
@remaining_deferred_or_pending_count = current_user.todos.with_tag(tag.id).deferred_or_blocked.count
|
@remaining_deferred_or_pending_count = current_user.todos.with_tag(tag.id).deferred_or_blocked.count
|
||||||
@remaining_in_context = current_user.contexts.find_by_id(context_id).todos.active.not_hidden.with_tag(tag.id).count
|
@remaining_in_context = current_user.contexts.find(context_id).todos.active.not_hidden.with_tag(tag.id).count
|
||||||
@target_context_count = current_user.contexts.find_by_id(@todo.context_id).todos.active.not_hidden.with_tag(tag.id).count
|
@target_context_count = current_user.contexts.find(@todo.context_id).todos.active.not_hidden.with_tag(tag.id).count
|
||||||
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag.id).count
|
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag.id).count
|
||||||
}
|
}
|
||||||
from.project {
|
from.project {
|
||||||
project_id = @project_changed ? @original_item_project_id : @todo.project_id
|
project_id = @project_changed ? @original_item_project_id : @todo.project_id
|
||||||
@remaining_deferred_or_pending_count = current_user.projects.find_by_id(project_id).todos.deferred_or_blocked.count
|
@remaining_deferred_or_pending_count = current_user.projects.find(project_id).todos.deferred_or_blocked.count
|
||||||
|
|
||||||
if @todo_was_completed_from_deferred_or_blocked_state
|
if @todo_was_completed_from_deferred_or_blocked_state
|
||||||
@remaining_in_context = @remaining_deferred_or_pending_count
|
@remaining_in_context = @remaining_deferred_or_pending_count
|
||||||
else
|
else
|
||||||
@remaining_in_context = current_user.projects.find_by_id(project_id).todos.active_or_hidden.count
|
@remaining_in_context = current_user.projects.find(project_id).todos.active_or_hidden.count
|
||||||
end
|
end
|
||||||
|
|
||||||
@target_context_count = current_user.projects.find_by_id(project_id).todos.active.count
|
@target_context_count = current_user.projects.find(project_id).todos.active.count
|
||||||
}
|
}
|
||||||
from.calendar {
|
from.calendar {
|
||||||
@target_context_count = @new_due_id.blank? ? 0 : count_old_due_empty(@new_due_id)
|
@target_context_count = @new_due_id.blank? ? 0 : count_old_due_empty(@new_due_id)
|
||||||
}
|
}
|
||||||
from.context {
|
from.context {
|
||||||
context = current_user.contexts.find_by_id(context_id)
|
context = current_user.contexts.find(context_id)
|
||||||
@remaining_deferred_or_pending_count = context.todos.deferred_or_blocked.count
|
@remaining_deferred_or_pending_count = context.todos.deferred_or_blocked.count
|
||||||
|
|
||||||
remaining_actions_in_context = context.todos(true).active
|
remaining_actions_in_context = context.todos(true).active
|
||||||
|
|
@ -1067,7 +1067,7 @@ class TodosController < ApplicationController
|
||||||
@remaining_in_context = remaining_actions_in_context.count
|
@remaining_in_context = remaining_actions_in_context.count
|
||||||
|
|
||||||
if @todo_was_deferred_or_blocked
|
if @todo_was_deferred_or_blocked
|
||||||
actions_in_target = current_user.contexts.find_by_id(@todo.context_id).todos(true).active
|
actions_in_target = current_user.contexts.find(@todo.context_id).todos(true).active
|
||||||
actions_in_target = actions_in_target.not_hidden if !context.hide?
|
actions_in_target = actions_in_target.not_hidden if !context.hide?
|
||||||
else
|
else
|
||||||
actions_in_target = @todo.context.todos.deferred_or_blocked
|
actions_in_target = @todo.context.todos.deferred_or_blocked
|
||||||
|
|
@ -1075,8 +1075,8 @@ class TodosController < ApplicationController
|
||||||
@target_context_count = actions_in_target.count
|
@target_context_count = actions_in_target.count
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@remaining_in_context = current_user.contexts.find_by_id(context_id).todos(true).active.not_hidden.count if !@remaining_in_context
|
@remaining_in_context = current_user.contexts.find(context_id).todos(true).active.not_hidden.count if !@remaining_in_context
|
||||||
@target_context_count = current_user.contexts.find_by_id(@todo.context_id).todos(true).active.not_hidden.count if !@target_context_count
|
@target_context_count = current_user.contexts.find(@todo.context_id).todos(true).active.not_hidden.count if !@target_context_count
|
||||||
end
|
end
|
||||||
|
|
||||||
def determine_completed_count
|
def determine_completed_count
|
||||||
|
|
@ -1085,13 +1085,13 @@ class TodosController < ApplicationController
|
||||||
@completed_count = current_user.todos.not_hidden.completed.count
|
@completed_count = current_user.todos.not_hidden.completed.count
|
||||||
end
|
end
|
||||||
from.context do
|
from.context do
|
||||||
todos = current_user.contexts.find_by_id(@todo.context_id).todos.completed
|
todos = current_user.contexts.find(@todo.context_id).todos.completed
|
||||||
todos = todos.not_hidden if !@todo.context.hidden?
|
todos = todos.not_hidden if !@todo.context.hidden?
|
||||||
@completed_count = todos.count
|
@completed_count = todos.count
|
||||||
end
|
end
|
||||||
from.project do
|
from.project do
|
||||||
unless @todo.project_id == nil
|
unless @todo.project_id == nil
|
||||||
todos = current_user.projects.find_by_id(@todo.project_id).todos.completed
|
todos = current_user.projects.find(@todo.project_id).todos.completed
|
||||||
todos = todos.not_hidden if !@todo.project.hidden?
|
todos = todos.not_hidden if !@todo.project.hidden?
|
||||||
@completed_count = todos.count
|
@completed_count = todos.count
|
||||||
end
|
end
|
||||||
|
|
@ -1103,7 +1103,7 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def determine_deferred_tag_count(tag_name)
|
def determine_deferred_tag_count(tag_name)
|
||||||
tag = Tag.find_by_name(tag_name)
|
tag = Tag.where(:name => tag_name)
|
||||||
# tag.nil? should normally not happen, but is a workaround for #929
|
# tag.nil? should normally not happen, but is a workaround for #929
|
||||||
@remaining_deferred_or_pending_count = tag.nil? ? 0 : current_user.todos.deferred.with_tag(tag.id).count
|
@remaining_deferred_or_pending_count = tag.nil? ? 0 : current_user.todos.deferred.with_tag(tag.id).count
|
||||||
end
|
end
|
||||||
|
|
@ -1207,7 +1207,7 @@ class TodosController < ApplicationController
|
||||||
if params['project_name'] == 'None'
|
if params['project_name'] == 'None'
|
||||||
project = Project.null_object
|
project = Project.null_object
|
||||||
else
|
else
|
||||||
project = current_user.projects.find_by_name(params['project_name'].strip)
|
project = current_user.projects.where(:name => params['project_name'].strip).first
|
||||||
unless project
|
unless project
|
||||||
project = current_user.projects.build
|
project = current_user.projects.build
|
||||||
project.name = params['project_name'].strip
|
project.name = params['project_name'].strip
|
||||||
|
|
@ -1223,14 +1223,14 @@ class TodosController < ApplicationController
|
||||||
def update_todo_state_if_project_changed
|
def update_todo_state_if_project_changed
|
||||||
if @project_changed
|
if @project_changed
|
||||||
@todo.update_state_from_project
|
@todo.update_state_from_project
|
||||||
@remaining_undone_in_project = current_user.projects.find_by_id(@original_item_project_id).todos.active.count if source_view_is :project
|
@remaining_undone_in_project = current_user.projects.find(@original_item_project_id).todos.active.count if source_view_is :project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_context
|
def update_context
|
||||||
@context_changed = false
|
@context_changed = false
|
||||||
if params['todo']['context_id'].blank? && !params['context_name'].blank?
|
if params['todo']['context_id'].blank? && !params['context_name'].blank?
|
||||||
context = current_user.contexts.find_by_name(params['context_name'].strip)
|
context = current_user.contexts.where(:name => params['context_name'].strip).first
|
||||||
unless context
|
unless context
|
||||||
@new_context = current_user.contexts.build
|
@new_context = current_user.contexts.build
|
||||||
@new_context.name = params['context_name'].strip
|
@new_context.name = params['context_name'].strip
|
||||||
|
|
|
||||||
|
|
@ -69,4 +69,10 @@ class ContextTest < ActiveSupport::TestCase
|
||||||
assert_equal '', c.name
|
assert_equal '', c.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_new_record_before_save
|
||||||
|
assert !@agenda.new_record_before_save?, "existing records should not be new_record"
|
||||||
|
c = Context.where(:name => "I do not exist").first_or_create
|
||||||
|
assert c.new_record_before_save?, "newly created record should be new_record"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue