Browse files

Merge pull request #674 from cthiel/master

Fix all check_boxes being checked if collection given as array
  • Loading branch information...
2 parents 8843ed2 + 7691f5b commit a77267c1888c38ce2932abbecdae93dcb010e8c2 @justinfrench committed Sep 10, 2011
View
2 lib/formtastic/inputs/base/collections.rb
@@ -82,7 +82,7 @@ def collection_for_boolean
def send_or_call(duck, object)
if duck.respond_to?(:call)
duck.call(object)
- else
+ elsif object.respond_to? duck.to_sym
object.send(duck)
end
end
View
8 lib/formtastic/inputs/check_boxes_input.rb
@@ -153,13 +153,7 @@ def disabled?(value)
def selected_values
if object.respond_to?(method)
- if options[:collection].is_a?(Array) and
- options[:collection].flatten.all? {|i| i.is_a?(String) or i.is_a?(Integer)}
-
- selected_items = options[:collection]
- else
- selected_items = [object.send(method)].compact.flatten
- end
+ selected_items = [object.send(method)].compact.flatten
[*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact
else
View
4 spec/inputs/check_boxes_input_spec.rb
@@ -410,6 +410,10 @@
output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
end
end
+
+ it "should not check any items" do
+ output_buffer.should have_tag('form li input[@checked]', :count => 0)
+ end
end
end

0 comments on commit a77267c

Please sign in to comment.