Skip to content

Commit

Permalink
Merge pull request #205 from kufu/fixes/string_compare_condition
Browse files Browse the repository at this point in the history
Fix a bug Condition's includes action returns false positive when empty array,
  • Loading branch information
kinoppyd authored May 16, 2024
2 parents 838c003 + ce2a2cf commit acbe84b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 1 addition & 3 deletions app/models/trigger/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def count_check(num, operator)
end

def includes_check(includes)
resolve_model_attribute.each do |obj|
return false unless includes.include?(obj)
end
resolve_model_attribute.any? { |obj| includes.include?(obj) }
end
end
end
20 changes: 17 additions & 3 deletions test/models/trigger/condition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,23 @@ class ConditionTest < ActiveSupport::TestCase
assert_not condition.satisfy?
end

test '#satisfy? returns true when include action chain methods' do
Friend.create!(from: profiles(:profile_one).id, to: profiles(:profile_two).id)
test '#satisfy? returns false when include action(with empty array)' do
condition = Trigger::Condition.new(
{
model: 'Friend',
target: 'Profile',
props: {
from: 'target'
},
action: { 'includes' => [profiles(:profile_three).id], 'attribute' => 'to' }
},
profiles(:profile_one)
)

assert_not condition.satisfy?
end

test '#satisfy? returns false when include action chain methods' do
condition = Trigger::Condition.new(
{
model: 'Friend',
Expand All @@ -392,7 +406,7 @@ class ConditionTest < ActiveSupport::TestCase
profiles(:profile_one)
)

assert condition.satisfy?
assert_not condition.satisfy?
end

test '#satisfy? returns true when include action chain methods with eager loading' do
Expand Down

0 comments on commit acbe84b

Please sign in to comment.