Browse files

use action prefix in forl css class, closes #360

  • Loading branch information...
1 parent c30d4af commit e2df674c2d5adb2882bd53665abc9e1953e730a9 @nashby nashby committed Dec 3, 2011
View
3 lib/simple_form/action_view_extensions/form_helper.rb
@@ -48,7 +48,8 @@ def css_class(record, html_options)
record
else
record = record.last if record.is_a?(Array)
- dom_class(record)
+ action = record.respond_to?(:persisted?) && record.persisted? ? :edit : :new
+ dom_class(record, action)
end
end
View
10 test/action_view_extensions/form_helper_test.rb
@@ -42,9 +42,15 @@ class FormHelperTest < ActionView::TestCase
assert_select 'form.simple_form.user'
end
- test 'simple form should add object class name as css class to form' do
+ test 'simple form should add object class name with new prefix as css class to form if record is not persisted' do
+ @user.new_record!
concat(simple_form_for(@user) do |f| end)
- assert_select 'form.simple_form.user'
+ assert_select 'form.simple_form.new_user'
+ end
+
+ test 'simple form should add edit class prefix as css class to form if record is persisted' do
+ concat(simple_form_for(@user) do |f| end)
+ assert_select 'form.simple_form.edit_user'
end
test 'simple form should not add object class to form if css_class is specified' do

0 comments on commit e2df674

Please sign in to comment.