Skip to content

Commit

Permalink
all specs pass
Browse files Browse the repository at this point in the history
  • Loading branch information
klobuczek committed Oct 24, 2019
1 parent c8c3833 commit 299be3a
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 182 deletions.
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Layout/EmptyLineBetweenDefs:
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- 'bin/neo4j-jars'
- 'lib/neo4j/migration.rb'
- 'lib/neo4j/migrations/runner.rb'
- 'lib/neo4j/model_schema.rb'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gemspec
branch = ENV['NEO4J_CORE_BRANCH'] || ENV['TRAVIS_PULL_REQUEST_BRANCH'] || ENV['TRAVIS_BRANCH']
slug = !ENV['TRAVIS_PULL_REQUEST_SLUG'].to_s.empty? ? ENV['TRAVIS_PULL_REQUEST_SLUG'] : ENV['TRAVIS_REPO_SLUG']

# gem 'neo4j-ruby-driver', path: '../neo4j-ruby-driver'

gem 'listen', '< 3.1'

active_model_version = ENV['ACTIVE_MODEL_VERSION']
Expand Down
33 changes: 0 additions & 33 deletions bin/neo4j-jars

This file was deleted.

9 changes: 5 additions & 4 deletions lib/neo4j/core/cypher_session/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'neo4j/core/cypher_session/query_builder'
require 'neo4j/core/cypher_session/has_uri'
require 'neo4j/core/cypher_session/schema'
require 'neo4j/core/cypher_session/responses'

module Neo4j
module Core
Expand All @@ -18,6 +19,7 @@ class Driver
include Neo4j::Core::Instrumentable
include HasUri
include Schema
include Responses

USER_AGENT_STRING = "neo4j-gem/#{::Neo4j::VERSION} (https://github.com/neo4jrb/neo4j)"

Expand Down Expand Up @@ -126,11 +128,10 @@ def close
def query_set(transaction, queries, options = {})
setup_queries!(queries, transaction, skip_instrumentation: options[:skip_instrumentation])

responses = queries.map do |query|
transaction.root_tx.run(query.cypher, query.parameters)
self.wrap_level = options[:wrap_level] || @options[:wrap_level] || Neo4j::Core::Config.wrapping_level
queries.map do |query|
result_from_data(transaction.root_tx.run(query.cypher, query.parameters))
end
wrap_level = options[:wrap_level] || @options[:wrap_level]
Responses.new(responses, wrap_level: wrap_level).to_a
rescue Neo4j::Driver::Exceptions::Neo4jException => e
raise Neo4j::Core::CypherSession::CypherError.new_from(e.code, e.message) # , e.stack_track.to_a
end
Expand Down
33 changes: 14 additions & 19 deletions lib/neo4j/core/cypher_session/responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
module Neo4j
module Core
module CypherSession
class Responses
include Enumerable
module Responses
extend ActiveSupport::Concern

def initialize(responses, options = {})
@responses = responses
@wrap_level = options[:wrap_level] || Neo4j::Core::Config.wrapping_level
included do
attr_accessor :wrap_level
end

def each
@responses.each do |response|
yield result_from_data(response)
end
end

private

def result_from_data(entities_data)
rows = entities_data.map do |entity_data|
wrap(entity_data.values)
Expand All @@ -27,27 +18,31 @@ def result_from_data(entities_data)
Neo4j::Core::CypherSession::Result.new(entities_data.keys, rows)
end

private

def wrap(value)
case value
when Array
value.map(&method(:wrap))
when Hash
value.map { |key, val| [key, wrap(val)] }.to_h
when Neo4j::Driver::Types::Entity
wrap_by_level(value)
when Neo4j::Driver::Types::Path
value
when Hash
value.map { |key, val| [key, wrap(val)] }.to_h
when Enumerable
value.map(&method(:wrap))
else
value
end
end

def wrap_by_level(entity)
case @wrap_level
case wrap_level
when :core_entity
entity
when :proc
entity.wrap
else
fail ArgumentError, "Invalid wrap_level: #{@wrap_level.inspect}"
fail ArgumentError, "Invalid wrap_level: #{wrap_level.inspect}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Neo4j
VERSION = '9.6.0'
VERSION = '10.0.0-alpha.1'
end
2 changes: 1 addition & 1 deletion neo4j.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DESCRIPTION

