From 17a880d2fa2566010ebaa2a404851d2d0eeac0af Mon Sep 17 00:00:00 2001 From: lukemelia Date: Wed, 26 Sep 2007 12:05:21 +0000 Subject: [PATCH] The recent changeset to the API introduced some test failures. I fixed those and also eliminated some warnings that were appearing while running the tests. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@600 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/helpers/application_helper.rb | 2 +- tracks/app/helpers/feedlist_helper.rb | 6 +++--- tracks/app/helpers/todos_helper.rb | 2 +- tracks/app/models/preference.rb | 9 +++++---- tracks/app/views/preferences/edit.rhtml | 2 +- tracks/app/views/preferences/index.rhtml | 2 +- tracks/test/functional/backend_controller_test.rb | 14 ++++++++------ 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index ad5cef0a..dece18b8 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -47,7 +47,7 @@ module ApplicationHelper "Due Tomorrow " # due 2-7 days away when 2..7 - if prefs.due_style == Preference::DUE_ON_DUE_STYLE + if prefs.due_style == Preference.due_styles[:due_on] "Due on #{due.strftime("%A")} " else "Due in #{pluralize(days, 'day')} " diff --git a/tracks/app/helpers/feedlist_helper.rb b/tracks/app/helpers/feedlist_helper.rb index 45ba5854..bfcf7ea8 100644 --- a/tracks/app/helpers/feedlist_helper.rb +++ b/tracks/app/helpers/feedlist_helper.rb @@ -2,17 +2,17 @@ module FeedlistHelper def rss_formatted_link(options = {}) image_tag = image_tag("feed-icon.png", :size => "16X16", :border => 0, :class => "rss-icon") - linkoptions = merge_hashes( { :format => 'rss'}, user_token_hash, options) + linkoptions = merge_hashes( {:format => 'rss'}, user_token_hash, options) link_to(image_tag, linkoptions, :title => "RSS feed") end def text_formatted_link(options = {}) - linkoptions = merge_hashes( { :format => 'txt'}, user_token_hash, options) + linkoptions = merge_hashes( {:format => 'txt'}, user_token_hash, options) link_to('TXT', linkoptions, :title => "Plain text feed" ) end def ical_formatted_link(options = {}) - linkoptions = merge_hashes ( { :format => 'ics'}, user_token_hash, options) + linkoptions = merge_hashes( {:format => 'ics'}, user_token_hash, options) link_to('iCal', linkoptions, :title => "iCal feed" ) end diff --git a/tracks/app/helpers/todos_helper.rb b/tracks/app/helpers/todos_helper.rb index 03011397..04ad65c8 100644 --- a/tracks/app/helpers/todos_helper.rb +++ b/tracks/app/helpers/todos_helper.rb @@ -139,7 +139,7 @@ module TodosHelper "Show Tomorrow " # due 2-7 days away when 2..7 - if prefs.due_style == Preference::DUE_ON_DUE_STYLE + if prefs.due_style == Preference.due_styles[:due_on] "Show on " + due.strftime("%A") + " " else "Show in " + days.to_s + " days " diff --git a/tracks/app/models/preference.rb b/tracks/app/models/preference.rb index 3d22d73a..b97bbbf7 100644 --- a/tracks/app/models/preference.rb +++ b/tracks/app/models/preference.rb @@ -3,10 +3,11 @@ class Preference < ActiveRecord::Base composed_of :tz, :class_name => 'TimeZone', :mapping => %w(time_zone name) - - DUE_ON_DUE_STYLE = 1 - DUE_IN_N_DAYS_DUE_STYLE = 0 - + + def self.due_styles + { :due_in_n_days => 0, :due_on => 1} + end + def self.day_number_to_name_map { 0 => "Sunday", 1 => "Monday", diff --git a/tracks/app/views/preferences/edit.rhtml b/tracks/app/views/preferences/edit.rhtml index 72f806d5..ee9ab1e4 100644 --- a/tracks/app/views/preferences/edit.rhtml +++ b/tracks/app/views/preferences/edit.rhtml @@ -55,7 +55,7 @@ <%= table_row('time_zone', false) { time_zone_select('prefs','time_zone') } %> <%= row_with_select_field("week_starts", Preference.day_number_to_name_map.invert.sort{|a,b| a[1]<=>b[1]})%> - <%= row_with_select_field("due_style", [['Due in ___ days',Preference::DUE_IN_N_DAYS_DUE_STYLE],['Due on _______',Preference::DUE_ON_DUE_STYLE]]) %> + <%= row_with_select_field("due_style", [['Due in ___ days',Preference.due_styles[:due_in_n_days]],['Due on _______',Preference.due_styles[:due_on]]]) %> <%= row_with_select_field("show_completed_projects_in_sidebar") %> <%= row_with_select_field("show_hidden_projects_in_sidebar") %> <%= row_with_select_field("show_hidden_contexts_in_sidebar") %> diff --git a/tracks/app/views/preferences/index.rhtml b/tracks/app/views/preferences/index.rhtml index 37dd3bd3..49026ca8 100644 --- a/tracks/app/views/preferences/index.rhtml +++ b/tracks/app/views/preferences/index.rhtml @@ -16,7 +16,7 @@
  • Go to project page on todo complete: <%= prefs.show_project_on_todo_done %>
  • Staleness starts after <%= prefs.staleness_starts %> days
  • Due style: - <% if prefs.due_style == Preference::DUE_IN_N_DAYS_DUE_STYLE %> + <% if prefs.due_style == Preference.due_styles[:due_in_n_days] %> Due in ___ days <% else %> Due on ________ diff --git a/tracks/test/functional/backend_controller_test.rb b/tracks/test/functional/backend_controller_test.rb index 495bc83d..52e969fc 100644 --- a/tracks/test/functional/backend_controller_test.rb +++ b/tracks/test/functional/backend_controller_test.rb @@ -14,15 +14,15 @@ class BackendControllerTest < Test::Rails::TestCase end def test_new_todo_fails_with_incorrect_token - assert_raises_invalid_token { @controller.new_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test') } + assert_raises_invalid_token { @controller.new_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test', 'test') } end def test_new_todo_fails_with_context_that_does_not_belong_to_user - assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_todo(users('other_user').login, users('other_user').token, contexts('agenda').id, 'test') } + assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_todo(users('other_user').login, users('other_user').token, contexts('agenda').id, 'test', 'test') } end def test_new_rich_todo_fails_with_incorrect_token - assert_raises_invalid_token { @controller.new_rich_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test') } + assert_raises_invalid_token { @controller.new_rich_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test', 'test') } end #"Call mfox @call > Build a working time machine" should create the "Call mfox" todo in the 'call' context and the 'Build a working time machine' project. @@ -39,27 +39,29 @@ class BackendControllerTest < Test::Rails::TestCase def test_new_rich_todo_creates_todo_with_new_project max_todo_id = Todo.maximum('id') max_project_id = Project.maximum('id') - @controller.new_rich_todo(users(:admin_user).login, users(:admin_user).token, contexts(:agenda).id, 'Call mfox @call > new:Run for president') + @controller.new_rich_todo(users(:admin_user).login, users(:admin_user).token, contexts(:agenda).id, 'Call mfox @call > new:Run for president', 'test') todo = Todo.find(:first, :conditions => ["id > ?", max_todo_id]) new_project = Project.find(:first, :conditions => ["id > ?", max_project_id]) assert_equal(users(:admin_user).id, todo.user_id) assert_equal(contexts(:call).id, todo.context_id) assert_equal(new_project.id, todo.project_id) assert_equal("Call mfox", todo.description) + assert_equal("test", todo.notes) end def assert_new_rich_todo_creates_mfox_todo(description_input) max_id = Todo.maximum('id') - @controller.new_rich_todo(users(:admin_user).login, users(:admin_user).token, contexts(:agenda).id, 'Call mfox @cal > Build') + @controller.new_rich_todo(users(:admin_user).login, users(:admin_user).token, contexts(:agenda).id, 'Call mfox @cal > Build', 'test') todo = Todo.find(:first, :conditions => ["id > ?", max_id]) assert_equal(users(:admin_user).id, todo.user_id) assert_equal(contexts(:call).id, todo.context_id) assert_equal(projects(:timemachine).id, todo.project_id) + assert_equal('test', todo.notes) assert_equal("Call mfox", todo.description) end def test_new_rich_todo_fails_with_context_that_does_not_belong_to_user - assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_rich_todo(users('other_user').login, users('other_user').token, contexts('agenda').id, 'test') } + assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_rich_todo(users('other_user').login, users('other_user').token, contexts('agenda').id, 'test', 'test') } end def test_list_projects_fails_with_incorrect_token