Skip to content

Commit c2096c4

Browse files
committed
Properly tested and fixed the bug that added the data-update-elements attribute to simple form inputs even when no :update_elements were given
1 parent edacfc6 commit c2096c4

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

lib/rails3-jquery-autocomplete/simple_form_plugin.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def has_placeholder?
1616
end
1717

1818
def update_elements(elements)
19-
{'data-update-elements' => elements.to_json}
19+
if elements
20+
{'data-update-elements' => elements.to_json}
21+
else
22+
{}
23+
end
2024
end
2125
end
2226
end

test-unit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
runner: console
22
console_options:
3-
# arguments: --use-color=true --verbose=verbose
3+
#arguments: --use-color=true --verbose=verbose
44
arguments: --use-color=true
55
color_scheme: new_and_improved
66
color_schemes:

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
module Rails3JQueryAutocomplete
55
class SimpleFormPluginTest < ActionView::TestCase
66

7-
def setup
8-
with_input_for @user, :name, :autocomplete, :url => '/test'
9-
end
10-
117
should "apply a class of 'autocomplete'" do
8+
with_input_for @user, :name, :autocomplete
129
assert_select "input#user_name.autocomplete[type=text][name='user[name]']"
1310
end
1411

1512
should "add a data-autocomplete attribute with the provided :url" do
13+
with_input_for @user, :name, :autocomplete, :url => '/test'
1614
assert_select "input#user_name[data-autocomplete=/test]"
1715
end
1816

17+
should "not add a data-update-elements attribute if not passed an :update_elements option" do
18+
with_input_for @user, :name, :autocomplete, :url => '/test'
19+
assert_no_select "input#user_name[data-update-elements]"
20+
end
21+
1922
end
2023
end

test/test_helper.rb

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
$LOAD_PATH.unshift(File.dirname(__FILE__))
66

77
ENV["RAILS_ENV"] = "test"
8+
module Rails
9+
def self.env
10+
ActiveSupport::StringInquirer.new("test")
11+
end
12+
end
813

914
require 'rails/all'
1015
require 'mongoid'

test/view_test_helper.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class ActionView::TestCase
6666
setup :set_response
6767
setup :setup_new_user
6868

69+
def assert_no_select(selector, value = nil)
70+
assert_select(selector, :text => value, :count => 0)
71+
end
72+
6973
def with_concat_form_for(*args, &block)
7074
concat simple_form_for(*args, &block)
7175
end
@@ -102,4 +106,3 @@ def user_path(*args)
102106
end
103107
alias :users_path :user_path
104108
end
105-

0 commit comments

Comments
 (0)