Skip to content

Commit 3cdd6a5

Browse files
committed
adding more complete test coverage for the simple_form plugin, and removing the fake test for it in integration
1 parent c2096c4 commit 3cdd6a5

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

integration/features/autocomplete.feature

-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ Feature: Autocomplete
5757
And I choose "Shiny" in the autocomplete list
5858
Then the "Feature Name" field should contain "Glowy,Shiny"
5959

60-
@javascript
61-
Scenario: Autocomplete with simple_form
62-
Given I go to the new simple form page
63-
And I fill in "Brand name" with "al"
64-
And I choose "Alpha" in the autocomplete list
65-
Then the "Brand name" field should contain "Alpha"
66-
6760
@javascript
6861
Scenario: Autocomplete with scope
6962
Given the "Kappa" brand has an address

lib/rails3-jquery-autocomplete/simple_form_plugin.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module SimpleForm
2+
23
module Inputs
34
class AutocompleteInput < Base
45
def input
5-
@builder.autocomplete_field(attribute_name, options[:url], input_html_options.merge(update_elements(options[:update_elements])))
6+
@builder.autocomplete_field(
7+
attribute_name,
8+
options[:url],
9+
html_options
10+
)
611
end
712

813
protected
@@ -15,6 +20,10 @@ def has_placeholder?
1520
placeholder_present?
1621
end
1722

23+
def html_options
24+
input_html_options.merge update_elements options[:update_elements]
25+
end
26+
1827
def update_elements(elements)
1928
if elements
2029
{'data-update-elements' => elements.to_json}
@@ -24,10 +33,9 @@ def update_elements(elements)
2433
end
2534
end
2635
end
27-
end
2836

29-
module SimpleForm
3037
class FormBuilder
3138
map_type :autocomplete, :to => SimpleForm::Inputs::AutocompleteInput
3239
end
40+
3341
end

test/lib/rails3-jquery-autocomplete/simple_form_plugin_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ class SimpleFormPluginTest < ActionView::TestCase
1414
assert_select "input#user_name[data-autocomplete=/test]"
1515
end
1616

17+
should "add a data-update-elements attribute with encoded data if passed an :update_elements option" do
18+
with_input_for @user, :name, :autocomplete, :update_elements => { :id => '#this', :ego => '#that' }
19+
assert_select "input#user_name[data-update-elements='{&quot;id&quot;:&quot;#this&quot;,&quot;ego&quot;:&quot;#that&quot;}']"
20+
end
21+
1722
should "not add a data-update-elements attribute if not passed an :update_elements option" do
1823
with_input_for @user, :name, :autocomplete, :url => '/test'
1924
assert_no_select "input#user_name[data-update-elements]"
2025
end
2126

27+
should "add arbitrary html options, if specified" do
28+
with_input_for @user, :name, :autocomplete, :input_html => { :class => "superego" }
29+
assert_select "input#user_name.superego"
30+
end
31+
2232
end
2333
end

0 commit comments

Comments
 (0)