From 94c19d724908b19cd474c3e64892b43633f3bdab Mon Sep 17 00:00:00 2001 From: Matthew Banbury Date: Tue, 16 Apr 2024 21:56:18 +0000 Subject: [PATCH 1/4] Convert expected values to float before comparison This converts the expected values to a float before a `<` and `>` comparison to prevent potential issues around the parsing of integer values as strings when loading the YAML files. This is particularly of issue with flat million numbers which are persisted in YAML as 6e+06 which is treated as a string when the YAML is parsed. --- lib/toggles/feature.rb | 6 +++--- spec/toggles/feature/operation_spec.rb | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/toggles/feature.rb b/lib/toggles/feature.rb index 01fc80c..52959c2 100644 --- a/lib/toggles/feature.rb +++ b/lib/toggles/feature.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true - + module Feature Error = Class.new(StandardError) Unknown = Class.new(Error) @@ -75,8 +75,8 @@ def self.disabled?(*sym, **criteria) end } -Feature.operations[:gt] = ->(entity, attr_name, expected) { entity.send(attr_name) > expected } -Feature.operations[:lt] = ->(entity, attr_name, expected) { entity.send(attr_name) < expected } +Feature.operations[:gt] = ->(entity, attr_name, expected) { entity.send(attr_name) > expected.to_f } +Feature.operations[:lt] = ->(entity, attr_name, expected) { entity.send(attr_name) < expected.to_f } Feature.operations[:range] = lambda { |args| raise StandardError, 'Invalid range operation' if args.size != 2 diff --git a/spec/toggles/feature/operation_spec.rb b/spec/toggles/feature/operation_spec.rb index a796e6b..1e3b8e1 100644 --- a/spec/toggles/feature/operation_spec.rb +++ b/spec/toggles/feature/operation_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true - + RSpec.describe 'operations' do context 'and' do subject { Feature.operations[:and] } @@ -19,6 +19,10 @@ specify do expect(subject.call(double(id: 50), :id, 40)).to eq true expect(subject.call(double(id: 50), :id, 60)).to eq false + expect(subject.call(double(id: 5_500_000), :id, "6e+06")).to eq false + expect(subject.call(double(id: 5_500_000), :id, 6e+06)).to eq false + expect(subject.call(double(id: 6_500_000), :id, "6e+06")).to eq true + expect(subject.call(double(id: 6_500_000), :id, 6e+06)).to eq true end end @@ -38,6 +42,10 @@ specify do expect(subject.call(double(id: 50), :id, 60)).to eq true expect(subject.call(double(id: 50), :id, 40)).to eq false + expect(subject.call(double(id: 5_500_000), :id, "6e+06")).to eq true + expect(subject.call(double(id: 5_500_000), :id, 6e+06)).to eq true + expect(subject.call(double(id: 6_500_000), :id, "6e+06")).to eq false + expect(subject.call(double(id: 6_500_000), :id, 6e+06)).to eq false end end From c3d1af9b4fbf2ee55fff4c3d2f11ebb26a1ac2c2 Mon Sep 17 00:00:00 2001 From: Matthew Banbury Date: Tue, 16 Apr 2024 21:59:04 +0000 Subject: [PATCH 2/4] Bump version to 0.6.0 --- lib/toggles/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/toggles/version.rb b/lib/toggles/version.rb index 7e150b1..85132c7 100644 --- a/lib/toggles/version.rb +++ b/lib/toggles/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Toggles - VERSION = '0.5.0' + VERSION = '0.6.0' end From 91104e4a45444e8fe48b64b9150ac17e3c28ea2d Mon Sep 17 00:00:00 2001 From: Marc Gomez Date: Mon, 21 Oct 2024 17:35:32 -0700 Subject: [PATCH 3/4] Bump version to 0.6.1 --- lib/toggles/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/toggles/version.rb b/lib/toggles/version.rb index 85132c7..6f59659 100644 --- a/lib/toggles/version.rb +++ b/lib/toggles/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Toggles - VERSION = '0.6.0' + VERSION = '0.6.1' end From c53510ef27eebcc75dfa1b2a41244095319291da Mon Sep 17 00:00:00 2001 From: Marc Gomez Date: Mon, 21 Oct 2024 18:40:52 -0700 Subject: [PATCH 4/4] Existing v0.6.0 tag does not appear to be tied to anything. Bumping this back down. --- lib/toggles/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/toggles/version.rb b/lib/toggles/version.rb index 6f59659..85132c7 100644 --- a/lib/toggles/version.rb +++ b/lib/toggles/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Toggles - VERSION = '0.6.1' + VERSION = '0.6.0' end