draper 2.0.0 → 2.1.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +2 -1
- data/lib/draper/decorator.rb +15 -0
- data/lib/draper/factory.rb +1 -1
- data/lib/draper/tasks/test.rake +1 -1
- data/lib/draper/version.rb +1 -1
- data/spec/draper/decorator_spec.rb +57 -2
- data/spec/draper/factory_spec.rb +11 -0
- data/spec/dummy/spec/spec_helper.rb +0 -1
- data/spec/spec_helper.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b85cf531330b6947bd3bd6970e527ca62149975a
|
4
|
+
data.tar.gz: e063ca4cd9757a4bfc7ad5eb3970b852fa62f1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d51ffa67dbb810f7d093bf2bf7c7b0c216cc03231150dbec62b0915fc098ac7bd28b8975541ac99abe3fcdae541d98133d3e7fc176335f16615c6cd6169111bb
|
7
|
+
data.tar.gz: 0006c748a474980dcc613530ed51fa1b9b469e3bbf63eb5ed3eb72d06ab2d5c692c439d5cc43cc139c00ce0032329ac77518600efc351c10b0b1c5b6fa81af51
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Draper Changelog
|
2
2
|
|
3
|
+
## 2.1.0 - 2015-03-26
|
4
|
+
|
5
|
+
* Cleared most issues and merged a few PRs
|
6
|
+
* Improved behavior when decorating structs
|
7
|
+
* Improved how equality is handled
|
8
|
+
* Minor improvements to the README
|
9
|
+
|
3
10
|
## 2.0.0 - 2015-03-26
|
4
11
|
|
5
12
|
Working to breathe new life into the project by shedding baggage.
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/drapergem/draper)
|
4
4
|
[](https://codeclimate.com/github/drapergem/draper)
|
5
|
+
[](http://inch-ci.org/github/drapergem/draper)
|
5
6
|
|
6
7
|
Draper adds an object-oriented layer of presentation logic to your Rails
|
7
8
|
application.
|
@@ -260,7 +261,7 @@ the `object`:
|
|
260
261
|
|
261
262
|
```ruby
|
262
263
|
class PaginatingDecorator < Draper::CollectionDecorator
|
263
|
-
delegate :current_page, :total_pages, :limit_value
|
264
|
+
delegate :current_page, :total_pages, :limit_value, :entry_name, :total_count, :offset_value, :last_page?
|
264
265
|
end
|
265
266
|
```
|
266
267
|
|
data/lib/draper/decorator.rb
CHANGED
@@ -173,6 +173,21 @@ module Draper
|
|
173
173
|
Draper::Decoratable::Equality.test(object, other)
|
174
174
|
end
|
175
175
|
|
176
|
+
# Delegates equality to :== as expected
|
177
|
+
#
|
178
|
+
# @return [Boolean]
|
179
|
+
def eql?(other)
|
180
|
+
self == other
|
181
|
+
end
|
182
|
+
|
183
|
+
# Returns a unique hash for a decorated object based on
|
184
|
+
# the decorator class and the object being decorated.
|
185
|
+
#
|
186
|
+
# @return [Fixnum]
|
187
|
+
def hash
|
188
|
+
self.class.hash ^ object.hash
|
189
|
+
end
|
190
|
+
|
176
191
|
# Checks if `self.kind_of?(klass)` or `object.kind_of?(klass)`
|
177
192
|
#
|
178
193
|
# @param [Class] klass
|
data/lib/draper/factory.rb
CHANGED
data/lib/draper/tasks/test.rake
CHANGED
data/lib/draper/version.rb
CHANGED
@@ -526,13 +526,12 @@ module Draper
|
|
526
526
|
object.should_receive(:==).with(other).and_return(false)
|
527
527
|
expect(decorator == other).to be_falsey
|
528
528
|
end
|
529
|
-
|
530
529
|
end
|
531
530
|
|
532
531
|
describe "#===" do
|
533
532
|
it "is true when #== is true" do
|
534
533
|
decorator = Decorator.new(Model.new)
|
535
|
-
decorator.
|
534
|
+
allow(decorator).to receive(:==) { true }
|
536
535
|
|
537
536
|
expect(decorator === :anything).to be_truthy
|
538
537
|
end
|
@@ -545,6 +544,32 @@ module Draper
|
|
545
544
|
end
|
546
545
|
end
|
547
546
|
|
547
|
+
describe "#eql?" do
|
548
|
+
it "is true when #eql? is true" do
|
549
|
+
first = Decorator.new('foo')
|
550
|
+
second = Decorator.new('foo')
|
551
|
+
|
552
|
+
expect(first.eql? second).to be
|
553
|
+
end
|
554
|
+
|
555
|
+
it "is false when #eql? is false" do
|
556
|
+
first = Decorator.new('foo')
|
557
|
+
second = Decorator.new('bar')
|
558
|
+
|
559
|
+
expect(first.eql? second).to_not be
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
describe "#hash" do
|
564
|
+
it "is consistent for equal objects" do
|
565
|
+
object = Model.new
|
566
|
+
first = Decorator.new(object)
|
567
|
+
second = Decorator.new(object)
|
568
|
+
|
569
|
+
expect(first.hash == second.hash).to be
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
548
573
|
describe ".delegate" do
|
549
574
|
protect_class Decorator
|
550
575
|
|
@@ -757,5 +782,35 @@ module Draper
|
|
757
782
|
end
|
758
783
|
end
|
759
784
|
|
785
|
+
describe "Enumerable hash and equality functionality" do
|
786
|
+
describe "#uniq" do
|
787
|
+
it "removes duplicate objects with same decorator" do
|
788
|
+
object = Model.new
|
789
|
+
array = [Decorator.new(object), Decorator.new(object)]
|
790
|
+
|
791
|
+
expect(array.uniq.count).to eq(1)
|
792
|
+
end
|
793
|
+
|
794
|
+
it "separates different objects with identical decorators" do
|
795
|
+
array = [Decorator.new('foo'), Decorator.new('bar')]
|
796
|
+
|
797
|
+
expect(array.uniq.count).to eq(2)
|
798
|
+
end
|
799
|
+
|
800
|
+
it "separates identical objects with different decorators" do
|
801
|
+
object = Model.new
|
802
|
+
array = [Decorator.new(object), OtherDecorator.new(object)]
|
803
|
+
|
804
|
+
expect(array.uniq.count).to eq(2)
|
805
|
+
end
|
806
|
+
|
807
|
+
it "distinguishes between an objects and its decorated version" do
|
808
|
+
object = Model.new
|
809
|
+
array = [Decorator.new(object), object]
|
810
|
+
|
811
|
+
expect(array.uniq.count).to eq(2)
|
812
|
+
end
|
813
|
+
end
|
814
|
+
end
|
760
815
|
end
|
761
816
|
end
|
data/spec/draper/factory_spec.rb
CHANGED
@@ -190,6 +190,17 @@ module Draper
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|
193
|
+
|
194
|
+
context "when the object is a struct" do
|
195
|
+
it "returns a singular decorator" do
|
196
|
+
object = Struct.new(:stuff).new("things")
|
197
|
+
|
198
|
+
decorator_class = Class.new(Decorator)
|
199
|
+
worker = Factory::Worker.new(decorator_class, object)
|
200
|
+
|
201
|
+
expect(worker.decorator).to eq decorator_class.method(:decorate)
|
202
|
+
end
|
203
|
+
end
|
193
204
|
end
|
194
205
|
|
195
206
|
context "for a collection object" do
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,6 @@ require 'action_controller'
|
|
5
5
|
require 'action_controller/test_case'
|
6
6
|
|
7
7
|
RSpec.configure do |config|
|
8
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
8
|
config.expect_with(:rspec) {|c| c.syntax = :expect}
|
10
9
|
config.order = :random
|
11
10
|
config.mock_with :rspec do |mocks|
|