<commit_before>require 'spec_helper'

module Neography
  describe "Properties" do

    before do
      @db = mock(Neography::Rest, :is_a? => true).as_null_object
      Rest.stub(:new) { @db }
    end

    context "Node" do

      subject(:node) do
        node = Node.create
        node.stub(:neo_id => 42)
        node
      end

      it "sets properties as accessor" do
        @db.should_receive(:"set_node_properties").with(42, { "key" => "value" })
        node.key = "value"
      end

      it "sets properties as array entry" do
        @db.should_receive(:"set_node_properties").with(42, { "key" => "value" })
        node["key"] = "value"
      end

      it "gets properties as accessor" do
        @db.stub(:"set_node_properties").with(42, { "key" => "value" })
        node.key = "value"
        node.key.should == "value"
      end

      it "gets properties as array entry" do
        @db.stub(:"set_node_properties").with(42, { "key" => "value" })
        node["key"] = "value"
        node["key"].should == "value"
      end

      it "resets properties as accessor" do
        @db.should_receive(:"remove_node_properties").with(42, ["key"])
        node.key = nil
      end

      it "resets properties as array entry" do
        @db.should_receive(:"remove_node_properties").with(42, ["key"])
        node["key"] = nil
      end

      it "gets unknown properties as nil" do
        node.unknown.should == nil
      end

      it "overwrites existing properties" do
        @db.should_receive(:"set_node_properties").with(42, { "key" => "value1" })
        node.key = "value1"

        @db.should_receive(:"set_node_properties").with(42, { "key" => "value2" })
        node.key = "value2"
      end

    end

    context "Relationship" do

      subject(:relationship) do
        from = Node.create
        to = Node.create

        rel = Relationship.create(:type, from, to)
        rel.stub(:neo_id => 42)
        rel
      end

      it "sets properties as accessor" do
        @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value" })
        relationship.key = "value"
      end

      it "sets properties as array entry" do
        @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value" })
        relationship["key"] = "value"
      end

      it "gets properties as accessor" do
        @db.stub(:"set_relationship_properties").with(42, { "key" => "value" })
        relationship.key = "value"
        relationship.key.should == "value"
      end

      it "gets properties as array entry" do
        @db.stub(:"set_relationship_properties").with(42, { "key" => "value" })<commit_msg>No need for .with on stubs.<commit_after>require 'spec_helper'

module Neography
  describe "Properties" do

    before do
      @db = mock(Neography::Rest, :is_a? => true).as_null_object
      Rest.stub(:new) { @db }
    end

    context "Node" do

      subject(:node) do
        node = Node.create
        node.stub(:neo_id => 42)
        node
      end

      it "sets properties as accessor" do
        @db.should_receive(:"set_node_properties").with(42, { "key" => "value" })
        node.key = "value"
      end

      it "sets properties as array entry" do
        @db.should_receive(:"set_node_properties").with(42, { "key" => "value" })
        node["key"] = "value"
      end

      it "gets properties as accessor" do
        @db.stub(:"set_node_properties")
        node.key = "value"
        node.key.should == "value"
      end

      it "gets properties as array entry" do
        @db.stub(:"set_node_properties")
        node["key"] = "value"
        node["key"].should == "value"
      end

      it "resets properties as accessor" do
        @db.should_receive(:"remove_node_properties").with(42, ["key"])
        node.key = nil
      end

      it "resets properties as array entry" do
        @db.should_receive(:"remove_node_properties").with(42, ["key"])
        node["key"] = nil
      end

      it "gets unknown properties as nil" do
        node.unknown.should == nil
      end

      it "overwrites existing properties" do
        @db.should_receive(:"set_node_properties").with(42, { "key" => "value1" })
        node.key = "value1"

        @db.should_receive(:"set_node_properties").with(42, { "key" => "value2" })
        node.key = "value2"
      end

    end

    context "Relationship" do

      subject(:relationship) do
        from = Node.create
        to = Node.create

        rel = Relationship.create(:type, from, to)
        rel.stub(:neo_id => 42)
        rel
      end

      it "sets properties as accessor" do
        @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value" })
        relationship.key = "value"
      end

      it "sets properties as array entry" do
        @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value" })
        relationship["key"] = "value"
      end

      it "gets properties as accessor" do
        @db.stub(:"set_relationship_properties")
        relationship.key = "value"
        relationship.key.should == "value"
      end

      it "gets properties as array entry" do
        @db.stub(:"set_relationship_properties")
{'fraction_non_alphanumeric': 0.13775901765157328, 'fraction_numerical': 0.010744435917114352, 'mean_word_length': 2.3161577608142494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1656850', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1595, 'n_words': 391}