mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-21 17:50:13 +01:00
Removed superfluous 'tracks' directory at the root of the repository.
Testing commits to github.
This commit is contained in:
parent
6a42901514
commit
4cbf5a34d3
2269 changed files with 0 additions and 0 deletions
32
vendor/plugins/unobtrusive_javascript/test/asset_tag_helper_patches_test.rb
vendored
Normal file
32
vendor/plugins/unobtrusive_javascript/test/asset_tag_helper_patches_test.rb
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
require 'asset_tag_helper_patches'
|
||||
|
||||
class JavascriptIncludeTagWithUnobtrusiveOption < Test::Unit::TestCase
|
||||
include ActionView::Helpers::AssetTagHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
@output = javascript_include_tag(:unobtrusive).split("\n")
|
||||
end
|
||||
|
||||
def test_should_render_script_tag_for_lowpro
|
||||
assert @output.include?('<script src="/javascripts/lowpro.js?" type="text/javascript"></script>')
|
||||
end
|
||||
|
||||
def test_should_render_script_tag_for_current_requests_behaviour
|
||||
assert @output.include?('<script src="/behaviours/controller_stub.js?" type="text/javascript"></script>')
|
||||
end
|
||||
|
||||
def test_should_render_index_behaviour_when_request_path_is_just_a_forward_slash
|
||||
@controller.request.stubs(:path).returns('/')
|
||||
@output = javascript_include_tag(:unobtrusive).split("\n")
|
||||
assert @output.include?('<script src="/behaviours/index.js?" type="text/javascript"></script>')
|
||||
end
|
||||
|
||||
def test_should_render_index_behaviour_when_request_path_is_blank_as_a_result_of_a_url_prefix
|
||||
@controller.request.stubs(:path).returns('')
|
||||
@output = javascript_include_tag(:unobtrusive).split("\n")
|
||||
assert @output.include?('<script src="/behaviours/index.js?" type="text/javascript"></script>')
|
||||
end
|
||||
end
|
||||
180
vendor/plugins/unobtrusive_javascript/test/behaviour_helper_test.rb
vendored
Normal file
180
vendor/plugins/unobtrusive_javascript/test/behaviour_helper_test.rb
vendored
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
require 'prototype_helper_patches'
|
||||
require 'scriptaculous_helper_patches'
|
||||
require 'ujs/behaviour_helper'
|
||||
|
||||
class MakeSortableTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
end
|
||||
|
||||
def test_should_output_sortable_javascript
|
||||
output = make_sortable
|
||||
|
||||
assert_equal sortable_element_js(javascript_variable('this')), output
|
||||
end
|
||||
|
||||
def test_should_pass_arguments_through
|
||||
output = make_sortable :onUpdate => 'function() { alert("updated") }'
|
||||
assert_equal 'Sortable.create(this, {onUpdate:function() { alert("updated") }});', output
|
||||
end
|
||||
end
|
||||
|
||||
class MakeRemoteLinkTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
end
|
||||
|
||||
def test_should_generate_ajax_request
|
||||
output = make_remote_link
|
||||
assert_match(/new Ajax\.Request/, output)
|
||||
end
|
||||
|
||||
def test_should_default_to_element_href
|
||||
output = make_remote_link
|
||||
assert_match(/\(this\.href/, output)
|
||||
end
|
||||
|
||||
def test_should_respond_to_given_options
|
||||
output = make_remote_link( :update => 'fartknocker' )
|
||||
assert_match(/new Ajax\.Updater\('fartknocker'/, output)
|
||||
end
|
||||
end
|
||||
|
||||
class MakeRemoteFormTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
end
|
||||
|
||||
def test_should_generate_ajax_request
|
||||
output = make_remote_form
|
||||
assert_match(/new Ajax\.Request/, output)
|
||||
end
|
||||
|
||||
def test_should_default_to_form_action
|
||||
output = make_remote_form
|
||||
assert_match(/\(this\.action/, output)
|
||||
end
|
||||
end
|
||||
|
||||
class MakeDraggableTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
end
|
||||
|
||||
def test_should_create_draggable_instance
|
||||
output = make_draggable
|
||||
assert_match(/new Draggable/, output)
|
||||
end
|
||||
|
||||
def test_should_pass_this
|
||||
output = make_draggable
|
||||
assert_match(/\(this/, output)
|
||||
end
|
||||
|
||||
def test_should_respond_to_options
|
||||
output = make_draggable( :revert => true )
|
||||
assert_match(/revert\:true/, output)
|
||||
end
|
||||
end
|
||||
|
||||
class MakeDropRecievingTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
end
|
||||
|
||||
def test_should_add_to_droppables
|
||||
output = make_drop_receiving
|
||||
assert_match(/Droppables\.add/, output)
|
||||
end
|
||||
|
||||
def test_should_pass_this
|
||||
output = make_drop_receiving
|
||||
assert_match(/\(this/, output)
|
||||
end
|
||||
|
||||
def test_should_generate_a_url_from_options
|
||||
output = make_drop_receiving( :url => { :action => "bingo" } )
|
||||
assert_match(/controller_stub\/bingo/, output)
|
||||
end
|
||||
end
|
||||
|
||||
class MakeObservedTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
|
||||
def setup
|
||||
initialize_test_request
|
||||
end
|
||||
|
||||
def test_should_make_form_observer
|
||||
output = make_observed(:form)
|
||||
assert_match(/new Form\.EventObserver/, output)
|
||||
end
|
||||
|
||||
def test_should_make_field_observer
|
||||
output = make_observed(:field)
|
||||
assert_match(/new Form\.Element\.EventObserver/, output)
|
||||
end
|
||||
|
||||
def test_should_pass_this
|
||||
output = make_observed(:field)
|
||||
assert_match(/\(this/, output)
|
||||
end
|
||||
|
||||
def test_should_make_a_timed_observer_if_frequency_passed
|
||||
output = make_observed(:form, :frequency => 3 )
|
||||
assert_match(/new Form.Observer/, output)
|
||||
assert_match(/3,/, output)
|
||||
end
|
||||
|
||||
def test_should_generate_a_url_from_options
|
||||
output = make_observed(:field, :url => { :action => "bingo" } )
|
||||
assert_match(/controller_stub\/bingo/, output)
|
||||
end
|
||||
|
||||
def test_should_respond_to_options
|
||||
output = make_observed(:field, :function => 'alert("boo")' )
|
||||
assert_match(/function\(element, value\) \{alert\("boo"\)\}/, output)
|
||||
end
|
||||
end
|
||||
|
||||
72
vendor/plugins/unobtrusive_javascript/test/behaviour_script_converter_test.rb
vendored
Normal file
72
vendor/plugins/unobtrusive_javascript/test/behaviour_script_converter_test.rb
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
class DefaultBehaviourScriptConversionTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@output = UJS::BehaviourScriptConverter.convert_to_hash(@script)
|
||||
end
|
||||
|
||||
def test_should_have_no_rules_and_the_correct_default_options
|
||||
assert_equal({ :options => { :cache => false, :reapply_after_ajax => true },
|
||||
:rules => [] }, @output)
|
||||
end
|
||||
end
|
||||
|
||||
class EmptyBehaviourScriptWithDifferentOptionsConversionTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new(true, false)
|
||||
@output = UJS::BehaviourScriptConverter.convert_to_hash(@script)
|
||||
end
|
||||
|
||||
def test_should_have_no_rules_and_the_correct_options
|
||||
assert_equal({ :options => { :cache => true, :reapply_after_ajax => false },
|
||||
:rules => [] }, @output)
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithOneRuleConversionTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.add_rule('div.foo:click', 'alert("TEST")')
|
||||
@output = UJS::BehaviourScriptConverter.convert_to_hash(@script)
|
||||
end
|
||||
|
||||
def test_should_have_one_behaviour_and_correct_options
|
||||
assert_equal({ :options => { :cache => false, :reapply_after_ajax => true },
|
||||
:rules => [
|
||||
['div.foo:click', 'alert("TEST")']
|
||||
] }, @output)
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithTwoRuleConversionTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.add_rule('div.foo:click', 'alert("TEST")')
|
||||
@script.add_rule('div.bar:click', 'alert("TEST 2")')
|
||||
@output = UJS::BehaviourScriptConverter.convert_to_hash(@script)
|
||||
end
|
||||
|
||||
def test_should_have_one_behaviour_and_correct_options
|
||||
assert_equal({ :options => { :cache => false, :reapply_after_ajax => true },
|
||||
:rules => [
|
||||
['div.foo:click', 'alert("TEST")'],
|
||||
['div.bar:click', 'alert("TEST 2")']
|
||||
] }, @output)
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptFromHashTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.add_rule('div.foo:click', 'alert("TEST")')
|
||||
@script.add_rule('div.bar:click', 'alert("TEST 2")')
|
||||
@converted_script = UJS::BehaviourScriptConverter.convert_from_hash(@script.to_hash)
|
||||
end
|
||||
|
||||
def test_should_equal_the_script_it_was_converted_from_in_the_first_place
|
||||
assert_equal @script.cache?, @converted_script.cache?
|
||||
assert_equal @script.reapply_after_ajax?, @converted_script.reapply_after_ajax?
|
||||
assert_equal @script.rules, @converted_script.rules
|
||||
end
|
||||
end
|
||||
98
vendor/plugins/unobtrusive_javascript/test/behaviour_script_test.rb
vendored
Normal file
98
vendor/plugins/unobtrusive_javascript/test/behaviour_script_test.rb
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
require 'ujs/behaviour_script'
|
||||
|
||||
class NewBehaviourScriptTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
end
|
||||
|
||||
def test_should_render_nothing_on_to_string
|
||||
assert_equal "", @script.to_s
|
||||
end
|
||||
|
||||
def test_should_not_be_cached
|
||||
assert !@script.cache?
|
||||
end
|
||||
|
||||
def test_should_be_reapplied_after_an_ajax_request
|
||||
assert @script.reapply_after_ajax?
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithOneRuleTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.add_rule("div.header:click", "alert('Hello World')")
|
||||
end
|
||||
|
||||
def test_should_render_the_rule_as_a_javascript_event_on_to_s
|
||||
expected_js = "Event.addBehavior({\n\"div.header:click\": function(event) {\nalert('Hello World')\n}\n});"
|
||||
assert_equal expected_js, @script.to_s
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithTwoRulesTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.add_rule("div.header:mouseover", "alert('Hello World')")
|
||||
@script.add_rule("div.header:mouseout", "alert('Goodbye World')")
|
||||
end
|
||||
|
||||
def test_should_render_all_rules_as_javascript_events_on_to_s
|
||||
expected_js = "Event.addBehavior({\n\"div.header:mouseover\": function(event) {\nalert('Hello World')\n},"
|
||||
expected_js = expected_js + "\n\"div.header:mouseout\": function(event) {\nalert('Goodbye World')\n}\n});"
|
||||
assert_equal expected_js, @script.to_s
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithRuleThatCancelsDefaultTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.add_rule("div.header:mouseover", "alert('Hello World');", true)
|
||||
end
|
||||
|
||||
def test_should_render_rule_with_return_false_appended_on_to_s
|
||||
expected_js = "Event.addBehavior({\n\"div.header:mouseover\": function(event) {\nalert('Hello World'); return false;\n}\n});"
|
||||
assert_equal expected_js, @script.to_s
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithNoRulesTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
end
|
||||
|
||||
def test_should_render_nothing_on_to_s
|
||||
assert_equal "", @script.to_s
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptWithRulesSetToNotReapplyAfterAjaxTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new
|
||||
@script.reapply_after_ajax = false
|
||||
@script.add_rule("div.header:click", "alert('Hello World')")
|
||||
end
|
||||
|
||||
def test_should_append_reapply_javascript_to_end_of_rules_javascript_on_to_s
|
||||
expected_js = "Event.addBehavior({\n\"div.header:click\": function(event) {\nalert('Hello World')\n}\n});"
|
||||
expected_js = expected_js + "\nEvent.addBehavior.reapplyAfterAjax = false;"
|
||||
assert_equal expected_js, @script.to_s
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourScriptToHashTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@script = UJS::BehaviourScript.new(true, false)
|
||||
@script.add_rule("div.header:mouseover", "alert('Hello World')")
|
||||
@script.add_rule("div.header:mouseout", "alert('Goodbye World')")
|
||||
end
|
||||
|
||||
def test_should_return_converted_behaviour_script
|
||||
assert_equal({ :options => { :cache => true, :reapply_after_ajax => false },
|
||||
:rules => [
|
||||
['div.header:mouseover', "alert('Hello World')"],
|
||||
['div.header:mouseout', "alert('Goodbye World')"]
|
||||
] }, @script.to_hash)
|
||||
end
|
||||
end
|
||||
19
vendor/plugins/unobtrusive_javascript/test/config/database.yml
vendored
Normal file
19
vendor/plugins/unobtrusive_javascript/test/config/database.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
test:
|
||||
adapter: sqlite3
|
||||
dbfile: test.sqlite3.db
|
||||
|
||||
# adapter: sqlite
|
||||
# dbfile: test.sqlite.db
|
||||
|
||||
# adapter: mysql
|
||||
# host: localhost
|
||||
# username:
|
||||
# password:
|
||||
# database: test
|
||||
|
||||
# adapter: postgresql
|
||||
# host: localhost
|
||||
# username:
|
||||
# password:
|
||||
# database: test
|
||||
|
||||
8
vendor/plugins/unobtrusive_javascript/test/config/environment.rb
vendored
Normal file
8
vendor/plugins/unobtrusive_javascript/test/config/environment.rb
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Rails::Initializer.run do |config|
|
||||
config.cache_classes = true
|
||||
config.whiny_nils = true
|
||||
config.action_controller.consider_all_requests_local = true
|
||||
config.action_controller.perform_caching = false
|
||||
config.action_mailer.delivery_method = :test
|
||||
config.action_mailer.perform_deliveries = true
|
||||
end
|
||||
4
vendor/plugins/unobtrusive_javascript/test/config/routes.rb
vendored
Normal file
4
vendor/plugins/unobtrusive_javascript/test/config/routes.rb
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ActionController::Routing::Routes.draw do |map|
|
||||
map.connect ':controller/:action/:id'
|
||||
UJS::routes
|
||||
end
|
||||
3
vendor/plugins/unobtrusive_javascript/test/config/schema.rb
vendored
Normal file
3
vendor/plugins/unobtrusive_javascript/test/config/schema.rb
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ActiveRecord::Schema.define(:version => 2) do
|
||||
|
||||
end
|
||||
48
vendor/plugins/unobtrusive_javascript/test/controller_methods_test.rb
vendored
Normal file
48
vendor/plugins/unobtrusive_javascript/test/controller_methods_test.rb
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
class ControllerWithControllerMethodsInjected < Test::Unit::TestCase
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
end
|
||||
|
||||
def test_should_add_a_before_filter_that_creates_a_new_behaviour_script
|
||||
assert ControllerStub.before_filters.include?(:initialise_js_behaviours)
|
||||
assert_instance_of UJS::BehaviourScript, assigns(:js_behaviours)
|
||||
assert_equal "", assigns(:js_behaviours).to_s
|
||||
end
|
||||
|
||||
def test_should_store_applied_behaviours_in_the_behaviour_script
|
||||
@controller.apply_behaviour("div.foo", "alert('foo')")
|
||||
assert_equal 1, assigns(:js_behaviours).rules.size
|
||||
end
|
||||
|
||||
def test_should_add_an_after_filter_that_stores_the_behaviour_script_in_the_session_as_a_hash
|
||||
assert ControllerStub.after_filters.include?(:store_js_behaviours)
|
||||
assert_equal session[:js_behaviours], assigns(:js_behaviours).to_hash
|
||||
end
|
||||
|
||||
def test_should_not_store_behaviour_script_in_the_session_if_js_behaviours_is_nil
|
||||
@controller.send(:reset_js_behaviours)
|
||||
assert_nil @controller.send(:js_behaviours)
|
||||
end
|
||||
|
||||
def test_should_turn_behaviour_script_caching_on_when_cache_behaviours_is_called
|
||||
@controller.cache_behaviours
|
||||
assert assigns(:js_behaviours).cache?
|
||||
end
|
||||
|
||||
def test_should_toggle_reload_after_ajax_when_set
|
||||
@controller.reapply_behaviours_after_ajax = false
|
||||
assert !assigns(:js_behaviours).reapply_after_ajax?
|
||||
@controller.reapply_behaviours_after_ajax = true
|
||||
assert assigns(:js_behaviours).reapply_after_ajax?
|
||||
end
|
||||
|
||||
def test_should_also_allow_american_spelling_for_apply_behaviour
|
||||
@controller.apply_behavior("div.foo", "alert('foo')")
|
||||
assert_equal 1, assigns(:js_behaviours).rules.size
|
||||
end
|
||||
end
|
||||
186
vendor/plugins/unobtrusive_javascript/test/helpers_test.rb
vendored
Normal file
186
vendor/plugins/unobtrusive_javascript/test/helpers_test.rb
vendored
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
class ApplyingBehaviourWithStringOfJavascriptTest < Test::Unit::TestCase
|
||||
include UJS::Helpers
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
@output = apply_behaviour("#mydiv:click", "alert('hello world')")
|
||||
end
|
||||
|
||||
def test_should_store_registered_behaviour
|
||||
assert_equal 1, assigns(:js_behaviours).rules.size
|
||||
assert_equal "#mydiv:click", assigns(:js_behaviours).rules.first[0]
|
||||
assert_equal "alert('hello world');", assigns(:js_behaviours).rules.first[1]
|
||||
end
|
||||
end
|
||||
|
||||
class ApplyingBehaviourThatIsRendererdInlineTest < Test::Unit::TestCase
|
||||
include UJS::Helpers
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
@output = apply_behaviour("#mydiv:click", "alert('hello world')", :external => false)
|
||||
end
|
||||
|
||||
def test_should_not_store_registered_behaviour
|
||||
assert_equal 0, assigns(:js_behaviours).rules.size
|
||||
end
|
||||
end
|
||||
|
||||
class PreventDefaultBehaviourOptionTest < Test::Unit::TestCase
|
||||
include UJS::Helpers
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
@output = apply_behaviour("#mydiv:click", "alert('hello world')", :prevent_default => true)
|
||||
end
|
||||
|
||||
def test_should_return_false_with_prevent_default
|
||||
assert_equal ['#mydiv:click', "alert('hello world'); return false;"], assigns(:js_behaviours).rules.last
|
||||
end
|
||||
end
|
||||
|
||||
class ApplyingBehaviourWithBlockTest < Test::Unit::TestCase
|
||||
include UJS::Helpers
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
end
|
||||
|
||||
def test_should_use_page_argument
|
||||
apply_behaviour '#thing' do |page|
|
||||
page.alert('hello')
|
||||
end
|
||||
|
||||
assert_equal '#thing', assigns(:js_behaviours).rules.last[0]
|
||||
assert_equal "alert(\"hello\");", assigns(:js_behaviours).rules.last[1]
|
||||
end
|
||||
|
||||
def test_should_use_element_argument
|
||||
apply_behaviour '#thing' do |page, element|
|
||||
element.hide
|
||||
end
|
||||
|
||||
assert_equal '#thing', assigns(:js_behaviours).rules.last[0]
|
||||
assert_equal "this.hide();", assigns(:js_behaviours).rules.last[1]
|
||||
end
|
||||
|
||||
def test_should_use_event_argument
|
||||
apply_behaviour '#thing' do |page, element, event|
|
||||
event.stop
|
||||
end
|
||||
|
||||
assert_equal '#thing', assigns(:js_behaviours).rules.last[0]
|
||||
assert_equal "Event.stop(event);", assigns(:js_behaviours).rules.last[1]
|
||||
end
|
||||
|
||||
def test_should_use_allow_multiple_calls
|
||||
apply_behaviour '#thing' do |page, element, event|
|
||||
page.alert('hiding thing')
|
||||
element.hide
|
||||
element.show
|
||||
event.stop
|
||||
end
|
||||
|
||||
assert_equal '#thing', assigns(:js_behaviours).rules.last[0]
|
||||
assert_equal "alert(\"hiding thing\");\nthis.hide();\nthis.show();\nEvent.stop(event);", assigns(:js_behaviours).rules.last[1]
|
||||
end
|
||||
|
||||
def test_should_allow_options_with_block_without_specifying_string
|
||||
apply_behaviour '#thing2', :prevent_default => true do |page|
|
||||
page.alert('boo')
|
||||
end
|
||||
|
||||
assert_equal '#thing2', assigns(:js_behaviours).rules.last[0]
|
||||
assert_equal "alert(\"boo\"); return false;", assigns(:js_behaviours).rules.last[1]
|
||||
end
|
||||
|
||||
def test_should_allow_element_proxy_methods_to_be_called
|
||||
apply_behaviour '#thing3' do |page, element|
|
||||
element.replace_html '<strong>Wow!</strong>'
|
||||
end
|
||||
|
||||
assert_equal '#thing3', assigns(:js_behaviours).rules.last[0]
|
||||
assert_equal "this.update(\"<strong>Wow!</strong>\");", assigns(:js_behaviours).rules.last[1]
|
||||
end
|
||||
end
|
||||
|
||||
class MultipleBehavioursAppliedAtOnceTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
include UJS::Helpers
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
apply_behaviours do
|
||||
on "div.foo", "alert('foo')"
|
||||
on "div.bar", "alert('bar')"
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_all_get_registered_in_the_behaviour_script
|
||||
assert_equal 2, assigns(:js_behaviours).rules.size
|
||||
end
|
||||
|
||||
def test_should_work_with_apply_behaviour_helpers
|
||||
apply_behaviours do
|
||||
on "ul.sortable", make_sortable
|
||||
end
|
||||
assert_equal 3, assigns(:js_behaviours).rules.size
|
||||
end
|
||||
end
|
||||
|
||||
class MultipleBehavioursAppliedAtOnceWithExternalFalseTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::JavaScriptHelper
|
||||
include ActionView::Helpers::ScriptaculousHelper
|
||||
include ActionView::Helpers::PrototypeHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include UJS::BehaviourHelper
|
||||
include UJS::Helpers
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
@output = apply_behaviours do
|
||||
on "div.foo", "alert('foo')", :external => false
|
||||
on "div.bar", :external => false do |page|
|
||||
page.alert('bar')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_output_behaviours
|
||||
assert_not_equal '', @output
|
||||
assert_match(/<script/, @output)
|
||||
assert_match(/alert\('foo'\)/, @output)
|
||||
assert_match(/alert\("bar"\)/, @output)
|
||||
end
|
||||
end
|
||||
|
||||
3
vendor/plugins/unobtrusive_javascript/test/javascript_proxies_test.rb
vendored
Normal file
3
vendor/plugins/unobtrusive_javascript/test/javascript_proxies_test.rb
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
# TODO
|
||||
26
vendor/plugins/unobtrusive_javascript/test/lib/ptk/boot.rb
vendored
Normal file
26
vendor/plugins/unobtrusive_javascript/test/lib/ptk/boot.rb
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# We are always a test environment and should never be anything else
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
|
||||
require File.join(File.dirname(__FILE__), 'ptk')
|
||||
|
||||
# Set up RAILS_ROOT to #{plugin_path}/test
|
||||
unless defined?(RAILS_ROOT)
|
||||
root_path = PTK::LoadPath.expand(__FILE__, '..', '..')
|
||||
|
||||
unless RUBY_PLATFORM =~ /mswin32/
|
||||
require 'pathname'
|
||||
root_path = Pathname.new(root_path).cleanpath(true).to_s
|
||||
end
|
||||
|
||||
RAILS_ROOT = root_path
|
||||
end
|
||||
|
||||
# add #{plugin_path}/test/lib
|
||||
PTK::LoadPath.add RAILS_ROOT, 'lib'
|
||||
|
||||
# add #{plugin_path}/lib
|
||||
PTK::LoadPath.add RAILS_ROOT, '..', 'lib'
|
||||
|
||||
require 'rubygems'
|
||||
require 'test/unit'
|
||||
require 'active_support'
|
||||
11
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_controller.rb
vendored
Normal file
11
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_controller.rb
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require 'action_pack'
|
||||
require 'action_controller'
|
||||
require 'action_controller/test_process'
|
||||
|
||||
ActionController::Base.ignore_missing_templates = true
|
||||
|
||||
if PTK::Configuration.load :routes
|
||||
ActionController::Routing::Routes.reload rescue nil
|
||||
end
|
||||
|
||||
class ActionController::Base; def rescue_action(e) raise e end; end
|
||||
4
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_mailer.rb
vendored
Normal file
4
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_mailer.rb
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
require 'action_mailer'
|
||||
|
||||
ActionMailer::Base.delivery_method = :test
|
||||
ActionMailer::Base.perform_deliveries = true
|
||||
27
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/active_record.rb
vendored
Normal file
27
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/active_record.rb
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
require 'active_record'
|
||||
require 'active_record/fixtures'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new(File.join(RAILS_ROOT, 'test.log'))
|
||||
|
||||
# Load the database.yml from #{plugin_path}/test/config if it exists
|
||||
if file = PTK::Configuration.find_path(:database)
|
||||
|
||||
config = YAML::load_file(file)
|
||||
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
||||
|
||||
# Load a schema if it exists
|
||||
if schema = PTK::Configuration.find_path(:schema)
|
||||
|
||||
load(schema)
|
||||
|
||||
# Setup fixtures if the directory exists
|
||||
if fixtures = PTK::Configuration.find_path(:fixtures)
|
||||
|
||||
PTK::LoadPath.add fixtures
|
||||
|
||||
Test::Unit::TestCase.fixture_path = fixtures
|
||||
Test::Unit::TestCase.use_instantiated_fixtures = false
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
31
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/rails.rb
vendored
Normal file
31
vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/rails.rb
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# We require the initializer to setup the environment properly
|
||||
unless defined?(Rails::Initializer)
|
||||
if File.directory?("#{RAILS_ROOT}/../../../rails")
|
||||
require "#{RAILS_ROOT}/../../../rails/railties/lib/initializer"
|
||||
else
|
||||
require 'rubygems'
|
||||
require_gem 'rails'
|
||||
require 'initializer'
|
||||
end
|
||||
Rails::Initializer.run(:set_load_path)
|
||||
end
|
||||
|
||||
# We overwrite load_environment so we can have only one file
|
||||
module Rails
|
||||
class Initializer
|
||||
def load_environment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# We overwrite the default log to be a directory up
|
||||
module Rails
|
||||
class Configuration
|
||||
def default_log_path
|
||||
File.join(root_path, "#{environment}.log")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# We then load it manually
|
||||
PTK::Configuration.load :environment
|
||||
148
vendor/plugins/unobtrusive_javascript/test/lib/ptk/ptk.rb
vendored
Normal file
148
vendor/plugins/unobtrusive_javascript/test/lib/ptk/ptk.rb
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
require 'singleton'
|
||||
|
||||
module PTK
|
||||
|
||||
class Configuration
|
||||
class << self
|
||||
def load(config, fatal = false)
|
||||
if (file = PTK::PathSet.instance.send(config)) == :ignore then false
|
||||
elsif File.exists?(file)
|
||||
require file
|
||||
true
|
||||
elsif fatal then raise LoadError, "PTK could not find #{file}"
|
||||
else
|
||||
STDERR.puts "PTK::WARNING: could not find #{file}"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def find_path(config, fatal = false)
|
||||
if (file = PTK::PathSet.instance.send(config)) == :ignore then false
|
||||
elsif File.exists?(file) then file
|
||||
elsif fatal then raise LoadError, "PTK could not find #{file}"
|
||||
else
|
||||
STDERR.puts "PTK::WARNING: could not find #{file}"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
yield PTK::PathSet.instance
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class PathSet
|
||||
include Singleton
|
||||
|
||||
attr_accessor :ptk_prefix
|
||||
attr_accessor :config
|
||||
attr_accessor :fixtures
|
||||
attr_accessor :environment
|
||||
attr_accessor :schema
|
||||
attr_accessor :database
|
||||
attr_accessor :routes
|
||||
|
||||
def initialize
|
||||
self.ptk_prefix = 'ptk'
|
||||
self.config = File.join(RAILS_ROOT, 'config')
|
||||
self.fixtures = File.join(RAILS_ROOT, 'fixtures')
|
||||
|
||||
self.environment = File.join(self.config, 'environment.rb')
|
||||
|
||||
self.database = File.join(self.config, 'database.yml')
|
||||
self.schema = File.join(self.config, 'schema.rb')
|
||||
|
||||
self.routes = File.join(self.config, 'routes.rb')
|
||||
end
|
||||
end
|
||||
|
||||
class Initializer
|
||||
|
||||
# The init.rb in the root directory of the plugin will be loaded by default
|
||||
attr_accessor :init
|
||||
|
||||
# The specific environmental frameworks of a plugin, such as needing the ActionController
|
||||
# ActionMailer or ActiveRecord gems to be preloaded. A special requirement called
|
||||
# 'environment' will load tests as though they were in the test environment of a normal
|
||||
# Rails application.
|
||||
attr_accessor :frameworks
|
||||
def frameworks
|
||||
[@frameworks].flatten
|
||||
end
|
||||
|
||||
# Suites are test extensions including assertions and various tools for easier testing
|
||||
attr_accessor :suites
|
||||
def suites
|
||||
[@suites].flatten
|
||||
end
|
||||
|
||||
# A container for the PathSet instance
|
||||
attr_reader :paths
|
||||
|
||||
def initialize
|
||||
self.init = true
|
||||
self.frameworks = :none
|
||||
self.suites = :all
|
||||
@paths = PTK::PathSet.instance
|
||||
end
|
||||
|
||||
def self.run(command = :process)
|
||||
initializer = PTK::Initializer.new
|
||||
yield initializer if block_given?
|
||||
initializer.send(command)
|
||||
end
|
||||
|
||||
def process
|
||||
initialize_frameworks
|
||||
initialize_suites
|
||||
initialize_plugin
|
||||
end
|
||||
|
||||
def initialize_frameworks
|
||||
return if frameworks.include?(:none)
|
||||
self.frameworks = [:rails] if frameworks.include?(:rails)
|
||||
frameworks.each { |lib| require_ptk File.join('gem', lib.to_s) }
|
||||
end
|
||||
|
||||
def initialize_suites
|
||||
return if suites.include?(:none)
|
||||
self.suites = all_suites if suites.include?(:all)
|
||||
suites.each { |lib| require_ptk File.join('suite', lib.to_s) }
|
||||
end
|
||||
|
||||
def initialize_plugin
|
||||
return unless self.init
|
||||
require File.join(RAILS_ROOT, '..', 'init')
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def all_suites
|
||||
Dir.glob(File.join(RAILS_ROOT, 'lib', 'ptk', 'suite', '*.rb')).inject([]) do |a, file|
|
||||
a << File.basename(file, '.rb').to_sym
|
||||
a
|
||||
end
|
||||
end
|
||||
|
||||
def require_ptk(library)
|
||||
file = paths.ptk_prefix.empty? ? library : File.join(paths.ptk_prefix, library)
|
||||
require file
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class LoadPath
|
||||
|
||||
def self.expand(file, *dirs)
|
||||
File.join(*([File.expand_path(File.dirname(file))] << dirs))
|
||||
end
|
||||
|
||||
def self.add(*dirs)
|
||||
path = File.expand_path(File.join(*dirs))
|
||||
$:.unshift path
|
||||
$:.uniq!
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
23
vendor/plugins/unobtrusive_javascript/test/lib/ptk/suite/difference.rb
vendored
Normal file
23
vendor/plugins/unobtrusive_javascript/test/lib/ptk/suite/difference.rb
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class Test::Unit::TestCase
|
||||
|
||||
# http://project.ioni.st/post/217#post-217
|
||||
#
|
||||
# def test_new_publication
|
||||
# assert_difference(Publication, :count) do
|
||||
# post :create, :publication => {...}
|
||||
# # ...
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# modified by mabs29 to include arguments
|
||||
def assert_difference(object, method = nil, difference = 1, *args)
|
||||
initial_value = object.send(method, *args)
|
||||
yield
|
||||
assert_equal initial_value + difference, object.send(method, *args), "#{object}##{method}"
|
||||
end
|
||||
|
||||
def assert_no_difference(object, method, *args, &block)
|
||||
assert_difference object, method, 0, *args, &block
|
||||
end
|
||||
|
||||
end
|
||||
10
vendor/plugins/unobtrusive_javascript/test/lib/stubs/controller_stub.rb
vendored
Normal file
10
vendor/plugins/unobtrusive_javascript/test/lib/stubs/controller_stub.rb
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
require 'action_controller/test_process'
|
||||
require 'ujs/controller_methods'
|
||||
|
||||
class ControllerStub < ActionController::Base
|
||||
def index
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
||||
|
||||
ControllerStub.send(:include, UJS::ControllerMethods)
|
||||
29
vendor/plugins/unobtrusive_javascript/test/ptk_helper.rb
vendored
Normal file
29
vendor/plugins/unobtrusive_javascript/test/ptk_helper.rb
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Do not comment out this line; it sets the RAILS_ROOT constant and load paths, not Rails itself
|
||||
require File.join(File.dirname(__FILE__), 'lib', 'ptk', 'boot')
|
||||
|
||||
PTK::Initializer.run do |setup|
|
||||
# You can also redefine the paths of certain directories and files, namely:
|
||||
#setup.paths.config = File.join(RAILS_ROOT, 'config')
|
||||
#setup.paths.fixtures = File.join(RAILS_ROOT, 'fixtures')
|
||||
|
||||
#setup.paths.database = File.join(setup.paths.config, 'database.yml')
|
||||
#setup.paths.schema = File.join(setup.paths.config, 'schema.rb')
|
||||
#setup.paths.routes = File.join(setup.paths.config, 'routes.rb')
|
||||
#setup.paths.environment = File.join(setup.paths.config, 'environment.rb')
|
||||
|
||||
# If any of these paths are set to ':ignore', no warnings will appear if they are missing.
|
||||
|
||||
# Frameworks are the gems from Rails which you need PTK to load for your plugin.
|
||||
# The special :rails framework creates a fully-fledged Rails environment and requires
|
||||
# the environment.rb file.
|
||||
# Valid options are: :action_controller, :action_mailer, :active_record, :rails
|
||||
setup.frameworks = :action_controller # :active_record, :action_controller
|
||||
|
||||
# Extra libraries of assertions and other common methods that provide more testing
|
||||
# utilities. To hand-pick which suites you want, uncomment the below
|
||||
#setup.suites = :difference
|
||||
|
||||
# If for some particular reason you do not want your plugin's init to be called
|
||||
# at the end of this block, uncomment the below:
|
||||
setup.init = false
|
||||
end
|
||||
59
vendor/plugins/unobtrusive_javascript/test/tag_helper_patches_test.rb
vendored
Normal file
59
vendor/plugins/unobtrusive_javascript/test/tag_helper_patches_test.rb
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
class ContentTagWithJavascriptEventsTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
@output = content_tag('div', 'my test div', {
|
||||
:id => 'my_test_div', :class => 'some_class',
|
||||
:onclick => 'alert("foo")',
|
||||
:onmouseup => 'alert("foo")',
|
||||
:onmousedown => 'alert("foo")',
|
||||
:ondblclick => 'alert("foo")',
|
||||
:onmouseover => 'alert("foo")',
|
||||
:onmouseout => 'alert("foo")',
|
||||
:onload => 'alert("foo")',
|
||||
:onmousemove => 'alert("foo")'
|
||||
})
|
||||
end
|
||||
|
||||
def test_result_should_not_contain_any_inline_javascript_events
|
||||
assert_equal '<div class="some_class" id="my_test_div">my test div</div>', @output
|
||||
end
|
||||
|
||||
def test_should_have_javascript_events_registered_as_unobtrusive
|
||||
assert_equal 8, assigns(:js_behaviours).rules.size
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:click', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:mouseup', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:mousedown', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:dblclick', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:mouseover', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:mouseout', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:load', 'alert("foo");'])
|
||||
assert assigns(:js_behaviours).rules.include?(['#my_test_div:mousemove', 'alert("foo");'])
|
||||
end
|
||||
end
|
||||
|
||||
class TagOptionsForFormTextFieldsTest < Test::Unit::TestCase
|
||||
include ActionView::Helpers::FormTagHelper
|
||||
include ActionView::Helpers::FormHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def setup
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
@text_field_tag = text_field_tag('login')
|
||||
@text_field = text_field(:user, :first_name)
|
||||
end
|
||||
|
||||
def test_should_not_contain_any_inline_javascript_events
|
||||
assert_equal '<input id="login" name="login" type="text" />', @text_field_tag
|
||||
assert_equal '<input id="user_first_name" name="user[first_name]" size="30" type="text" />', @text_field
|
||||
end
|
||||
end
|
||||
25
vendor/plugins/unobtrusive_javascript/test/test_helper.rb
vendored
Normal file
25
vendor/plugins/unobtrusive_javascript/test/test_helper.rb
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
ENV["RAILS_ENV"] = "test"
|
||||
|
||||
# load plugin test kit
|
||||
require File.join(File.dirname(__FILE__), 'ptk_helper')
|
||||
|
||||
# load stubba and other stubs
|
||||
require 'stubba'
|
||||
require 'stubs/controller_stub'
|
||||
|
||||
# load plugin files
|
||||
require 'actionview_helpers_patches'
|
||||
require 'prototype_helper_patches'
|
||||
require 'scriptaculous_helper_patches'
|
||||
require 'asset_tag_helper_patches'
|
||||
require 'tag_helper_patches'
|
||||
require 'behaviour_caching'
|
||||
|
||||
$:.unshift(File.join(File.dirname(__FILE__), '../lib/'))
|
||||
|
||||
def initialize_test_request
|
||||
@controller = ControllerStub.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :index
|
||||
end
|
||||
95
vendor/plugins/unobtrusive_javascript/test/unobtrusive_javascript_controller_test.rb
vendored
Normal file
95
vendor/plugins/unobtrusive_javascript/test/unobtrusive_javascript_controller_test.rb
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
# inject the controller methods to add the appropriate filters
|
||||
# before loading in the unobtrusive js controller otherwise its
|
||||
# skip_ filters will be fubarred.
|
||||
ActionController::Base.send(:include, UJS::ControllerMethods)
|
||||
|
||||
require 'controllers/unobtrusive_javascript_controller'
|
||||
|
||||
class BehaviourGenerationControllerTest < Test::Unit::TestCase
|
||||
def test_should_always_skip_the_initialise_js_behaviours_filter
|
||||
assert !UnobtrusiveJavascriptController.before_filters.include?(:initialise_js_behaviours)
|
||||
end
|
||||
|
||||
def test_should_always_skip_the_store_js_behaviours_filter
|
||||
assert !UnobtrusiveJavascriptController.before_filters.include?(:store_js_behaviours)
|
||||
end
|
||||
|
||||
def test_should_always_perform_any_caching_after_a_request
|
||||
assert UnobtrusiveJavascriptController.after_filters.include?(:perform_any_caching)
|
||||
end
|
||||
|
||||
def test_should_always_reset_any_js_behaviours_after_a_request
|
||||
assert UnobtrusiveJavascriptController.after_filters.include?(:reset_js_behaviours)
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourGenerationWithNoBehavioursTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@controller = UnobtrusiveJavascriptController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
UnobtrusiveJavascriptController.any_instance.stubs(:js_behaviours).returns(UJS::BehaviourScript.new)
|
||||
get :generate
|
||||
end
|
||||
|
||||
def test_should_set_content_type_to_text_javascript
|
||||
assert_equal "text/javascript", @response.headers["Content-Type"]
|
||||
end
|
||||
|
||||
def test_should_render_nothing
|
||||
assert_equal "", @response.body
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourGenerationWithAppliedBehavioursTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@behaviours = UJS::BehaviourScript.new
|
||||
@behaviours.add_rule("div.foo", "alert('foo')")
|
||||
@behaviours.add_rule("div.bar", "alert('bar')")
|
||||
UnobtrusiveJavascriptController.any_instance.stubs(:js_behaviours).returns(@behaviours)
|
||||
@controller = UnobtrusiveJavascriptController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
get :generate
|
||||
end
|
||||
|
||||
def test_should_set_content_type_to_text_javascript
|
||||
assert_equal "text/javascript", @response.headers["Content-Type"]
|
||||
end
|
||||
|
||||
def test_should_render_behaviour_script_output
|
||||
assert_equal @behaviours.to_s, @response.body
|
||||
end
|
||||
|
||||
def test_should_generate_an_etag_for_the_behaviours
|
||||
assert_equal Digest::MD5.hexdigest(@behaviours.to_s), @response.headers["ETag"]
|
||||
end
|
||||
end
|
||||
|
||||
class BehaviourGenerationWithUnchangedBehavioursTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@behaviours = UJS::BehaviourScript.new
|
||||
@behaviours.add_rule("div.foo", "alert('foo')")
|
||||
@behaviours.add_rule("div.bar", "alert('bar')")
|
||||
UnobtrusiveJavascriptController.any_instance.stubs(:js_behaviours).returns(@behaviours)
|
||||
@controller = UnobtrusiveJavascriptController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@request.env['HTTP_IF_NONE_MATCH'] = Digest::MD5.hexdigest(@behaviours.to_s)
|
||||
get :generate
|
||||
end
|
||||
|
||||
def test_should_set_content_type_to_text_javascript
|
||||
assert_equal "text/javascript", @response.headers["Content-Type"]
|
||||
end
|
||||
|
||||
def test_should_render_nothing
|
||||
assert_equal " ", @response.body
|
||||
end
|
||||
|
||||
def test_should_send_304_not_modified_http_status
|
||||
assert_response 304
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue