mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
improve tests for preferences and fix a pending cucumber step
This commit is contained in:
parent
07b05d01f7
commit
84ad01a6f6
4 changed files with 74 additions and 35 deletions
|
|
@ -291,6 +291,7 @@ module TodosHelper
|
||||||
def update_needs_to_hide_context
|
def update_needs_to_hide_context
|
||||||
return (@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) ||
|
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 && @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)
|
(@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)
|
return false if source_view_is_one_of(:project, :calendar)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ Feature: Tagging todos
|
||||||
@selenium
|
@selenium
|
||||||
Scenario: I can add a new todo from tag view with a different tag and it will not be added to the page
|
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"
|
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"
|
Then I should not see "prepare release"
|
||||||
|
|
||||||
@selenium
|
@selenium
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,84 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
require 'preferences_controller'
|
require 'preferences_controller'
|
||||||
require 'preference'
|
|
||||||
|
|
||||||
# Re-raise errors caught by the controller.
|
# Re-raise errors caught by the controller.
|
||||||
class PreferencesController; def rescue_action(e) raise e end; end
|
class PreferencesController; def rescue_action(e) raise e end; end
|
||||||
|
|
||||||
class PreferencesControllerTest < ActionController::TestCase
|
class PreferencesControllerTest < ActionController::TestCase
|
||||||
fixtures :users, :preferences
|
fixtures :users, :preferences
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
assert_equal "test", ENV['RAILS_ENV']
|
assert_equal "test", ENV['RAILS_ENV']
|
||||||
assert_equal "change-me", Tracks::Config.salt
|
assert_equal "change-me", Tracks::Config.salt
|
||||||
@controller = PreferencesController.new
|
|
||||||
@request = ActionController::TestRequest.new
|
|
||||||
@response = ActionController::TestResponse.new
|
|
||||||
end
|
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
|
get :index # should fail because no login
|
||||||
assert_redirected_to :controller => 'login', :action => 'login'
|
assert_redirected_to :controller => 'login', :action => 'login'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "index sets prefs and user" do
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal assigns['page_title'], "TRACKS::Preferences"
|
assert_equal assigns['page_title'], "TRACKS::Preferences"
|
||||||
assert_not_nil assigns['prefs']
|
assert_not_nil assigns['prefs']
|
||||||
|
assert_not_nil assigns['user']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_edit_preferences
|
test "should update preferences" do
|
||||||
get :edit # should fail because no login
|
|
||||||
assert_redirected_to :controller => 'login', :action => 'login'
|
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :edit
|
post :update, {
|
||||||
assert_response :success
|
:user => { :first_name => 'Jane', :last_name => 'Doe'},
|
||||||
assert_equal assigns['page_title'], "TRACKS::Edit Preferences"
|
: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" }}
|
||||||
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" }}
|
|
||||||
updated_admin_user = users(:admin_user).reload
|
updated_admin_user = users(:admin_user).reload
|
||||||
assert_not_nil updated_admin_user.preference
|
assert_not_nil updated_admin_user.preference
|
||||||
assert_equal 'Jane', updated_admin_user.first_name
|
assert_equal 'Jane', updated_admin_user.first_name
|
||||||
assert_equal 'Doe', updated_admin_user.last_name
|
assert_equal 'Doe', updated_admin_user.last_name
|
||||||
assert_redirected_to :action => 'index'
|
assert_redirected_to :action => 'index'
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,15 @@ require File.expand_path(File.dirname(__FILE__) + "/../app/controllers/applicati
|
||||||
require 'test_help'
|
require 'test_help'
|
||||||
require 'flexmock/test_unit' #and the flexmock gem, too!
|
require 'flexmock/test_unit' #and the flexmock gem, too!
|
||||||
require 'action_web_service/test_invoke'
|
require 'action_web_service/test_invoke'
|
||||||
|
|
||||||
module Tracks
|
module Tracks
|
||||||
class Config
|
class Config
|
||||||
def self.salt
|
def self.salt
|
||||||
"change-me"
|
"change-me"
|
||||||
end
|
end
|
||||||
|
def self.auth_schemes
|
||||||
|
return ["database","open_id"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -30,9 +33,9 @@ class Test::Unit::TestCase
|
||||||
actual_error = model_instance.errors.on attribute.to_sym
|
actual_error = model_instance.errors.on attribute.to_sym
|
||||||
assert_equal expected_error, actual_error
|
assert_equal expected_error, actual_error
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :assert_errors_on, :assert_error_on
|
alias_method :assert_errors_on, :assert_error_on
|
||||||
|
|
||||||
def assert_value_changed(object, method = nil)
|
def assert_value_changed(object, method = nil)
|
||||||
initial_value = object.send(method)
|
initial_value = object.send(method)
|
||||||
yield
|
yield
|
||||||
|
|
@ -42,7 +45,7 @@ class Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
|
|
||||||
# Generates a random string of ascii characters (a-z, "1 0")
|
# Generates a random string of ascii characters (a-z, "1 0")
|
||||||
# of a given length for testing assignment to fields
|
# of a given length for testing assignment to fields
|
||||||
# for validation purposes
|
# for validation purposes
|
||||||
|
|
@ -56,11 +59,11 @@ class ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
return string
|
return string
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_week
|
def next_week
|
||||||
1.week.from_now.utc
|
1.week.from_now.utc
|
||||||
end
|
end
|
||||||
|
|
||||||
# Courtesy of http://habtm.com/articles/2006/02/20/assert-yourself-man-redirecting-with-rjs
|
# Courtesy of http://habtm.com/articles/2006/02/20/assert-yourself-man-redirecting-with-rjs
|
||||||
def assert_js_redirected_to(options={}, message=nil)
|
def assert_js_redirected_to(options={}, message=nil)
|
||||||
clean_backtrace do
|
clean_backtrace do
|
||||||
|
|
@ -104,12 +107,12 @@ end
|
||||||
|
|
||||||
class ActionController::IntegrationTest
|
class ActionController::IntegrationTest
|
||||||
Tag #avoid errors in integration tests
|
Tag #avoid errors in integration tests
|
||||||
|
|
||||||
def assert_test_environment_ok
|
def assert_test_environment_ok
|
||||||
assert_equal "test", ENV['RAILS_ENV']
|
assert_equal "test", ENV['RAILS_ENV']
|
||||||
assert_equal "change-me", Tracks::Config.salt
|
assert_equal "change-me", Tracks::Config.salt
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticated_post_xml(url, username, password, parameters, headers = {})
|
def authenticated_post_xml(url, username, password, parameters, headers = {})
|
||||||
post url,
|
post url,
|
||||||
parameters,
|
parameters,
|
||||||
|
|
@ -118,7 +121,7 @@ class ActionController::IntegrationTest
|
||||||
'CONTENT_TYPE' => 'application/xml'
|
'CONTENT_TYPE' => 'application/xml'
|
||||||
}.merge(headers)
|
}.merge(headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticated_get_xml(url, username, password, parameters, headers = {})
|
def authenticated_get_xml(url, username, password, parameters, headers = {})
|
||||||
get url,
|
get url,
|
||||||
parameters,
|
parameters,
|
||||||
|
|
@ -127,7 +130,7 @@ class ActionController::IntegrationTest
|
||||||
'CONTENT_TYPE' => 'application/xml'
|
'CONTENT_TYPE' => 'application/xml'
|
||||||
}.merge(headers)
|
}.merge(headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_response_and_body(type, body, message = nil)
|
def assert_response_and_body(type, body, message = nil)
|
||||||
assert_equal body, @response.body, message
|
assert_equal body, @response.body, message
|
||||||
assert_response type, message
|
assert_response type, message
|
||||||
|
|
@ -137,13 +140,13 @@ class ActionController::IntegrationTest
|
||||||
assert_response type, message
|
assert_response type, message
|
||||||
assert_match body_regex, @response.body, message
|
assert_match body_regex, @response.body, message
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_401_unauthorized
|
def assert_401_unauthorized
|
||||||
assert_response_and_body 401, "401 Unauthorized: You are not authorized to interact with Tracks."
|
assert_response_and_body 401, "401 Unauthorized: You are not authorized to interact with Tracks."
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_401_unauthorized_admin
|
def assert_401_unauthorized_admin
|
||||||
assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function."
|
assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function."
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue