Skip to content

Commit

Permalink
Follow up a81a25f - Fixes #4948 - Trigger Condition "contains not" do…
Browse files Browse the repository at this point in the history
…esn't...
  • Loading branch information
mantas authored and zammad-sync committed Dec 29, 2023
1 parent 99f28af commit b6f796f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/selector/sql.rb
Expand Up @@ -466,7 +466,7 @@ def condition_sql(block_condition)
elsif block_condition[:operator] == 'contains not'
# NOT LIKE is always false on NULL values
# https://github.com/zammad/zammad/issues/4948
query << "#{attribute} NOT #{like} (?) OR #{attribute} IS NULL"
query << "(#{attribute} NOT #{like} (?) OR #{attribute} IS NULL)"
bind_params.push "%#{SqlHelper.quote_like(block_condition[:value])}%"
elsif block_condition[:operator] == 'matches regex'
query << sql_helper.regex_match(attribute, negated: false)
Expand Down
98 changes: 98 additions & 0 deletions spec/lib/selector/sql_spec.rb
Expand Up @@ -713,6 +713,104 @@ def get_condition(operator, range)

end

describe 'complex conditions' do
context "when 'contains not' operator is after negative operator" do
let(:condition) do
{ operator: 'AND', conditions: [
{
name: 'ticket.title',
operator: 'is not',
value: 'title',
}, {
name: 'ticket.note',
operator: 'contains not',
value: 'some',
},
] }
end

let(:additional_ticket_attributes) { { title: 'title' } }

before do
ticket
end

include_examples 'does not find the ticket'
end

context "when 'contains not' operator is before negative operator" do
let(:condition) do
{ operator: 'AND', conditions: [
{
name: 'ticket.note',
operator: 'contains not',
value: 'some',
}, {
name: 'ticket.title',
operator: 'is not',
value: 'title',
}
] }
end

let(:additional_ticket_attributes) { { title: 'title' } }

before do
ticket
end

include_examples 'does not find the ticket'
end

context "when 'contains not' operator on a related table is after negative operator" do
let(:condition) do
{ operator: 'AND', conditions: [
{
name: 'ticket.title',
operator: 'is not',
value: 'title',
}, {
name: 'customer.email',
operator: 'contains not',
value: 'some',
},
] }
end

let(:additional_ticket_attributes) { { title: 'title' } }

before do
ticket
end

include_examples 'does not find the ticket'
end

context "when 'contains not' operator on a related table is before negative operator" do
let(:condition) do
{ operator: 'AND', conditions: [
{
name: 'customer.email',
operator: 'contains not',
value: 'some',
}, {
name: 'ticket.title',
operator: 'is not',
value: 'title',
}
] }
end

let(:additional_ticket_attributes) { { title: 'title' } }

before do
ticket
end

include_examples 'does not find the ticket'
end
end

describe 'external data source field', db_adapter: :postgresql, db_strategy: :reset do
let(:external_data_source_attribute) do
create(:object_manager_attribute_autocompletion_ajax_external_data_source,
Expand Down

0 comments on commit b6f796f

Please sign in to comment.