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-10-09 08:51:40 +00:00
|
|
|
it { should contain "class YourModelDecorator < Draper::Decorator" }
|
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
|
2012-12-01 17:49:18 +00:00
|
|
|
describe 'decorator inherited from Draper::Decorator' do
|
2012-05-11 23:17:12 +00:00
|
|
|
before { run_generator ["YourModel"] }
|
|
|
|
|
|
|
|
subject { file('app/decorators/your_model_decorator.rb') }
|
|
|
|
it { should exist }
|
2012-10-09 08:51:40 +00:00
|
|
|
it { should contain "class YourModelDecorator < Draper::Decorator" }
|
2012-05-11 23:17:12 +00:00
|
|
|
end
|
|
|
|
|
2012-12-01 17:49:18 +00:00
|
|
|
describe "decorator inherited from ApplicationDecorator if it's present" do
|
2012-05-11 23:17:12 +00:00
|
|
|
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
|
|
|
|
|
2012-09-21 16:02:06 +00:00
|
|
|
context 'using rspec with namespaced model' do
|
|
|
|
before { run_generator ["Namespace::YourModel", "-t=rspec"] }
|
|
|
|
|
|
|
|
describe 'spec/decorators/your_model_decorator_spec.rb' do
|
|
|
|
subject { file('spec/decorators/namespace/your_model_decorator_spec.rb') }
|
|
|
|
it { should exist }
|
|
|
|
it { should contain "describe Namespace::YourModelDecorator" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using test-unit' 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 }
|
2013-01-12 08:05:06 +00:00
|
|
|
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-09-21 16:02:06 +00:00
|
|
|
|
|
|
|
context 'using test-unit with namespaced model' do
|
|
|
|
before { run_generator ["Namespace::YourModel", "-t=test_unit"] }
|
|
|
|
|
|
|
|
describe 'test/decorators/your_model_decorator_test.rb' do
|
|
|
|
subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
|
|
|
|
it { should exist }
|
2013-01-12 08:05:06 +00:00
|
|
|
it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
2012-09-21 16:02:06 +00:00
|
|
|
end
|
|
|
|
end
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|