1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Split macros test into their own suite

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2194 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-09-11 08:40:46 +00:00
parent a15068726f
commit 2be3c00863
3 changed files with 53 additions and 29 deletions

View file

@ -6,7 +6,7 @@ module ActionView
# larger units. These macros also rely on counter parts in the controller that provides them with their backing. The in-place
# editing relies on ActionController::Base.in_place_edit_for and the auto completion relies on
# ActionController::Base.auto_complete_for.
module JavaScriptMacroHelper
module JavaScriptMacrosHelper
# Makes an HTML element specified by the DOM ID +field_id+ become an in-place
# editor of a property.
#

View file

@ -0,0 +1,52 @@
require File.dirname(__FILE__) + '/../abstract_unit'
class JavaScriptMacrosHelperTest < Test::Unit::TestCase
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::JavaScriptMacrosHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::FormHelper
include ActionView::Helpers::CaptureHelper
def setup
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
url = "http://www.example.com/"
url << options[:action].to_s if options and options[:action]
url
end
end
@controller = @controller.new
end
def test_auto_complete_field
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" });
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
end
def test_auto_complete_result
result = [ { :title => 'test1' }, { :title => 'test2' } ]
assert_equal %(<ul><li>test1</li><li>test2</li></ul>),
auto_complete_result(result, :title)
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
auto_complete_result(result, :title, "est")
resultuniq = [ { :title => 'test1' }, { :title => 'test1' } ]
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li></ul>),
auto_complete_result(resultuniq, :title, "est")
end
def test_text_field_with_auto_complete
assert_match "<style>",
text_field_with_auto_complete(:message, :recipient)
assert_equal %(<input autocomplete=\"off\" id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})</script>),
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
end
end

View file

@ -112,34 +112,6 @@ class JavaScriptHelperTest < Test::Unit::TestCase
observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
end
def test_auto_complete_field
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" });
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
end
def test_auto_complete_result
result = [ { :title => 'test1' }, { :title => 'test2' } ]
assert_equal %(<ul><li>test1</li><li>test2</li></ul>),
auto_complete_result(result, :title)
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
auto_complete_result(result, :title, "est")
resultuniq = [ { :title => 'test1' }, { :title => 'test1' } ]
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li></ul>),
auto_complete_result(resultuniq, :title, "est")
end
def test_text_field_with_auto_complete
assert_match "<style>",
text_field_with_auto_complete(:message, :recipient)
assert_equal %(<input autocomplete=\"off\" id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})</script>),
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
end
def test_effect
assert_equal "new Effect.Highlight('posts',{});", visual_effect(:highlight, "posts")
assert_equal "new Effect.Highlight('posts',{});", visual_effect("highlight", :posts)