diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index b437a684..f9b879f7 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -18,9 +18,9 @@ class DataController < ApplicationController def yaml_export all_tables = {} - all_tables['todos'] = current_user.todos.includes(:tags) - all_tables['contexts'] = current_user.contexts - all_tables['projects'] = current_user.projects + all_tables['todos'] = current_user.todos.includes(:tags).load + all_tables['contexts'] = current_user.contexts.load + all_tables['projects'] = current_user.projects.load 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_tables['taggings'] = taggings - all_tables['notes'] = current_user.notes - all_tables['recurring_todos'] = current_user.recurring_todos + all_tables['tags'] = tags.load + all_tables['taggings'] = taggings.load + all_tables['notes'] = current_user.notes.load + all_tables['recurring_todos'] = current_user.recurring_todos.load result = all_tables.to_yaml result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bb6a2d7e..2eb67b81 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -138,7 +138,7 @@ class UsersController < ApplicationController def destroy @deleted_user = User.find(params[:id]) @saved = @deleted_user.destroy - @total_users = User.size + @total_users = User.count respond_to do |format| format.html do diff --git a/config/initializers/monkey_patch_arel.rb b/config/initializers/monkey_patch_arel.rb new file mode 100644 index 00000000..bed0da5c --- /dev/null +++ b/config/initializers/monkey_patch_arel.rb @@ -0,0 +1,15 @@ +# From https://github.com/rails/arel/issues/149 +# Also fixes https://github.com/rails/rails/issues/9263 + +module Arel + module Nodes + class SqlLiteral < String + def encode_with(coder) + coder['string'] = to_s + end + def init_with(coder) + clear << coder['string'] + end + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d440ebf4..54e305f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ Tracksapp::Application.routes.draw do root :to => 'todos#index' post 'login' => 'login#login' + get 'login' => 'login#login' get 'login/expire_session' => 'login#expire_session' get 'login/check_expiry' => 'login#check_expiry' get 'logout' => 'login#logout' diff --git a/test/controllers/data_controller_test.rb b/test/controllers/data_controller_test.rb index 763e5b7c..e78c75e8 100644 --- a/test/controllers/data_controller_test.rb +++ b/test/controllers/data_controller_test.rb @@ -1,19 +1,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') -require 'data_controller' - -# Re-raise errors caught by the controller. -class DataController; def rescue_action(e) raise e end; end class DataControllerTest < ActionController::TestCase - fixtures :users, :preferences, :projects, :notes def setup - @controller = DataController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new end - # Replace this with your real tests. def test_csv_export_completes_without_error login_as :admin_user get :csv_notes diff --git a/test/controllers/recurring_todos_controller_test.rb b/test/controllers/recurring_todos_controller_test.rb index fe687ca3..b506a69f 100644 --- a/test/controllers/recurring_todos_controller_test.rb +++ b/test/controllers/recurring_todos_controller_test.rb @@ -54,7 +54,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "yearly_month_of_year"=>"6", "yearly_selector"=>"yearly_every_x_day" }, - "tag_list"=>"one, two, three, four" + "tag_list"=>"one, two, three, four", :format => :js # check new recurring todo added assert_equal orig_rt_count+1, RecurringTodo.count @@ -156,7 +156,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "recurring_show_days_before"=>"0", "recurring_target"=>"due_date", "recurring_show_always" => "1", - "start_from"=>"1/10/2012", # adjust after 2012 + "start_from"=>"1/10/2012", "weekly_every_x_week"=>"1", "weekly_return_monday"=>"w", "yearly_day_of_week"=>"0", @@ -166,7 +166,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "yearly_month_of_year"=>"10", "yearly_selector"=>"yearly_every_xth_day" }, - "tag_list"=>"one, two, three, four" + "tag_list"=>"one, two, three, four", :format => :js # check new recurring todo added assert_equal orig_rt_count+1, RecurringTodo.count @@ -220,7 +220,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "yearly_month_of_year"=>"10", "yearly_selector"=>"yearly_every_xth_day" }, - "tag_list"=>"one, two, three, four" + "tag_list"=>"one, two, three, four", :format => :js # check new recurring todo added assert_equal orig_rt_count+1, RecurringTodo.count diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index a9d2004b..9a60c68a 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -621,11 +621,11 @@ class TodosControllerTest < ActionController::TestCase assert todo_1.completed? # check that there is only one active todo belonging to recurring_todo - count = Todo.count(:all, :conditions => {:recurring_todo_id => recurring_todo_1.id, :state => 'active'}) + count = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'active').count assert_equal 1, count # check there is a new todo linked to the recurring pattern - next_todo = Todo.find(:first, :conditions => {:recurring_todo_id => recurring_todo_1.id, :state => 'active'}) + next_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'active').first assert_equal "Call Bill Gates every day", next_todo.description # check that the new todo is not the same as todo_1 assert_not_equal todo_1.id, next_todo.id @@ -651,11 +651,11 @@ class TodosControllerTest < ActionController::TestCase # check that there are three todos belonging to recurring_todo: two # completed and one deferred - count = Todo.count(:all, :conditions => {:recurring_todo_id => recurring_todo_1.id}) + count = Todo.where(:recurring_todo_id => recurring_todo_1.id).count assert_equal 3, count # check there is a new todo linked to the recurring pattern in the tickler - next_todo = Todo.find(:first, :conditions => {:recurring_todo_id => recurring_todo_1.id, :state => 'deferred'}) + next_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'deferred').first assert !next_todo.nil? assert_equal "Call Bill Gates every day", next_todo.description # check that the todo is in the tickler @@ -825,7 +825,7 @@ class TodosControllerTest < ActionController::TestCase assert_equal 0, successor.predecessors.size # add predecessor - put :add_predecessor, :predecessor=>predecessor.id, :successor=>successor.id + put :add_predecessor, :predecessor=>predecessor.id, :successor=>successor.id, :format => "js" assert_equal 1, successor.predecessors.count assert_equal predecessor.id, successor.predecessors.first.id @@ -839,10 +839,10 @@ class TodosControllerTest < ActionController::TestCase other_todo = todos(:phone_grandfather) # predecessor -> successor - put :add_predecessor, :predecessor=>predecessor.id, :successor=>successor.id + put :add_predecessor, :predecessor=>predecessor.id, :successor=>successor.id, :format => "js" # other_todo -> predecessor -> successor - put :add_predecessor, :predecessor=>other_todo.id, :successor=>predecessor.id + put :add_predecessor, :predecessor=>other_todo.id, :successor=>predecessor.id, :format => "js" assert_equal 1, successor.predecessors(true).count assert_equal 0, other_todo.predecessors(true).count @@ -861,12 +861,12 @@ class TodosControllerTest < ActionController::TestCase t4 = todos(:construct_dilation_device) # t1 -> t2 - put :add_predecessor, :predecessor=>t1.id, :successor=>t2.id + put :add_predecessor, :predecessor=>t1.id, :successor=>t2.id, :format => "js" # t3 -> t4 - put :add_predecessor, :predecessor=>t3.id, :successor=>t4.id + put :add_predecessor, :predecessor=>t3.id, :successor=>t4.id, :format => "js" # t2 -> t4 - put :add_predecessor, :predecessor=>t2.id, :successor=>t4.id + put :add_predecessor, :predecessor=>t2.id, :successor=>t4.id, :format => "js" # should be: t1 -> t2 -> t4 and t3 -> t4 assert t4.predecessors.map(&:id).include?(t2.id) @@ -884,12 +884,12 @@ class TodosControllerTest < ActionController::TestCase t4 = todos(:construct_dilation_device) # t1 -> t2 - put :add_predecessor, :predecessor=>t1.id, :successor=>t2.id + put :add_predecessor, :predecessor=>t1.id, :successor=>t2.id, :format => "js" # t3 -> t4 - put :add_predecessor, :predecessor=>t3.id, :successor=>t4.id + put :add_predecessor, :predecessor=>t3.id, :successor=>t4.id, :format => "js" # t3 -> t2 - put :add_predecessor, :predecessor=>t3.id, :successor=>t2.id + put :add_predecessor, :predecessor=>t3.id, :successor=>t2.id, :format => "js" # should be: t1 -> t2 and t3 -> t4 & t2 assert t3.successors.map(&:id).include?(t4.id) @@ -909,12 +909,12 @@ class TodosControllerTest < ActionController::TestCase # create same dependency tree as previous test # should be: t1 -> t2 -> t4 and t3 -> t4 - put :add_predecessor, :predecessor=>t1.id, :successor=>t2.id - put :add_predecessor, :predecessor=>t3.id, :successor=>t4.id - put :add_predecessor, :predecessor=>t2.id, :successor=>t4.id + put :add_predecessor, :predecessor=>t1.id, :successor=>t2.id, :format => "js" + put :add_predecessor, :predecessor=>t3.id, :successor=>t4.id, :format => "js" + put :add_predecessor, :predecessor=>t2.id, :successor=>t4.id, :format => "js" # removing t4 as successor of t2 should leave t4 blocked with t3 as predecessor - put :remove_predecessor, :predecessor=>t2.id, :id=>t4.id + put :remove_predecessor, :predecessor=>t2.id, :id=>t4.id, :format => "js" t4.reload assert t4.pending?, "t4 should remain pending" diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 4271ad6f..4590c102 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -38,10 +38,10 @@ class UsersControllerTest < ActionController::TestCase def test_destroy_user login_as :admin_user - @no_users_before = User.find(:all).size + @no_users_before = User.count user_id = users(:ldap_user).id xhr :post, :destroy, :id => user_id.to_param - assert_equal @no_users_before-1, User.find(:all).size + assert_equal @no_users_before-1, User.count end def test_update_password_successful @@ -67,7 +67,7 @@ class UsersControllerTest < ActionController::TestCase login_as :admin_user post :update_password, :id => users(:admin_user).id, :user => {:password => 'newpassword', :password_confirmation => 'wrong'} assert_redirected_to change_password_user_path(users(:admin_user)) - assert_equal 'Validation failed: Password doesn\'t match confirmation', flash[:error] + assert_equal 'Validation failed: Password confirmation doesn\'t match confirmation', flash[:error] end def test_update_password_validation_errors diff --git a/test/integration/recurring_todos_test.rb b/test/integration/recurring_todos_test.rb index 5a2bf136..39e2fc77 100644 --- a/test/integration/recurring_todos_test.rb +++ b/test/integration/recurring_todos_test.rb @@ -28,7 +28,7 @@ class RecurringTodosTest < ActionDispatch::IntegrationTest rt.reload # then there should be two todos referencing assert_equal 2, rt.todos.size - todo2 = Todo.find(:first, :conditions => {:recurring_todo_id => rt.id, :state => 'active'}) + todo2 = Todo.where(:recurring_todo_id => rt.id, :state => 'active').first assert_not_equal todo2.id, todo.id # and the todos should be different # when I delete the recurring todo diff --git a/test/models/todo_test.rb b/test/models/todo_test.rb index f62bfa32..8568f5d1 100644 --- a/test/models/todo_test.rb +++ b/test/models/todo_test.rb @@ -18,7 +18,7 @@ class TodoTest < ActiveSupport::TestCase assert_equal "Call Bill Gates to find out how much he makes per day", @not_completed1.description assert_nil @not_completed1.notes assert @not_completed1.completed? == false - assert_equal 1.week.ago.beginning_of_day.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.strftime("%Y-%m-%d %H:%M") + assert_equal 1.week.ago.beginning_of_day.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.beginning_of_day.strftime("%Y-%m-%d %H:%M") assert_equal 2.week.from_now.beginning_of_day.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d") assert_nil @not_completed1.completed_at assert_equal 1, @not_completed1.user_id