diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 732ca49e..4f8b6cc8 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -291,6 +291,7 @@ module TodosHelper def update_needs_to_hide_context return (@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) || (@remaining_in_context == 0 && @todo_was_deferred_from_active_state) || + (@remaining_in_context == 0 && @tag_was_removed) || (@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag) return false if source_view_is_one_of(:project, :calendar) diff --git a/features/tagging_todos.feature b/features/tagging_todos.feature index 280d3704..04ced4c0 100644 --- a/features/tagging_todos.feature +++ b/features/tagging_todos.feature @@ -28,7 +28,7 @@ Feature: Tagging todos @selenium Scenario: I can add a new todo from tag view with a different tag and it will not be added to the page When I go to the tag page for "tracks" - And I submit a new action with description "prepare release" with tags "release, next" in the context "@pc" + And I submit a new action with description "prepare release" and the tags "release, next" in the context "@pc" Then I should not see "prepare release" @selenium diff --git a/test/functional/preferences_controller_test.rb b/test/functional/preferences_controller_test.rb index c12b007f..13d478b9 100644 --- a/test/functional/preferences_controller_test.rb +++ b/test/functional/preferences_controller_test.rb @@ -1,49 +1,84 @@ -require File.expand_path(File.dirname(__FILE__) + '/../test_helper') +require File.dirname(__FILE__) + '/../test_helper' require 'preferences_controller' -require 'preference' # 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 "change-me", Tracks::Config.salt - @controller = PreferencesController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new end - def test_preferences + test "render_date_format requires login" do + get :render_date_format + assert_redirected_to :controller => 'login', :action => 'login' + end + + test "calling render_date_format returns date" do + login_as :admin_user + + get :render_date_format + assert_response :success + assert_equal I18n.l(Time.zone.now, :format => "%Y-%m-%d"), @response.body + + get(:render_date_format, {:date_format => "%A %Y"}) + assert_response :success + assert_equal I18n.l(Time.zone.now, :format => "%A %Y"), @response.body + end + + test "index page requires login" do get :index # should fail because no login assert_redirected_to :controller => 'login', :action => 'login' + end + + test "index sets prefs and user" do login_as :admin_user get :index assert_response :success assert_equal assigns['page_title'], "TRACKS::Preferences" assert_not_nil assigns['prefs'] + assert_not_nil assigns['user'] end - - def test_edit_preferences - get :edit # should fail because no login - assert_redirected_to :controller => 'login', :action => 'login' + + test "should update preferences" do login_as :admin_user - get :edit - assert_response :success - assert_equal assigns['page_title'], "TRACKS::Edit Preferences" - assert_template 'preferences/edit' - end - - def test_update_preferences - login_as :admin_user - post :update, {:user => { :first_name => 'Jane', :last_name => 'Doe'}, :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }} + post :update, { + :user => { :first_name => 'Jane', :last_name => 'Doe'}, + :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }} updated_admin_user = users(:admin_user).reload assert_not_nil updated_admin_user.preference assert_equal 'Jane', updated_admin_user.first_name assert_equal 'Doe', updated_admin_user.last_name assert_redirected_to :action => 'index' end - + + test "should not update password if left empty" do + login_as :admin_user + + old_password_hash = users(:admin_user).password + + post :update, { + :user => { :first_name => 'Jane', :last_name => 'Doe', :password => "", :password_confirmation => ""}, + :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }} + + updated_admin_user = users(:admin_user).reload + assert_equal old_password_hash, updated_admin_user.password + end + + test "should be able to change authentication type" do + assert Tracks::Config.auth_schemes.include?("open_id"), "open_id should be a valid authentication scheme" + + login_as :admin_user + + post :update, { + :user => { :first_name => 'Jane', :last_name => 'Doe', :auth_type => "open_id", :open_id_url => "http://test"}, + :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }} + + updated_admin_user = users(:admin_user).reload + assert_equal "open_id", updated_admin_user.auth_type + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index 07d55071..40d8a464 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,12 +5,15 @@ require File.expand_path(File.dirname(__FILE__) + "/../app/controllers/applicati require 'test_help' require 'flexmock/test_unit' #and the flexmock gem, too! require 'action_web_service/test_invoke' - + module Tracks class Config def self.salt "change-me" end + def self.auth_schemes + return ["database","open_id"] + end end end @@ -30,9 +33,9 @@ class Test::Unit::TestCase actual_error = model_instance.errors.on attribute.to_sym assert_equal expected_error, actual_error end - + alias_method :assert_errors_on, :assert_error_on - + def assert_value_changed(object, method = nil) initial_value = object.send(method) yield @@ -42,7 +45,7 @@ class Test::Unit::TestCase end class ActiveSupport::TestCase - + # Generates a random string of ascii characters (a-z, "1 0") # of a given length for testing assignment to fields # for validation purposes @@ -56,11 +59,11 @@ class ActiveSupport::TestCase end return string end - + def next_week 1.week.from_now.utc end - + # Courtesy of http://habtm.com/articles/2006/02/20/assert-yourself-man-redirecting-with-rjs def assert_js_redirected_to(options={}, message=nil) clean_backtrace do @@ -104,12 +107,12 @@ end class ActionController::IntegrationTest Tag #avoid errors in integration tests - + def assert_test_environment_ok assert_equal "test", ENV['RAILS_ENV'] assert_equal "change-me", Tracks::Config.salt end - + def authenticated_post_xml(url, username, password, parameters, headers = {}) post url, parameters, @@ -118,7 +121,7 @@ class ActionController::IntegrationTest 'CONTENT_TYPE' => 'application/xml' }.merge(headers) end - + def authenticated_get_xml(url, username, password, parameters, headers = {}) get url, parameters, @@ -127,7 +130,7 @@ class ActionController::IntegrationTest 'CONTENT_TYPE' => 'application/xml' }.merge(headers) end - + def assert_response_and_body(type, body, message = nil) assert_equal body, @response.body, message assert_response type, message @@ -137,13 +140,13 @@ class ActionController::IntegrationTest assert_response type, message assert_match body_regex, @response.body, message end - + def assert_401_unauthorized assert_response_and_body 401, "401 Unauthorized: You are not authorized to interact with Tracks." end - + def assert_401_unauthorized_admin assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function." end - + end