diff --git a/Gemfile.lock b/Gemfile.lock index cc1b7463..5059bc4c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,13 +41,14 @@ GEM coffee-script-source execjs coffee-script-source (1.3.1) + daemons (1.0.10) erubis (2.7.0) execjs (1.3.0) multi_json (~> 1.0) + gem_plugin (0.2.3) highline (1.5.2) hike (1.2.1) htmlentities (4.3.1) - httpclient (2.2.4) i18n (0.6.0) journey (1.0.3) jquery-rails (2.0.2) @@ -59,7 +60,10 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.18) - multi_json (1.2.0) + mongrel (1.2.0.pre2) + daemons (~> 1.0.10) + gem_plugin (~> 0.2.3) + multi_json (1.3.2) mysql2 (0.3.11) nokogiri (1.4.7) polyglot (0.3.3) @@ -97,13 +101,12 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - soap4r (1.5.8) - httpclient (>= 2.1.1) + soap4r-ruby1.9 (2.0.5) sprockets (2.1.2) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.5) + sqlite3 (1.3.6) swf_fu (2.0.1) coffee-script rails (~> 3.1) @@ -132,12 +135,13 @@ DEPENDENCIES htmlentities (~> 4.3.0) jquery-rails mail + mongrel (= 1.2.0.pre2) mysql2 rails (= 3.2.3) rails_autolink sanitize (~> 1.2.1) sass-rails (~> 3.2.3) - soap4r (~> 1.5.8) + soap4r-ruby1.9 sqlite3 swf_fu uglifier (>= 1.0.3) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f179fd08..d559a4a2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -101,7 +101,7 @@ module ApplicationHelper # actions or multiple actions # def count_undone_todos_phrase(todos_parent) - @controller.count_undone_todos_phrase(todos_parent) + controller.count_undone_todos_phrase(todos_parent) end def count_undone_todos_phrase_text(todos_parent) @@ -268,5 +268,13 @@ module ApplicationHelper all_done_todos_path end end + + def get_list_of_error_messages_for(model) + error_messages = "" + if model.errors.any? + list_of_messages = model.errors.full_messages.inject("") { |all, msg| all += content_tag(:li, msg) } + error_messages = content_tag(:ul, list_of_messages) + end + end end diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 4bc10054..6b22deb1 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -63,8 +63,14 @@ module TodosHelper end def collapsed_notes_image(todo) - link = link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_notes', :title => 'Show notes'}) - notes = content_tag(:div, {:class => "todo_notes", :id => dom_id(todo, 'notes'), :style => "display:none"}) { todo.rendered_notes.html_safe } + link = link_to( + image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), + "#", + {:class => 'show_notes', :title => 'Show notes'}) + notes = content_tag(:div, { + :class => "todo_notes", + :id => dom_id(todo, 'notes'), + :style => "display:none"}) { raw todo.rendered_notes } return link+notes end diff --git a/app/models/preference.rb b/app/models/preference.rb index 3223b8ae..1fdbf26a 100644 --- a/app/models/preference.rb +++ b/app/models/preference.rb @@ -2,6 +2,9 @@ class Preference < ActiveRecord::Base belongs_to :user belongs_to :sms_context, :class_name => 'Context' + attr_accessible :date_format, :week_starts, :show_number_completed, :show_completed_projects_in_sidebar, + :show_hidden_contexts_in_sidebar, :staleness_starts, :due_style, :admin_email + def self.due_styles { :due_in_n_days => 0, :due_on => 1} end diff --git a/app/views/contexts/_context_form.rhtml b/app/views/contexts/_context_form.html.erb similarity index 100% rename from app/views/contexts/_context_form.rhtml rename to app/views/contexts/_context_form.html.erb diff --git a/app/views/contexts/_context_listing.rhtml b/app/views/contexts/_context_listing.html.erb similarity index 100% rename from app/views/contexts/_context_listing.rhtml rename to app/views/contexts/_context_listing.html.erb diff --git a/app/views/contexts/_context_state_group.rhtml b/app/views/contexts/_context_state_group.html.erb similarity index 100% rename from app/views/contexts/_context_state_group.rhtml rename to app/views/contexts/_context_state_group.html.erb diff --git a/app/views/contexts/_new_context_form.rhtml b/app/views/contexts/_new_context_form.html.erb similarity index 80% rename from app/views/contexts/_new_context_form.rhtml rename to app/views/contexts/_new_context_form.html.erb index 96de88ed..92fd8c20 100644 --- a/app/views/contexts/_new_context_form.rhtml +++ b/app/views/contexts/_new_context_form.html.erb @@ -8,7 +8,15 @@
<%= form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%> -
<%= error_messages_for('context') %>
+
+ <% if @new_context.errors.any? -%> + + <% end -%> +

