Permalink
Browse files

Added Percentage#eql? and #==

  • Loading branch information...
1 parent 526fd88 commit de74f4b5f349c46d590d861f00266fbc2d520756 @jnunemaker committed Sep 16, 2012
Showing with 26 additions and 0 deletions.
  1. +5 −0 lib/flipper/types/percentage.rb
  2. +21 −0 spec/flipper/types/percentage_spec.rb
@@ -6,6 +6,11 @@ class Percentage < Type
def initialize(value)
@value = value.to_i
end
+
+ def eql?(other)
+ self.class.eql?(other.class) && value == other.value
+ end
+ alias :== :eql?
end
end
end
@@ -2,5 +2,26 @@
require 'flipper/types/percentage_of_actors'
describe Flipper::Types::Percentage do
+ subject {
+ described_class.new(5)
+ }
it_should_behave_like 'a percentage'
+
+ describe "#eql?" do
+ it "returns true for same class and value" do
+ subject.eql?(described_class.new(subject.value)).should be_true
+ end
+
+ it "returns false for different value" do
+ subject.eql?(described_class.new(subject.value + 1)).should be_false
+ end
+
+ it "returns false for different class" do
+ subject.eql?(Object.new).should be_false
+ end
+
+ it "is aliased to ==" do
+ (subject == described_class.new(subject.value)).should be_true
+ end
+ end
end

0 comments on commit de74f4b

Please sign in to comment.