Permalink
Browse files

adding more complete test coverage for the simple_form plugin, and re…

…moving the fake test for it in integration
  • Loading branch information...
1 parent c2096c4 commit 3cdd6a54e6a306eecf27b29b11969865f41c5da4 @chadoh chadoh committed Apr 18, 2012
@@ -58,13 +58,6 @@ Feature: Autocomplete
Then the "Feature Name" field should contain "Glowy,Shiny"
@javascript
- Scenario: Autocomplete with simple_form
- Given I go to the new simple form page
- And I fill in "Brand name" with "al"
- And I choose "Alpha" in the autocomplete list
- Then the "Brand name" field should contain "Alpha"
-
- @javascript
Scenario: Autocomplete with scope
Given the "Kappa" brand has an address
Given I go to the new scoped autocomplete page
@@ -1,8 +1,13 @@
module SimpleForm
+
module Inputs
class AutocompleteInput < Base
def input
- @builder.autocomplete_field(attribute_name, options[:url], input_html_options.merge(update_elements(options[:update_elements])))
+ @builder.autocomplete_field(
+ attribute_name,
+ options[:url],
+ html_options
+ )
end
protected
@@ -15,6 +20,10 @@ def has_placeholder?
placeholder_present?
end
+ def html_options
+ input_html_options.merge update_elements options[:update_elements]
+ end
+
def update_elements(elements)
if elements
{'data-update-elements' => elements.to_json}
@@ -24,10 +33,9 @@ def update_elements(elements)
end
end
end
-end
-module SimpleForm
class FormBuilder
map_type :autocomplete, :to => SimpleForm::Inputs::AutocompleteInput
end
+
end
@@ -14,10 +14,20 @@ class SimpleFormPluginTest < ActionView::TestCase
assert_select "input#user_name[data-autocomplete=/test]"
end
+ should "add a data-update-elements attribute with encoded data if passed an :update_elements option" do
+ with_input_for @user, :name, :autocomplete, :update_elements => { :id => '#this', :ego => '#that' }
+ assert_select "input#user_name[data-update-elements='{&quot;id&quot;:&quot;#this&quot;,&quot;ego&quot;:&quot;#that&quot;}']"
+ end
+
should "not add a data-update-elements attribute if not passed an :update_elements option" do
with_input_for @user, :name, :autocomplete, :url => '/test'
assert_no_select "input#user_name[data-update-elements]"
end
+ should "add arbitrary html options, if specified" do
+ with_input_for @user, :name, :autocomplete, :input_html => { :class => "superego" }
+ assert_select "input#user_name.superego"
+ end
+
end
end

0 comments on commit 3cdd6a5

Please sign in to comment.