-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve DataKind eql? to consider object type (#304)
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
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,63 @@ | ||
require "spec_helper" | ||
|
||
module LaunchDarkly | ||
module Impl | ||
module DataStore | ||
describe DataKind do | ||
describe "eql?" do | ||
it "constant instances are equal to themselves" do | ||
expect(LaunchDarkly::FEATURES.eql?(LaunchDarkly::FEATURES)).to be true | ||
expect(LaunchDarkly::SEGMENTS.eql?(LaunchDarkly::SEGMENTS)).to be true | ||
end | ||
|
||
it "same constructions are equal" do | ||
expect(LaunchDarkly::FEATURES.eql?(DataKind.new(namespace: "features", priority: 1))).to be true | ||
expect(DataKind.new(namespace: "features", priority: 1).eql?(DataKind.new(namespace: "features", priority: 1))).to be true | ||
|
||
expect(LaunchDarkly::SEGMENTS.eql?(DataKind.new(namespace: "segments", priority: 0))).to be true | ||
expect(DataKind.new(namespace: "segments", priority: 0).eql?(DataKind.new(namespace: "segments", priority: 0))).to be true | ||
end | ||
|
||
it "distinct namespaces are not equal" do | ||
expect(DataKind.new(namespace: "features", priority: 1).eql?(DataKind.new(namespace: "segments", priority: 1))).to be false | ||
end | ||
|
||
it "distinct priorities are not equal" do | ||
expect(DataKind.new(namespace: "features", priority: 1).eql?(DataKind.new(namespace: "features", priority: 2))).to be false | ||
expect(DataKind.new(namespace: "segments", priority: 1).eql?(DataKind.new(namespace: "segments", priority: 2))).to be false | ||
end | ||
|
||
it "handles non-DataKind objects" do | ||
["example", true, 1, 1.0, [], {}].each do |obj| | ||
expect(LaunchDarkly::FEATURES.eql?(obj)).to be false | ||
end | ||
end | ||
end | ||
|
||
describe "hash" do | ||
it "constant instances are equal to themselves" do | ||
expect(LaunchDarkly::FEATURES.hash).to be LaunchDarkly::FEATURES.hash | ||
expect(LaunchDarkly::SEGMENTS.hash).to be LaunchDarkly::SEGMENTS.hash | ||
end | ||
|
||
it "same constructions are equal" do | ||
expect(LaunchDarkly::FEATURES.hash).to be DataKind.new(namespace: "features", priority: 1).hash | ||
expect(DataKind.new(namespace: "features", priority: 1).hash).to be DataKind.new(namespace: "features", priority: 1).hash | ||
|
||
expect(LaunchDarkly::SEGMENTS.hash).to be DataKind.new(namespace: "segments", priority: 0).hash | ||
expect(DataKind.new(namespace: "segments", priority: 0).hash).to be DataKind.new(namespace: "segments", priority: 0).hash | ||
end | ||
|
||
it "distinct namespaces are not equal" do | ||
expect(DataKind.new(namespace: "features", priority: 1).hash).not_to be DataKind.new(namespace: "segments", priority: 1).hash | ||
end | ||
|
||
it "distinct priorities are not equal" do | ||
expect(DataKind.new(namespace: "features", priority: 1).hash).not_to be DataKind.new(namespace: "features", priority: 2).hash | ||
expect(DataKind.new(namespace: "segments", priority: 1).hash).not_to be DataKind.new(namespace: "segments", priority: 2).hash | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |