1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge pull request #192 from nashby/fix-generators

use ApplicationDecorator if it's present
This commit is contained in:
Steve Klabnik 2012-05-11 17:15:48 -07:00
commit 28fd98414e
3 changed files with 24 additions and 3 deletions

View file

@ -17,7 +17,7 @@ module Rails
def parent_class_name
if options[:parent]
options[:parent]
elsif defined?(:ApplicationDecorator)
elsif defined?(ApplicationDecorator)
"ApplicationDecorator"
else
"Draper::Base"

View file

@ -1,5 +1,5 @@
<% module_namespacing do -%>
class <%= class_name %>Decorator < ApplicationDecorator
class <%= class_name %>Decorator < <%= parent_class_name %>
decorates :<%= singular_name %>
# Accessing Helpers

View file

@ -15,7 +15,7 @@ describe Rails::Generators::DecoratorGenerator do
describe 'app/decorators/your_model_decorator.rb' do
subject { file('app/decorators/your_model_decorator.rb') }
it { should exist }
it { should contain "class YourModelDecorator < ApplicationDecorator" }
it { should contain "class YourModelDecorator < Draper::Base" }
it { should contain "decorates :your_model" }
end
end
@ -30,6 +30,27 @@ describe Rails::Generators::DecoratorGenerator do
end
end
context 'parent decorator' do
describe 'decorator inhereted from Draper::Base' do
before { run_generator ["YourModel"] }
subject { file('app/decorators/your_model_decorator.rb') }
it { should exist }
it { should contain "class YourModelDecorator < Draper::Base" }
end
describe "decorator inhereted from ApplicationDecorator if it's present" do
before do
class ApplicationDecorator; end
run_generator ["YourModel"]
end
subject { file('app/decorators/your_model_decorator.rb') }
it { should exist }
it { should contain "class YourModelDecorator < ApplicationDecorator" }
end
end
context 'using rspec' do
before { run_generator ["YourModel", "-t=rspec"] }