draper 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG.md +140 -120
  4. data/Gemfile +5 -3
  5. data/Guardfile +22 -1
  6. data/README.md +4 -3
  7. data/draper.gemspec +3 -1
  8. data/lib/draper.rb +6 -0
  9. data/lib/draper/automatic_delegation.rb +8 -2
  10. data/lib/draper/collection_decorator.rb +17 -28
  11. data/lib/draper/decoratable.rb +6 -3
  12. data/lib/draper/decoratable/equality.rb +15 -3
  13. data/lib/draper/decorated_association.rb +11 -50
  14. data/lib/draper/decorates_assigned.rb +44 -0
  15. data/lib/draper/decorator.rb +19 -6
  16. data/lib/draper/factory.rb +87 -0
  17. data/lib/draper/helper_proxy.rb +2 -0
  18. data/lib/draper/railtie.rb +8 -2
  19. data/lib/draper/version.rb +1 -1
  20. data/lib/generators/decorator/decorator_generator.rb +9 -9
  21. data/spec/draper/collection_decorator_spec.rb +48 -28
  22. data/spec/draper/decoratable_spec.rb +13 -4
  23. data/spec/draper/decorated_association_spec.rb +53 -114
  24. data/spec/draper/decorates_assigned_spec.rb +71 -0
  25. data/spec/draper/decorator_spec.rb +58 -8
  26. data/spec/draper/factory_spec.rb +238 -0
  27. data/spec/draper/helper_proxy_spec.rb +11 -0
  28. data/spec/draper/lazy_helpers_spec.rb +21 -0
  29. data/spec/dummy/app/controllers/posts_controller.rb +3 -1
  30. data/spec/dummy/app/decorators/mongoid_post_decorator.rb +2 -0
  31. data/spec/dummy/app/views/posts/show.html.erb +1 -1
  32. data/spec/dummy/config/application.rb +1 -0
  33. data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +11 -0
  34. data/spec/dummy/spec/decorators/post_decorator_spec.rb +12 -0
  35. data/spec/dummy/spec/models/mongoid_post_spec.rb +2 -4
  36. data/spec/dummy/spec/models/post_spec.rb +2 -10
  37. data/spec/dummy/spec/shared_examples/decoratable.rb +24 -0
  38. data/spec/generators/decorator/decorator_generator_spec.rb +83 -91
  39. data/spec/spec_helper.rb +1 -0
  40. metadata +50 -43
