Skip to content
Browse files

[Fix] Input boolean checked values do not reflect database values

  • Loading branch information...
1 parent b73dc40 commit 77ae6ad2f522d60e23625be51e795c8d9918ff74 @lardawge lardawge committed with Nov 14, 2010
Showing with 12 additions and 2 deletions.
  1. +2 −1 lib/formtastic.rb
  2. +9 −0 spec/inputs/boolean_input_spec.rb
  3. +1 −1 spec/spec_helper.rb
View
3 lib/formtastic.rb
@@ -1280,9 +1280,10 @@ def boolean_input(method, options)
input = template.check_box_tag(
"#{@object_name}[#{method}]",
checked_value,
- (@object && @object.send(:"#{method}") == checked_value),
+ (@object && @object.send(:"#{method}")),
:id => field_id
)
+
options = options_for_label(options)
options[:for] ||= field_id
View
9 spec/inputs/boolean_input_spec.rb
@@ -36,6 +36,15 @@
output_buffer.should have_tag('form li label input[@name="post[allow_comments]"]')
output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"]')
end
+
+ it 'should generate a checked checkbox input if object and object.method is true' do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:allow_comments, :as => :boolean))
+ end
+
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag('form li label input[@checked="checked"]')
+ end
it 'should allow checked and unchecked values to be sent' do
form = semantic_form_for(@new_post) do |builder|
View
2 spec/spec_helper.rb
@@ -257,7 +257,7 @@ def new_author_path; "/authors/new"; end
@new_post.stub!(:phone)
@new_post.stub!(:time_zone)
@new_post.stub!(:category_name)
- @new_post.stub!(:allow_comments)
+ @new_post.stub!(:allow_comments).and_return(true)
@new_post.stub!(:country)
@new_post.stub!(:country_subdivision)
@new_post.stub!(:country_code)

0 comments on commit 77ae6ad

Please sign in to comment.
Something went wrong with that request. Please try again.