2011-10-06 20:58:04 +00:00
|
|
|
require 'spec_helper'
|
2013-04-29 14:08:47 +00:00
|
|
|
require 'rails'
|
2013-01-17 02:36:56 +00:00
|
|
|
require 'ammeter/init'
|
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
|
2013-02-05 11:24:40 +00:00
|
|
|
destination File.expand_path("../tmp", __FILE__)
|
2011-10-06 20:58:04 +00:00
|
|
|
|
|
|
|
before { prepare_destination }
|
2013-02-12 08:44:14 +00:00
|
|
|
after(:all) { FileUtils.rm_rf destination_root }
|
2011-10-06 20:58:04 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "the generated decorator" do
|
|
|
|
subject { file("app/decorators/your_model_decorator.rb") }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "naming" do
|
|
|
|
before { run_generator %w(YourModel) }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "class YourModelDecorator" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "namespacing" do
|
|
|
|
subject { file("app/decorators/namespace/your_model_decorator.rb") }
|
|
|
|
before { run_generator %w(Namespace::YourModel) }
|
2012-05-11 23:17:12 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "class Namespace::YourModelDecorator" }
|
2012-05-11 23:17:12 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "inheritance" do
|
|
|
|
context "by default" do
|
|
|
|
before { run_generator %w(YourModel) }
|
|
|
|
|
|
|
|
it { should contain "class YourModelDecorator < Draper::Decorator" }
|
2012-05-11 23:17:12 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
context "with the --parent option" do
|
|
|
|
before { run_generator %w(YourModel --parent=FooDecorator) }
|
|
|
|
|
|
|
|
it { should contain "class YourModelDecorator < FooDecorator" }
|
2012-06-08 23:14:48 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
context "with an ApplicationDecorator" do
|
|
|
|
before do
|
|
|
|
Object.any_instance.stub(:require).with("application_decorator").and_return do
|
|
|
|
stub_const "ApplicationDecorator", Class.new
|
|
|
|
end
|
|
|
|
end
|
2012-05-11 23:17:12 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
before { run_generator %w(YourModel) }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "class YourModelDecorator < ApplicationDecorator" }
|
|
|
|
end
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
context "with -t=rspec" do
|
|
|
|
describe "the generated spec" do
|
|
|
|
subject { file("spec/decorators/your_model_decorator_spec.rb") }
|
2012-09-21 16:02:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "naming" do
|
|
|
|
before { run_generator %w(YourModel -t=rspec) }
|
2012-09-21 16:02:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "describe YourModelDecorator" }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "namespacing" do
|
|
|
|
subject { file("spec/decorators/namespace/your_model_decorator_spec.rb") }
|
|
|
|
before { run_generator %w(Namespace::YourModel -t=rspec) }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "describe Namespace::YourModelDecorator" }
|
|
|
|
end
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-09-21 16:02:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
context "with -t=test_unit" do
|
|
|
|
describe "the generated test" do
|
|
|
|
subject { file("test/decorators/your_model_decorator_test.rb") }
|
2012-09-21 16:02:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "naming" do
|
|
|
|
before { run_generator %w(YourModel -t=test_unit) }
|
|
|
|
|
|
|
|
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
|
|
|
end
|
2013-01-14 11:57:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "namespacing" do
|
|
|
|
subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
|
|
|
|
before { run_generator %w(Namespace::YourModel -t=test_unit) }
|
2013-01-14 11:57:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
|
|
|
end
|
2013-01-14 11:57:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
context "with -t=mini_test" do
|
|
|
|
describe "the generated test" do
|
|
|
|
subject { file("test/decorators/your_model_decorator_test.rb") }
|
2013-01-14 11:57:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "naming" do
|
|
|
|
before { run_generator %w(YourModel -t=mini_test) }
|
2013-01-14 11:57:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
|
|
|
end
|
2013-01-14 11:57:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "namespacing" do
|
|
|
|
subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
|
|
|
|
before { run_generator %w(Namespace::YourModel -t=mini_test) }
|
|
|
|
|
|
|
|
it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
|
|
|
end
|
2013-01-14 11:57:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
context "with -t=mini_test --spec" do
|
|
|
|
describe "the generated test" do
|
|
|
|
subject { file("test/decorators/your_model_decorator_test.rb") }
|
2013-01-14 11:57:06 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
describe "naming" do
|
|
|
|
before { run_generator %w(YourModel -t=mini_test --spec) }
|
|
|
|
|
|
|
|
it { should contain "describe YourModelDecorator" }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "namespacing" do
|
|
|
|
subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
|
|
|
|
before { run_generator %w(Namespace::YourModel -t=mini_test --spec) }
|
|
|
|
|
|
|
|
it { should contain "describe Namespace::YourModelDecorator" }
|
|
|
|
end
|
2013-01-14 11:57:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|