@@ -0,0 +1,238 @@
1
+ require 'spec_helper'
2
+
3
+ module Draper
4
+ describe Factory do
5
+
6
+ describe "#initialize" do
7
+ it "accepts valid options" do
8
+ valid_options = {with: Decorator, context: {foo: "bar"}}
9
+ expect{Factory.new(valid_options)}.not_to raise_error
10
+ end
11
+
12
+ it "rejects invalid options" do
13
+ expect{Factory.new(foo: "bar")}.to raise_error ArgumentError, /Unknown key/
14
+ end
15
+ end
16
+
17
+ describe "#decorate" do
18
+ context "when source is nil" do
19
+ it "returns nil" do
20
+ factory = Factory.new
21
+
22
+ expect(factory.decorate(nil)).to be_nil
23
+ end
24
+ end
25
+
26
+ it "calls a worker" do
27
+ factory = Factory.new
28
+ worker = ->(*){ :decorated }
29
+
30
+ Factory::Worker.should_receive(:new).and_return(worker)
31
+ expect(factory.decorate(double)).to be :decorated
32
+ end
33
+
34
+ it "passes the source to the worker" do
35
+ factory = Factory.new
36
+ source = double
37
+
38
+ Factory::Worker.should_receive(:new).with(anything(), source).and_return(->(*){})
39
+ factory.decorate(source)
40
+ end
41
+
42
+ context "when the :with option was given" do
43
+ it "passes the decorator class to the worker" do
44
+ decorator_class = double
45
+ factory = Factory.new(with: decorator_class)
46
+
47
+ Factory::Worker.should_receive(:new).with(decorator_class, anything()).and_return(->(*){})
48
+ factory.decorate(double)
49
+ end
50
+ end
51
+
52
+ context "when the :with option was omitted" do
53
+ it "passes nil to the worker" do
54
+ factory = Factory.new
55
+
56
+ Factory::Worker.should_receive(:new).with(nil, anything()).and_return(->(*){})
57
+ factory.decorate(double)
58
+ end
59
+ end
60
+
61
+ it "passes options to the call" do
62
+ factory = Factory.new
63
+ worker = ->(*){}
64
+ Factory::Worker.stub new: worker
65
+ options = {foo: "bar"}
66
+
67
+ worker.should_receive(:call).with(options)
68
+ factory.decorate(double, options)
69
+ end
70
+
71
+ context "when the :context option was given" do
72
+ it "sets the passed context" do
73
+ factory = Factory.new(context: {foo: "bar"})
74
+ worker = ->(*){}
75
+ Factory::Worker.stub new: worker
76
+
77
+ worker.should_receive(:call).with(baz: "qux", context: {foo: "bar"})
78
+ factory.decorate(double, {baz: "qux"})
79
+ end
80
+
81
+ it "is overridden by explicitly-specified context" do
82
+ factory = Factory.new(context: {foo: "bar"})
83
+ worker = ->(*){}
84
+ Factory::Worker.stub new: worker
85
+
86
+ worker.should_receive(:call).with(context: {baz: "qux"})
87
+ factory.decorate(double, context: {baz: "qux"})
88
+ end
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ describe Factory::Worker do
95
+
96
+ describe "#call" do
97
+ it "calls the decorator method" do
98
+ source = double
99
+ options = {foo: "bar"}
100
+ worker = Factory::Worker.new(double, source)
101
+ decorator = ->(*){}
102
+ worker.stub decorator: decorator
103
+
104
+ decorator.should_receive(:call).with(source, options).and_return(:decorated)
105
+ expect(worker.call(options)).to be :decorated
106
+ end
107
+
108
+ context "when the :context option is callable" do
109
+ it "calls it" do
110
+ worker = Factory::Worker.new(double, double)
111
+ decorator = ->(*){}
112
+ worker.stub decorator: decorator
113
+ context = {foo: "bar"}
114
+
115
+ decorator.should_receive(:call).with(anything(), context: context)
116
+ worker.call(context: ->{ context })
117
+ end
118
+
119
+ it "receives arguments from the :context_args option" do
120
+ worker = Factory::Worker.new(double, double)
121
+ worker.stub decorator: ->(*){}
122
+ context = ->{}
123
+
124
+ context.should_receive(:call).with(:foo, :bar)
125
+ worker.call(context: context, context_args: [:foo, :bar])
126
+ end
127
+
128
+ it "wraps non-arrays passed to :context_args" do
129
+ worker = Factory::Worker.new(double, double)
130
+ worker.stub decorator: ->(*){}
131
+ context = ->{}
132
+ hash = {foo: "bar"}
133
+
134
+ context.should_receive(:call).with(hash)
135
+ worker.call(context: context, context_args: hash)
136
+ end
137
+ end
138
+
139
+ context "when the :context option is not callable" do
140
+ it "doesn't call it" do
141
+ worker = Factory::Worker.new(double, double)
142
+ decorator = ->(*){}
143
+ worker.stub decorator: decorator
144
+ context = {foo: "bar"}
145
+
146
+ decorator.should_receive(:call).with(anything(), context: context)
147
+ worker.call(context: context)
148
+ end
149
+ end
150
+
151
+ it "does not pass the :context_args option to the decorator" do
152
+ worker = Factory::Worker.new(double, double)
153
+ decorator = ->(*){}
154
+ worker.stub decorator: decorator
155
+
156
+ decorator.should_receive(:call).with(anything(), foo: "bar")
157
+ worker.call(foo: "bar", context_args: [])
158
+ end
159
+ end
160
+
161
+ describe "#decorator" do
162
+ context "for a singular source" do
163
+ context "when decorator_class is specified" do
164
+ it "returns the .decorate method from the decorator" do
165
+ decorator_class = Class.new(Decorator)
166
+ worker = Factory::Worker.new(decorator_class, double)
167
+
168
+ expect(worker.decorator).to eq decorator_class.method(:decorate)
169
+ end
170
+ end
171
+
172
+ context "when decorator_class is unspecified" do
173
+ context "and the source is decoratable" do
174
+ it "returns the source's #decorate method" do
175
+ source = double
176
+ options = {foo: "bar"}
177
+ worker = Factory::Worker.new(nil, source)
178
+
179
+ source.should_receive(:decorate).with(options).and_return(:decorated)
180
+ expect(worker.decorator.call(source, options)).to be :decorated
181
+ end
182
+ end
183
+
184
+ context "and the source is not decoratable" do
185
+ it "raises an error" do
186
+ source = double
187
+ worker = Factory::Worker.new(nil, source)
188
+
189
+ expect{worker.decorator}.to raise_error UninferrableDecoratorError
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ context "for a collection source" do
196
+ context "when decorator_class is a CollectionDecorator" do
197
+ it "returns the .decorate method from the collection decorator" do
198
+ decorator_class = Class.new(CollectionDecorator)
199
+ worker = Factory::Worker.new(decorator_class, [])
200
+
201
+ expect(worker.decorator).to eq decorator_class.method(:decorate)
202
+ end
203
+ end
204
+
205
+ context "when decorator_class is a Decorator" do
206
+ it "returns the .decorate_collection method from the decorator" do
207
+ decorator_class = Class.new(Decorator)
208
+ worker = Factory::Worker.new(decorator_class, [])
209
+
210
+ expect(worker.decorator).to eq decorator_class.method(:decorate_collection)
211
+ end
212
+ end
213
+
214
+ context "when decorator_class is unspecified" do
215
+ context "and the source is decoratable" do
216
+ it "returns the source's #decorate method" do
217
+ source = []
218
+ options = {foo: "bar"}
219
+ worker = Factory::Worker.new(nil, source)
220
+
221
+ source.should_receive(:decorate).with(options).and_return(:decorated)
222
+ expect(worker.decorator.call(source, options)).to be :decorated
223
+ end
224
+ end
225
+
226
+ context "and the source is not decoratable" do
227
+ it "returns the .decorate method from CollectionDecorator" do
228
+ worker = Factory::Worker.new(nil, [])
229
+
230
+ expect(worker.decorator).to eq CollectionDecorator.method(:decorate)
231
+ end
232
+ end
233
+ end
234
+ end
235
+ end
236
+
237
+ end
238
+ end
@@ -38,5 +38,16 @@ module Draper
38
38
  expect(HelperProxy.instance_methods).to include :foo
