Skip to content

Commit

Permalink
fix docs, add test coverage around form generator
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Apr 10, 2012
1 parent 61c222e commit 9946ae5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/generators/formtastic/form/form_generator.rb
Expand Up @@ -7,8 +7,9 @@ module Formtastic
# $ rails generate formtastic:form Post
# @example Copy the partial code to the pasteboard rather than generating a partial
# $ rails generate formtastic:form Post --copy
# @example Return HAML output instead of default template engine
# $ rails generate formtastic:form Post --haml
# @example Return HAML or Slim output instead of default ERB
# $ rails generate formtastic:form Post --template-engine haml
# $ rails generate formtastic:form Post --template-engine slim
# @example Generate a form for specific model attributes
# $ rails generate formtastic:form Post title:string body:text
# @example Generate a form for a specific controller
Expand Down
21 changes: 17 additions & 4 deletions spec/generators/formtastic/form/form_generator_spec.rb
Expand Up @@ -21,6 +21,10 @@
mock('reflection', :name => :attachment, :options => {:polymorphic => true}, :macro => :belongs_to),
])
end

after do
FileUtils.rm_rf(File.expand_path("../../../../../tmp", __FILE__))
end

describe 'without model' do
it 'should raise Thor::RequiredArgumentMissingError' do
Expand Down Expand Up @@ -78,13 +82,22 @@
end

describe 'haml' do
before { run_generator %w(Post --template-engine haml) }


describe 'app/views/posts/_form.html.haml' do
before { run_generator %w(Post --template-engine haml) }
subject { file('app/views/posts/_form.html.haml') }
it { should exist }
it { should contain "= semantic_form_for @post do |f|" }
end

context 'with copy option' do
describe 'app/views/posts/_form.html.haml' do
before { run_generator %w(Post --copy --template-engine haml) }
subject { file('app/views/posts/_form.html.haml') }
it { should_not exist }
end
end

end

describe 'slim' do
Expand All @@ -97,10 +110,10 @@
end
end
end

describe 'with copy option' do
before { run_generator %w(Post --copy) }

describe 'app/views/posts/_form.html.erb' do
subject { file('app/views/posts/_form.html.erb') }
it { should_not exist }
Expand Down

0 comments on commit 9946ae5

Please sign in to comment.