draper 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +140 -120
- data/Gemfile +5 -3
- data/Guardfile +22 -1
- data/README.md +4 -3
- data/draper.gemspec +3 -1
- data/lib/draper.rb +6 -0
- data/lib/draper/automatic_delegation.rb +8 -2
- data/lib/draper/collection_decorator.rb +17 -28
- data/lib/draper/decoratable.rb +6 -3
- data/lib/draper/decoratable/equality.rb +15 -3
- data/lib/draper/decorated_association.rb +11 -50
- data/lib/draper/decorates_assigned.rb +44 -0
- data/lib/draper/decorator.rb +19 -6
- data/lib/draper/factory.rb +87 -0
- data/lib/draper/helper_proxy.rb +2 -0
- data/lib/draper/railtie.rb +8 -2
- data/lib/draper/version.rb +1 -1
- data/lib/generators/decorator/decorator_generator.rb +9 -9
- data/spec/draper/collection_decorator_spec.rb +48 -28
- data/spec/draper/decoratable_spec.rb +13 -4
- data/spec/draper/decorated_association_spec.rb +53 -114
- data/spec/draper/decorates_assigned_spec.rb +71 -0
- data/spec/draper/decorator_spec.rb +58 -8
- data/spec/draper/factory_spec.rb +238 -0
- data/spec/draper/helper_proxy_spec.rb +11 -0
- data/spec/draper/lazy_helpers_spec.rb +21 -0
- data/spec/dummy/app/controllers/posts_controller.rb +3 -1
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +2 -0
- data/spec/dummy/app/views/posts/show.html.erb +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +11 -0
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +12 -0
- data/spec/dummy/spec/models/mongoid_post_spec.rb +2 -4
- data/spec/dummy/spec/models/post_spec.rb +2 -10
- data/spec/dummy/spec/shared_examples/decoratable.rb +24 -0
- data/spec/generators/decorator/decorator_generator_spec.rb +83 -91
- data/spec/spec_helper.rb +1 -0
- 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 +1 @@
|
|
1
|
-
<%= render
|
1
|
+
<%= render post %>
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
24
|
-
|
14
|
+
describe "naming" do
|
15
|
+
before { run_generator %w(YourModel) }
|
25
16
|
|
26
|
-
|
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
|
-
|
34
|
-
|
35
|
-
before { run_generator
|
20
|
+
describe "namespacing" do
|
21
|
+
subject { file("app/decorators/namespace/your_model_decorator.rb") }
|
22
|
+
before { run_generator %w(Namespace::YourModel) }
|
36
23
|
|
37
|
-
|
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 "
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
49
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
59
|
-
before { run_generator ["YourModel", "-t=rspec"] }
|
47
|
+
before { run_generator %w(YourModel) }
|
60
48
|
|
61
|
-
|
62
|
-
|
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
|
69
|
-
|
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
|
-
|
72
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
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
|
89
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
99
|
-
|
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
|
-
|
102
|
-
|
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
|
109
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
119
|
-
|
99
|
+
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
100
|
+
end
|
120
101
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
129
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
|