tracks/tracks/test/functional/preferences_controller_test.rb
lukemelia 1cce7f076c This changeset is larger than I prefer, and may be unstable with databases besides mysql.
Also, for developers: two new gems are required for running tests: zentest and flexmock.

I applied James Kebinger's patch to add starred actions. These are implemented behind the scenes as a tag, so you can see all starred actions the way you would look at actions for any tag. Closes #387. Thanks, James!  
Tests now rely the ZenTest gem. Thanks Ryan Davis & Eric Hodel.
I improved test coverage of a few models and created a test for the new helper methods to support the stars. (Helper method tests are made possible by ZenTest. The helper tests use mock objects to isolate them, courtesy of flexmock. Thanks, Jim Weirich!)
Modified a few selenium tests to work properly with mysql.
Upgraded the has_many_polymorphs plugin.
Add rails_rcov plugin to get test coverage numbers more easily.
Convert toggle_check action to correspond to a PUT instead of a POST (follows CRUD<->HTTP mapping better).

I'm having some issues running tests with sqlite3 that I haven't been able to figure out. I'll work on it, but wanted to check in so I can check out and work from the beach this weekend.

Happy holiday weekend to those of you in the U.S.!




git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@544 a4c988fc-2ded-0310-b66e-134b36920a42
2007-05-25 19:01:08 +00:00

50 lines
2 KiB
Ruby

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 < Test::Rails::TestCase
fixtures :users
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
get :index # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
@request.session['user_id'] = users(:admin_user).id # log in the admin user
get :index
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Preferences"
assert_not_nil assigns['prefs']
end
def test_edit_preferences
get :edit # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
@request.session['user_id'] = users(:admin_user).id # log in the admin user
get :edit
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Edit Preferences"
assert_not_nil assigns['prefs']
assert_template 'preferences/edit'
end
def test_update_preferences
@request.session['user_id'] = users(:admin_user).id # log in the 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" }}
updated_admin_user = User.find(users(:admin_user).id)
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
end