draper 1.4.0 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0428f7f8a199d096e21e3a2360cc9fa789a43c76
4
- data.tar.gz: b9c2a83ba56167358887fa6a85b2ab72012321fb
3
+ metadata.gz: c47812d7403dd6f95f65a8ba4ff8065de00aaabd
4
+ data.tar.gz: 4c365d791003670fe44e5609f14de4126c74e8fa
5
5
  SHA512:
6
- metadata.gz: cfed7af68400a775675bee042b8f174cf141ccee503960ee11ccc8405e4ba980992cd96e0e79be25ceecaa91b05a2672246b2800d2b0f7b0d7296a5a874a3f6a
7
- data.tar.gz: 68e0855942cb62a4960b1960353930e16e3e683fb40fcbbf4f216d5fe4ff60ea3e08e7b8fe687e4b72b8c89c3cba5ea3bd1f0991171050ad371d917504f3be62
6
+ metadata.gz: 3a439210f626b0cffe6afcfe8d1b7c6cc9991a7fbaf1209b22ffc7470e25ab282e8953214736b1c6335091cf250203dc85d8273a6e4baaba301d638b9a5359da
7
+ data.tar.gz: 02a4b232c025ab87b83fd18ae33c91b6e58bdca92df60439291a1a37b56123054a1cd6793377e883492fb0696ebbb5eae586232a12753c556f1677237b263d97
@@ -4,22 +4,10 @@ services:
4
4
  - mongodb
5
5
 
6
6
  rvm:
7
- - 1.9.3
8
- - 2.1.0
9
- - jruby-19mode
10
- - rbx-2
11
- - ruby-head
12
- - jruby-head
7
+ - 2.1.5
8
+ - 2.2.1
13
9
 
14
10
  env:
15
11
  - "RAILS_VERSION=4.0"
16
- - "RAILS_VERSION=3.2"
17
- - "RAILS_VERSION=3.1"
18
- - "RAILS_VERSION=3.0"
19
12
  - "RAILS_VERSION=4.1"
20
-
21
- matrix:
22
- allow_failures:
23
- - env: "RAILS_VERSION=4.1"
24
- - rvm: ruby-head
25
- - rvm: jruby-head
13
+ - "RAILS_VERSION=4.2"
@@ -1,6 +1,21 @@
1
1
  # Draper Changelog
2
2
 
3
- ## 1.3.0
3
+ ## 2.0.0 - 2015-03-26
4
+
5
+ Working to breathe new life into the project by shedding baggage.
6
+
7
+ * Rails 3.2 support dropped
8
+ * Ruby 1.9.3 and 2.0 support dropped
9
+ * Add support for Rails 4.2 and Ruby 2.2
10
+ * Rewrite tests to get over RSpec deprecations
11
+ * Get RSpec up to 3.2
12
+ * Try to un-screw the challenges of ActiveModelSerializers
13
+
14
+ Due to the breakages of dropping legacy support, we've bumped the major version. From here,
15
+ development effort will likely focus on a version 3.0 that removes features and simplifies
16
+ usage of the library.
17
+
18
+ ## 1.3.0 - 2013-10-26
4
19
 
