-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from haines/issue_426
Check for `decorated?` before using `source` in #==
- Loading branch information
Showing
7 changed files
with
85 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Draper | ||
module Decoratable | ||
module Equality | ||
# Compares self with a possibly-decorated object. | ||
# | ||
# @return [Boolean] | ||
def ==(other) | ||
super || | ||
other.respond_to?(:decorated?) && other.decorated? && | ||
other.respond_to?(:source) && self == other.source | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
require 'support/shared_examples/decoratable_equality' | ||
|
||
module Draper | ||
describe Decoratable::Equality do | ||
describe "#==" do | ||
it_behaves_like "decoration-aware #==", Object.new.extend(Decoratable::Equality) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
shared_examples_for "decoration-aware #==" do |subject| | ||
it "is true for itself" do | ||
expect(subject == subject).to be_true | ||
end | ||
|
||
it "is false for another object" do | ||
expect(subject == Object.new).to be_false | ||
end | ||
|
||
it "is true for a decorated version of itself" do | ||
decorated = double(source: subject, decorated?: true) | ||
|
||
expect(subject == decorated).to be_true | ||
end | ||
|
||
it "is false for a decorated other object" do | ||
decorated = double(source: Object.new, decorated?: true) | ||
|
||
expect(subject == decorated).to be_false | ||
end | ||
|
||
it "is false for a decoratable object with a `source` association" do | ||
decoratable = double(source: subject, decorated?: false) | ||
|
||
expect(subject == decoratable).to be_false | ||
end | ||
|
||
it "is false for an undecoratable object with a `source` association" do | ||
undecoratable = double(source: subject) | ||
|
||
expect(subject == undecoratable).to be_false | ||
end | ||
|
||
it "is true for a multiply-decorated version of itself" do | ||
decorated = double(source: subject, decorated?: true) | ||
redecorated = double(source: decorated, decorated?: true) | ||
|
||
expect(subject == redecorated).to be_true | ||
end | ||
end |