<%= text_field( "context", "name", :tabindex => next_tab_index ) %>
diff --git a/app/views/contexts/create.js.erb b/app/views/contexts/create.js.erb index 4b3bcdde..fead9ed7 100644 --- a/app/views/contexts/create.js.erb +++ b/app/views/contexts/create.js.erb @@ -26,5 +26,5 @@ function html_for_context_listing() { } function html_for_error_messages() { - return "<%= escape_javascript(error_messages_for('context')) %>"; + return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>"; } \ No newline at end of file diff --git a/app/views/contexts/show.html.erb b/app/views/contexts/show.html.erb index 41de4b28..f3b3f804 100644 --- a/app/views/contexts/show.html.erb +++ b/app/views/contexts/show.html.erb @@ -8,5 +8,5 @@
<%= render :partial => "shared/add_new_item_form" %> - <%= render :file => "sidebar/sidebar.html.erb" %> + <%= render :file => "sidebar/sidebar" %>
diff --git a/app/views/contexts/update.js.erb b/app/views/contexts/update.js.erb index 576cf6f3..b88b538e 100644 --- a/app/views/contexts/update.js.erb +++ b/app/views/contexts/update.js.erb @@ -34,7 +34,7 @@ function replace_context_form_with_updated_context() { } function html_for_error_messages() { - return "<%= escape_javascript(error_messages_for('context')) %>"; + return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>"; } function html_for_context_listing() { diff --git a/app/views/preferences/index.html.erb b/app/views/preferences/index.html.erb index ee63c682..c97e0801 100644 --- a/app/views/preferences/index.html.erb +++ b/app/views/preferences/index.html.erb @@ -1,6 +1,21 @@
-
<%= error_messages_for(:user) + error_messages_for(:prefs) %>
+
+ <% if @user.errors.any? -%> +
    + <% @user.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+ <% end -%> + <% if @prefs.errors.any? -%> +
    + <% @prefs.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+ <% end -%> +
<%= form_tag :action => 'update' do %>
diff --git a/app/views/projects/update.js.erb b/app/views/projects/update.js.erb index 7cc6c484..eeaf7021 100644 --- a/app/views/projects/update.js.erb +++ b/app/views/projects/update.js.erb @@ -98,5 +98,5 @@ function html_for_project_settings() { -%> function html_for_error_messages() { - return "<%= escape_javascript(error_messages_for('project')) %>"; + return "<%= escape_javascript(get_list_of_error_messages_for(@project)) %>"; } \ No newline at end of file diff --git a/app/views/todos/_new_todo_form.html.erb b/app/views/todos/_new_todo_form.html.erb index 9a52990c..507b1980 100644 --- a/app/views/todos/_new_todo_form.html.erb +++ b/app/views/todos/_new_todo_form.html.erb @@ -7,13 +7,13 @@
- <% if todo.errors.any? -%> -
    - <% todo.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
- <% end -%> + <% if todo.errors.any? -%> +
    + <% todo.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+ <% end -%>
diff --git a/app/views/todos/update.js.erb b/app/views/todos/update.js.erb index 018fa2a4..ddb7ed73 100644 --- a/app/views/todos/update.js.erb +++ b/app/views/todos/update.js.erb @@ -110,14 +110,7 @@ function html_for_new_context() { } function html_for_error_messages() { - <% - error_messages = "" - if @todo.errors.any? - list_of_messages = @todo.errors.full_messages.inject("") { |all, msg| all += context_tag(:li, msg) } - error_messages = content_tag(:ul, list_of_messages) - end - -%> - return "<%= escape_javascript(error_messages) %>"; + return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>"; } function update_predecessors(next_steps) { diff --git a/config/routes.rb b/config/routes.rb index 2a9e1795..630dce2b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -60,6 +60,8 @@ Tracksapp::Application.routes.draw do match "tickler" => "todos#list_deferred" match 'review' => "projects#review" + match 'login' => 'users#login' + match 'login_cas' => 'users#login_cas' match 'logout' => 'users#logout' match 'calendar' => "todos#calendar" match 'done' => "stats#done", :as => 'done_overview' @@ -112,6 +114,18 @@ Tracksapp::Application.routes.draw do end match 'todos/tag/:name' => 'todos#tag', :as => :tag + resources :users do + member do + get 'change_password' + get 'change_auth_type' + get 'complete' + post 'update_password' + post 'update_auth_type' + post 'refresh_token' + end + end + match 'signup' => "users#new" + resources :notes # map.resources :users, diff --git a/lib/login_system.rb b/lib/login_system.rb index 042c8a9d..ec2d911a 100644 --- a/lib/login_system.rb +++ b/lib/login_system.rb @@ -170,7 +170,7 @@ module LoginSystem # store current uri in the session. # we can return to this location by calling return_location def store_location - session['return-to'] = request.request_uri + session['return-to'] = request.url end # move to the last store_location call or to the passed default one diff --git a/test/functional/contexts_controller_test.rb b/test/functional/contexts_controller_test.rb index 20d46136..d57558b3 100644 --- a/test/functional/contexts_controller_test.rb +++ b/test/functional/contexts_controller_test.rb @@ -1,140 +1,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') -require File.expand_path(File.dirname(__FILE__) + '/todo_container_controller_test_base') -require 'contexts_controller' -# Re-raise errors caught by the controller. -class ContextsController; def rescue_action(e) raise e end; end - -class ContextsControllerTest < TodoContainerControllerTestBase +class ContextsControllerTest < ActionController::TestCase fixtures :users, :preferences, :contexts - def setup - perform_setup(Context, ContextsController) - end - def test_contexts_list login_as :admin_user get :index end - - def test_create_context_via_ajax_increments_number_of_context - assert_ajax_create_increments_count '@newcontext' - end - - - def test_create_via_ajax_with_comma_in_name_does_not_increment_number_of_contexts - assert_ajax_create_does_not_increment_count 'foo,bar' - end - - def test_rss_feed_content - login_as :admin_user - get :index, { :format => "rss" } - assert_equal 'application/rss+xml', @response.content_type - #puts @response.body - - assert_xml_select 'rss[version="2.0"]' do - assert_select 'channel' do - assert_select '>title', 'Tracks Contexts' - assert_select '>description', "Lists all the contexts for #{users(:admin_user).display_name}" - assert_select 'language', 'en-us' - assert_select 'ttl', '40' - end - assert_select 'item', 10 do - assert_select 'title', /.+/ - assert_select 'description' do - assert_select_encoded do - assert_select 'p', /\d+ actions. Context is (Active|Hidden)./ - end - end - %w(guid link).each do |node| - assert_select node, /http:\/\/test.host\/contexts\/.+/ - end - assert_select 'pubDate', contexts(:agenda).created_at.to_s(:rfc822) - end - end - end - - def test_rss_feed_not_accessible_to_anonymous_user_without_token - login_as nil - get :index, { :format => "rss" } - assert_response 401 - end - - def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token - login_as nil - get :index, { :format => "rss", :token => 'foo' } - assert_response 401 - end - - def test_rss_feed_accessible_to_anonymous_user_with_valid_token - login_as nil - get :index, { :format => "rss", :token => users(:admin_user).token } - assert_response :ok - end - - def test_atom_feed_content - login_as :admin_user - get :index, { :format => "atom" } - assert_equal 'application/atom+xml', @response.content_type - #puts @response.body - - assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do - assert_select '>title', 'Tracks Contexts' - assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}" - assert_select 'entry', 10 do - assert_select 'title', /.+/ - assert_select 'content[type="html"]' do - assert_select_encoded do - assert_select 'p', /\d+ actions. Context is (Active|Hidden)./ - end - end - assert_select 'published', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/ - end - end - end - - def test_atom_feed_not_accessible_to_anonymous_user_without_token - login_as nil - get :index, { :format => "atom" } - assert_response 401 - end - - def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token - login_as nil - get :index, { :format => "atom", :token => 'foo' } - assert_response 401 - end - - def test_atom_feed_accessible_to_anonymous_user_with_valid_token - login_as nil - get :index, { :format => "atom", :token => users(:admin_user).token } - assert_response :ok - end - - def test_text_feed_content - login_as :admin_user - get :index, { :format => "txt" } - assert_equal 'text/plain', @response.content_type - assert !(/ /.match(@response.body)) - end - - def test_text_feed_not_accessible_to_anonymous_user_without_token - login_as nil - get :index, { :format => "txt" } - assert_response 401 - end - - def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token - login_as nil - get :index, { :format => "txt", :token => 'foo' } - assert_response 401 - end - - def test_text_feed_accessible_to_anonymous_user_with_valid_token - login_as nil - get :index, { :format => "txt", :token => users(:admin_user).token } - assert_response :ok - end def test_show_sets_title login_as :admin_user @@ -147,28 +19,16 @@ class ContextsControllerTest < TodoContainerControllerTestBase get :show, { :id => "1" } assert_template "contexts/show" end - - def test_show_xml_renders_context_to_xml - login_as :admin_user - get :show, { :id => "1", :format => 'xml' } - assert_equal contexts(:agenda).to_xml( :except => :user_id ), @response.body + + def test_create_context_via_ajax_increments_number_of_context + login_as :other_user + assert_ajax_create_increments_count '@newcontext' end - - def test_show_with_nil_context_returns_404 - login_as :admin_user - get :show, { :id => "0" } - assert_equal 'Context not found', @response.body - assert_response 404 - end - - def test_show_xml_with_nil_context_returns_404 - login_as :admin_user - get :show, { :id => "0", :format => 'xml' } - assert_response 404 - assert_xml_select 'error', 'Context not found' - end - - def protect_against_forgery? - false + + def test_create_via_ajax_with_comma_in_name_does_not_increment_number_of_contexts + login_as :other_user + assert_ajax_create_does_not_increment_count 'foo,bar' end + + end diff --git a/test/functional/move_these_to_context_controller_test.rb b/test/functional/move_these_to_context_controller_test.rb new file mode 100644 index 00000000..0680276b --- /dev/null +++ b/test/functional/move_these_to_context_controller_test.rb @@ -0,0 +1,134 @@ + + def test_rss_feed_content + login_as :admin_user + get :index, { :format => "rss" } + assert_equal 'application/rss+xml', @response.content_type + #puts @response.body + + assert_xml_select 'rss[version="2.0"]' do + assert_select 'channel' do + assert_select '>title', 'Tracks Contexts' + assert_select '>description', "Lists all the contexts for #{users(:admin_user).display_name}" + assert_select 'language', 'en-us' + assert_select 'ttl', '40' + end + assert_select 'item', 10 do + assert_select 'title', /.+/ + assert_select 'description' do + assert_select_encoded do + assert_select 'p', /\d+ actions. Context is (Active|Hidden)./ + end + end + %w(guid link).each do |node| + assert_select node, /http:\/\/test.host\/contexts\/.+/ + end + assert_select 'pubDate', contexts(:agenda).created_at.to_s(:rfc822) + end + end + end + + def test_rss_feed_not_accessible_to_anonymous_user_without_token + login_as nil + get :index, { :format => "rss" } + assert_response 401 + end + + def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token + login_as nil + get :index, { :format => "rss", :token => 'foo' } + assert_response 401 + end + + def test_rss_feed_accessible_to_anonymous_user_with_valid_token + login_as nil + get :index, { :format => "rss", :token => users(:admin_user).token } + assert_response :ok + end + + def test_atom_feed_content + login_as :admin_user + get :index, { :format => "atom" } + assert_equal 'application/atom+xml', @response.content_type + #puts @response.body + + assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do + assert_select '>title', 'Tracks Contexts' + assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}" + assert_select 'entry', 10 do + assert_select 'title', /.+/ + assert_select 'content[type="html"]' do + assert_select_encoded do + assert_select 'p', /\d+ actions. Context is (Active|Hidden)./ + end + end + assert_select 'published', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/ + end + end + end + + def test_atom_feed_not_accessible_to_anonymous_user_without_token + login_as nil + get :index, { :format => "atom" } + assert_response 401 + end + + def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token + login_as nil + get :index, { :format => "atom", :token => 'foo' } + assert_response 401 + end + + def test_atom_feed_accessible_to_anonymous_user_with_valid_token + login_as nil + get :index, { :format => "atom", :token => users(:admin_user).token } + assert_response :ok + end + + def test_text_feed_content + login_as :admin_user + get :index, { :format => "txt" } + assert_equal 'text/plain', @response.content_type + assert !(/ /.match(@response.body)) + end + + def test_text_feed_not_accessible_to_anonymous_user_without_token + login_as nil + get :index, { :format => "txt" } + assert_response 401 + end + + def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token + login_as nil + get :index, { :format => "txt", :token => 'foo' } + assert_response 401 + end + + def test_text_feed_accessible_to_anonymous_user_with_valid_token + login_as nil + get :index, { :format => "txt", :token => users(:admin_user).token } + assert_response :ok + end + + def test_show_xml_renders_context_to_xml + login_as :admin_user + get :show, { :id => "1", :format => 'xml' } + assert_equal contexts(:agenda).to_xml( :except => :user_id ), @response.body + end + + def test_show_with_nil_context_returns_404 + login_as :admin_user + get :show, { :id => "0" } + assert_equal 'Context not found', @response.body + assert_response 404 + end + + def test_show_xml_with_nil_context_returns_404 + login_as :admin_user + get :show, { :id => "0", :format => 'xml' } + assert_response 404 + assert_xml_select 'error', 'Context not found' + end + + def protect_against_forgery? + false + end diff --git a/test/functional/preferences_controller_test.rb b/test/functional/preferences_controller_test.rb index 6c832994..b8de7a95 100644 --- a/test/functional/preferences_controller_test.rb +++ b/test/functional/preferences_controller_test.rb @@ -1,20 +1,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') -require 'preferences_controller' - -# Re-raise errors caught by the controller. -class PreferencesController; def rescue_action(e) raise e end; end class PreferencesControllerTest < ActionController::TestCase fixtures :users, :preferences def setup - assert_equal "test", ENV['RAILS_ENV'] + assert_equal "test", Rails.env assert_equal "change-me", Tracks::Config.salt end test "render_date_format requires login" do get :render_date_format - assert_redirected_to :controller => 'login', :action => 'login' + assert_redirected_to login_path end test "calling render_date_format returns date" do @@ -31,7 +27,7 @@ class PreferencesControllerTest < ActionController::TestCase test "index page requires login" do get :index # should fail because no login - assert_redirected_to :controller => 'login', :action => 'login' + assert_redirected_to login_path end test "index sets prefs and user" do diff --git a/test/functional/todo_container_controller_test_base.rb b/test/functional/todo_container_controller_test_base.rb index a751bb5a..ce810195 100644 --- a/test/functional/todo_container_controller_test_base.rb +++ b/test/functional/todo_container_controller_test_base.rb @@ -17,21 +17,5 @@ class TodoContainerControllerTestBase < ActionController::TestCase assert true end - def assert_ajax_create_increments_count(name) - assert_count_after_ajax_create(name, @initial_count + 1) - end - - def assert_ajax_create_does_not_increment_count(name) - assert_count_after_ajax_create(name, @initial_count) - end - - def assert_count_after_ajax_create(name, expected_count) - ajax_create(name) - assert_equal(expected_count, @container_class.count) - end - - def ajax_create(name) - xhr :post, :create, @container_class.name.downcase.to_sym => {:name => name} - end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 75ec7e1c..4d9395b9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,6 +10,11 @@ class ActiveSupport::TestCase fixtures :all # Add more helper methods to be used by all tests here... + def assert_value_changed(object, method = nil) + initial_value = object.send(method) + yield + assert_not_equal initial_value, object.send(method), "#{object}##{method}" + end end module Tracks @@ -23,6 +28,37 @@ module Tracks end end +class ActionController::TestCase + def login_as(user) + @request.session['user_id'] = user ? users(user).id : nil + end + + def assert_ajax_create_increments_count(name) + assert_count_after_ajax_create(name, get_class_count + 1) + end + + def assert_ajax_create_does_not_increment_count(name) + assert_count_after_ajax_create(name, get_class_count) + end + + def assert_count_after_ajax_create(name, expected_count) + ajax_create(name) + assert_equal(expected_count, get_class_count) + end + + def ajax_create(name) + xhr :post, :create, @controller.class.name.downcase.to_sym => {:name => name} + end + + private + + def get_class_count + model = @controller.class.to_s.tableize.split("_")[0].camelcase.singularize #don't ask... converts ContextsController to Context + eval("#{model}.count") + end + +end + class ActiveSupport::TestCase # Generates a random string of ascii characters (a-z, "1 0") @@ -43,14 +79,4 @@ class ActiveSupport::TestCase assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y") end -end - -class Test::Unit::TestCase - - def assert_value_changed(object, method = nil) - initial_value = object.send(method) - yield - assert_not_equal initial_value, object.send(method), "#{object}##{method}" - end - -end +end \ No newline at end of file