Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(filter): Add match all value for charge_filters #1767

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/charge_filter_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class ChargeFilterValue < ApplicationRecord
include Discard::Model
self.discard_column = :deleted_at

MATCH_ALL_FILTER_VALUES = '__LAGO_MATCH_ALL_FILTER_VALUES__'

belongs_to :charge_filter
belongs_to :billable_metric_filter

Expand All @@ -16,6 +18,7 @@ class ChargeFilterValue < ApplicationRecord
private

def validate_value
return if value == MATCH_ALL_FILTER_VALUES
return if billable_metric_filter&.values&.include?(value) # rubocop:disable Performance/InefficientHashSearch

errors.add(:value, :inclusion)
Expand Down
6 changes: 6 additions & 0 deletions spec/models/charge_filter_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
expect(charge_filter_value.errors[:value]).to include('value_is_invalid')
end
end

context 'when value is MATCH_ALL_FILTER_VALUES' do
let(:value) { ChargeFilterValue::MATCH_ALL_FILTER_VALUES }

it { expect(charge_filter_value).to be_valid }
end
end
end
Loading