Permalink
Browse files

Properly tested and fixed the bug that added the data-update-elements…

… attribute to simple form inputs even when no :update_elements were given
  • Loading branch information...
1 parent edacfc6 commit c2096c4a554285f74ab0cc06e4b0833368428639 @chadoh chadoh committed Apr 18, 2012
@@ -16,7 +16,11 @@ def has_placeholder?
end
def update_elements(elements)
- {'data-update-elements' => elements.to_json}
+ if elements
+ {'data-update-elements' => elements.to_json}
+ else
+ {}
+ end
end
end
end
View
@@ -1,6 +1,6 @@
runner: console
console_options:
- # arguments: --use-color=true --verbose=verbose
+ #arguments: --use-color=true --verbose=verbose
arguments: --use-color=true
color_scheme: new_and_improved
color_schemes:
@@ -4,17 +4,20 @@
module Rails3JQueryAutocomplete
class SimpleFormPluginTest < ActionView::TestCase
- def setup
- with_input_for @user, :name, :autocomplete, :url => '/test'
- end
-
should "apply a class of 'autocomplete'" do
+ with_input_for @user, :name, :autocomplete
assert_select "input#user_name.autocomplete[type=text][name='user[name]']"
end
should "add a data-autocomplete attribute with the provided :url" do
+ with_input_for @user, :name, :autocomplete, :url => '/test'
assert_select "input#user_name[data-autocomplete=/test]"
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
+
end
end
View
@@ -5,6 +5,11 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
ENV["RAILS_ENV"] = "test"
+module Rails
+ def self.env
+ ActiveSupport::StringInquirer.new("test")
+ end
+end
require 'rails/all'
require 'mongoid'
@@ -66,6 +66,10 @@ class ActionView::TestCase
setup :set_response
setup :setup_new_user
+ def assert_no_select(selector, value = nil)
+ assert_select(selector, :text => value, :count => 0)
+ end
+
def with_concat_form_for(*args, &block)
concat simple_form_for(*args, &block)
end
@@ -102,4 +106,3 @@ def user_path(*args)
end
alias :users_path :user_path
end
-

0 comments on commit c2096c4

Please sign in to comment.