draper 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ module Draper
15
15
  end
16
16
 
17
17
  describe "#decorate" do
18
- context "when source is nil" do
18
+ context "when object is nil" do
19
19
  it "returns nil" do
20
20
  factory = Factory.new
21
21
 
@@ -31,12 +31,12 @@ module Draper
31
31
  expect(factory.decorate(double)).to be :decorated
32
32
  end
33
33
 
34
- it "passes the source to the worker" do
34
+ it "passes the object to the worker" do
35
35
  factory = Factory.new
36
- source = double
36
+ object = double
37
37
 
38
- Factory::Worker.should_receive(:new).with(anything(), source).and_return(->(*){})
39
- factory.decorate(source)
38
+ Factory::Worker.should_receive(:new).with(anything(), object).and_return(->(*){})
39
+ factory.decorate(object)
40
40
  end
41
41
 
42
42
  context "when the :with option was given" do
@@ -95,13 +95,13 @@ module Draper
95
95
 
96
96
  describe "#call" do
97
97
  it "calls the decorator method" do
98
- source = double
98
+ object = double
99
99
  options = {foo: "bar"}
100
- worker = Factory::Worker.new(double, source)
100
+ worker = Factory::Worker.new(double, object)
101
101
  decorator = ->(*){}
102
102
  worker.stub decorator: decorator
103
103
 
104
- decorator.should_receive(:call).with(source, options).and_return(:decorated)
104
+ decorator.should_receive(:call).with(object, options).and_return(:decorated)
105
105
  expect(worker.call(options)).to be :decorated
106
106
  end
107
107
 
@@ -159,7 +159,7 @@ module Draper
159
159
  end
160
160
 
161
161
  describe "#decorator" do
162
- context "for a singular source" do
162
+ context "for a singular object" do
163
163
  context "when decorator_class is specified" do
164
164
  it "returns the .decorate method from the decorator" do
165
165
  decorator_class = Class.new(Decorator)
@@ -170,21 +170,21 @@ module Draper
170
170
  end
171
171
 
172
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
173
+ context "and the object is decoratable" do
174
+ it "returns the object's #decorate method" do
175
+ object = double
176
176
  options = {foo: "bar"}
177
- worker = Factory::Worker.new(nil, source)
177
+ worker = Factory::Worker.new(nil, object)
178
178
 
179
- source.should_receive(:decorate).with(options).and_return(:decorated)
180
- expect(worker.decorator.call(source, options)).to be :decorated
179
+ object.should_receive(:decorate).with(options).and_return(:decorated)
180
+ expect(worker.decorator.call(object, options)).to be :decorated
181
181
  end
182
182
  end
183
183
 
184
- context "and the source is not decoratable" do
184
+ context "and the object is not decoratable" do
185
185
  it "raises an error" do
186
- source = double
187
- worker = Factory::Worker.new(nil, source)
186
+ object = double
187
+ worker = Factory::Worker.new(nil, object)
188
188
 
189
189
  expect{worker.decorator}.to raise_error UninferrableDecoratorError
190
190
  end
@@ -192,7 +192,7 @@ module Draper
192
192
  end
193
193
  end
194
194
 
195
- context "for a collection source" do
195
+ context "for a collection object" do
196
196
  context "when decorator_class is a CollectionDecorator" do
197
197
  it "returns the .decorate method from the collection decorator" do
198
198
  decorator_class = Class.new(CollectionDecorator)
@@ -212,18 +212,20 @@ module Draper
212
212
  end
213
213
 
214
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
215
+ context "and the object is decoratable" do
216
+ it "returns the .decorate_collection method from the object's decorator" do
217
+ object = []
218
+ decorator_class = Class.new(Decorator)
219
+ object.stub decorator_class: decorator_class
220
+ object.stub decorate: nil
221
+ worker = Factory::Worker.new(nil, object)
222
+
223
+ decorator_class.should_receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated)
224
+ expect(worker.decorator.call(object, foo: "bar")).to be :decorated
223
225
  end
224
226
  end
225
227
 
226
- context "and the source is not decoratable" do
228
+ context "and the object is not decoratable" do
227
229
  it "returns the .decorate method from CollectionDecorator" do
228
230
  worker = Factory::Worker.new(nil, [])
229
231
 
@@ -16,7 +16,7 @@ module Draper
16
16
  Product.stub(:find).and_return(found)
17
17
  decorator = ProductDecorator.find(1)
18
18
  expect(decorator).to be_a ProductDecorator
19
- expect(decorator.source).to be found
19
+ expect(decorator.object).to be found
20
20
  end
21
21
 
22
22
  it "passes context to the decorator" do
@@ -39,7 +39,7 @@ module Draper
39
39
  Product.stub(:find_by_name).and_return(found)
40
40
  decorator = ProductDecorator.find_by_name("apples")
41
41
  expect(decorator).to be_a ProductDecorator
42
- expect(decorator.source).to be found
42
+ expect(decorator.object).to be found
43
43
  end
44
44
 
45
45
  it "proxies complex ProductDecorators" do
@@ -127,7 +127,7 @@ module Draper
127
127
  Product.stub(:first).and_return(first)
128
128
  decorator = ProductDecorator.first
129
129
  expect(decorator).to be_a ProductDecorator
130
- expect(decorator.source).to be first
130
+ expect(decorator.object).to be first
131
131
  end
132
132
 
133
133
  it "passes context to the decorator" do