39
39
  end
40
40
  end
41
+
42
+ describe "proxying methods which are overriding" do
43
+ it "proxies :capture" do
44
+ view_context = double
45
+ helper_proxy = HelperProxy.new(view_context)
46
+
47
+ view_context.stub(:capture).and_return{|*args, &block| [*args, block.call] }
48
+ expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \
49
+ be_eql [:first_arg, :second_arg, :yielded]
50
+ end
51
+ end
41
52
  end
42
53
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Draper
4
+ describe LazyHelpers do
5
+ describe "#method_missing" do
6
+ let(:decorator) do
7
+ Struct.new(:helpers){include Draper::LazyHelpers}.new(double)
8
+ end
9
+
10
+ it "proxies methods to #helpers" do
11
+ decorator.helpers.stub(:foo).and_return{|arg| arg}
12
+ expect(decorator.foo(:passed)).to be :passed
13
+ end
14
+
15
+ it "passes blocks" do
16
+ decorator.helpers.stub(:foo).and_return{|&block| block.call}
17
+ expect(decorator.foo{:yielded}).to be :yielded
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,8 @@
1
1
  class PostsController < ApplicationController
2
+ decorates_assigned :post
3
+
2
4
  def show
3
- @post = Post.find(params[:id]).decorate
5
+ @post = Post.find(params[:id])
4
6
  end
5
7
 
6
8
  def mail
