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 ordering of ON MATCH / ON CREATE and SET #333

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/neo4j/core/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def inspect
# DETACH DELETE clause
# @return [Query]

METHODS = %w[start match optional_match call using where create create_unique merge set on_create_set on_match_set remove unwind delete detach_delete with with_distinct return order skip limit] # rubocop:disable Metrics/LineLength
METHODS = %w[start match optional_match call using where create create_unique merge on_create_set on_match_set set remove unwind delete detach_delete with with_distinct return order skip limit] # rubocop:disable Metrics/LineLength
BREAK_METHODS = %(with with_distinct call)

CLAUSIFY_CLAUSE = proc { |method| const_get(method.to_s.split('_').map(&:capitalize).join + 'Clause') }
Expand Down
10 changes: 10 additions & 0 deletions spec/neo4j/core/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ def self.it_generates(cypher, params = {})
it_generates 'ON CREATE SET n = {name: "Brian"}'
end

# ON CREATE SET must come before SET (and immediately after MERGE) or the cypher is invalid
describe '.on_create_set(n: { name: "Brian" }).set(n: { age: 30 })' do
it_generates 'ON CREATE SET n.`name` = {setter_n_name} SET n.`age` = {setter_n_age}', setter_n_name: 'Brian', setter_n_age: 30
end

describe '.on_create_set(n: {})' do
it_generates '', {}
end
Expand All @@ -877,6 +882,11 @@ def self.it_generates(cypher, params = {})
it_generates 'ON MATCH SET n = {name: "Brian"}'
end

# ON MATCH SET must come before SET (and immediately after MERGE) or the cypher is invalid
describe '.on_match_set(n: { name: "Brian" }).set(n: { age: 30 })' do
it_generates 'ON MATCH SET n.`name` = {setter_n_name} SET n.`age` = {setter_n_age}', setter_n_name: 'Brian', setter_n_age: 30
end

describe '.on_match_set(n: {})' do
it_generates '', {}
end
Expand Down