@@ -150,7 +150,7 @@ module Draper
150
150
  Product.stub(:last).and_return(last)
151
151
  decorator = ProductDecorator.last
152
152
  expect(decorator).to be_a ProductDecorator
153
- expect(decorator.source).to be last
153
+ expect(decorator.object).to be last
154
154
  end
155
155
 
156
156
  it "passes context to the decorator" do
@@ -15,7 +15,7 @@ class PostDecorator < Draper::Decorator
15
15
  end
16
16
 
17
17
  def path_with_model
18
- h.post_path(source)
18
+ h.post_path(object)
19
19
  end
20
20
 
21
21
  def path_with_id
@@ -23,7 +23,7 @@ class PostDecorator < Draper::Decorator
23
23
  end
24
24
 
25
25
  def url_with_model
26
- h.post_url(source)
26
+ h.post_url(object)
27
27
  end
28
28
 
29
29
  def url_with_id
@@ -9,8 +9,8 @@ Draper::ViewContext.test_strategy :fast
9
9
  Post = Struct.new(:id) { extend ActiveModel::Naming }
10
10
 
11
11
  describe PostDecorator do
12
- let(:decorator) { PostDecorator.new(source) }
13
- let(:source) { Post.new(42) }
12
+ let(:decorator) { PostDecorator.new(object) }
13
+ let(:object) { Post.new(42) }
14
14
 
15
15
  it "can use built-in helpers" do
16
16
  expect(decorator.truncated).to eq "Once upon a..."
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PostDecorator do
4
- let(:decorator) { PostDecorator.new(source) }
5
- let(:source) { Post.create }
4
+ let(:decorator) { PostDecorator.new(object) }
5
+ let(:object) { Post.create }
6
6
 
7
7
  it "can use built-in helpers" do
8
8
  expect(decorator.truncated).to eq "Once upon a..."
@@ -17,23 +17,23 @@ describe PostDecorator do
17
17
  end
18
18
 
19
19
  it "can use path helpers with its model" do
20
- expect(decorator.path_with_model).to eq "/en/posts/#{source.id}"
20
+ expect(decorator.path_with_model).to eq "/en/posts/#{object.id}"
21
21
  end
22
22
 
23
23
  it "can use path helpers with its id" do
24
- expect(decorator.path_with_id).to eq "/en/posts/#{source.id}"
24
+ expect(decorator.path_with_id).to eq "/en/posts/#{object.id}"
25
25
  end
26
26
 
27
27
  it "can use url helpers with its model" do
28
- expect(decorator.url_with_model).to eq "http://www.example.com:12345/en/posts/#{source.id}"
28
+ expect(decorator.url_with_model).to eq "http://www.example.com:12345/en/posts/#{object.id}"
29
29
  end
30
30
 
31
31
  it "can use url helpers with its id" do
32
- expect(decorator.url_with_id).to eq "http://www.example.com:12345/en/posts/#{source.id}"
32
+ expect(decorator.url_with_id).to eq "http://www.example.com:12345/en/posts/#{object.id}"
33
33
  end
34
34
 
35
35
  it "can be passed implicitly to url_for" do
36
- expect(decorator.link).to eq "<a href=\"/en/posts/#{source.id}\">#{source.id}</a>"
36
+ expect(decorator.link).to eq "<a href=\"/en/posts/#{object.id}\">#{object.id}</a>"
37
37
  end
38
38
 
39
39
  it "serializes overriden attributes" do
@@ -1,4 +1,2 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path('../../config/environment', __FILE__)
3
- require 'minitest/autorun'
1
+ require 'test_helper'
4
2
  require 'minitest/rails'
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'rails'
2
3
  require 'ammeter/init'
3
4
  require 'generators/decorator/decorator_generator'
4
5
 
@@ -8,32 +8,32 @@ shared_examples_for "decoration-aware #==" do |subject|
8
8
  end
9
9
 
10
10
  it "is true for a decorated version of itself" do
11
- decorated = double(source: subject, decorated?: true)
11
+ decorated = double(object: subject, decorated?: true)
12
12
 
13
13
  expect(subject == decorated).to be_true
14
14
  end
15
15
 
16
16
  it "is false for a decorated other object" do
17
- decorated = double(source: Object.new, decorated?: true)
17
+ decorated = double(object: Object.new, decorated?: true)
18
18
 
19
19
  expect(subject == decorated).to be_false
20
20
  end
21
21
 
22
- it "is false for a decoratable object with a `source` association" do
23
- decoratable = double(source: subject, decorated?: false)
22
+ it "is false for a decoratable object with a `object` association" do
23
+ decoratable = double(object: subject, decorated?: false)
24
24
 
25
25
  expect(subject == decoratable).to be_false
26
26
  end
27
27
 
28
- it "is false for an undecoratable object with a `source` association" do
29
- undecoratable = double(source: subject)
28
+ it "is false for an undecoratable object with a `object` association" do
29
+ undecoratable = double(object: subject)
30
30
 
31
31
  expect(subject == undecoratable).to be_false
32
32
  end
33
33
 
34
34
  it "is true for a multiply-decorated version of itself" do
35
- decorated = double(source: subject, decorated?: true)
36
- redecorated = double(source: decorated, decorated?: true)
35
+ decorated = double(object: subject, decorated?: true)
36
+ redecorated = double(object: decorated, decorated?: true)
37
37
 
38
38
  expect(subject == redecorated).to be_true
39
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Casimir
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-01 00:00:00.000000000 Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport