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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c47812d7403dd6f95f65a8ba4ff8065de00aaabd
4
- data.tar.gz: 4c365d791003670fe44e5609f14de4126c74e8fa
3
+ metadata.gz: b85cf531330b6947bd3bd6970e527ca62149975a
4
+ data.tar.gz: e063ca4cd9757a4bfc7ad5eb3970b852fa62f1f8
5
5
  SHA512:
6
- metadata.gz: 3a439210f626b0cffe6afcfe8d1b7c6cc9991a7fbaf1209b22ffc7470e25ab282e8953214736b1c6335091cf250203dc85d8273a6e4baaba301d638b9a5359da
7
- data.tar.gz: 02a4b232c025ab87b83fd18ae33c91b6e58bdca92df60439291a1a37b56123054a1cd6793377e883492fb0696ebbb5eae586232a12753c556f1677237b263d97
6
+ metadata.gz: d51ffa67dbb810f7d093bf2bf7c7b0c216cc03231150dbec62b0915fc098ac7bd28b8975541ac99abe3fcdae541d98133d3e7fc176335f16615c6cd6169111bb
7
+ data.tar.gz: 0006c748a474980dcc613530ed51fa1b9b469e3bbf63eb5ed3eb72d06ab2d5c692c439d5cc43cc139c00ce0032329ac77518600efc351c10b0b1c5b6fa81af51
@@ -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
  [![TravisCI Build Status](https://travis-ci.org/drapergem/draper.svg?branch=master)](http://travis-ci.org/drapergem/draper)
4
4
  [![Code Climate](https://codeclimate.com/github/drapergem/draper.png)](https://codeclimate.com/github/drapergem/draper)
5
+ [![Inline docs](http://inch-ci.org/github/drapergem/draper.png?branch=master)](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
 
@@ -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
@@ -75,7 +75,7 @@ module Draper
75
75
  end
76
76
 
77
77
  def collection?
78
- object.respond_to?(:first)
78
+ object.respond_to?(:first) && !object.is_a?(Struct)
79
79
  end
80
80
 
81
81
  def decoratable?
@@ -15,7 +15,7 @@ namespace :test do
15
15
  end
16
16
  end
17
17
 
18
- if Rake::Task.task_defined?('test:run')
18
+ if Rails.version.to_f < 4.2 && Rake::Task.task_defined?('test:run')
19
19
  Rake::Task['test:run'].enhance do
20
20
  Rake::Task['test:decorators'].invoke
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module Draper
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -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.stub(:==).with(:anything).and_return(true)
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
@@ -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
@@ -3,7 +3,6 @@ require File.expand_path('../../config/environment', __FILE__)
3
3
  require 'rspec/rails'
4
4
 
5
5
  RSpec.configure do |config|
6
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
6
  config.expect_with(:rspec) {|c| c.syntax = :expect}
8
7
  config.order = :random
9
8
  end
@@ -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|
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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Casimir