Merge pull request #131 from yakko/master
draper:decorator defaults to rspec too
This commit is contained in:
commit
49952fff8c
|
@ -1,5 +1,5 @@
|
||||||
module Draper
|
module Draper
|
||||||
class DecoratorGenerator < Rails::Generators::NamedBase
|
class DecoratorGenerator < Rails::Generators::Base
|
||||||
desc <<-DESC
|
desc <<-DESC
|
||||||
Description:
|
Description:
|
||||||
Generate a decorator for the given model.
|
Generate a decorator for the given model.
|
||||||
|
@ -8,14 +8,36 @@ module Draper
|
||||||
"spec/decorators/article_decorator_spec"
|
"spec/decorators/article_decorator_spec"
|
||||||
DESC
|
DESC
|
||||||
|
|
||||||
|
argument :resource_name, :type => :string
|
||||||
|
class_option "test-framework", :type => :string, :default => "rspec", :aliases => "-t", :desc => "Test framework to be invoked"
|
||||||
|
|
||||||
source_root File.expand_path('../templates', __FILE__)
|
source_root File.expand_path('../templates', __FILE__)
|
||||||
|
|
||||||
DECORATORS_ROOT = 'app/decorators/'
|
DECORATORS_ROOT = 'app/decorators/'
|
||||||
|
|
||||||
def build_model_decorator
|
def build_model_decorator
|
||||||
template 'decorator.rb', "#{DECORATORS_ROOT}#{singular_name}_decorator.rb"
|
template 'decorator.rb', "#{DECORATORS_ROOT}#{resource_name.singularize}_decorator.rb"
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def build_decorator_tests
|
||||||
|
case options["test-framework"]
|
||||||
|
when "rspec"
|
||||||
|
build_decorator_spec
|
||||||
|
when "test_unit"
|
||||||
|
build_decorator_test
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def build_decorator_spec
|
||||||
|
empty_directory 'spec/decorators'
|
||||||
|
template 'decorator_spec.rb', File.join('spec/decorators', "#{resource_name.singularize}_decorator_spec.rb")
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_decorator_test
|
||||||
|
empty_directory 'test/decorators/'
|
||||||
|
template 'decorator_test.rb', File.join('test/decorators', "#{resource_name.singularize}_decorator_test.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
hook_for :test_framework
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class <%= singular_name.camelize %>Decorator < ApplicationDecorator
|
class <%= resource_name.singularize.camelize %>Decorator < ApplicationDecorator
|
||||||
decorates :<%= singular_name.to_sym %>
|
decorates :<%= resource_name.singularize.to_sym %>
|
||||||
|
|
||||||
# Accessing Helpers
|
# Accessing Helpers
|
||||||
# You can access any helper via a proxy
|
# You can access any helper via a proxy
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe <%= singular_name.camelize %>Decorator do
|
describe <%= resource_name.singularize.camelize %>Decorator do
|
||||||
before { ApplicationController.new.set_current_view_context }
|
before { ApplicationController.new.set_current_view_context }
|
||||||
end
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class <%= singular_name.camelize %>DecoratorTest < ActiveSupport::TestCase
|
class <%= resource_name.singularize.camelize %>DecoratorTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
ApplicationController.new.set_current_view_context
|
ApplicationController.new.set_current_view_context
|
||||||
end
|
end
|
|
@ -1,11 +0,0 @@
|
||||||
module Rspec
|
|
||||||
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
|
||||||
source_root File.expand_path('../templates', __FILE__)
|
|
||||||
|
|
||||||
SPEC_ROOT = 'spec/decorators/'
|
|
||||||
|
|
||||||
def build_model_and_application_decorator_specs
|
|
||||||
template 'decorator_spec.rb', "#{SPEC_ROOT}#{singular_name}_decorator_spec.rb"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,11 +0,0 @@
|
||||||
module TestUnit
|
|
||||||
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
|
||||||
source_root File.expand_path('../templates', __FILE__)
|
|
||||||
|
|
||||||
TEST_ROOT = 'test/decorators/'
|
|
||||||
|
|
||||||
def build_model_decorator_tests
|
|
||||||
template 'decorator_test.rb', "#{TEST_ROOT}#{singular_name}_decorator_test.rb"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -9,6 +9,50 @@ describe Draper::DecoratorGenerator do
|
||||||
|
|
||||||
before { prepare_destination }
|
before { prepare_destination }
|
||||||
|
|
||||||
|
context 'decorator context' do
|
||||||
|
before { run_generator ["product"] }
|
||||||
|
|
||||||
|
describe 'app/decorators/product_decorator.rb' do
|
||||||
|
subject { file('app/decorators/product_decorator.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "class ProductDecorator < ApplicationDecorator" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'default test framework' do
|
||||||
|
before { run_generator ["product"] }
|
||||||
|
|
||||||
|
describe 'spec/decorators/product_decorator_spec.rb' do
|
||||||
|
subject { file('spec/decorators/product_decorator_spec.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "describe ProductDecorator" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'using rspec' do
|
||||||
|
before { run_generator ["product", "-t=rspec"] }
|
||||||
|
|
||||||
|
describe 'spec/decorators/product_decorator_spec.rb' do
|
||||||
|
subject { file('spec/decorators/product_decorator_spec.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "describe ProductDecorator" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'using rspec' do
|
||||||
|
before { run_generator ["product", "-t=test_unit"] }
|
||||||
|
|
||||||
|
describe 'test/decorators/product_decorator_test.rb' do
|
||||||
|
subject { file('test/decorators/product_decorator_test.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "class ProductDecoratorTest < ActiveSupport::TestCase" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
=begin
|
||||||
describe 'no arguments' do
|
describe 'no arguments' do
|
||||||
before { run_generator %w(products) }
|
before { run_generator %w(products) }
|
||||||
|
|
||||||
|
@ -17,6 +61,43 @@ describe Draper::DecoratorGenerator do
|
||||||
it { should exist }
|
it { should exist }
|
||||||
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'simple' do
|
||||||
|
before { run_generator %w(products) }
|
||||||
|
|
||||||
|
describe 'app/decorators/products_decorator.rb' do
|
||||||
|
subject { file('app/decorators/products_decorator.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
context 'using rspec' do
|
||||||
|
|
||||||
|
describe 'app/decorators/products_decorator.rb' do
|
||||||
|
subject { file('app/decorators/products_decorator.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for "ApplicationDecoratorGenerator" do
|
||||||
|
describe 'app/decorators/application_decorator.rb' do
|
||||||
|
subject { file('app/decorators/application_decorator.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "class ApplicationDecorator < Draper::Base" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'spec/decorators/application_decorator_spec.rb' do
|
||||||
|
subject { file('spec/decorators/application_decorator_spec.rb') }
|
||||||
|
it { should exist }
|
||||||
|
it { should contain "describe ApplicationDecorator do" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
=end
|
|
@ -1,22 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
# Generators are not automatically loaded by Rails
|
|
||||||
require 'generators/rspec/decorator_generator'
|
|
||||||
|
|
||||||
describe Rspec::DecoratorGenerator do
|
|
||||||
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
||||||
destination File.expand_path("../../../../tmp", __FILE__)
|
|
||||||
|
|
||||||
before { prepare_destination }
|
|
||||||
|
|
||||||
describe 'no arguments' do
|
|
||||||
before { run_generator %w(products) }
|
|
||||||
|
|
||||||
describe 'spec/decorators/products_decorator_spec.rb' do
|
|
||||||
subject { file('spec/decorators/products_decorator_spec.rb') }
|
|
||||||
it { should exist }
|
|
||||||
it { should contain "describe ProductsDecorator" }
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,22 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
# Generators are not automatically loaded by Rails
|
|
||||||
require 'generators/test_unit/decorator_generator'
|
|
||||||
|
|
||||||
describe TestUnit::DecoratorGenerator do
|
|
||||||
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
|
||||||
destination File.expand_path("../../../../tmp", __FILE__)
|
|
||||||
|
|
||||||
before { prepare_destination }
|
|
||||||
|
|
||||||
describe 'no arguments' do
|
|
||||||
before { run_generator %w(products) }
|
|
||||||
|
|
||||||
describe 'test/decorators/products_decorator_test.rb' do
|
|
||||||
subject { file('test/decorators/products_decorator_test.rb') }
|
|
||||||
it { should exist }
|
|
||||||
it { should contain "class ProductsDecoratorTest < ActiveSupport::TestCase" }
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue