From 9639cbcfed9772bc5c03553c670c4d8e1364c0fa Mon Sep 17 00:00:00 2001 From: klobuczek <@Coto16531653> Date: Wed, 8 Feb 2023 11:20:20 -0900 Subject: [PATCH 1/2] partial neo4j 5 support --- .github/workflows/test.yml | 43 +++++++++++++++++++ .travis.yml | 39 ----------------- cancancan-activegraph.gemspec | 3 +- .../active_graph/cypher_constructor.rb | 12 +++--- spec/spec_helper.rb | 4 +- 5 files changed, 52 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..152417a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,43 @@ +name: Test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.ruby == 'ruby' }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + ruby: [ jruby-9.3.10.0, ruby-3.2.0 ] + neo4j: [ 3.5.35, 4.0.12, 4.1.12, 4.2.19, 4.3.23, 4.4.17, 5.4.0 ] + env: + NEO4J_VERSION: ${{ matrix.neo4j }} + JRUBY_OPTS: --debug -J-Xmx1280m -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -Xcompile.mode=OFF + steps: + - name: Start neo4j + run: docker run --name neo4j --env NEO4J_AUTH=neo4j/password --env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes -p7687:7687 -p7474:7474 --rm neo4j:${{ matrix.neo4j }}-enterprise & + + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Install dependencies + run: bundle update + + - name: Wait for neo4j + run: while [ $((curl localhost:7474/ > /dev/null 2>&1); echo $?) -ne 0 ]; do sleep 1; done + + - name: Run tests + run: bundle exec rspec diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 74ca8ee..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -dist: xenial - -before_script: - - "travis_retry bin/rake neo4j:install[$NEO4J_VERSION] --trace" - - "bin/rake neo4j:config[development,7474] --trace" - - "if [ -f ./db/neo4j/development/conf/neo4j-wrapper.conf ]; then WRAPPER=-wrapper; fi" - - "echo 'dbms.memory.pagecache.size=600m' >> ./db/neo4j/development/conf/neo4j.conf" - - "echo 'dbms.memory.heap.max_size=600m' >> ./db/neo4j/development/conf/neo4j$WRAPPER.conf" - - "echo 'dbms.memory.heap.initial_size=600m' >> ./db/neo4j/development/conf/neo4j$WRAPPER.conf" - - "bin/rake neo4j:start --trace" - - wget https://github.com/neo4j-drivers/seabolt/releases/download/v1.7.4/seabolt-1.7.4-Linux-ubuntu-16.04.deb - - sudo dpkg -i seabolt-1.7.4-Linux-ubuntu-16.04.deb - - "while [ $((curl localhost:7474/ > /dev/null 2>&1); echo $?) -ne 0 ]; do sleep 1; done" -script: - - "travis_retry bin/rake default --trace" -language: ruby -cache: bundler -jdk: openjdk11 -rvm: - - 2.7.1 - - jruby-9.2.11.1 - - jruby-9.2.12.0 -env: - global: - - JRUBY_OPTS="--debug -J-Xmx1280m -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -Xcompile.mode=OFF" - - NEO4J_URL="bolt://localhost:7472" - matrix: - - NEO4J_VERSION=enterprise-3.5.19 - - NEO4J_VERSION=enterprise-4.0.6 -matrix: - include: - # Testing older versions of ActiveModel - - rvm: 2.5.8 - jdk: openjdk8 - env: NEO4J_VERSION=community-3.4.18 ACTIVE_MODEL_VERSION=5.2.3 - - - rvm: jruby-9.2.11.1 - env: driver=java NEO4J_VERSION=enterprise-4.0.6 \ No newline at end of file diff --git a/cancancan-activegraph.gemspec b/cancancan-activegraph.gemspec index e51f15c..3b55b81 100644 --- a/cancancan-activegraph.gemspec +++ b/cancancan-activegraph.gemspec @@ -18,11 +18,10 @@ Gem::Specification.new do |spec| spec.files = `git ls-files lib init.rb cancancan-activegraph.gemspec`.split($INPUT_RECORD_SEPARATOR) spec.require_paths = ['lib'] - spec.add_dependency 'activegraph', '>= 10.0.0' + spec.add_dependency 'activegraph', '>= 11.2.0' spec.add_dependency 'cancancan' spec.add_development_dependency 'bundler', '>= 1.3' - spec.add_development_dependency("neo4j-#{RUBY_PLATFORM =~ /java/ ? 'java' : 'ruby'}-driver", '>= 0.3.0') spec.add_development_dependency('neo4j-rake_tasks', '>= 0.3.0') spec.add_development_dependency 'pry', '>= 0.11.3' spec.add_development_dependency 'rake', '>= 10.1' diff --git a/lib/cancancan/active_graph/cypher_constructor.rb b/lib/cancancan/active_graph/cypher_constructor.rb index c1d976c..f0d4b1e 100644 --- a/lib/cancancan/active_graph/cypher_constructor.rb +++ b/lib/cancancan/active_graph/cypher_constructor.rb @@ -21,7 +21,7 @@ def construct_cypher(rule_cyphers) rule_cyphers.each do |rule_cypher| construct_cypher_for_rule(rule_cypher) end - unwind_query_with_distinct + unwind_query_with_distinct(rule_cyphers.map { |rc| "#{rc.options[:var_label]}_col" }) end def construct_cypher_for_rule(rule_cypher) @@ -39,14 +39,14 @@ def update_scope(rule_cypher) @scope = rule_cypher.options[:scope] end - def unwind_query_with_distinct + def unwind_query_with_distinct(vars) var = CanCanCan::ActiveGraph::CypherConstructorHelper.var_name(@model_class) - @query = unwind_qeury("#{var}_can") + @query = unwind_qeury("#{var}_can", vars) .with("DISTINCT #{var}_can as #{var}") end - def unwind_qeury(var_name) - @query = @query.unwind("#{@current_collection} as #{var_name}") + def unwind_qeury(var_name, vars = [@current_collection]) + @query = @query.unwind("#{vars.join(' + ')} as #{var_name}") end def construct_can_cypher(rule_cypher) @@ -60,7 +60,7 @@ def with_clause_for_rule(rule_cypher, can_rule) var = rule_cypher.options[:var_label] with = "collect(DISTINCT #{var}) as #{var}_col" if can_rule && @current_collection - with = "#{@current_collection} + #{with}" + with = "#{@current_collection}, #{with}" end @current_collection = "#{var}_col" with diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a708433..f8d261b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,9 +27,9 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } def set_default_driver - server_url = ENV['NEO4J_URL'] || 'bolt://localhost:7472' + server_url = ENV['NEO4J_URL'] || 'bolt://localhost:7689' ActiveGraph::Base.driver = - Neo4j::Driver::GraphDatabase.driver(server_url, Neo4j::Driver::AuthTokens.none, encryption: false) + Neo4j::Driver::GraphDatabase.driver(server_url, Neo4j::Driver::AuthTokens.basic('neo4j', 'password'), encryption: false) end set_default_driver From 47ef1c8897b35a04ddc58f1a6e7c08c89ae84b3d Mon Sep 17 00:00:00 2001 From: klobuczek <@Coto16531653> Date: Wed, 8 Feb 2023 13:05:59 -0900 Subject: [PATCH 2/2] fixed test port --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f8d261b..d014627 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,7 +27,7 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } def set_default_driver - server_url = ENV['NEO4J_URL'] || 'bolt://localhost:7689' + server_url = ENV['NEO4J_URL'] || 'bolt://localhost:7687' ActiveGraph::Base.driver = Neo4j::Driver::GraphDatabase.driver(server_url, Neo4j::Driver::AuthTokens.basic('neo4j', 'password'), encryption: false) end