diff --git a/CHANGELOG.md b/CHANGELOG.md index 53eaeb669..1292f7dc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,10 @@ All notable changes to this project will be documented in this file. This file should follow the standards specified on [http://keepachangelog.com/] This project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleaed] +## [Unreleased] + +### Changed +- `_classname` property has been completely removed, officially dropping support for Neo4j < 2.1.5. ### Added diff --git a/lib/neo4j/active_node/has_n/association.rb b/lib/neo4j/active_node/has_n/association.rb index ed77c415b..e099562f5 100644 --- a/lib/neo4j/active_node/has_n/association.rb +++ b/lib/neo4j/active_node/has_n/association.rb @@ -128,12 +128,6 @@ def relationship_class @relationship_class ||= @relationship_class_name && @relationship_class_name.constantize end - def inject_classname(properties) - return properties unless relationship_class - properties[Neo4j::Config.class_name_property] = relationship_class_name if relationship_class.cached_class?(true) - properties - end - def unique? return relationship_class.unique? if rel_class? @origin ? origin_association.unique? : !!@unique diff --git a/lib/neo4j/active_node/node_wrapper.rb b/lib/neo4j/active_node/node_wrapper.rb index d33c62bc5..bae70d474 100644 --- a/lib/neo4j/active_node/node_wrapper.rb +++ b/lib/neo4j/active_node/node_wrapper.rb @@ -15,7 +15,7 @@ def wrapper def class_to_wrap load_classes_from_labels - (named_class || ::Neo4j::ActiveNode::Labels.model_for_labels(labels)).tap do |model_class| + Neo4j::ActiveNode::Labels.model_for_labels(labels).tap do |model_class| Neo4j::Node::Wrapper.populate_constants_for_labels_cache(model_class, labels) end end @@ -48,11 +48,5 @@ def self.populate_constants_for_labels_cache(model_class, labels) def self.association_model_namespace Neo4j::Config.association_model_namespace_string end - - def named_class - property = Neo4j::Config.class_name_property - - Neo4j::Node::Wrapper.constant_for_label(self.props[property]) if self.props.is_a?(Hash) && self.props.key?(property) - end end end diff --git a/lib/neo4j/active_node/query/query_proxy.rb b/lib/neo4j/active_node/query/query_proxy.rb index 7f5a73029..6ffeb648c 100644 --- a/lib/neo4j/active_node/query/query_proxy.rb +++ b/lib/neo4j/active_node/query/query_proxy.rb @@ -178,8 +178,6 @@ def create(other_nodes, properties) fail 'Can only create relationships on associations' if !@association other_nodes = _nodeify!(*other_nodes) - properties = @association.inject_classname(properties) - Neo4j::Transaction.run do other_nodes.each do |other_node| other_node.save unless other_node.neo_id @@ -221,7 +219,7 @@ def _create_relationship_with_rel_class(other_node_or_nodes, properties) Array(other_node_or_nodes).each do |other_node| node_props = (association.direction == :in) ? {from_node: other_node, to_node: @start_object} : {from_node: @start_object, to_node: other_node} - association.relationship_class.create(properties.except(:_classname).merge(node_props)) + association.relationship_class.create(properties.merge(node_props)) end end diff --git a/lib/neo4j/active_rel/rel_wrapper.rb b/lib/neo4j/active_rel/rel_wrapper.rb index cf4bb64c0..191ffc443 100644 --- a/lib/neo4j/active_rel/rel_wrapper.rb +++ b/lib/neo4j/active_rel/rel_wrapper.rb @@ -3,7 +3,7 @@ module Wrapper def wrapper props.symbolize_keys! begin - most_concrete_class = sorted_wrapper_classes + most_concrete_class = class_from_type wrapped_rel = most_concrete_class.constantize.new rescue NameError return self @@ -15,10 +15,6 @@ def wrapper private - def sorted_wrapper_classes - props[Neo4j::Config.class_name_property] || class_from_type - end - def class_from_type Neo4j::ActiveRel::Types::WRAPPED_CLASSES[rel_type] || Neo4j::ActiveRel::Types::WRAPPED_CLASSES[rel_type] = rel_type.camelize end diff --git a/lib/neo4j/active_rel/types.rb b/lib/neo4j/active_rel/types.rb index dc8245807..d73f54cd1 100644 --- a/lib/neo4j/active_rel/types.rb +++ b/lib/neo4j/active_rel/types.rb @@ -15,9 +15,6 @@ module Types # # A model is added to WRAPPED_CLASSES when it is initalized AND when the `type` class method is called within a model. This means that # it's possible a model will be added twice: once with the rel_type version of the model name, again with the custom type. deal_with_it.gif. - # - # As an alternative to this, you can call the `set_classname` class method to insert a `_classname` property into your relationship, - # which will completely bypass this whole process. WRAPPED_CLASSES = {} included do @@ -76,7 +73,7 @@ def rel_type? def assign_type!(given_type, auto) @rel_type = (auto ? decorated_rel_type(given_type) : given_type).tap do |type| - add_wrapped_class(type) unless uses_classname? + add_wrapped_class(type) end end end diff --git a/lib/neo4j/config.rb b/lib/neo4j/config.rb index e5f00c00a..8c9cf3a7b 100644 --- a/lib/neo4j/config.rb +++ b/lib/neo4j/config.rb @@ -96,10 +96,6 @@ def to_yaml configuration.to_yaml end - def class_name_property - @_class_name_property = Neo4j::Config[CLASS_NAME_PROPERTY_KEY] || :_classname - end - def include_root_in_json # we use ternary because a simple || will always evaluate true Neo4j::Config[:include_root_in_json].nil? ? true : Neo4j::Config[:include_root_in_json] diff --git a/lib/neo4j/migration.rb b/lib/neo4j/migration.rb index f18734a81..1162aef45 100644 --- a/lib/neo4j/migration.rb +++ b/lib/neo4j/migration.rb @@ -123,97 +123,5 @@ def new_id_for(model) end end end - - class AddClassnames < Neo4j::Migration - def initialize(path = default_path) - @classnames_filename = 'add_classnames.yml' - @classnames_filepath = File.join(joined_path(path), classnames_filename) - end - - def migrate - output 'Adding classnames. This make take some time.' - execute(true) - end - - def test - output 'TESTING! No queries will be executed.' - execute(false) - end - - def setup - output "Creating file #{classnames_filepath}. Please use this as the migration guide." - FileUtils.mkdir_p('db/neo4j-migrate') - - return if File.file?(classnames_filepath) - - source = File.join(File.dirname(__FILE__), '..', '..', 'config', 'neo4j', classnames_filename) - FileUtils.copy_file(source, classnames_filepath) - end - - private - - attr_reader :classnames_filename, :classnames_filepath, :model_map - - def execute(migrate = false) - file_init - map = [] - map.push :nodes if model_map[:nodes] - map.push :relationships if model_map[:relationships] - map.each do |type| - model_map[type].each do |action, labels| - do_classnames(action, labels, type, migrate) - end - end - end - - def do_classnames(action, labels, type, migrate = false) - method = type == :nodes ? :node_cypher : :rel_cypher - labels.each do |label| - output cypher = self.send(method, label, action) - execute_cypher(cypher) if migrate - end - end - - def file_init - @model_map = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(classnames_filepath)) - end - - def node_cypher(label, action) - where, phrase_start = action_variables(action, 'n') - output "#{phrase_start} _classname '#{label}' on nodes with matching label:" - "MATCH (n:`#{label}`) #{where} SET n._classname = '#{label}' RETURN COUNT(n) as modified" - end - - def rel_cypher(hash, action) - label = hash[0] - value = hash[1] - from = value[:from] - fail "All relationships require a 'type'" unless value[:type] - - from_cypher = from ? "(from:`#{from}`)" : '(from)' - to = value[:to] - to_cypher = to ? "(to:`#{to}`)" : '(to)' - type = "[r:`#{value[:type]}`]" - where, phrase_start = action_variables(action, 'r') - output "#{phrase_start} _classname '#{label}' where type is '#{value[:type]}' using cypher:" - "MATCH #{from_cypher}-#{type}->#{to_cypher} #{where} SET r._classname = '#{label}' return COUNT(r) as modified" - end - - def execute_cypher(query_string) - output "Modified #{Neo4j::Session.query(query_string).first.modified} records" - output '' - end - - def action_variables(action, identifier) - case action - when 'overwrite' - ['', 'Overwriting'] - when 'add' - ["WHERE NOT HAS(#{identifier}._classname)", 'Adding'] - else - fail "Invalid action #{action} specified" - end - end - end end end diff --git a/lib/neo4j/shared/persistence.rb b/lib/neo4j/shared/persistence.rb index aa1bf1ee6..dca8159df 100644 --- a/lib/neo4j/shared/persistence.rb +++ b/lib/neo4j/shared/persistence.rb @@ -2,8 +2,6 @@ module Neo4j::Shared module Persistence extend ActiveSupport::Concern - USES_CLASSNAME = [] - # @return [Hash] Given a node's state, will call the appropriate `props_for_{action}` method. def props_for_persistence _persisted_obj ? props_for_update : props_for_create @@ -18,7 +16,6 @@ def update_model # Returns a hash containing: # * All properties and values for insertion in the database # * A `uuid` (or equivalent) key and value - # * A `_classname` property, if one is to be set # * Timestamps, if the class is set to include them. # Note that the UUID is added to the hash but is not set on the node. # The timestamps, by comparison, are set on the node prior to addition in this hash. @@ -27,7 +24,6 @@ def props_for_create inject_timestamps! props_with_defaults = inject_defaults!(props) converted_props = props_for_db(props_with_defaults) - inject_classname!(converted_props) return converted_props unless self.class.respond_to?(:default_property_values) inject_primary_key!(converted_props) end @@ -187,61 +183,16 @@ def update_magic_properties self.updated_at = DateTime.now if respond_to?(:updated_at=) && (updated_at.nil? || (changed? && !updated_at_changed?)) end - # Inserts the _classname property into an object's properties during object creation. - def inject_classname!(props, check_version = true) - props[:_classname] = self.class.name if self.class.cached_class?(check_version) - end - - def set_classname(props, check_version = true) - warning = 'This method has been replaced with `inject_classname!` and will be removed in a future version'.freeze - ActiveSupport::Deprecation.warn warning, caller - inject_classname!(props, check_version) - end - def inject_timestamps! now = DateTime.now self.created_at ||= now if respond_to?(:created_at=) self.updated_at ||= now if respond_to?(:updated_at=) end - - def set_timestamps warning = 'This method has been replaced with `inject_timestamps!` and will be removed in a future version'.freeze ActiveSupport::Deprecation.warn warning, caller inject_timestamps! end - - module ClassMethods - # Determines whether a model should insert a _classname property. This can be used to override the automatic matching of returned - # objects to models. - def cached_class?(check_version = true) - uses_classname? || (!!Neo4j::Config[:cache_class_names] && (check_version ? neo4j_session.version < '2.1.5' : true)) - end - - # @return [Boolean] status of whether this model will add a _classname property - def uses_classname? - Neo4j::Shared::Persistence::USES_CLASSNAME.include?(self.name) - end - - # Adds this model to the USES_CLASSNAME array. When new rels/nodes are created, a _classname property will be added. This will override the - # automatic matching of label/rel type to model. - # - # You'd want to do this if you have multiple models for the same label or relationship type. When it comes to labels, there isn't really any - # reason to do this because you can have multiple labels; on the other hand, an argument can be made for doing this with relationships since - # rel type is a bit more restrictive. - # - # It could also be speculated that there's a slight performance boost to using _classname since the gem immediately knows what model is responsible - # for a returned object. At the same time, it is a bit restrictive and changing it can be a bit of a PITA. Use carefully! - def set_classname - Neo4j::Shared::Persistence::USES_CLASSNAME << self.name - end - - # Removes this model from the USES_CLASSNAME array. When new rels/nodes are create, no _classname property will be injected. Upon returning of - # the object from the database, it will be matched to a model using its relationship type or labels. - def unset_classname - Neo4j::Shared::Persistence::USES_CLASSNAME.delete self.name - end - end end end diff --git a/spec/e2e/active_model_spec.rb b/spec/e2e/active_model_spec.rb index 870af7847..585a5454e 100644 --- a/spec/e2e/active_model_spec.rb +++ b/spec/e2e/active_model_spec.rb @@ -328,75 +328,6 @@ def true_results?(node, verb) end end - describe 'cached classnames' do - after(:all) { Neo4j::Config[:cache_class_names] = true } - before do - stub_const('CacheTest', UniqueClass.create do - include Neo4j::ActiveNode - end) - end - - context 'with cache_class set in config' do - before { Neo4j::Session.current.class.any_instance.stub(version: db_version) } - - before do - Neo4j::Config[:cache_class_names] = true - @cached = CacheTest.create - @unwrapped = Neo4j::Node._load(@cached.neo_id) - end - - context 'server version 2.1.4' do - let(:db_version) { '2.1.4' } - - it 'responds true to :cached_class?' do - expect(CacheTest.cached_class?).to be_truthy - end - - it 'sets _classname property equal to class name' do - expect(@unwrapped[:_classname]).to eq @cached.class.name - end - - it 'removes the _classname property from the wrapped class' do - expect(@cached.props).to_not have_key(:_classname) - end - end - - context 'server version 2.1.5' do - let(:db_version) { '2.1.5' } - - it 'responds false to :cached_class?' do - expect(CacheTest.cached_class?).to be_falsey - end - - it 'does not set _classname' do - expect(@unwrapped[:_classname]).to be_nil - end - - it 'removes the _classname property from the wrapped class' do - expect(@cached.props).to_not have_key(:_classname) - end - end - end - - context 'without cache_class set in model' do - before do - Neo4j::Config[:cache_class_names] = false - @uncached = CacheTest.create - @unwrapped = Neo4j::Node._load(@uncached.neo_id) - end - - before { Neo4j::Config[:cache_class_names] = false } - - it 'response false to :cached_class?' do - expect(CacheTest.cached_class?).to be_falsey - end - - it 'does not set _classname on the node' do - expect(@unwrapped.props).to_not have_key(:_classname) - end - end - end - before(:each) do stub_active_node_class('Person') do property :name diff --git a/spec/e2e/classname_spec.rb b/spec/e2e/classname_spec.rb deleted file mode 100644 index 278005f7d..000000000 --- a/spec/e2e/classname_spec.rb +++ /dev/null @@ -1,138 +0,0 @@ -require 'spec_helper' - -describe '_classname property' do - before(:each) do - Neo4j::ActiveRel::Types::WRAPPED_CLASSES.clear - - stub_active_node_class('Student') do - property :name - - has_many :out, :lessons, model_class: 'Lesson', rel_class: 'EnrolledIn' - has_many :out, :lessons_with_type, model_class: 'Lesson', rel_class: 'StudentLesson' - has_many :out, :lessons_with_classname, model_class: 'Lesson', rel_class: 'EnrolledInClassname' - end - - stub_active_node_class('Lesson') do - property :subject - end - - stub_active_node_class('NodeWithClassname') do - set_classname - end - - stub_active_rel_class('EnrolledIn') do - from_class 'Student' - to_class 'Lesson' - end - - stub_active_rel_class('StudentLesson') do - from_class 'Student' - to_class 'Lesson' - type 'ENROLLED_IN_SPECIAL' - end - - stub_active_rel_class('EnrolledInClassname') do - from_class 'Student' - to_class 'Lesson' - type 'ENROLLED_IN' - set_classname - end - end - - before(:each) do - @billy = Student.create(name: 'Billy') - @science = Lesson.create(subject: 'Science') - @math = Lesson.create(subject: 'Math') - @history = Lesson.create(subject: 'History') - - EnrolledIn.create(from_node: @billy, to_node: @science) - StudentLesson.create(from_node: @billy, to_node: @math) - EnrolledInClassname.create(from_node: @billy, to_node: @history) - end - - after(:each) do - [Lesson, Student].each(&:delete_all) - end - - # these specs will fail if tested against Neo4j < 2.1.5 - describe 'neo4j 2.1.5+' do - describe 'ActiveNode models' do - it 'does not add _classname to nodes by default' do - expect(@billy._persisted_obj.props).not_to have_key(:_classname) - end - - it 'adds _classname when `set_classname` is called' do - node = NodeWithClassname.create - expect(node._persisted_obj.props).to have_key(:_classname) - end - end - - context 'without _classname or type' do - let(:rel) { @billy.lessons.first_rel_to(@science) } - - it 'does not add a classname property' do - expect(rel._persisted_obj.props).not_to have_key(:_classname) - end - - it 'is the expected type' do - expect(rel).to be_a(EnrolledIn) - end - end - - context 'without classname, with type' do - let(:rel) { @billy.lessons_with_type.first_rel_to(@math) } - - it 'does not add a classname property' do - expect(rel._persisted_obj.props).not_to have_key(:_classname) - end - - it 'is the expected type' do - expect(rel).to be_a(StudentLesson) - end - end - - context 'with classname and type' do - let(:rel) { @billy.lessons_with_classname.first_rel_to(@history) } - - it 'adds a classname property' do - expect(rel._persisted_obj.props).to have_key(:_classname) - end - - it 'is the expected type' do - expect(rel).to be_a(EnrolledInClassname) - end - end - end - - describe 'neo4j 2.1.4' do - let(:session) { Neo4j::Session.current } - before do - expect(session).to receive(:version).at_least(1).times.and_return('2.1.4') - - @billy = Student.create(name: 'Billy') - @science = Lesson.create(subject: 'Science') - @math = Lesson.create(subject: 'Math') - @history = Lesson.create(subject: 'History') - - EnrolledIn.create(from_node: @billy, to_node: @science) - StudentLesson.create(from_node: @billy, to_node: @math) - EnrolledInClassname.create(from_node: @billy, to_node: @history) - end - - it 'always adds _classname and is of the expected class' do - expect(@billy._persisted_obj.props).to have_key(:_classname) - - science_rel = @billy.lessons.first_rel_to(@science) - expect(science_rel._persisted_obj.props).to have_key(:_classname) - expect(science_rel).to be_a(EnrolledIn) - - math_rel = @billy.lessons_with_type.first_rel_to(@math) - expect(math_rel._persisted_obj.props).to have_key(:_classname) - expect(math_rel).to be_a(StudentLesson) - - history_rel = @billy.lessons_with_classname.first_rel_to(@history) - expect(history_rel._persisted_obj.props).to have_key(:_classname) - expect(history_rel).to be_a(EnrolledInClassname) - end - end -end diff --git a/spec/e2e/migration_spec.rb b/spec/e2e/migration_spec.rb index 27dca6665..1b9aae774 100644 --- a/spec/e2e/migration_spec.rb +++ b/spec/e2e/migration_spec.rb @@ -42,7 +42,6 @@ class SecondRelClass from_class false to_class false type 'singers' - set_classname end class ThirdRelClass @@ -51,10 +50,6 @@ class ThirdRelClass to_class false type 'singers' end - - def self.classname_count(label) - proc { Neo4j::Session.query("MATCH (n:`#{label}`) WHERE n._classname = '#{label}' RETURN COUNT(n) as countable").first.countable } - end end end @@ -119,73 +114,4 @@ def self.classname_count(label) expect(user.neo_id).to eq neo_id end end - - describe 'AddClassnames class' do - let(:full_path) { '/hd/gems/rails/add_classnames.yml' } - let(:clazz) { Neo4j::Migration::AddClassnames } - let(:map_template) do - { - nodes: {'add' => ['MigrationSpecs::User'], 'overwrite' => ['MigrationSpecs::Song']}, - relationships: { - 'add' => {'MigrationSpecs::FirstRelClass' => {type: 'songs'}}, - 'overwrite' => {'MigrationSpecs::ThirdRelClass' => {type: 'singers'}} - } - } - end - let(:tony) { MigrationSpecs::User.create(name: 'Tony') } - let(:ronnie) { MigrationSpecs::User.create(name: 'Ronnie') } - let(:children) { MigrationSpecs::Song.create(name: 'Children of the Sea') } - let(:neon) { MigrationSpecs::Song.create(name: 'Neon Knights') } - - before do - Rails.stub_chain(:root, :join).and_return('/hd/gems/rails/add_classnames.yml') - YAML.stub(:load_file).and_return(map_template) - clazz.any_instance.stub(:file_init).and_return(map_template) - clazz.any_instance.stub(:model_map).and_return(map_template) - clazz.any_instance.instance_variable_set(:@model_map, map_template) - end - - after(:each) { [MigrationSpecs::User, MigrationSpecs::Song].each(&:delete_all) } - - it 'loads an initialization file' do - expect { clazz.new }.not_to raise_error - end - - describe 'nodes' do - it 'adds given classname to nodes' do - Neo4j::Session.query('CREATE (n:`MigrationSpecs::User`) set n.name = "Geezer" return n') - geezer_query = MigrationSpecs.classname_count('MigrationSpecs::User') - expect(geezer_query.call).to eq 0 - clazz.new.migrate - expect(geezer_query.call).to eq 1 - end - - it 'replaces given classnames' do - Neo4j::Session.query('CREATE (n:`MigrationSpecs::Song`) set n.name = "Country Girl", n._classname = "Wrong" return n') - country_query = MigrationSpecs.classname_count('MigrationSpecs::Song') - expect(country_query.call).to eq 0 - clazz.new.migrate - expect(country_query.call).to eq 1 - end - end - - describe 'relationships' do - it 'adds given classnames to rels' do - tony.songs << children - expect(tony.songs(:s, :r).pluck(:r).first._persisted_obj.props).not_to have_key(:_classname) - expect(tony.songs.first).to eq children - clazz.new.migrate - expect(tony.songs(:s, :r).pluck(:r).first._persisted_obj.props).to have_key(:_classname) - end - - it 'overwrites given classnames on rels' do - neon.singers << ronnie - expect(neon.singers(:o).pluck(:o).first).to eq ronnie - expect(neon.singers(:o, :r).pluck(:r).first).to be_a(MigrationSpecs::SecondRelClass) - clazz.new.migrate - expect(neon.new_singers(:o).pluck(:o).first).to eq ronnie - expect(neon.new_singers(:o, :r).pluck(:r).first).to be_a(MigrationSpecs::ThirdRelClass) - end - end - end end diff --git a/spec/integration/node_persistence_spec.rb b/spec/integration/node_persistence_spec.rb index 344ee2dd6..6ffd86d2b 100644 --- a/spec/integration/node_persistence_spec.rb +++ b/spec/integration/node_persistence_spec.rb @@ -13,7 +13,6 @@ class MyThing before do SecureRandom.stub(:uuid) { 'secure123' } - MyThing.stub(:cached_class?).and_return(false) Neo4j::Session.stub(:current).and_return(session) end diff --git a/spec/unit/active_node/persistance_spec.rb b/spec/unit/active_node/persistance_spec.rb index 20f3a5c06..b6ff93dbb 100644 --- a/spec/unit/active_node/persistance_spec.rb +++ b/spec/unit/active_node/persistance_spec.rb @@ -42,7 +42,6 @@ def self.fetch_upstream_primitive(_) o = clazz.new(name: 'kalle', age: '42') o.stub(:serialized_properties).and_return({}) allow_any_instance_of(Object).to receive(:serialized_properties_keys).and_return([]) - clazz.stub(:cached_class?).and_return(false) clazz.should_receive(:neo4j_session).and_return(session) clazz.should_receive(:mapped_label_names).and_return(:MyClass) node.should_receive(:props).and_return(name: 'kalle2', age: '43') @@ -70,30 +69,6 @@ def self.fetch_upstream_primitive(_) expect(node).to receive(:update_props).and_return(name: 'sune') o.save end - - describe 'with cached_class? true' do - it 'adds a _classname property' do - clazz.stub(:default_property_values).and_return({}) - clazz.stub(:cached_class?).and_return(true) - start_props = {name: 'jasmine', age: 5} - end_props = {name: 'jasmine', age: 5, _classname: 'MyClass'} - o = clazz.new - - o.stub(:props).and_return(start_props) - o.stub(:serialized_properties).and_return({}) - o.class.stub(:name).and_return('MyClass') # set_classname looks for this - clazz.stub(:neo4j_session).and_return(session) - - clazz.stub(:mapped_label_names).and_return(:MyClass) - expect(session).to receive(:create_node).with(end_props, :MyClass).and_return(node) - expect(o).to receive(:init_on_load).with(node, end_props) - allow_any_instance_of(Object).to receive(:serialized_properties_keys).and_return([]) - - expect(node).to receive(:props).and_return(end_props) - - o.save - end - end end describe 'new_record?' do @@ -128,7 +103,6 @@ def self.fetch_upstream_primitive(_) before do clazz.send(:include, Neo4j::ActiveNode::IdProperty) clazz.id_property :uuid, auto: :uuid, constraint: false - allow(clazz).to receive(:cached_class?).and_return false end it 'adds the primary key' do diff --git a/spec/unit/active_node/validation_spec.rb b/spec/unit/active_node/validation_spec.rb index 5c1a3de29..cf696dd90 100644 --- a/spec/unit/active_node/validation_spec.rb +++ b/spec/unit/active_node/validation_spec.rb @@ -45,7 +45,6 @@ def self.fetch_upstream_primitive(_attr) o.stub(:serialized_properties).and_return({}) o.serialized_properties clazz.stub(:default_property_values).and_return({}) - clazz.stub(:cached_class?).and_return(false) clazz.should_receive(:neo4j_session).and_return(session) node.should_receive(:props).and_return(name: 'kalle2', age: '43') session.should_receive(:create_node).with({name: 'kalle', age: 42}, :MyClass).and_return(node) diff --git a/spec/unit/active_rel/persistence_spec_bad.rb b/spec/unit/active_rel/persistence_spec_bad.rb index 957b55b62..cfbabf933 100644 --- a/spec/unit/active_rel/persistence_spec_bad.rb +++ b/spec/unit/active_rel/persistence_spec_bad.rb @@ -44,10 +44,10 @@ describe 'save' do it 'creates a relationship if not already persisted' do start_props = {from_node: node1, to_node: node2, friends_since: 'sunday', level: 9001} - end_props = {friends_since: 'sunday', level: 9001, _classname: Class} + end_props = {friends_since: 'sunday', level: 9001} r = clazz.new(start_props) r.stub(:confirm_node_classes).and_return(:true) - expect(node1).to receive(:create_rel).with(:friends_with, node2, friends_since: 'sunday', level: 9001, _classname: nil).and_return(rel) + expect(node1).to receive(:create_rel).with(:friends_with, node2, friends_since: 'sunday', level: 9001).and_return(rel) rel.stub(:props).and_return(end_props) expect(r.save).to be_truthy end diff --git a/spec/unit/active_rel/property_spec.rb b/spec/unit/active_rel/property_spec.rb index 98023b886..a300966cc 100644 --- a/spec/unit/active_rel/property_spec.rb +++ b/spec/unit/active_rel/property_spec.rb @@ -15,10 +15,6 @@ def self.name 'Clazz' end - def self.uses_classname? - false - end - include Neo4j::ActiveRel::Property include Neo4j::ActiveRel::Types end diff --git a/spec/unit/active_rel/rel_wrapper_spec.rb b/spec/unit/active_rel/rel_wrapper_spec.rb index 90dc25254..fbdb6f461 100644 --- a/spec/unit/active_rel/rel_wrapper_spec.rb +++ b/spec/unit/active_rel/rel_wrapper_spec.rb @@ -3,7 +3,6 @@ describe Neo4j::Relationship::Wrapper do class RelClass; end - let(:clazz) do Class.new do include Neo4j::Relationship::Wrapper @@ -25,17 +24,4 @@ class RelClass; end it 'returns self when unable to find a valid class' do expect(r.wrapper).to eq(r) end - - it 'calls init_on_load when finding a valid model from _classname' do - r.stub(:props).and_return(name: 'superman', _classname: 'RelClass') - expect(r).to receive(:_start_node_id) - expect(r).to receive(:_end_node_id) - expect(r).to receive(:rel_type).and_return('myrel') - expect(r.wrapper).to be_a(RelClass) - end - - it 'returns self when classname is invalid' do - r.stub(:props).and_return(_classname: 'FakeClass') - expect(r.wrapper).to eq r - end end diff --git a/spec/unit/shared/persistence_spec.rb b/spec/unit/shared/persistence_spec.rb index 1f0d95565..f460e0bb1 100644 --- a/spec/unit/shared/persistence_spec.rb +++ b/spec/unit/shared/persistence_spec.rb @@ -14,7 +14,6 @@ def self.extract_association_attributes!(props) props end end) - allow(MyModel).to receive(:cached_class?).and_return false end let(:node) { MyModel.new } diff --git a/spec/unit/wrapper_spec.rb b/spec/unit/wrapper_spec.rb index 6185844f4..e65996e7d 100644 --- a/spec/unit/wrapper_spec.rb +++ b/spec/unit/wrapper_spec.rb @@ -7,42 +7,6 @@ end describe 'wrapper' do - describe 'with class_name_property' do - context 'when set in config.yml' do - it 'looks for a property with the same name' do - wrapper.stub(:props).and_return(_defined_property_name: 'Bar') - wrapper.stub(:labels).and_return([]) - Bar = Object - Neo4j::Config.stub(:class_name_property).and_return(:_defined_property_name) - - expect(wrapper.class_to_wrap).to eq Bar - end - end - - context 'when using default and present on class' do - before do - wrapper.stub(:props).and_return(_classname: 'CachedClassName') - wrapper.stub(:labels).and_return([]) - end - - CachedClassName = Object - - it 'does not call :_class_wrappers' do - expect(wrapper).to_not receive(:_class_wrappers) - wrapper.class_to_wrap - end - - it 'looks for a key called "_classname"' do - expect(wrapper.props).to receive(:key?).with(:_classname).and_return true - wrapper.class_to_wrap - end - - it 'returns the constantized value of "_classname"' do - expect(wrapper.class_to_wrap).to eq CachedClassName - end - end - end - it 'can find the wrapper even if it is auto loaded' do module AutoLoadTest end