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

Fix a bug Condition's includes action returns false positive when empty array, #205

Merged
merged 1 commit into from
May 16, 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
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
Loading