Skip to content

Commit

Permalink
Properly tested and fixed the bug that added the data-update-elements…
Browse files Browse the repository at this point in the history
… attribute to simple form inputs even when no :update_elements were given
  • Loading branch information
chadoh committed Apr 18, 2012
1 parent edacfc6 commit c2096c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/rails3-jquery-autocomplete/simple_form_plugin.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def has_placeholder?
end end


def update_elements(elements) def update_elements(elements)
{'data-update-elements' => elements.to_json} if elements
{'data-update-elements' => elements.to_json}
else
{}
end
end end
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion test-unit.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
runner: console runner: console
console_options: console_options:
# arguments: --use-color=true --verbose=verbose #arguments: --use-color=true --verbose=verbose
arguments: --use-color=true arguments: --use-color=true
color_scheme: new_and_improved color_scheme: new_and_improved
color_schemes: color_schemes:
Expand Down
11 changes: 7 additions & 4 deletions test/lib/rails3-jquery-autocomplete/simple_form_plugin_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
module Rails3JQueryAutocomplete module Rails3JQueryAutocomplete
class SimpleFormPluginTest < ActionView::TestCase class SimpleFormPluginTest < ActionView::TestCase


def setup
with_input_for @user, :name, :autocomplete, :url => '/test'
end

should "apply a class of 'autocomplete'" do should "apply a class of 'autocomplete'" do
with_input_for @user, :name, :autocomplete
assert_select "input#user_name.autocomplete[type=text][name='user[name]']" assert_select "input#user_name.autocomplete[type=text][name='user[name]']"
end end


should "add a data-autocomplete attribute with the provided :url" do 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]" assert_select "input#user_name[data-autocomplete=/test]"
end 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
end end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))


ENV["RAILS_ENV"] = "test" ENV["RAILS_ENV"] = "test"
module Rails
def self.env
ActiveSupport::StringInquirer.new("test")
end
end


require 'rails/all' require 'rails/all'
require 'mongoid' require 'mongoid'
Expand Down
5 changes: 4 additions & 1 deletion test/view_test_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ActionView::TestCase
setup :set_response setup :set_response
setup :setup_new_user 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) def with_concat_form_for(*args, &block)
concat simple_form_for(*args, &block) concat simple_form_for(*args, &block)
end end
Expand Down Expand Up @@ -102,4 +106,3 @@ def user_path(*args)
end end
alias :users_path :user_path alias :users_path :user_path
end end

0 comments on commit c2096c4

Please sign in to comment.