@@ -0,0 +1,2 @@
1
+ class MongoidPostDecorator < Draper::Decorator
2
+ end
@@ -1 +1 @@
1
- <%= render @post %>
1
+ <%= render post %>
@@ -9,6 +9,7 @@ require 'rails/all'
9
9
  require 'draper'
10
10
  attempt_require 'mongoid'
11
11
  attempt_require 'devise'
12
+ require 'active_model_serializers'
12
13
 
13
14
  module Dummy
14
15
  class Application < Rails::Application
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Draper::CollectionDecorator do
4
+ describe "#active_model_serializer" do
5
+ it "returns ActiveModel::ArraySerializer" do
6
+ collection_decorator = Draper::CollectionDecorator.new([])
7
+
8
+ expect(collection_decorator.active_model_serializer).to be ActiveModel::ArraySerializer
9
+ end
10
+ end
11
+ end
@@ -40,6 +40,18 @@ describe PostDecorator do
40
40
  expect(decorator.serializable_hash["updated_at"]).to be :overridden
41
41
  end
42
42
 
43
+ it "serializes to JSON" do
44
+ json = decorator.to_json
45
+ expect(json).to match /"updated_at":"overridden"/
46
+ end
47
+
48
+ it "serializes to XML" do
49
+ pending("Rails < 3.2 does not use `serializable_hash` in `to_xml`") if Rails.version.to_f < 3.2
50
+
51
+ xml = Capybara.string(decorator.to_xml)
52
+ expect(xml).to have_css "post > updated-at", text: "overridden"
53
+ end
54
+
43
55
  it "uses a test view context from ApplicationController" do
44
56
  expect(Draper::ViewContext.current.controller).to be_an ApplicationController
45
57
  end
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
+ require 'shared_examples/decoratable'
2
3
 
3
4
  if defined?(Mongoid)
4
5
  describe MongoidPost do
5
- it "is decoratable" do
6
- expect(MongoidPost).to respond_to :decorator_class
7
- expect(MongoidPost.new).to respond_to :decorate
8
- end
6
+ it_behaves_like "a decoratable model"
9
7
  end
10
8
  end
@@ -1,14 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'shared_examples/decoratable'
2
3
 
3
4
  describe Post do
4
- describe "#==" do
5
- it "is true for other instances' decorators" do
6
- Post.create
7
- one = Post.first
8
- other = Post.first
9
-
10
- expect(one).not_to be other
11
- expect(one == other.decorate).to be_true
12
- end
13
- end
5
+ it_behaves_like "a decoratable model"
14
6
  end
@@ -0,0 +1,24 @@
1
+ shared_examples_for "a decoratable model" do
2
+ describe ".decorate" do
3
+ it "applies a collection decorator to a scope" do
4
+ described_class.create
5
+ decorated = described_class.limit(1).decorate
6
+
7
+ expect(decorated).to have(1).items
8
+ expect(decorated).to be_decorated
9
+ end
10
+ end
11
+
12
+ describe "#==" do
13
+ it "is true for other instances' decorators" do
14
+ pending "Mongoid < 3.1 overrides `#==`" if defined?(Mongoid) && Mongoid::VERSION.to_f < 3.1 && described_class < Mongoid::Document
15
+
16
+ described_class.create
17
+ one = described_class.first
18
+ other = described_class.first
19
+
20
+ expect(one).not_to be other
21
+ expect(one == other.decorate).to be_true
22
+ end
23
+ end
24
+ end
@@ -1,137 +1,129 @@
1
1
  require 'spec_helper'
2
2
  require 'ammeter/init'
3
-
4
- # Generators are not automatically loaded by Rails
5
3
  require 'generators/decorator/decorator_generator'
6
4
 
7
5
  describe Rails::Generators::DecoratorGenerator do
8
- # Tell the generator where to put its output (what it thinks of as Rails.root)
9
- destination File.expand_path("../../../../../tmp", __FILE__)
6
+ destination File.expand_path("../tmp", __FILE__)
10
7
 
11
8
  before { prepare_destination }
9
+ after(:all) { FileUtils.rm_rf destination_root }
12
10
 