s.require_path = 'lib'
s.files = Dir.glob('{bin,lib,config}/**/*') + %w(README.md CHANGELOG.md CONTRIBUTORS Gemfile neo4j.gemspec)
s.executables = ['neo4j-jars']
s.executables = []
s.extra_rdoc_files = %w( README.md )
s.rdoc_options = ['--quiet', '--title', 'Neo4j.rb', '--line-numbers', '--main', 'README.rdoc', '--inline-source']
s.metadata = {
Expand Down
31 changes: 0 additions & 31 deletions spec/e2e/active_rel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,37 +465,6 @@ class ActiveRelSpecTypesInheritedRelClass < ActiveRelSpecTypesAutomaticRelType
expect(new_rel.to_node).not_to receive(:loaded)
expect { new_rel.inspect }.not_to raise_error
end

context 'single from/to class' do
it 'inserts the class names in String' do
next if Neo4j::VERSION >= '6.0.0'
expect(new_rel.inspect).to include('(FromClass)-[:rel_class_type]->(ToClass)')
end
end

context 'array of from/to class' do
before { MyRelClass.from_class([:FromClass, :ToClass]) }

it 'joins with ||' do
next if Neo4j::VERSION >= '6.0.0'
expect(new_rel.inspect).to include('(FromClass || ToClass)-[:rel_class_type]->(ToClass)')
end
end
end

context 'with set, unloaded from_node/to_node' do
let(:new_rel) { MyRelClass.create(from_node: from_node, to_node: to_node) }
let(:reloaded) { Neo4j::Relationship.load(new_rel.id) }
let(:inspected) { reloaded.inspect }

# Neo4j Embedded always returns nodes with rels. This is only possible in Server mode.
it 'notes the ids of the nodes' do
next if Neo4j::VERSION >= '6.0.0'
next if TEST_SESSION_MODE == :embedded
[from_node.neo_id, to_node.neo_id].each do |id|
expect(inspected).to include("(Node with neo_id #{id})")
end
end
end
end

Expand Down
14 changes: 5 additions & 9 deletions spec/e2e/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,14 @@
context 'when using `ActionController::Parameters`' do
let(:params) { action_controller_params('type' => 'image').permit! }
it 'assigns enums correctly when instancing a new class' do
using_action_controller do
file = StoredFile.new(params)
expect(file.type).to eq('image')
end
file = StoredFile.new(params)
expect(file.type).to eq('image')
end

it 'assigns enums correctly when assigning to `attributes`' do
using_action_controller do
file = StoredFile.new
file.attributes = params
expect(file.type).to eq('image')
end
file = StoredFile.new
file.attributes = params
expect(file.type).to eq('image')
end
end

Expand Down
4 changes: 1 addition & 3 deletions spec/e2e/marshal_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe Neo4j::Shared::Marshal do
describe Neo4j::Shared::Marshal, :ffi do
describe 'ActiveNode' do
before do
stub_active_node_class('Parent')
Expand All @@ -11,7 +11,6 @@
let(:node) { Child.create(foo: 'bar') }

it 'marshals correctly' do
pending "Java type is not serializable, cannot be marshaled. Is this really necessary"
id = node.id
neo_id = node.neo_id
unmarshaled = Marshal.load(Marshal.dump(node))
Expand Down Expand Up @@ -40,7 +39,6 @@
let(:rel) { HasParent.create(Person.create, Person.create, foo: 'bar') }

it 'marshals correctly' do
pending "Java type is not serializable, cannot be marshaled. Is this really necessary"
neo_id = rel.neo_id
unmarshaled = Marshal.load(Marshal.dump(rel))

Expand Down
37 changes: 0 additions & 37 deletions spec/neo4j_spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,6 @@ def action_controller_params(args)
ActionController::Parameters.new(args)
end

def handle_child_output(read, write)
read.close
begin
rest = yield
write.puts [Marshal.dump(rest)].pack('m')
rescue StandardError => e
write.puts [Marshal.dump(e)].pack('m')
end
exit!
end

def do_in_child(&block)
read, write = IO.pipe
pid = fork do
handle_child_output(read, write, &block)
end
write.close
result = Marshal.load(read.read.unpack('m').first)
Process.wait2(pid)

fail result if result.class < Exception
result
end

# A trick to load action_controller without requiring in all specs. Not working in JRuby.
def using_action_controller
if RUBY_PLATFORM == 'java'
require 'action_controller'
yield
else
do_in_child do
require 'action_controller'
yield
end
end
end

class_methods do
def let_config(var_name, value)
around do |example|
Expand Down
44 changes: 14 additions & 30 deletions spec/shared_examples/forbidden_attributes_shared_examples.rb
Original file line number Diff line number Diff line change
@@ -1,63 +1,47 @@
shared_examples 'handles permitted parameters' do
describe '#new' do
it 'assigns permitted params' do
using_action_controller do
params.permit!
expect(klass.new(create_params).attributes).to include(params.to_h)
end
params.permit!
expect(klass.new(create_params).attributes).to include(params.to_h)
end

it 'fails on unpermitted parameters' do
using_action_controller do
expect { klass.new(create_params) }.to raise_error ActiveModel::ForbiddenAttributesError
end
expect { klass.new(create_params) }.to raise_error ActiveModel::ForbiddenAttributesError
end
end

describe '#create' do
it 'assigns permitted params' do
using_action_controller do
params.permit!
expect(klass.create(create_params).attributes).to include(params.to_h)
end
params.permit!
expect(klass.create(create_params).attributes).to include(params.to_h)
end

it 'fails on unpermitted parameters' do
using_action_controller do
expect { klass.create(create_params) }.to raise_error ActiveModel::ForbiddenAttributesError
end
expect { klass.create(create_params) }.to raise_error ActiveModel::ForbiddenAttributesError
end
end

describe '#attributes=' do
it 'assigns permitted params' do
using_action_controller do
params.permit!
subject.attributes = params
expect(subject.attributes).to include(params.to_h)
end
params.permit!
subject.attributes = params
expect(subject.attributes).to include(params.to_h)
end

it 'fails on unpermitted parameters' do
using_action_controller do
expect { subject.attributes = params }.to raise_error ActiveModel::ForbiddenAttributesError
end
expect { subject.attributes = params }.to raise_error ActiveModel::ForbiddenAttributesError
end
end

describe '#update' do
it 'assigns permitted params' do
using_action_controller do
params.permit!
subject.update(params)
expect(subject.attributes).to include(params.to_h)
end
params.permit!
subject.update(params)
expect(subject.attributes).to include(params.to_h)
end

it 'fails on unpermitted parameters' do
using_action_controller do
expect { klass.new.update(params) }.to raise_error ActiveModel::ForbiddenAttributesError
end
expect { klass.new.update(params) }.to raise_error ActiveModel::ForbiddenAttributesError
end
end
end
Loading

0 comments on commit 299be3a

Please sign in to comment.