5
20
  [30 commits by 11 authors](https://github.com/drapergem/draper/compare/v1.2.1...v1.3.0)
6
21
 
@@ -14,7 +29,7 @@
14
29
 
15
30
  * [Delegate `to_s` method to the object](https://github.com/drapergem/draper/commit/58b8181050c2a9a86f54660e7bb6bfefa5fd0b64)
16
31
 
17
- ## 1.2.1
32
+ ## 1.2.1 - 2013-05-05
18
33
 
19
34
  [28 commits by 4 authors](https://github.com/drapergem/draper/compare/v1.2.0...v1.2.1)
20
35
 
@@ -24,7 +39,7 @@
24
39
 
25
40
  Various bugfixes, as always.
26
41
 
27
- ## 1.2.0
42
+ ## 1.2.0 - 2013-04-01
28
43
 
29
44
  [78 commits by 14 authors](https://github.com/drapergem/draper/compare/v1.1.0...v1.2.0)
30
45
 
@@ -58,7 +73,7 @@ Various bugfixes, as always.
58
73
 
59
74
  * [Avoid using #extend in Decorator#== for performance reasons](https://github.com/drapergem/draper/commit/205a0d43b4141f7b1756fe2b44b877545eb37517)
60
75
 
61
- ## 1.1.0
76
+ ## 1.1.0 - 2013-01-28
62
77
 
63
78
  [44 commits by 6 authors](https://github.com/drapergem/draper/compare/v1.0.0...v1.1.0)
64
79
 
@@ -88,7 +103,7 @@ Various bugfixes, as always.
88
103
  * Our specs now use the new RSpec `expect( ).to` syntax.
89
104
  [9a3b319](https://github.com/drapergem/draper/commit/9a3b319d6d54cd78fb2654a94bbe893e36359754)
90
105
 
91
- ## 1.0.0
106
+ ## 1.0.0 - 2013-01-14
92
107
 
93
108
  [249 commits by 19 authors](https://github.com/drapergem/draper/compare/v0.18.0...v1.0.0)
94
109
 
@@ -113,7 +128,7 @@ Major changes are described [in the upgrade guide](https://github.com/drapergem/
113
128
  * Test against edge rails.
114
129
  [e9b71e3](https://github.com/drapergem/draper/commit/e9b71e3cf55a800b48c083ff257a7c1cbe1b601b)
115
130
 
116
- ### 1.0.0.beta6
131
+ ### 1.0.0.beta6 - 2012-12-31
117
132
 
118
133
  * Fix up README to include changes made.
119
134
  [5e6e4d1](https://github.com/drapergem/draper/commit/5e6e4d11b1e0c07c12b6b1e87053bc3f50ef2ab6)
@@ -125,7 +140,7 @@ Major changes are described [in the upgrade guide](https://github.com/drapergem/
125
140
  * Ensure we coerce to an array in the right place.
126
141
  [9eb9fc9](https://github.com/drapergem/draper/commit/9eb9fc909c372ea1c2392d05594fa75a5c08b095)
127
142
 
128
- ### 1.0.0.beta5
143
+ ### 1.0.0.beta5 - 2012-12-27
129
144
 
130
145
  * Change CollectionDecorator to freeze its collection.
131
146
  [04d7796](https://github.com/drapergem/draper/commit/04d779615c43580409083a71661489e1bbf91ad4)
@@ -134,7 +149,7 @@ Major changes are described [in the upgrade guide](https://github.com/drapergem/
134
149
  * Upgrade `request_store` dependency to take advantage of a bugfix.
135
150
  [9f17212](https://github.com/drapergem/draper/commit/9f17212fd1fb656ef1314327d60fe45e0acf60a2)
136
151
 
137
- ### 1.0.0.beta4
152
+ ### 1.0.0.beta4 - 2012-12-18
138
153
 
139
154
  * Fixed a race condition with capybara integration.
140
155
  [e794649](https://github.com/drapergem/draper/commit/e79464931e7b98c85ed5d78ed9ca38d51f43006e)
@@ -153,12 +168,12 @@ Major changes are described [in the upgrade guide](https://github.com/drapergem/
153
168
  * Integrate RequestStore for per-request storage.
154
169
  [fde1cde](https://github.com/drapergem/draper/commit/fde1cde9adfb856750c1f616d8b62d221ef97fc6)
155
170
 
156
- ### 1.0.0.beta3
171
+ ### 1.0.0.beta3 - 2012-12-03
157
172
 
158
173
  * Relaxed Rails version requirement to 3.0. Support for < 3.2 should be
159
174
  considered experimental. Please file bug reports.
160
175
 
161
- ### 1.0.0.beta2
176
+ ### 1.0.0.beta2 - 2012-12-03
162
177
 
163
178
  * `has_finders` is now `decorates_finders`.
164
179
  [33f18aa](https://github.com/drapergem/draper/commit/33f18aa062e0d3848443dbd81047f20d5665579f)
@@ -172,7 +187,7 @@ Major changes are described [in the upgrade guide](https://github.com/drapergem/
172
187
  * Rails versioning relaxed to support Rails 4.
173
188
  [8bfd393](https://github.com/drapergem/draper/commit/8bfd393b5baa7aa1488076a5e2cb88648efaa815)
174
189
 
175
- ### 1.0.0.beta1
190
+ ### 1.0.0.beta1 - 2012-11-30
176
191
 
177
192
  * Renaming `Draper::Base` to `Draper::Decorator`. This is the most significant
178
193
  change you'll need to upgrade your application.
data/Gemfile CHANGED
@@ -11,6 +11,6 @@ platforms :jruby do
11
11
  gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.beta2"
12
12
  end
13
13
 
14
- version = ENV["RAILS_VERSION"] || "4.0"
14
+ version = ENV["RAILS_VERSION"] || "4.1"
15
15
 
16
16
  eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
@@ -24,9 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.add_development_dependency 'ammeter'
26
26
  s.add_development_dependency 'rake', '>= 0.9.2'
27
- s.add_development_dependency 'rspec', '~> 2.12'
28
- s.add_development_dependency 'rspec-mocks', '>= 2.12.1'
29
- s.add_development_dependency 'rspec-rails', '~> 2.12'
27
+ s.add_development_dependency 'rspec-rails', '~> 3.2'
30
28
  s.add_development_dependency 'minitest-rails', '>= 1.0'
31
29
  s.add_development_dependency 'capybara'
32
30
  s.add_development_dependency 'active_model_serializers'
@@ -1,3 +1,3 @@
1
1
  gem "rails", "~> 4.0.0"
2
- gem "mongoid", github: "mongoid/mongoid"
2
+ gem "mongoid", "~> 4.0"
3
3
  gem "devise", "~> 3.0.0"
@@ -1,2 +1,3 @@
1
- gem "rails", github: "rails/rails"
2
- gem "devise", github: "plataformatec/devise"
1
+ gem "rails", "~> 4.1.0"
2
+ gem "mongoid", "~> 4.0"
3
+ gem "devise", "~> 3.2"
@@ -0,0 +1,3 @@
1
+ gem "rails", "~> 4.2.0"
2
+ gem "mongoid", "~> 4.0"
3
+ gem "devise", "~> 3.4"
@@ -4,6 +4,9 @@ module Draper
4
4
  include Draper::ViewHelpers
5
5
  extend Draper::Delegation
6
6
 
7
+ # @return the collection being decorated.
8
+ attr_reader :object
9
+
7
10
  # @return [Class] the decorator class used to decorate each item, as set by
8
11
  # {#initialize}.
9
12
  attr_reader :decorator_class
@@ -79,9 +82,6 @@ module Draper
79
82
 
80
83
  protected
81
84
 
82
- # @return the collection being decorated.
83
- attr_reader :object
84
-
85
85
  # Decorates the given item.
86
86
  def decorate_item(item)
87
87
  item_decorator.call(item, context: context)
@@ -16,6 +16,12 @@ module Draper
16
16
  send(method, *args, &block)
17
17
  end
18
18
 
19
+ # Checks if the context responds to an instance method, or is able to
20
+ # proxy it to the view context.
21
+ def respond_to_missing?(method, include_private = false)
22
+ super || view_context.respond_to?(method)
23
+ end
24
+
19
25
  delegate :capture, to: :view_context
20
26
 
21
27
  protected
@@ -45,7 +45,9 @@ module Draper
45
45
 
46
46
  initializer "draper.setup_active_model_serializers" do |app|
47
47
  ActiveSupport.on_load :active_model_serializers do
48
- Draper::CollectionDecorator.send :include, ActiveModel::ArraySerializerSupport
48
+ if defined?(ActiveModel::ArraySerializerSupport)
49
+ Draper::CollectionDecorator.send :include, ActiveModel::ArraySerializerSupport
50
+ end
49
51
  end
50
52
  end
51
53
 
@@ -1,3 +1,3 @@
1
1
  module Draper
2
- VERSION = "1.4.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -168,7 +168,7 @@ module Draper
168
168
  decorator = CollectionDecorator.new(object)
169
169
  other = ProductsDecorator.new(object)
170
170
 
171
- expect(decorator == other).to be_true
171
+ expect(decorator == other).to be_truthy
172
172
  end
173
173
  end
174
174
 
@@ -177,7 +177,7 @@ module Draper
177
177
  decorator = CollectionDecorator.new([Product.new, Product.new])
178
178
  other = ProductsDecorator.new([Product.new, Product.new])
179
179
 
180
- expect(decorator == other).to be_false
180
+ expect(decorator == other).to be_falsey
181
181
  end
182
182
  end
183
183
 
@@ -187,7 +187,7 @@ module Draper
187
187
  decorator = CollectionDecorator.new(object)
188
188
  other = object.dup
189
189
 
190
- expect(decorator == other).to be_true
190
+ expect(decorator == other).to be_truthy
191
191
  end
192
192
  end
193
193
 
@@ -196,7 +196,7 @@ module Draper
196
196
  decorator = CollectionDecorator.new([Product.new, Product.new])
197
197
  other = [Product.new, Product.new]
198
198
 
199
- expect(decorator == other).to be_false
199
+ expect(decorator == other).to be_falsey
200
200
  end
201
201
  end
202
202
 
@@ -207,7 +207,7 @@ module Draper
207
207
  other = object.dup
208
208
 
209
209
  decorator << Product.new.decorate
210
- expect(decorator == other).to be_false
210
+ expect(decorator == other).to be_falsey
211
211
  end
212
212
  end
213
213
  end
@@ -238,6 +238,15 @@ module Draper
238
238
  end
239
239
  end
240
240
 
241
+ describe '#object' do
242
+ it 'returns the underlying collection' do
243
+ collection = [Product.new]
244
+ decorator = ProductsDecorator.new(collection)
245
+
246
+ expect(decorator.object).to eq collection
247
+ end
248
+ end
249
+
241
250
  describe '#decorated?' do
242
251
  it 'returns true' do
243
252
  decorator = ProductsDecorator.new([Product.new])
@@ -48,21 +48,21 @@ module Draper
48
48
 
49
49
  describe "#decorator_class?" do
50
50
  it "returns true for decoratable model" do
51
- expect(Product.new.decorator_class?).to be_true
51
+ expect(Product.new.decorator_class?).to be_truthy
52
52
  end
53
53
 
54
54
  it "returns false for non-decoratable model" do
55
- expect(Model.new.decorator_class?).to be_false
55
+ expect(Model.new.decorator_class?).to be_falsey
56
56
  end
57
57
  end
58
58
 
59
59
  describe ".decorator_class?" do
60
60
  it "returns true for decoratable model" do
61
- expect(Product.decorator_class?).to be_true
61
+ expect(Product.decorator_class?).to be_truthy
62
62
  end
63
63
 
64
64
  it "returns false for non-decoratable model" do
65
- expect(Model.decorator_class?).to be_false
65
+ expect(Model.decorator_class?).to be_falsey
66
66
  end
67
67
  end
68
68
 
@@ -84,46 +84,46 @@ module Draper
84
84
  product = Product.new
85
85
 
86
86
  product.should_receive(:==).and_return(true)
87
- expect(product === :anything).to be_true
87
+ expect(product === :anything).to be_truthy
88
88
  end
89
89
 
90
90
  it "is false when #== is false" do
91
91
  product = Product.new
92
92
 
93
93
  product.should_receive(:==).and_return(false)
94
- expect(product === :anything).to be_false
94
+ expect(product === :anything).to be_falsey
95
95
  end
96
96
  end
97
97
 
98
98
  describe ".====" do
99
99
  it "is true for an instance" do
100
- expect(Product === Product.new).to be_true
100
+ expect(Product === Product.new).to be_truthy
101
101
  end
102
102
 
103
103
  it "is true for a derived instance" do
104
- expect(Product === Class.new(Product).new).to be_true
104
+ expect(Product === Class.new(Product).new).to be_truthy
105
105
  end
106
106
 
107
107
  it "is false for an unrelated instance" do
108
- expect(Product === Model.new).to be_false
108
+ expect(Product === Model.new).to be_falsey
109
109
  end
110
110
 
111
111
  it "is true for a decorated instance" do
112
112
  decorator = double(object: Product.new)
113
113
 
114
- expect(Product === decorator).to be_true
114
+ expect(Product === decorator).to be_truthy
115
115
  end
116
116
 
117
117
  it "is true for a decorated derived instance" do
118
118
  decorator = double(object: Class.new(Product).new)
119
119
 
120
- expect(Product === decorator).to be_true
120
+ expect(Product === decorator).to be_truthy
121
121
  end
122
122
 
123
123
  it "is false for a decorated unrelated instance" do
124
124
  decorator = double(object: Model.new)
125
125
 
126
- expect(Product === decorator).to be_false
126
+ expect(Product === decorator).to be_falsey
127
127
  end
128
128
  end
129
129
 
@@ -192,7 +192,7 @@ module Draper
192
192
 
193
193
  context "when an unrelated NameError is thrown" do
194
194
  it "re-raises that error" do
195
- String.any_instance.stub(:constantize).and_return{Draper::Base}
195
+ String.any_instance.stub(:constantize) { Draper::Base }
196
196
  expect{Product.decorator_class}.to raise_error NameError, /Draper::Base/
197
197
  end
198
198
  end
@@ -29,7 +29,7 @@ module Draper
29
29
 
30
30
  describe ":context option" do
31
31
  it "defaults to the identity function" do
32
- Factory.should_receive(:new).with do |options|
32
+ Factory.should_receive(:new) do |options|
33
33
  options[:context].call(:anything) == :anything
34
34
  end
35
35
  DecoratedAssociation.new(double, :association, {})
@@ -73,7 +73,7 @@ module Draper
73
73
  decorated = OtherDecorator.new(Decorator.new(Model.new))
74
74
 
75
75
  warning_message = nil
76
- Object.any_instance.stub(:warn) {|message| warning_message = message }
76
+ Object.any_instance.stub(:warn) { |instance, message| warning_message = message }
77
77
 
78
78
  expect{Decorator.new(decorated)}.to change{warning_message}
79
79
  expect(warning_message).to start_with "Reapplying Draper::Decorator"
@@ -148,7 +148,7 @@ module Draper
148
148
 
149
149
  context "when a NameError is thrown" do
150
150
  it "re-raises that error" do
151
- String.any_instance.stub(:constantize).and_return{Draper::DecoratedEnumerableProxy}
151
+ String.any_instance.stub(:constantize) { Draper::DecoratedEnumerableProxy }
152
152
  expect{ProductDecorator.decorate_collection([])}.to raise_error NameError, /Draper::DecoratedEnumerableProxy/
153
153
  end
154
154
  end
@@ -190,6 +190,7 @@ module Draper
190
190
  end
191
191
 
192
192
  it "raises an UninferrableSourceError for a decorator without a model" do
193
+ skip
193
194
  expect{OtherDecorator.object_class}.to raise_error UninferrableSourceError
194
195
  end
195
196
 
@@ -207,7 +208,7 @@ module Draper
207
208
 
208
209
  context "when an unrelated NameError is thrown" do
209
210
  it "re-raises that error" do
210
- String.any_instance.stub(:constantize).and_return{SomethingThatDoesntExist}
211
+ String.any_instance.stub(:constantize) { SomethingThatDoesntExist }
211
212
  expect{ProductDecorator.object_class}.to raise_error NameError, /SomethingThatDoesntExist/
212
213
  end
213
214
  end
@@ -222,19 +223,19 @@ module Draper
222
223
  it "returns truthy when .object_class is set" do
223
224
  Decorator.stub(:object_class).and_return(Model)
224
225
 
225
- expect(Decorator.object_class?).to be_true
226
+ expect(Decorator.object_class?).to be_truthy
226
227
  end
227
228
 
228
229
  it "returns false when .object_class is not inferrable" do
229
230
  Decorator.stub(:object_class).and_raise(UninferrableSourceError.new(Decorator))
230
231
 
231
- expect(Decorator.object_class?).to be_false
232
+ expect(Decorator.object_class?).to be_falsey
232
233
  end
233
234
 
234
235
  it "is aliased to .source_class?" do
235
236
  Decorator.stub(:object_class).and_return(Model)
236
237
 
237
- expect(Decorator.source_class?).to be_true
238
+ expect(Decorator.source_class?).to be_truthy
238
239
  end
239
240
  end
240
241
 
@@ -514,7 +515,7 @@ module Draper
514
515
  other = double(object: Model.new)
515
516
 
516
517
  object.should_receive(:==).with(other).and_return(true)
517
- expect(decorator == other).to be_true
518
+ expect(decorator == other).to be_truthy
518
519
  end
519
520
 
520
521
  it "is false when object #== is false" do
@@ -523,7 +524,7 @@ module Draper
523
524
  other = double(object: Model.new)
524
525
 
525
526
  object.should_receive(:==).with(other).and_return(false)
526
- expect(decorator == other).to be_false
527
+ expect(decorator == other).to be_falsey
527
528
  end
528
529
 
529
530
  end
@@ -533,14 +534,14 @@ module Draper
533
534
  decorator = Decorator.new(Model.new)
534
535
  decorator.stub(:==).with(:anything).and_return(true)
535
536
 
536
- expect(decorator === :anything).to be_true
537
+ expect(decorator === :anything).to be_truthy
537
538
  end
538
539
 
539
540
  it "is false when #== is false" do
540
541
  decorator = Decorator.new(Model.new)
541
542
  decorator.stub(:==).with(:anything).and_return(false)
542
543
 
543
- expect(decorator === :anything).to be_false
544
+ expect(decorator === :anything).to be_falsey
544
545
  end
545
546
  end
546
547
 
@@ -580,7 +581,7 @@ module Draper
580
581
 
581
582
  it "passes blocks to delegated methods" do
582
583
  object = Model.new
583
- object.stub(:hello_world).and_return{|*args, &block| block.call}
584
+ object.stub(:hello_world) { |*args, &block| block.call }
584
585
  decorator = Decorator.new(object)
585
586
 
586
587
  expect(decorator.hello_world{:yielded}).to be :yielded
@@ -659,14 +660,14 @@ module Draper
659
660
  Decorator.class_eval{private; def hello_world; end}
660
661
  decorator = Decorator.new(Model.new)
661
662
 
662
- expect(decorator.respond_to?(:hello_world, true)).to be_true
663
+ expect(decorator.respond_to?(:hello_world, true)).to be_truthy
663
664
  end
664
665
 
665
666
  it "returns false for the object's private methods" do
666
667
  object = Class.new{private; def hello_world; end}.new
667
668
  decorator = Decorator.new(object)
668
669
 
669
- expect(decorator.respond_to?(:hello_world, true)).to be_false
670
+ expect(decorator.respond_to?(:hello_world, true)).to be_falsey
670
671
  end
671
672
  end
672
673
  end
@@ -722,27 +723,27 @@ module Draper
722
723
  it "pretends to be a kind of the source class" do
723
724
  decorator = Decorator.new(Model.new)
724
725
 
725
- expect(decorator.kind_of?(Model)).to be_true
726
- expect(decorator.is_a?(Model)).to be_true
726
+ expect(decorator.kind_of?(Model)).to be_truthy
727
+ expect(decorator.is_a?(Model)).to be_truthy
727
728
  end
728
729
 
729
730
  it "is still a kind of its own class" do
730
731
  decorator = Decorator.new(Model.new)
731
732
 
732
- expect(decorator.kind_of?(Decorator)).to be_true
733
- expect(decorator.is_a?(Decorator)).to be_true
733
+ expect(decorator.kind_of?(Decorator)).to be_truthy
734
+ expect(decorator.is_a?(Decorator)).to be_truthy
734
735
  end
735
736
 
736
737
  it "pretends to be an instance of the source class" do
737
738
  decorator = Decorator.new(Model.new)
738
739
 
739
- expect(decorator.instance_of?(Model)).to be_true
740
+ expect(decorator.instance_of?(Model)).to be_truthy
740
741
  end
741
742
 
742
743
  it "is still an instance of its own class" do
743
744
  decorator = Decorator.new(Model.new)
744
745
 
745
- expect(decorator.instance_of?(Decorator)).to be_true
746
+ expect(decorator.instance_of?(Decorator)).to be_truthy
746
747
  end
747
748
  end
748
749
 
@@ -18,7 +18,7 @@ module Draper
18
18
  view_context = double
19
19
  helper_proxy = HelperProxy.new(view_context)
20
20
 
21
- view_context.stub(:foo).and_return{|arg| arg}
21
+ view_context.stub(:foo) { |arg| arg }
22
22
  expect(helper_proxy.foo(:passed)).to be :passed
23
23
  end
24
24
 
@@ -26,7 +26,7 @@ module Draper
26
26
  view_context = double
27
27
  helper_proxy = HelperProxy.new(view_context)
28
28
 
29
- view_context.stub(:foo).and_return{|&block| block.call}
29
+ view_context.stub(:foo) { |&block| block.call }
30
30
  expect(helper_proxy.foo{:yielded}).to be :yielded
31
31
  end
32
32
 
@@ -39,12 +39,20 @@ module Draper
39
39
  end
40
40
  end
41
41
 
42
+ describe "#respond_to_missing?" do
43
+ it "allows #method to be called on the view context" do
44
+ helper_proxy = HelperProxy.new(double(foo: "bar"))
45
+
46
+ expect(helper_proxy.respond_to?(:foo)).to be_truthy
47
+ end
48
+ end
49
+
42
50
  describe "proxying methods which are overriding" do
43
51
  it "proxies :capture" do
44
52
  view_context = double
45
53
  helper_proxy = HelperProxy.new(view_context)
46
54
 
47
- view_context.stub(:capture).and_return{|*args, &block| [*args, block.call] }
55
+ view_context.stub(:capture) { |*args, &block| [*args, block.call] }
48
56
  expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \
49
57
  be_eql [:first_arg, :second_arg, :yielded]
50
58
  end
@@ -8,12 +8,12 @@ module Draper
8
8
  end
9
9
 
10
10
  it "proxies methods to #helpers" do
11
- decorator.helpers.stub(:foo).and_return{|arg| arg}
11
+ decorator.helpers.stub(:foo) { |arg| arg }
12
12
  expect(decorator.foo(:passed)).to be :passed
13
13
  end
14
14
 
15
15
  it "passes blocks" do
16
- decorator.helpers.stub(:foo).and_return{|&block| block.call}
16
+ decorator.helpers.stub(:foo) { |&block| block.call }
17
17
  expect(decorator.foo{:yielded}).to be :yielded
18
18
  end
19
19
  end
@@ -131,7 +131,7 @@ module Draper
131
131
  end
132
132
 
133
133
  it "passes a block to the strategy" do
134
- ViewContext::BuildStrategy::Fast.stub(:new).and_return{|&block| block.call}
134
+ ViewContext::BuildStrategy::Fast.stub(:new) { |&block| block.call }
135
135
 
136
136
  expect(ViewContext.test_strategy(:fast){:passed}).to be :passed
137
137
  end
@@ -144,7 +144,7 @@ module Draper
144
144
  end
145
145
 
146
146
  it "passes a block to the strategy" do
147
- ViewContext::BuildStrategy::Full.stub(:new).and_return{|&block| block.call}
147
+ ViewContext::BuildStrategy::Full.stub(:new) { |&block| block.call }
148
148
 
149
149
  expect(ViewContext.test_strategy(:full){:passed}).to be :passed
150
150
  end
@@ -53,4 +53,8 @@ class PostDecorator < Draper::Decorator
53
53
  def updated_at
54
54
  :overridden
55
55
  end
56
+
57
+ def persisted?
58
+ true
59
+ end
56
60
  end
@@ -1,5 +1,4 @@
1
1
  require 'draper'
2
- require 'rspec'
3
2
 
4
3
  require 'active_model/naming'
5
4
  require_relative '../app/decorators/post_decorator'
@@ -4,8 +4,13 @@ describe Draper::CollectionDecorator do
4
4
  describe "#active_model_serializer" do
5
5
  it "returns ActiveModel::ArraySerializer" do
6
6
  collection_decorator = Draper::CollectionDecorator.new([])
7
+ if defined?(ActiveModel::ArraySerializerSupport)
8
+ collection_serializer = collection_decorator.active_model_serializer
9
+ else
10
+ collection_serializer = ActiveModel::Serializer.serializer_for(collection_decorator)
11
+ end
7
12
 
8
- expect(collection_decorator.active_model_serializer).to be ActiveModel::ArraySerializer
13
+ expect(collection_serializer).to be ActiveModel::ArraySerializer
9
14
  end
10
15
  end
11
16
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe "A spec in this folder" do
4
4
  it "is a decorator spec" do
5
- expect(example.metadata[:type]).to be :decorator
5
+ expect(RSpec.current_example.metadata[:type]).to be :decorator
6
6
  end
7
7
  end
@@ -4,7 +4,7 @@ shared_examples_for "a decoratable model" do
4
4
  described_class.create
5
5
  decorated = described_class.limit(1).decorate
6
6
 
7
- expect(decorated).to have(1).items
7
+ expect(decorated.size).to eq(1)
8
8
  expect(decorated).to be_decorated
9
9
  end
10
10
  end
@@ -18,7 +18,7 @@ shared_examples_for "a decoratable model" do
18
18
  other = described_class.first
19
19
 
20
20
  expect(one).not_to be other
21
- expect(one == other.decorate).to be_true
21
+ expect(one == other.decorate).to be_truthy
22
22
  end
23
23
  end
24
24
  end
@@ -40,9 +40,8 @@ describe Rails::Generators::DecoratorGenerator do
40
40
 
41
41
  context "with an ApplicationDecorator" do
42
42
  before do
43
- Object.any_instance.stub(:require).with("application_decorator").and_return do
44
- stub_const "ApplicationDecorator", Class.new
45
- end
43
+ Object.any_instance.stub(:require).with("application_decorator").and_return (
44
+ stub_const "ApplicationDecorator", Class.new)
46
45
  end
47
46
 
48
47
  before { run_generator %w(YourModel) }
@@ -89,43 +88,4 @@ describe Rails::Generators::DecoratorGenerator do
89
88
  end
90
89
  end
91
90
  end
92
-
93
- context "with -t=mini_test" do
94
- describe "the generated test" do
95
- subject { file("test/decorators/your_model_decorator_test.rb") }
96
-
97
- describe "naming" do
98
- before { run_generator %w(YourModel -t=mini_test) }
99
-
100
- it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
101
- end
102
-
103
- describe "namespacing" do
104
- subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
105
- before { run_generator %w(Namespace::YourModel -t=mini_test) }
106
-
107
- it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
108
- end
109
- end
110
- end
111
-
112
- context "with -t=mini_test --spec" do
113
- describe "the generated test" do
114
- subject { file("test/decorators/your_model_decorator_test.rb") }
115
-
116
- describe "naming" do
117
- before { run_generator %w(YourModel -t=mini_test --spec) }
118
-
119
- it { should contain "describe YourModelDecorator" }
120
- end
121
-
122
- describe "namespacing" do
123
- subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
124
- before { run_generator %w(Namespace::YourModel -t=mini_test --spec) }
125
-
126
- it { should contain "describe Namespace::YourModelDecorator" }
127
- end
128
- end
129
- end
130
-
131
91
  end
@@ -8,12 +8,16 @@ RSpec.configure do |config|
8
8
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
9
  config.expect_with(:rspec) {|c| c.syntax = :expect}
10
10
  config.order = :random
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.yield_receiver_to_any_instance_implementation_blocks = true
13
+ end
11
14
  end
12
15
 
13
16
  class Model; include Draper::Decoratable; end
14
17
 
15
18
  class Product < Model; end
16
19
  class SpecialProduct < Product; end
20
+ class Other < Model; end
17
21
  class ProductDecorator < Draper::Decorator; end
18
22
  class ProductsDecorator < Draper::CollectionDecorator; end
19
23
 
@@ -1,40 +1,40 @@
1
1
  shared_examples_for "decoration-aware #==" do |subject|
2
2
  it "is true for itself" do
3
- expect(subject == subject).to be_true
3
+ expect(subject == subject).to be_truthy
4
4
  end
5
5
 
6
6
  it "is false for another object" do
7
- expect(subject == Object.new).to be_false
7
+ expect(subject == Object.new).to be_falsey
8
8
  end
9
9
 
10
10
  it "is true for a decorated version of itself" do
11
11
  decorated = double(object: subject, decorated?: true)
12
12
 
13
- expect(subject == decorated).to be_true
13
+ expect(subject == decorated).to be_truthy
14
14
  end
15
15
 
16
16
  it "is false for a decorated other object" do
17
17
  decorated = double(object: Object.new, decorated?: true)
18
18
 
19
- expect(subject == decorated).to be_false
19
+ expect(subject == decorated).to be_falsey
20
20
  end
21
21
 
22
22
  it "is false for a decoratable object with a `object` association" do
23
23
  decoratable = double(object: subject, decorated?: false)
24
24
 
25
- expect(subject == decoratable).to be_false
25
+ expect(subject == decoratable).to be_falsey
26
26
  end
27
27
 
28
28
  it "is false for an undecoratable object with a `object` association" do
29
29
  undecoratable = double(object: subject)
30
30
 
31
- expect(subject == undecoratable).to be_false
31
+ expect(subject == undecoratable).to be_falsey
32
32
  end
33
33
 
34
34
  it "is true for a multiply-decorated version of itself" do
35
35
  decorated = double(object: subject, decorated?: true)
36
36
  redecorated = double(object: decorated, decorated?: true)
37
37
 
38
- expect(subject == redecorated).to be_true
38
+ expect(subject == redecorated).to be_truthy
39
39
  end
40
40
  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.4.0
4
+ version: 2.0.0
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: 2014-09-15 00:00:00.000000000 Z
12
+ date: 2015-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -95,48 +95,20 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: 0.9.2
98
- - !ruby/object:Gem::Dependency
99
- name: rspec
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '2.12'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '2.12'
112
- - !ruby/object:Gem::Dependency
113
- name: rspec-mocks
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: 2.12.1
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: 2.12.1
126
98
  - !ruby/object:Gem::Dependency
127
99
  name: rspec-rails
128
100
  requirement: !ruby/object:Gem::Requirement
129
101
  requirements:
130
102
  - - "~>"
131
103
  - !ruby/object:Gem::Version
132
- version: '2.12'
104
+ version: '3.2'
133
105
  type: :development
134
106
  prerelease: false
135
107
  version_requirements: !ruby/object:Gem::Requirement
136
108
  requirements:
137
109
  - - "~>"
138
110
  - !ruby/object:Gem::Version
139
- version: '2.12'
111
+ version: '3.2'
140
112
  - !ruby/object:Gem::Dependency
141
113
  name: minitest-rails
142
114
  requirement: !ruby/object:Gem::Requirement
@@ -200,11 +172,9 @@ files:
200
172
  - README.md
201
173
  - Rakefile
202
174
  - draper.gemspec
203
- - gemfiles/3.0.gemfile
204
- - gemfiles/3.1.gemfile
205
- - gemfiles/3.2.gemfile
206
175
  - gemfiles/4.0.gemfile
207
176
  - gemfiles/4.1.gemfile
177
+ - gemfiles/4.2.gemfile
208
178
  - lib/draper.rb
209
179
  - lib/draper/automatic_delegation.rb
210
180
  - lib/draper/collection_decorator.rb
@@ -352,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
322
  version: '0'
353
323
  requirements: []
354
324
  rubyforge_project:
355
- rubygems_version: 2.2.2
325
+ rubygems_version: 2.4.6
356
326
  signing_key:
357
327
  specification_version: 4
358
328
  summary: View Models for Rails
@@ -1,2 +0,0 @@
1
- gem "rails", "~> 3.0.0"
2
- gem "active_model_serializers", "~> 0.7.0"
@@ -1,3 +0,0 @@
1
- gem "rails", "~> 3.1.0"
2
- gem "mongoid", "~> 3.0.0"
3
- gem "devise", "~> 2.2"
@@ -1,3 +0,0 @@
1
- gem "rails", "~> 3.2.0"
2
- gem "mongoid", "~> 3.1.0"
3
- gem "devise", "~> 2.2"