13
- context 'decorator context' do
14
- before { run_generator ["YourModel"] }
15
-
16
- describe 'app/decorators/your_model_decorator.rb' do
17
- subject { file('app/decorators/your_model_decorator.rb') }
18
- it { should exist }
19
- it { should contain "class YourModelDecorator < Draper::Decorator" }
20
- end
21
- end
11
+ describe "the generated decorator" do
12
+ subject { file("app/decorators/your_model_decorator.rb") }
22
13
 
23
- context 'decorator name' do
24
- before { run_generator ["YourModel", '-t=rspec'] }
14
+ describe "naming" do
15
+ before { run_generator %w(YourModel) }
25
16
 
26
- describe 'spec/decorators/your_model_decorator_spec.rb' do
27
- subject { file('spec/decorators/your_model_decorator_spec.rb') }
28
- it { should exist }
29
- it { should contain "describe YourModelDecorator" }
17
+ it { should contain "class YourModelDecorator" }
30
18
  end
31
- end
32
19
 
33
- context 'parent decorator' do
34
- describe 'decorator inherited from Draper::Decorator' do
35
- before { run_generator ["YourModel"] }
20
+ describe "namespacing" do
21
+ subject { file("app/decorators/namespace/your_model_decorator.rb") }
22
+ before { run_generator %w(Namespace::YourModel) }
36
23
 
37
- subject { file('app/decorators/your_model_decorator.rb') }
38
- it { should exist }
39
- it { should contain "class YourModelDecorator < Draper::Decorator" }
24
+ it { should contain "class Namespace::YourModelDecorator" }
40
25
  end
41
26
 
42
- describe "decorator inherited from ApplicationDecorator if it's present" do
43
- before do
44
- class ApplicationDecorator; end
45
- run_generator ["YourModel"]
27
+ describe "inheritance" do
28
+ context "by default" do
29
+ before { run_generator %w(YourModel) }
30
+
31
+ it { should contain "class YourModelDecorator < Draper::Decorator" }
46
32
  end
47
33
 
48
- after do
49
- Object.send(:remove_const, :ApplicationDecorator)
34
+ context "with the --parent option" do
35
+ before { run_generator %w(YourModel --parent=FooDecorator) }
36
+
37
+ it { should contain "class YourModelDecorator < FooDecorator" }
50
38
  end
51
39
 
52
- subject { file('app/decorators/your_model_decorator.rb') }
53
- it { should exist }
54
- it { should contain "class YourModelDecorator < ApplicationDecorator" }
55
- end
56
- end
40
+ context "with an ApplicationDecorator" do
41
+ before do
42
+ Object.any_instance.stub(:require).with("application_decorator").and_return do
43
+ stub_const "ApplicationDecorator", Class.new
44
+ end
45
+ end
57
46
 
58
- context 'using rspec' do
59
- before { run_generator ["YourModel", "-t=rspec"] }
47
+ before { run_generator %w(YourModel) }
60
48
 
61
- describe 'spec/decorators/your_model_decorator_spec.rb' do
62
- subject { file('spec/decorators/your_model_decorator_spec.rb') }
63
- it { should exist }
64
- it { should contain "describe YourModelDecorator" }
49
+ it { should contain "class YourModelDecorator < ApplicationDecorator" }
50
+ end
65
51
  end
66
52
  end
67
53
 
68
- context 'using rspec with namespaced model' do
69
- before { run_generator ["Namespace::YourModel", "-t=rspec"] }
54
+ context "with -t=rspec" do
55
+ describe "the generated spec" do
56
+ subject { file("spec/decorators/your_model_decorator_spec.rb") }
70
57
 
71
- describe 'spec/decorators/your_model_decorator_spec.rb' do
72
- subject { file('spec/decorators/namespace/your_model_decorator_spec.rb') }
73
- it { should exist }
74
- it { should contain "describe Namespace::YourModelDecorator" }
75
- end
76
- end
58
+ describe "naming" do
59
+ before { run_generator %w(YourModel -t=rspec) }
77
60
 
