Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use action prefix in form css class, closes #360 #377

Merged
merged 1 commit into from
Dec 3, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/simple_form/action_view_extensions/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions test/action_view_extensions/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down