diff --git a/.github/workflows/e2e_test.yml b/.github/workflows/e2e_test.yml new file mode 100644 index 000000000..99e1357ec --- /dev/null +++ b/.github/workflows/e2e_test.yml @@ -0,0 +1,47 @@ +name: E2E Test + +on: + push: + branches: [ '11' ] + pull_request: + branches: [ '11' ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + e2e_test: + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + ruby: [ jruby-9.4.5.0, ruby-3.2.3 ] + neo4j: [ 5.16.0 ] + active_model: [ 7.1.3 ] + # jruby will fail till bug https://github.com/jruby/jruby-openssl/issues/290 is fixed + env: + ACTIVE_MODEL_VERSION: ${{ matrix.active_model }} + 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 --env NEO4J_dbms_directories_import= -p7687:7687 -p7474:7474 -v `pwd`/tmp:/var/lib/neo4j/import --rm neo4j:${{ matrix.neo4j }}-enterprise & + + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Wait for neo4j + run: while [ $((curl localhost:7474/ > /dev/null 2>&1); echo $?) -ne 0 ]; do sleep 1; done + + - name: Setup test rails app + run: ./e2e_tests/setup.sh + + - name: Install dependencies + run: bundle update + + - name: Run tests + run: bundle exec rspec -Oe2e_tests/.e2e_rspec e2e_tests/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b69b7274..0f1e6cfd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,18 +12,20 @@ on: jobs: test: runs-on: ubuntu-latest - continue-on-error: ${{ matrix.ruby == 'ruby' }} timeout-minutes: 30 strategy: fail-fast: false matrix: ruby: [ jruby-9.4.5.0, ruby-3.1.4 ] - neo4j: [ 5.15.0 ] - active_model: [ 7.0.8, 7.1.2 ] + neo4j: [ 5.16.0 ] + active_model: [ 7.0.8, 7.1.3 ] include: - - ruby: ruby-3.2.2 - neo4j: 5.15.0 - active_model: 7.1.2 + - ruby: ruby-3.2.3 + neo4j: 5.16.0 + active_model: 7.1.3 + - ruby: ruby-3.3.0 + neo4j: 5.16.0 + active_model: 7.1.3 env: NEO4J_VERSION: ${{ matrix.neo4j }} ACTIVE_MODEL_VERSION: ${{ matrix.active_model }} diff --git a/docs/Testing.rst b/docs/Testing.rst index 5b410dc82..1cdff114a 100644 --- a/docs/Testing.rst +++ b/docs/Testing.rst @@ -17,6 +17,16 @@ You can configure it to respond on a different port like so: If you are using Rails, you can edit the test configuration ``config/environments/test.rb`` or the ``config/neo4j.yml`` file (see :doc:`Setup `) +To run the e2e tests we first have to run setup script ``sh e2e_tests/setup.sh``. After that we can run e2e tests by ``rspec -Oe2e_tests/.e2e_rspec e2e_tests/`` command +To run the setup script with custom options we can leverage following environment variables + +.. code-block:: bash + + ACTIVEGRAPH_PATH=local path of activegraph code (root directory) + ACTIVE_MODEL_VERSION=version of activemodel + E2E_PORT=neo4j server port + E2E_NO_CRED=set this to true when neo4j server has auth disabled + How to clear the database ------------------------- diff --git a/docs/activegraph.rb b/docs/activegraph.rb index 90324e5a7..943836eb3 100644 --- a/docs/activegraph.rb +++ b/docs/activegraph.rb @@ -25,7 +25,7 @@ environment generator environment nil, env: 'development' do < template.tmp +else + echo "SHA=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_ENV + sed 's/.*gem '"'"'activegraph'"'"'.*/gem '"'"'activegraph'"'"', github: "neo4jrb\/activegraph", ref: "'"$(git rev-parse "$GITHUB_SHA")"'"/' docs/activegraph.rb > template.tmp +fi + +rails \_$ACTIVE_MODEL_VERSION\_ new myapp -O -m ./template.tmp +rm -f ./template.tmp +cd myapp + +if [[ -n "$E2E_PORT" ]] +then + sed 's/7687/'$E2E_PORT'/' config/environments/development.rb > dev_env.tmp + mv dev_env.tmp config/environments/development.rb +fi + +if [[ -n "$E2E_NO_CRED" ]] +then + sed "s/'neo4j'/''/" config/environments/development.rb > dev_env.tmp + mv dev_env.tmp config/environments/development.rb + sed "s/'password'/''/" config/environments/development.rb > dev_env.tmp + mv dev_env.tmp config/environments/development.rb +fi + +bundle exec rails generate model User name:string +bundle exec rails generate migration BlahMigration +bundle exec rake neo4j:migrate + +if echo 'puts "hi"' | bundle exec rails c +then + echo "rails console works correctly" +else + exit 1 +fi + +bundle exec rails s -d +until $(curl --output /dev/null --silent --head --fail localhost:3000); do + printf '.' + sleep 1 +done +kill `cat tmp/pids/server.pid` diff --git a/e2e_tests/spec_helper.rb b/e2e_tests/spec_helper.rb new file mode 100644 index 000000000..00c8ed282 --- /dev/null +++ b/e2e_tests/spec_helper.rb @@ -0,0 +1,11 @@ +require 'active_graph' +require 'find' + +server_url = ENV['NEO4J_URL'] || 'bolt://localhost:7687' +ActiveGraph::Base.driver = Neo4j::Driver::GraphDatabase.driver(server_url, Neo4j::Driver::AuthTokens.basic('neo4j', 'password')) + +def load_migration(suffix) + Find.find('myapp/db/neo4j/migrate') do |path| + load path if path =~ /.*#{suffix}$/ + end +end diff --git a/lib/active_graph.rb b/lib/active_graph.rb index fbe28a308..19be77304 100644 --- a/lib/active_graph.rb +++ b/lib/active_graph.rb @@ -26,6 +26,8 @@ loader.ignore(File.expand_path('rails', __dir__)) loader.ignore(File.expand_path('active_graph/railtie.rb', __dir__)) loader.inflector.inflect("ansi" => "ANSI") +module ActiveGraph +end loader.setup # loader.eager_load diff --git a/lib/active_graph/railtie.rb b/lib/active_graph/railtie.rb index 7f94a7c7b..3fdbeacb7 100644 --- a/lib/active_graph/railtie.rb +++ b/lib/active_graph/railtie.rb @@ -1,11 +1,6 @@ # Need the action_dispatch railtie to have action_dispatch.rescue_responses initialized correctly require 'action_dispatch/railtie' -require 'rails/generators' -require 'rails/generators/active_model' -require 'rails/generators/named_base' require 'rails/railtie' -require File.expand_path('../rails/generators/migration_helper.rb', __dir__) -Rails::Generators::GeneratedAttribute.include ActiveGraph::Generators::GeneratedAttribute require 'active_graph' module ActiveGraph @@ -44,6 +39,13 @@ def empty_config ActiveGraph::Config[:verbose_query_logs] = false end + # By default, Rails loads generators from load path. + # However, if we want to place generators at a different location we have to use "generators" hook + # https://api.rubyonrails.org/classes/Rails/Railtie.html + generators do + require File.expand_path('../rails/generators/migration_helper.rb', __dir__) + end + # Starting Neo after :load_config_initializers allows apps to # register migrations in config/initializers initializer 'neo4j.start', after: :load_config_initializers do |app| diff --git a/lib/active_graph/version.rb b/lib/active_graph/version.rb index a76f71995..77b4afd25 100644 --- a/lib/active_graph/version.rb +++ b/lib/active_graph/version.rb @@ -1,3 +1,3 @@ module ActiveGraph - VERSION = '12.0.0.beta.3' + VERSION = '12.0.0.beta.4' end diff --git a/lib/rails/generators/migration_helper.rb b/lib/rails/generators/migration_helper.rb index 5a2df2875..507e84333 100644 --- a/lib/rails/generators/migration_helper.rb +++ b/lib/rails/generators/migration_helper.rb @@ -101,3 +101,6 @@ def type_class end end end + +require 'rails/generators/named_base' +Rails::Generators::GeneratedAttribute.include ActiveGraph::Generators::GeneratedAttribute