78
- context 'using test-unit' do
79
- before { run_generator ["YourModel", "-t=test_unit"] }
61
+ it { should contain "describe YourModelDecorator" }
62
+ end
63
+
64
+ describe "namespacing" do
65
+ subject { file("spec/decorators/namespace/your_model_decorator_spec.rb") }
66
+ before { run_generator %w(Namespace::YourModel -t=rspec) }
80
67
 
81
- describe 'test/decorators/YourModel_decorator_test.rb' do
82
- subject { file('test/decorators/your_model_decorator_test.rb') }
83
- it { should exist }
84
- it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
68
+ it { should contain "describe Namespace::YourModelDecorator" }
69
+ end
85
70
  end
86
71
  end
87
72
 
88
- context 'using test-unit with namespaced model' do
89
- before { run_generator ["Namespace::YourModel", "-t=test_unit"] }
73
+ context "with -t=test_unit" do
74
+ describe "the generated test" do
75
+ subject { file("test/decorators/your_model_decorator_test.rb") }
90
76
 
91
- describe 'test/decorators/your_model_decorator_test.rb' do
92
- subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
93
- it { should exist }
94
- it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
95
- end
96
- end
77
+ describe "naming" do
78
+ before { run_generator %w(YourModel -t=test_unit) }
79
+
80
+ it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
81
+ end
97
82
 
98
- context 'using minitest-rails' do
99
- before { run_generator ["YourModel", "-t=mini_test"] }
83
+ describe "namespacing" do
84
+ subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
85
+ before { run_generator %w(Namespace::YourModel -t=test_unit) }
100
86
 
101
- describe 'test/decorators/your_model_decorator_test.rb' do
102
- subject { file('test/decorators/your_model_decorator_test.rb') }
103
- it { should exist }
104
- it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
87
+ it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
88
+ end
105
89
  end
106
90
  end
107
91
 
108
- context 'using minitest-rails with namespaced model' do
109
- before { run_generator ["Namespace::YourModel", "-t=mini_test"] }
92
+ context "with -t=mini_test" do
93
+ describe "the generated test" do
94
+ subject { file("test/decorators/your_model_decorator_test.rb") }
110
95
 
111
- describe 'test/decorators/your_model_decorator_test.rb' do
112
- subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
113
- it { should exist }
114
- it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
115
- end
116
- end
96
+ describe "naming" do
97
+ before { run_generator %w(YourModel -t=mini_test) }
117
98
 
118
- context 'using minitest-rails with spec syntax' do
119
- before { run_generator ["YourModel", "-t=mini_test", "--spec"] }
99
+ it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
100
+ end
120
101
 
121
- describe 'test/decorators/your_model_decorator_test.rb' do
122
- subject { file('test/decorators/your_model_decorator_test.rb') }
123
- it { should exist }
124
- it { should contain "describe YourModelDecorator" }
102
+ describe "namespacing" do
103
+ subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
104
+ before { run_generator %w(Namespace::YourModel -t=mini_test) }
105
+
106
+ it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
107
+ end
125
108
  end
126
109
  end
127
110
 
128
- context 'using minitest-rails with spec syntax with namespaced model' do
129
- before { run_generator ["Namespace::YourModel", "-t=mini_test", "--spec"] }
111
+ context "with -t=mini_test --spec" do
112
+ describe "the generated test" do
113
+ subject { file("test/decorators/your_model_decorator_test.rb") }
130
114
 
131
- describe 'test/decorators/your_model_decorator_test.rb' do
132
- subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
133
- it { should exist }
134
- it { should contain "describe Namespace::YourModelDecorator" }
115
+ describe "naming" do
116
+ before { run_generator %w(YourModel -t=mini_test --spec) }
117
+
118
+ it { should contain "describe YourModelDecorator" }
119
+ end
120
+
121
+ describe "namespacing" do
122
+ subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
123
+ before { run_generator %w(Namespace::YourModel -t=mini_test --spec) }
124
+
125
+ it { should contain "describe Namespace::YourModelDecorator" }
126
+ end
135
127
  end
136
128
  end
137
129