use ApplicationDecorator if it's present, closes #190

This commit is contained in:
Vasiliy Ermolovich 2012-05-12 02:17:12 +03:00 committed by Steve Klabnik
parent f2432cd402
commit cd95a16d14
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"] }