2011-10-06 20:58:04 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
# Generators are not automatically loaded by Rails
|
2012-05-09 17:32:58 +00:00
|
|
|
require 'generators/decorator/decorator_generator'
|
2011-10-06 20:58:04 +00:00
|
|
|
|
2012-05-09 17:32:58 +00:00
|
|
|
describe Rails::Generators::DecoratorGenerator do
|
2011-10-06 20:58:04 +00:00
|
|
|
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
|
|
destination File.expand_path("../../../../../tmp", __FILE__)
|
|
|
|
|
|
|
|
before { prepare_destination }
|
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
context 'decorator context' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'app/decorators/your_model_decorator.rb' do
|
|
|
|
subject { file('app/decorators/your_model_decorator.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-05-11 23:17:12 +00:00
|
|
|
it { should contain "class YourModelDecorator < Draper::Base" }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "decorates :your_model" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-27 14:33:19 +00:00
|
|
|
context 'decorator name' do
|
2012-04-28 19:26:57 +00:00
|
|
|
before { run_generator ["YourModel", '-t=rspec'] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'spec/decorators/your_model_decorator_spec.rb' do
|
|
|
|
subject { file('spec/decorators/your_model_decorator_spec.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "describe YourModelDecorator" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-11 23:17:12 +00:00
|
|
|
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
|
|
|
|
|
2012-06-08 23:14:48 +00:00
|
|
|
after do
|
|
|
|
Object.send(:remove_const, :ApplicationDecorator)
|
|
|
|
end
|
|
|
|
|
2012-05-11 23:17:12 +00:00
|
|
|
subject { file('app/decorators/your_model_decorator.rb') }
|
|
|
|
it { should exist }
|
|
|
|
it { should contain "class YourModelDecorator < ApplicationDecorator" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
context 'using rspec' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel", "-t=rspec"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'spec/decorators/your_model_decorator_spec.rb' do
|
|
|
|
subject { file('spec/decorators/your_model_decorator_spec.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "describe YourModelDecorator" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using rspec' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel", "-t=test_unit"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'test/decorators/YourModel_decorator_test.rb' do
|
|
|
|
subject { file('test/decorators/your_model_decorator_test.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "class YourModelDecoratorTest < ActiveSupport::TestCase" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|