├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── Guardfile ├── ISSUE_TEMPLATE.md ├── LICENSE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── Rakefile ├── code_of_conduct.md ├── lib └── neo4j │ ├── rake_tasks.rb │ └── rake_tasks │ ├── download.rb │ ├── neo4j_server.rake │ ├── server_manager.rb │ ├── starnix_server_manager.rb │ ├── version.rb │ └── windows_server_manager.rb ├── neo4j-rake_tasks.gemspec ├── neo4j_versions.yml ├── release_if_new.rb └── spec ├── config_server_spec.rb ├── files └── neo4j-community-2.2.3-unix.tar.gz ├── spec_helper.rb └── starnix_server_manager_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /coverage 3 | .idea 4 | Gemfile.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | script: bundle exec rake 2 | language: ruby 3 | cache: bundler 4 | sudo: false 5 | rvm: 6 | - 2.3.0 7 | 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This file should follow the standards specified on [http://keepachangelog.com/] 4 | This project adheres to [Semantic Versioning](http://semver.org/). 5 | 6 | ## [Unreleased][unreleased] 7 | 8 | ## [0.7.19] - 05-25-2018 9 | 10 | ### Fixed 11 | 12 | - Fix for pattern matching for jar files in Neo4j 3.4 13 | 14 | ## [0.7.18] - 10-15-2017 15 | 16 | ### Fixed 17 | 18 | - Fix for clearing of tasks from 0.7.17 19 | 20 | ## [0.7.17] - 10-15-2017 21 | 22 | ### Fixed 23 | 24 | - Previously defined `neo4j:*` tasks are cleared before defined in this gem (this is primarily to support the removal of `neo4j-rake_tasks` as a dependency of the `neo4j-core` gem) 25 | 26 | ## [0.7.16] - 09-21-2017 27 | 28 | ### Fixed 29 | 30 | - Fixed issue where I was in a rush 31 | 32 | ## [0.7.15] - 09-21-2017 33 | 34 | ### Fixed 35 | 36 | - Fixed issue with HTTPS in install downloads 37 | 38 | ## [0.7.14] - 09-21-2017 39 | 40 | ### Fixed 41 | 42 | - Fixed issue with query string in NEO4J_DIST 43 | 44 | ## [0.7.13] - 09-20-2017 45 | 46 | ### Fixed 47 | 48 | - Added `NEO4J_DIST` environment variable to allow for downloading from custom URL (neccessitated by Neo4j, Inc. removing public link). (thanks @klobuczek / see #39) 49 | 50 | ## [0.7.11] - 04-25-2017 51 | 52 | ### Fixed 53 | 54 | - Removed `colored` gem as dependency (fewer dependencies and less monkey patching are both good. Thanks @dominicsayers / see #38) 55 | 56 | ## [0.7.11] - 03-18-2017 57 | 58 | ### Fixed 59 | 60 | - Bug which caused auth to not be disabled in Neo4j 3.1.2 61 | 62 | ## [0.7.10] - 12-23-2016 63 | 64 | ### Fixed 65 | 66 | - Support for `neo4j:config` in Neo4j >= 3.1.0 (see #37, thanks to @ernestoe) 67 | 68 | ### Skip a few... 69 | 70 | ## [0.6.1] - 06-03-2016 71 | 72 | ### Removed `require` statements for `httparty` (thanks again ProGM!) 73 | 74 | ## [0.6.0] - 06-03-2016 75 | 76 | ### Changed 77 | 78 | - Removed dependency on HTTParty (thanks ProGM / see #28) 79 | 80 | ### Added 81 | 82 | - Progress bar for Neo4j install (thanks ProGM / see #28) 83 | 84 | ## [0.5.6] - 05-30-2016 85 | 86 | ### Fixed 87 | 88 | - Mixed up paths from 0.5.5 fix 89 | 90 | ## [0.5.5] - 05-29-2016 91 | 92 | ### Fixed 93 | 94 | - Fixed reset task for Neo4j 3.0 (see #27) 95 | - Make `config` task reset Bolt port as well as HTTP / HTTPS (see #27) 96 | 97 | ## [0.4.2] - 02-17-2016 98 | 99 | ### Fixed 100 | 101 | - Matching variables / values in `properties` (see #21, thanks to bobmazanec) 102 | - Default port in config task to 7474 103 | 104 | ## [0.4.0] - 01-13-2016 105 | 106 | ### Added 107 | 108 | - In addition to ability to `community-latest`, added ability to install `community-(stable|rc|release-candidate|milestone)` as defined in config 109 | - Ability to give an argument to `ServerManager#stop` with a timeout to force shutdown 110 | 111 | ## [0.3.0] - 09-27-2015 112 | 113 | ### Added 114 | - Add `shell` rake task. Start Neo4j if it is not already started (and stop afterward) 115 | 116 | ## [0.2.0] - 09-27-2015 117 | 118 | ### Added 119 | - Added `console` task (thanks to darrin-wortlehock via #13) 120 | 121 | ## [0.1.0] - 09-24-2015 122 | 123 | ### Changed 124 | - Use rubyzip rather than zip 125 | 126 | ### Fixed 127 | - Fix `rake neo4j:reset_yes_i_am_sure` not actually resetting the db 128 | 129 | ## [0.0.8] - 08-17-2015 130 | 131 | ### Fixed 132 | 133 | - Lack of an explicit `require 'rake'` could cause errors in projects using this gem. 134 | 135 | ## [0.0.1]-[0.0.7] 136 | - Early releases. Moved tasks from `neo4j-core` gem, refactored. 137 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group 'test' do 6 | gem 'coveralls', require: false 7 | gem 'guard-rspec', require: false 8 | gem 'neo4j-core' 9 | gem 'rake' 10 | gem 'rspec' 11 | gem 'rspec-its' 12 | gem 'simplecov-html', require: false 13 | end 14 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec feature) 6 | 7 | ## Uncomment to clear the screen before every task 8 | # clearing :on 9 | 10 | ## Guard internally checks for changes in the Guardfile and exits. 11 | ## If you want Guard to automatically start up again, run guard in a 12 | ## shell loop, e.g.: 13 | ## 14 | ## $ while bundle exec guard; do echo "Restarting Guard..."; done 15 | ## 16 | ## Note: if you are using the `directories` clause above and you are not 17 | ## watching the project directory ('.'), the you will want to move the Guardfile 18 | ## to a watched dir and symlink it back, e.g. 19 | # 20 | # $ mkdir config 21 | # $ mv Guardfile config/ 22 | # $ ln -s config/Guardfile . 23 | # 24 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 25 | 26 | guard :rubocop, cli: '--auto-correct --display-cop-names' do 27 | watch(/.+\.rb$/) 28 | watch(%r{(?:.+/)?\.rubocop.*\.yml$}) { |m| File.dirname(m[0]) } 29 | end 30 | 31 | guard :rspec, cmd: 'bundle exec rspec' do 32 | watch(%r{^spec/.+_spec\.rb$}) 33 | watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } 34 | watch('spec/spec_helper.rb') { 'spec' } 35 | end 36 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Additional information which could be helpful if relevent to your issue: 8 | 9 | ### Code example (inline, gist, or repo) 10 | 11 | 12 | 13 | ### Runtime information: 14 | 15 | Neo4j database version: 16 | `neo4j` gem version: 17 | `neo4j-core` gem version: 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Andreas Ronge 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | This pull introduces/changes: 4 | * 5 | * 6 | 7 | 8 | 9 | 10 | Pings: 11 | @cheerfulstoic 12 | @subvertallchris 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Rake tasks for managing a Neo4j database with your Ruby project 3 | 4 | [![Actively Maintained](https://img.shields.io/badge/Maintenance%20Level-Actively%20Maintained-green.svg)](https://gist.github.com/cheerfulstoic/d107229326a01ff0f333a1d3476e068d) 5 | 6 | Rake Tasks 7 | ========== 8 | 9 | The ``neo4j-rake_tasks`` gem includes some rake tasks which make it easy to install and manage a Neo4j server in the same directory as your Ruby project. 10 | 11 | WARNING: NOT FOR PRODUCTION USE! These rake tasks are intended to make installing and managing a Neo4j server in development and testing easier. Since authentication is disabled by default, this gem should not be used in production. If you need Neo4j in production, installation can be as easy as downloading, unzipping, and running the executable. 12 | 13 | NOTE: The ``neo4j-rake_tasks`` gem used to be included automatically with the ``neo4j-core`` gem (which is in turn included automatically in the ``neo4j`` gem). This is no longer the case because not everybody needs these tasks. 14 | 15 | ## neo4j:install 16 | 17 | ### Arguments 18 | 19 | ``version`` and ``environment`` (environment default is `development`) 20 | 21 | ### Example 22 | 23 | ``rake neo4j:install[community-latest,development]`` 24 | 25 | ... or to get a specific version 26 | 27 | ``rake neo4j:install[community-2.2.3,development]`` 28 | 29 | ### Description 30 | 31 | Downloads and installs Neo4j into ``$PROJECT_DIR/db/neo4j//`` 32 | 33 | ## neo4j:config 34 | 35 | ### Arguments 36 | 37 | ``environment`` and ``port`` 38 | 39 | ### Example 40 | 41 | ``rake neo4j:config[development,7000]`` 42 | 43 | ### Description 44 | 45 | Configure the port which Neo4j runs on. This affects the HTTP REST interface and the web console address. 46 | 47 | 48 | ## neo4j:start 49 | 50 | ### Arguments 51 | 52 | ``environment`` 53 | 54 | ### Example 55 | 56 | ``rake neo4j:start[development]`` 57 | 58 | ### Description 59 | 60 | Start the Neo4j server 61 | 62 | 63 | ## neo4j:start_no_wait 64 | 65 | ### Arguments 66 | 67 | ``environment`` 68 | 69 | ### Example 70 | 71 | ``rake neo4j:start_no_wait[development]`` 72 | 73 | ### Description 74 | 75 | Start the Neo4j server with the ``start-no-wait`` command 76 | 77 | ## neo4j:stop 78 | 79 | ### Arguments 80 | 81 | ``environment`` 82 | 83 | ### Example 84 | 85 | ``rake neo4j:stop[development]`` 86 | 87 | ### Description 88 | 89 | Stop the Neo4j server 90 | 91 | 92 | ## neo4j:indexes 93 | 94 | ### Arguments 95 | 96 | ``environment`` 97 | 98 | ### Example 99 | 100 | ``rake neo4j:indexes[development]`` 101 | 102 | ### Description 103 | 104 | Print out the indexes in the database 105 | 106 | 107 | 108 | ## neo4j:constraints 109 | 110 | ### Arguments 111 | 112 | ``environment`` 113 | 114 | ### Example 115 | 116 | ``rake neo4j:constraints[development]`` 117 | 118 | ### Description 119 | 120 | Print out the constraints in the database 121 | 122 | 123 | 124 | ## neo4j:reset_yes_i_am_sure 125 | 126 | ### Arguments 127 | 128 | ``environment`` 129 | 130 | ### Example 131 | 132 | ``rake neo4j:reset_yes_i_am_sure[development]`` 133 | 134 | ### Description 135 | 136 | - Stop the Neo4j server 137 | - Deletes all files matching `[db-root]/data/graph.db/*` 138 | - Deletes all files matching `[db-root]/data/log/*` 139 | - Start the Neo4j server 140 | 141 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'bundler/gem_tasks' 3 | 4 | desc 'Run specs' 5 | task 'spec' do 6 | success = system('rspec spec') 7 | abort('RSpec neo4j-core failed') unless success 8 | end 9 | 10 | desc 'Generate coverage report' 11 | task 'coverage' do 12 | ENV['COVERAGE'] = 'true' 13 | rm_rf 'coverage/' 14 | task = Rake::Task['spec'] 15 | task.reenable 16 | task.invoke 17 | end 18 | 19 | task default: [:spec] 20 | 21 | # require 'coveralls/rake/task' 22 | # Coveralls::RakeTask.new 23 | # task :test_with_coveralls => [:spec, 'coveralls:push'] 24 | # 25 | # task :default => ['test_with_coveralls'] 26 | -------------------------------------------------------------------------------- /code_of_conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. 6 | 7 | Examples of unacceptable behavior by participants include: 8 | 9 | * The use of sexualized language or imagery 10 | * Personal attacks 11 | * Trolling or insulting/derogatory comments 12 | * Public or private harassment 13 | * Publishing other's private information, such as physical or electronic addresses, without explicit permission 14 | * Other unethical or unprofessional conduct. 15 | 16 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. 17 | 18 | This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 21 | 22 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) 23 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks.rb: -------------------------------------------------------------------------------- 1 | require 'neo4j/rake_tasks/download' 2 | require 'neo4j/rake_tasks/starnix_server_manager' 3 | require 'neo4j/rake_tasks/windows_server_manager' 4 | require 'rake' 5 | load 'neo4j/rake_tasks/neo4j_server.rake' 6 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks/download.rb: -------------------------------------------------------------------------------- 1 | require 'ruby-progressbar' 2 | require 'net/http' 3 | 4 | module Neo4j 5 | module RakeTasks 6 | class Download 7 | def initialize(url) 8 | @url = url 9 | end 10 | 11 | def exists? 12 | status = head(@url).code.to_i 13 | (200...300).cover?(status) 14 | end 15 | 16 | def fetch(message) 17 | require 'open-uri' 18 | open(@url, 19 | content_length_proc: lambda do |total| 20 | create_progress_bar(message, total) if total && total > 0 21 | end, 22 | progress_proc: method(:update_progress_bar)).read 23 | end 24 | 25 | private 26 | 27 | def create_progress_bar(message, total) 28 | @progress_bar ||= ProgressBar.create title: message, 29 | total: total 30 | end 31 | 32 | def update_progress_bar(value) 33 | return unless @progress_bar 34 | 35 | value = @progress_bar.total >= value ? value : @progress_bar.total 36 | @progress_bar.progress = value 37 | end 38 | 39 | def head(url) 40 | uri = URI(url) 41 | Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| 42 | return http.head("#{uri.path}?#{uri.query}") 43 | end 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks/neo4j_server.rake: -------------------------------------------------------------------------------- 1 | # :nocov: 2 | # borrowed from architect4r 3 | require 'os' 4 | require 'zip' 5 | require 'pathname' 6 | require File.expand_path('windows_server_manager', __dir__) 7 | require File.expand_path('starnix_server_manager', __dir__) 8 | 9 | namespace :neo4j do 10 | def clear_task_if_defined(task_name) 11 | Rake::Task["neo4j:#{task_name}"].clear if Rake::Task.task_defined?("neo4j:#{task_name}") 12 | end 13 | 14 | def server_path(environment) 15 | Pathname.new('db/neo4j').join(environment.to_s) 16 | end 17 | 18 | def server_manager_class 19 | ::Neo4j::RakeTasks::ServerManager.class_for_os 20 | end 21 | 22 | def server_manager(environment) 23 | ::Neo4j::RakeTasks::ServerManager.new_for_os(server_path(environment)) 24 | end 25 | 26 | def cyanize(string) 27 | "\e[36m#{string}\e[0m" 28 | end 29 | 30 | clear_task_if_defined(:install) 31 | desc 'Install Neo4j with auth disabled in v2.2+' 32 | task :install, :edition, :environment do |_, args| 33 | args.with_defaults(edition: 'community-latest', environment: 'development') 34 | 35 | puts "Install Neo4j (#{args[:environment]} environment)..." 36 | 37 | server_manager = server_manager(args[:environment]) 38 | server_manager.install(args[:edition]) 39 | 40 | server_manager.config_auth_enabeled!(false) if server_manager.supports_auth? 41 | 42 | puts 'To start it type one of the following:' 43 | puts cyanize(' rake neo4j:start') 44 | puts cyanize(' rake neo4j:start[ENVIRONMENT]') 45 | puts 'To change the server port (default is 7474) type:' 46 | puts cyanize(' neo4j:config[ENVIRONMENT,PORT]') 47 | end 48 | 49 | clear_task_if_defined(:start) 50 | desc 'Start the Neo4j Server' 51 | task :start, :environment do |_, args| 52 | args.with_defaults(environment: :development) 53 | 54 | puts "Starting Neo4j in #{args[:environment]}..." 55 | server_manager = server_manager(args[:environment]) 56 | server_manager.start 57 | end 58 | 59 | clear_task_if_defined(:start_no_wait) 60 | desc 'Start the Neo4j Server asynchronously' 61 | task :start_no_wait, :environment do |_, args| 62 | args.with_defaults(environment: :development) 63 | 64 | puts "Starting Neo4j (no wait) in #{args[:environment]}..." 65 | server_manager = server_manager(args[:environment]) 66 | server_manager.start(false) 67 | end 68 | 69 | clear_task_if_defined(:console) 70 | desc 'Start the Neo4j Server in the foreground' 71 | task :console, :environment do |_, args| 72 | args.with_defaults(environment: :development) 73 | 74 | puts "Starting Neo4j (foreground) in #{args[:environment]}..." 75 | server_manager = server_manager(args[:environment]) 76 | server_manager.console 77 | end 78 | 79 | clear_task_if_defined(:shell) 80 | desc 'Open Neo4j REPL Shell' 81 | task :shell, :environment do |_, args| 82 | args.with_defaults(environment: :development) 83 | 84 | puts "Starting Neo4j shell in #{args[:environment]}..." 85 | server_manager = server_manager(args[:environment]) 86 | server_manager.shell 87 | end 88 | 89 | clear_task_if_defined(:config) 90 | desc 'Configure Server, e.g. rake neo4j:config[development,8888]' 91 | task :config, :environment, :port do |_, args| 92 | args.with_defaults(environment: :development, port: 7474) 93 | 94 | puts "Config Neo4j in #{args[:environment]}" 95 | 96 | server_manager = server_manager(args[:environment]) 97 | server_manager.config_port!(args[:port].to_i) 98 | end 99 | 100 | clear_task_if_defined(:stop) 101 | desc 'Stop the Neo4j Server' 102 | task :stop, :environment do |_, args| 103 | args.with_defaults(environment: :development) 104 | 105 | puts "Stopping Neo4j in #{args[:environment]}..." 106 | 107 | server_manager = server_manager(args[:environment]) 108 | server_manager.stop 109 | end 110 | 111 | clear_task_if_defined(:info) 112 | desc 'Get info for the Neo4j Server' 113 | task :info, :environment do |_, args| 114 | args.with_defaults(environment: :development) 115 | 116 | puts "Getting Neo4j info for #{args[:environment]}..." 117 | 118 | server_manager = server_manager(args[:environment]) 119 | server_manager.info 120 | end 121 | 122 | clear_task_if_defined(:indexes) 123 | desc 'List indexes for the Neo4j server' 124 | task :indexes, :environment do |_, args| 125 | args.with_defaults(environment: :development) 126 | 127 | puts "Getting Neo4j indexes for #{args[:environment]}..." 128 | 129 | server_manager = server_manager(args[:environment]) 130 | server_manager.print_indexes 131 | end 132 | 133 | clear_task_if_defined(:constraints) 134 | desc 'List constraints for the Neo4j server' 135 | task :constraints, :environment do |_, args| 136 | args.with_defaults(environment: :development) 137 | 138 | puts "Getting Neo4j constraints for #{args[:environment]}..." 139 | 140 | server_manager = server_manager(args[:environment]) 141 | server_manager.print_constraints 142 | end 143 | 144 | clear_task_if_defined(:restart) 145 | desc 'Restart the Neo4j Server' 146 | task :restart, :environment do |_, args| 147 | args.with_defaults(environment: :development) 148 | 149 | puts "Restarting Neo4j in #{args[:environment]}..." 150 | 151 | server_manager = server_manager(args[:environment]) 152 | server_manager.restart 153 | end 154 | 155 | clear_task_if_defined(:reset_yes_i_am_sure) 156 | desc 'Reset the Neo4j Server' 157 | task :reset_yes_i_am_sure, :environment do |_, args| 158 | args.with_defaults(environment: :development) 159 | 160 | puts "Resetting Neo4j in #{args[:environment]}..." 161 | 162 | server_manager = server_manager(args[:environment]) 163 | server_manager.reset 164 | end 165 | 166 | clear_task_if_defined(:change_password) 167 | desc 'Neo4j 2.2+: Change connection password' 168 | task :change_password do |_, _args| 169 | # Maybe we should take the environment as an arg and 170 | # find the port in the config file? 171 | server_manager_class.change_password! 172 | end 173 | 174 | clear_task_if_defined(:enable_auth) 175 | desc 'Neo4j 2.2+: Enable Auth' 176 | task :enable_auth, :environment do |_, args| 177 | args.with_defaults(environment: :development) 178 | 179 | server_manager = server_manager(args[:environment]) 180 | server_manager.config_auth_enabeled!(true) 181 | 182 | puts 'Neo4j basic authentication enabled. Restart server to apply.' 183 | end 184 | 185 | clear_task_if_defined(:disable_auth) 186 | desc 'Neo4j 2.2+: Disable Auth' 187 | task :disable_auth, :environment do |_, args| 188 | args.with_defaults(environment: :development) 189 | 190 | server_manager = server_manager(args[:environment]) 191 | server_manager.config_auth_enabeled!(false) 192 | 193 | puts 'Neo4j basic authentication disabled. Restart server to apply.' 194 | end 195 | end 196 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks/server_manager.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | require 'ostruct' 3 | 4 | module Neo4j 5 | module RakeTasks 6 | # Represents and manages a server installation at a specific path 7 | class ServerManager 8 | def initialize(path) 9 | @path = Pathname.new(path) 10 | FileUtils.mkdir_p(@path) 11 | end 12 | 13 | # MAIN COMMANDS 14 | 15 | def install(edition_string) 16 | version = version_from_edition(edition_string) 17 | 18 | if !neo4j_binary_path.exist? 19 | archive_path = download_neo4j(version) 20 | puts "Installing neo4j-#{version}" 21 | extract!(archive_path) 22 | 23 | FileUtils.rm archive_path 24 | end 25 | 26 | config_port!(7474) if server_version_greater_than_or_equal_to?('3.0.0') 27 | 28 | puts "Neo4j installed to: #{@path}" 29 | end 30 | 31 | def start(wait = true) 32 | system_or_fail(neo4j_command_path(start_argument(wait))).tap do 33 | @pid = pid_path.read.to_i 34 | end 35 | end 36 | 37 | def stop(timeout = nil) 38 | validate_is_system_admin! 39 | 40 | Timeout.timeout(timeout) do 41 | system_or_fail(neo4j_command_path(:stop)) 42 | end 43 | rescue Timeout::Error 44 | puts 'Shutdown timeout reached, killing process...' 45 | Process.kill('KILL', @pid) if @pid 46 | end 47 | 48 | def console 49 | system_or_fail(neo4j_command_path(:console)) 50 | end 51 | 52 | def shell 53 | not_started = !pid_path.exist? 54 | 55 | start if not_started 56 | 57 | system_or_fail(neo4j_shell_binary_path.to_s) 58 | 59 | stop if not_started 60 | end 61 | 62 | def info 63 | validate_is_system_admin! 64 | 65 | system_or_fail(neo4j_command_path(:info)) 66 | end 67 | 68 | def restart 69 | validate_is_system_admin! 70 | 71 | system_or_fail(neo4j_command_path(:restart)) 72 | end 73 | 74 | def reset 75 | validate_is_system_admin! 76 | 77 | stop 78 | 79 | paths = if server_version_greater_than_or_equal_to?('3.0.0') 80 | ['data/databases/graph.db/*', 'logs/*'] 81 | else 82 | ['data/graph.db/*', 'data/log/*'] 83 | end 84 | 85 | paths.each do |path| 86 | delete_path = @path.join(path) 87 | puts "Deleting all files matching #{delete_path}" 88 | FileUtils.rm_rf(Dir.glob(delete_path)) 89 | end 90 | 91 | start 92 | end 93 | 94 | def self.change_password! 95 | puts 'This will change the password for a Neo4j server' 96 | 97 | address, old_password, new_password = prompt_for_address_and_passwords! 98 | 99 | body = change_password_request(address, old_password, new_password) 100 | if body['errors'] 101 | puts "An error was returned: #{body['errors'][0]['message']}" 102 | else 103 | puts 'Password changed successfully! Please update your app to use:' 104 | puts 'username: neo4j' 105 | puts "password: #{new_password}" 106 | end 107 | end 108 | 109 | def supports_auth? 110 | Gem::Version.new(server_version) >= Gem::Version.new('2.2.0') 111 | end 112 | 113 | def config_auth_enabeled!(enabled) 114 | value = enabled ? 'true' : 'false' 115 | modify_config_file( 116 | 'dbms.security.authorization_enabled' => value, 117 | 'dbms.security.auth_enabled' => value) 118 | end 119 | 120 | def config_port!(port) 121 | puts "Config ports #{port} (HTTP) / #{port - 1} (HTTPS) / #{port - 2} (Bolt)" 122 | 123 | if server_version_greater_than_or_equal_to?('3.1.0') 124 | # These are not ideal, perhaps... 125 | modify_config_file('dbms.connector.https.enabled' => false, 126 | 'dbms.connector.http.enabled' => true, 127 | 'dbms.connector.http.listen_address' => "localhost:#{port}", 128 | 'dbms.connector.https.listen_address' => "localhost:#{port - 1}", 129 | 'dbms.connector.bolt.listen_address' => "localhost:#{port - 2}") 130 | elsif server_version_greater_than_or_equal_to?('3.0.0') 131 | modify_config_file('dbms.connector.https.enabled' => false, 132 | 'dbms.connector.http.enabled' => true, 133 | 'dbms.connector.http.address' => "localhost:#{port}", 134 | 'dbms.connector.https.address' => "localhost:#{port - 1}", 135 | 'dbms.connector.bolt.address' => "localhost:#{port - 2}") 136 | else 137 | modify_config_file('org.neo4j.server.webserver.https.enabled' => false, 138 | 'org.neo4j.server.webserver.port' => port, 139 | 'org.neo4j.server.webserver.https.port' => port - 1) 140 | end 141 | end 142 | 143 | # END MAIN COMMANDS 144 | 145 | def modify_config_file(properties) 146 | contents = File.read(property_configuration_path) 147 | 148 | File.open(property_configuration_path, 'w') { |file| file << modify_config_contents(contents, properties) } 149 | end 150 | 151 | def get_config_property(property) 152 | lines = File.read(property_configuration_path).lines 153 | config_lines = lines.grep(/^\s*[^#]/).map(&:strip).reject(&:empty?) 154 | 155 | lines.find do |line| 156 | line.match(/\s*#{property}=/) 157 | end.split('=')[1] 158 | end 159 | 160 | def modify_config_contents(contents, properties) 161 | properties.inject(contents) do |r, (property, value)| 162 | r.gsub(/^\s*(#\s*)?#{property}\s*=\s*(.+)/, "#{property}=#{value}") 163 | end 164 | end 165 | 166 | def self.class_for_os 167 | OS::Underlying.windows? ? WindowsServerManager : StarnixServerManager 168 | end 169 | 170 | def self.new_for_os(path) 171 | class_for_os.new(path) 172 | end 173 | 174 | def print_indexes 175 | print_indexes_or_constraints(:index) 176 | end 177 | 178 | def print_constraints 179 | print_indexes_or_constraints(:constraint) 180 | end 181 | 182 | protected 183 | 184 | def print_indexes_or_constraints(type) 185 | url = File.join(server_url, "db/data/schema/#{type}") 186 | data = JSON.load(open(url).read).map(&OpenStruct.method(:new)) 187 | if data.empty? 188 | puts "No #{type.to_s.pluralize} found" 189 | return 190 | end 191 | criteria = lambda { |i| i.label || i.relationshipType } 192 | data.sort_by(&criteria).chunk(&criteria).each do |label_or_type, rows| 193 | puts "\e[36m#{label_or_type}\e[0m" 194 | rows.each do |row| 195 | puts " #{row.type + ': ' if row.type}#{row.property_keys.join(', ')}" 196 | end 197 | end 198 | end 199 | 200 | def start_argument(wait) 201 | wait ? 'start' : 'start-no-wait' 202 | end 203 | 204 | def binary_command_path(binary_file) 205 | @path.join('bin', binary_file) 206 | end 207 | 208 | def neo4j_binary_path 209 | binary_command_path(neo4j_binary_filename) 210 | end 211 | 212 | def neo4j_command_path(command) 213 | neo4j_binary_path.to_s + " #{command}" 214 | end 215 | 216 | def neo4j_shell_binary_path 217 | binary_command_path(neo4j_shell_binary_filename) 218 | end 219 | 220 | def server_url 221 | if server_version_greater_than_or_equal_to?('3.1.0') 222 | get_config_property('dbms.connector.http.listen_address').strip.tap do |address| 223 | address.prepend('http://') unless address.match(/^http:\/\//) 224 | end 225 | elsif server_version_greater_than_or_equal_to?('3.0.0') 226 | get_config_property('dbms.connector.http.address').strip.tap do |address| 227 | address.prepend('http://') unless address.match(/^http:\/\//) 228 | end 229 | else 230 | port = get_config_property('org.neo4j.server.webserver.port') 231 | "http://localhost:#{port}" 232 | end.strip 233 | end 234 | 235 | def property_configuration_path 236 | if server_version_greater_than_or_equal_to?('3.0.0') 237 | @path.join('conf', 'neo4j.conf') 238 | else 239 | @path.join('conf', 'neo4j-server.properties') 240 | end 241 | end 242 | 243 | def validate_is_system_admin! 244 | nil 245 | end 246 | 247 | def system_or_fail(command) 248 | system(command.to_s) || 249 | fail("Unable to run: #{command}") 250 | end 251 | 252 | def version_from_edition(edition_string) 253 | edition_string.downcase.gsub(/-([a-z\-]+)$/) do 254 | v = $1 255 | puts "Retrieving #{v} version..." 256 | 257 | version = neo4j_versions[v] 258 | 259 | fail "Invalid version identifier: #{v}" if !neo4j_versions.key?(v) 260 | fail "There is not currently a version for #{v}" if version.nil? 261 | 262 | puts "#{v.capitalize} version is: #{version}" 263 | 264 | "-#{version}" 265 | end.gsub(/-[a-z\-\.0-9]+$/i, &:upcase) 266 | end 267 | 268 | def pid_path 269 | if server_version_greater_than_or_equal_to?('3.0.0') 270 | @path.join('run/neo4j.pid') 271 | else 272 | @path.join('data/neo4j-service.pid') 273 | end 274 | end 275 | 276 | private 277 | 278 | NEO4J_VERSIONS_URL = 'https://raw.githubusercontent.com/neo4jrb/neo4j-rake_tasks/master/neo4j_versions.yml' 279 | 280 | def server_version_greater_than_or_equal_to?(version) 281 | Gem::Version.new(server_version) >= Gem::Version.new(version) 282 | end 283 | 284 | def server_version 285 | kernel_jar_path = Dir.glob(@path.join('lib/neo4j-kernel-*.jar'))[0] 286 | kernel_jar_path.match(/neo4j-kernel[\-a-zA-Z]*-([\-a-zA-Z\d\.]+)\.jar$/)[1] 287 | end 288 | 289 | def neo4j_versions 290 | require 'open-uri' 291 | require 'yaml' 292 | 293 | YAML.load(open(NEO4J_VERSIONS_URL).read) 294 | end 295 | 296 | def download_neo4j(version) 297 | tempfile = Tempfile.open('neo4j-download', encoding: 'ASCII-8BIT') 298 | url = download_url(version) 299 | 300 | download = Download.new(url) 301 | raise "#{version} is not available to download" unless download.exists? 302 | 303 | tempfile << download.fetch("Fetching neo4j-#{version}") 304 | tempfile.flush 305 | tempfile.path 306 | ensure 307 | puts 308 | end 309 | 310 | # POSTs to an endpoint with the form required to change a Neo4j password 311 | # @param [String] address 312 | # The server address, with protocol and port, 313 | # against which the form should be POSTed 314 | # @param [String] old_password 315 | # The existing password for the "neo4j" user account 316 | # @param [String] new_password 317 | # The new password you want to use. Shocking, isn't it? 318 | # @return [Hash] The response from the server indicating success/failure. 319 | def self.change_password_request(address, old_password, new_password) 320 | uri = URI.parse("#{address}/user/neo4j/password") 321 | response = Net::HTTP.post_form(uri, 322 | 'password' => old_password, 323 | 'new_password' => new_password) 324 | JSON.parse(response.body) 325 | end 326 | 327 | def self.prompt_for(prompt, default = false) 328 | puts prompt 329 | print "#{default ? '[' + default.to_s + ']' : ''} > " 330 | result = STDIN.gets.chomp 331 | result = result.blank? ? default : result 332 | result 333 | end 334 | 335 | def prompt_for_address_and_passwords! 336 | address = prompt_for( 337 | 'Enter IP address / host name without protocal and port', 338 | 'http://localhost:7474') 339 | 340 | old_password = prompt_for( 341 | 'Input current password. Leave blank for a fresh installation', 342 | 'neo4j') 343 | 344 | new_password = prompt_for 'Input new password.' 345 | fail 'A new password is required' if new_password == false 346 | 347 | [address, old_password, new_password] 348 | end 349 | end 350 | end 351 | end 352 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks/starnix_server_manager.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('server_manager', __dir__) 2 | 3 | module Neo4j 4 | module RakeTasks 5 | # Represents and manages a server on *NIX systems 6 | class StarnixServerManager < ServerManager 7 | def neo4j_binary_filename 8 | 'neo4j' 9 | end 10 | 11 | def neo4j_shell_binary_filename 12 | 'neo4j-shell' 13 | end 14 | 15 | protected 16 | 17 | def extract!(zip_path) 18 | Dir.mktmpdir do |temp_dir_path| 19 | system_or_fail("cd #{temp_dir_path} && tar -xvf #{zip_path}") 20 | subdir = Dir.glob(File.join(temp_dir_path, '*'))[0] 21 | system_or_fail("mv #{File.join(subdir, '*')} #{@path}/") 22 | end 23 | end 24 | 25 | def download_url(version) 26 | ENV.fetch('NEO4J_DIST', 'http://dist.neo4j.org/neo4j-VERSION-unix.tar.gz').gsub('VERSION', version) 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks/version.rb: -------------------------------------------------------------------------------- 1 | module Neo4j 2 | module RakeTasks 3 | VERSION = '0.7.19'.freeze 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/neo4j/rake_tasks/windows_server_manager.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('server_manager', __dir__) 2 | 3 | module Neo4j 4 | module RakeTasks 5 | # Represents and manages a server on Windows 6 | class WindowsServerManager < ServerManager 7 | def neo4j_binary_filename 8 | 'Neo4j.bat' 9 | end 10 | 11 | def neo4j_shell_binary_filename 12 | 'Neo4jShell.bat' 13 | end 14 | 15 | def install 16 | super 17 | 18 | return unless nt_admin? 19 | 20 | system_or_fail(neo4j_command_path(:install)) 21 | puts 'Neo4j Installed as a service.' 22 | end 23 | 24 | def validate_is_system_admin! 25 | return if nt_admin? 26 | 27 | raise 'You do not have administrative rights to stop the Neo4j Service' 28 | end 29 | 30 | protected 31 | 32 | def download_url(version) 33 | "http://dist.neo4j.org/neo4j-#{version}-windows.zip" 34 | end 35 | 36 | def extract!(zip_path) 37 | each_file_in_zip(zip_path) do |file| 38 | f_path = @path.join(file.name) 39 | FileUtils.mkdir_p(File.dirname(f_path)) 40 | begin 41 | file.extract(f_path) unless File.exist?(f_path) 42 | rescue 43 | puts "#{file.name} failed to extract." 44 | end 45 | end 46 | end 47 | 48 | def start_argument(wait) 49 | nt_admin? ? super : '' 50 | end 51 | 52 | private 53 | 54 | def each_file_in_zip(zip_path) 55 | Zip::File.open(zip_path) do |zip_file| 56 | zip_file.each do |file| 57 | yield file 58 | end 59 | end 60 | end 61 | 62 | def nt_admin? 63 | !system_or_fail('reg query "HKU\\S-1-5-19"').empty? 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /neo4j-rake_tasks.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path('lib', __dir__) 2 | $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) 3 | 4 | require 'neo4j/rake_tasks/version' 5 | 6 | Gem::Specification.new do |s| 7 | s.name = 'neo4j-rake_tasks' 8 | s.version = Neo4j::RakeTasks::VERSION 9 | s.required_ruby_version = '>= 1.9.3' 10 | 11 | s.authors = 'Brian Underwood' 12 | s.email = 'public@brian-underwood.codes' 13 | s.homepage = 'https://github.com/neo4jrb/neo4j-rake_tasks' 14 | s.summary = <= 1.1.7') 44 | 45 | # s.add_development_dependency('vcr') 46 | s.add_development_dependency('guard') 47 | s.add_development_dependency('guard-rubocop') 48 | s.add_development_dependency('pry') 49 | s.add_development_dependency('rubocop') 50 | s.add_development_dependency('simplecov') 51 | end 52 | -------------------------------------------------------------------------------- /neo4j_versions.yml: -------------------------------------------------------------------------------- 1 | --- 2 | stable: &stable '3.4.1' 3 | alpha: 3.5.0-alpha04 4 | milestone: 3.4.1 5 | rc: &rc 3.4.0-rc02 6 | 7 | # aliases 8 | latest: *stable 9 | release-candidate: *rc 10 | -------------------------------------------------------------------------------- /release_if_new.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'logger' 4 | require 'rubygems' 5 | 6 | LOGGER = Logger.new(STDOUT) 7 | 8 | gemspec_files = Dir.glob('*.gemspec') 9 | 10 | raise 'Too many gemspecs!' if gemspec_files.size > 1 11 | 12 | gemspec_file = gemspec_files.first 13 | gem_name = File.basename(gemspec_file, '.*') 14 | 15 | spec = Gem::Specification.load(gemspec_file) 16 | 17 | LOGGER.info "Checking to see if version #{spec.version} of gem `#{gem_name}` exists" 18 | 19 | http_result = `curl --head https://rubygems.org/gems/#{gem_name}/versions/#{spec.version} | head -1` 20 | 21 | status_code = http_result.match(%r{^HTTP/[\d\.]+ (\d+)})[1].to_i 22 | 23 | if status_code == 200 24 | LOGGER.info 'Version already exists' 25 | else 26 | LOGGER.info 'Version does not exist. Releasing...' 27 | system('rake release') 28 | end 29 | -------------------------------------------------------------------------------- /spec/config_server_spec.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo4jrb/neo4j-rake_tasks/b79b7c0cdb3ea690346c81cf00042b7c56f2b20a/spec/config_server_spec.rb -------------------------------------------------------------------------------- /spec/files/neo4j-community-2.2.3-unix.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo4jrb/neo4j-rake_tasks/b79b7c0cdb3ea690346c81cf00042b7c56f2b20a/spec/files/neo4j-community-2.2.3-unix.tar.gz -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # To run coverage via travis 2 | require 'coveralls' 3 | Coveralls.wear! 4 | 5 | # require 'vcr' 6 | # VCR.configure do |config| 7 | # config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' 8 | # config.hook_into :webmock 9 | # end 10 | 11 | require 'rubygems' 12 | require 'bundler/setup' 13 | require 'rspec' 14 | require 'rspec/its' 15 | 16 | # Introduces `let_context` helper method 17 | # This allows us to simplify the case where we want to 18 | # have a context which contains one or more `let` statements 19 | module FixingRSpecHelpers 20 | # Supports giving either a Hash or a String and a Hash as arguments 21 | # In both cases the Hash will be used to define `let` statements 22 | # When a String is specified that becomes the context description 23 | # If String isn't specified, Hash#inspect becomes the context description 24 | def let_context(*args, &block) 25 | context_string, hash = 26 | case args.map(&:class) 27 | when [String, Hash] then ["#{args[0]} #{args[1]}", args[1]] 28 | when [Hash] then [args[0].inspect, args[0]] 29 | end 30 | 31 | context(context_string) do 32 | hash.each { |var, value| let(var) { value } } 33 | 34 | instance_eval(&block) 35 | end 36 | end 37 | 38 | def subject_should_raise(error, message = nil) 39 | it_string = error.to_s 40 | it_string += " (#{message.inspect})" if message 41 | 42 | it it_string do 43 | expect { subject }.to raise_error error, message 44 | end 45 | end 46 | end 47 | 48 | RSpec.configure do |config| 49 | config.extend FixingRSpecHelpers 50 | end 51 | -------------------------------------------------------------------------------- /spec/starnix_server_manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'pathname' 3 | require 'fileutils' 4 | require 'neo4j-core' 5 | require 'open-uri' 6 | 7 | require 'neo4j/rake_tasks/starnix_server_manager' 8 | 9 | BASE_PATHNAME = Pathname.new(File.expand_path(__dir__)) 10 | 11 | module Neo4j 12 | module RakeTasks 13 | describe StarnixServerManager, vcr: true do 14 | let(:path) { BASE_PATHNAME.join('tmp', 'db') } 15 | 16 | let(:server_manager) { StarnixServerManager.new(path) } 17 | 18 | describe '#modify_config_contents' do 19 | subject { server_manager.modify_config_contents(contents, properties) } 20 | after(:each) { path.rmtree } 21 | 22 | let_context properties: { prop: 2 } do 23 | let_context(contents: 'prop=1') { it { should eq('prop=2') } } 24 | let_context(contents: 'prop =1') { it { should eq('prop=2') } } 25 | let_context(contents: 'prop= 1') { it { should eq('prop=2') } } 26 | let_context(contents: 'prop = 1') { it { should eq('prop=2') } } 27 | 28 | let_context(contents: " prop = 1 \n") { it { should eq("prop=2\n") } } 29 | 30 | let_context(contents: "foo=5\n prop = 1 \nbar=6") { it { should eq("foo=5\nprop=2\nbar=6") } } 31 | 32 | let_context(contents: '#prop=1') { it { should eq('prop=2') } } 33 | let_context(contents: ' #prop=1') { it { should eq('prop=2') } } 34 | let_context(contents: '# prop=1') { it { should eq('prop=2') } } 35 | let_context(contents: ' # prop=1') { it { should eq('prop=2') } } 36 | let_context(contents: "foo=5\n # prop=1\nbar=6") { it { should eq("foo=5\nprop=2\nbar=6") } } 37 | end 38 | 39 | let_context contents: 'prop=false' do 40 | let_context(properties: { prop: true }) { it { should eq('prop=true') } } 41 | end 42 | 43 | let_context contents: 'prop=true' do 44 | let_context(properties: { prop: false }) { it { should eq('prop=false') } } 45 | end 46 | end 47 | 48 | describe 'server commands' do 49 | let(:pidfile_path) { path.join('data', 'neo4j-service.pid') } 50 | 51 | def server_up(port) 52 | open("http://localhost:#{port}/browser/") 53 | true 54 | rescue Errno::ECONNREFUSED 55 | false 56 | end 57 | 58 | before(:each) do 59 | if server_up(neo4j_port) 60 | raise "There is a server already running on port #{neo4j_port}. Can't run spec" 61 | end 62 | 63 | if path.exist? 64 | message = 'DB temporary directory already exists! ' 65 | message += "Delete #{path} if safe to do so and then proceed" 66 | 67 | raise message 68 | end 69 | end 70 | 71 | after(:each) do 72 | pid_path = path.join('data', 'neo4j-service.pid') 73 | if pid_path.exist? 74 | pid = pid_path.read.to_i 75 | Process.kill('TERM', pid) 76 | begin 77 | sleep(1) while Process.kill(0, pid) 78 | rescue Errno::ESRCH 79 | nil 80 | end 81 | end 82 | path.rmtree 83 | end 84 | 85 | let(:neo4j_port) { 7474 } 86 | 87 | def open_session(port) 88 | Neo4j::Session.open(:server_db, "http://localhost:#{port}") 89 | end 90 | 91 | let(:neo4j_session) { open_session(neo4j_port) } 92 | 93 | def install(server_manager, edition = 'community-latest') 94 | tempfile = Tempfile.new("neo4j-#{edition}") 95 | 96 | neo4j_archive = 'spec/files/neo4j-community-2.2.3-unix.tar.gz' 97 | FileUtils.cp(neo4j_archive, tempfile.path) 98 | 99 | expect(server_manager) 100 | .to receive(:download_neo4j).and_return(tempfile.path) 101 | expect(server_manager) 102 | .to receive(:version_from_edition).and_return('community-2.2.3') 103 | 104 | # VCR.use_cassette('neo4j-install') do 105 | server_manager.install(edition) 106 | # end 107 | end 108 | 109 | describe '#install' do 110 | it 'should install' do 111 | install(server_manager) 112 | end 113 | end 114 | 115 | describe '#start' do 116 | before(:each) do 117 | install(server_manager) 118 | end 119 | 120 | it 'should start' do 121 | expect(pidfile_path).not_to exist 122 | 123 | server_manager.start 124 | 125 | expect(pidfile_path).to exist 126 | 127 | pid = pidfile_path.read.to_i 128 | expect(Process.kill(0, pid)).to be 1 129 | 130 | server_manager.stop 131 | end 132 | end 133 | 134 | describe '#stop' do 135 | before(:each) do 136 | install(server_manager) 137 | 138 | server_manager.start 139 | end 140 | 141 | it 'should stop a started instance' do 142 | expect(pidfile_path).to exist 143 | pid = pidfile_path.read.to_i 144 | expect(Process.kill(0, pid)).to be 1 145 | 146 | server_manager.stop 147 | 148 | expect(pidfile_path).not_to exist 149 | expect { Process.kill(0, pid) }.to raise_error Errno::ESRCH 150 | end 151 | end 152 | 153 | describe '#reset' do 154 | before(:each) do 155 | install(server_manager) 156 | server_manager.config_auth_enabeled!(false) 157 | 158 | server_manager.start 159 | end 160 | 161 | it 'should wipe out the data' do 162 | open_session(neo4j_port).query("CREATE (:User {name: 'Bob'})") 163 | 164 | expect do 165 | server_manager.reset 166 | end.to change { open_session(neo4j_port).query('MATCH (u:User) RETURN count(u) AS count').first.count }.from(1).to(0) 167 | 168 | server_manager.stop 169 | end 170 | end 171 | 172 | describe '#config' do 173 | before(:each) do 174 | install(server_manager) 175 | 176 | server_manager.config_auth_enabeled!(false) 177 | server_manager.config_port!(neo4j_port) 178 | 179 | server_manager.start 180 | end 181 | 182 | context 'port 7470' do 183 | let(:neo4j_port) { 7470 } 184 | 185 | it 'should configure the port' do 186 | expect { open_session(7474) } 187 | .to raise_error Faraday::ConnectionFailed 188 | 189 | expect { open_session(neo4j_port) }.not_to raise_error 190 | 191 | server_manager.stop 192 | end 193 | end 194 | end 195 | 196 | describe '#download_url' do 197 | it 'should return default neo4j download url' do 198 | ENV['NEO4J_DIST'] = nil 199 | expect(server_manager.send(:download_url, 'community-9.9.9')) 200 | .to eq('http://dist.neo4j.org/neo4j-community-9.9.9-unix.tar.gz') 201 | end 202 | 203 | it 'should return custom neo4j download url' do 204 | ENV['NEO4J_DIST'] = 'file://custom-location/neo4j-VERSION-unix.tar.gz' 205 | expect(server_manager.send(:download_url, 'community-9.9.9')) 206 | .to eq('file://custom-location/neo4j-community-9.9.9-unix.tar.gz') 207 | ENV['NEO4J_DIST'] = nil 208 | end 209 | end 210 | end 211 | end 212 | end 213 | end 214 | --------------------------------------------------------------------------------