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

use ApplicationDecorator if it's present, closes #190

This commit is contained in:
Vasiliy Ermolovich 2012-05-12 02:17:12 +03:00
parent f1bd79b71d
commit b302e8dd42
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"] }