neoid 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/neoid/node.rb +2 -2
- data/lib/neoid/version.rb +1 -1
- data/spec/neoid/node_spec.rb +131 -0
- data/spec/neoid/relationship_spec.rb +102 -0
- metadata +6 -4
- data/spec/neoid/model_additions_spec.rb +0 -222
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Neoid offers querying Neo4j for IDs of objects and then fetch them from your RDB
|
|
15
15
|
|
16
16
|
## Changelog
|
17
17
|
|
18
|
-
[See Changelog](https://github.com/elado/neoid/blob/master/CHANGELOG.md)
|
18
|
+
[See Changelog](https://github.com/elado/neoid/blob/master/CHANGELOG.md). Including some breaking changes (and solutions) from previos versions.
|
19
19
|
|
20
20
|
|
21
21
|
## Installation
|
@@ -23,7 +23,7 @@ Neoid offers querying Neo4j for IDs of objects and then fetch them from your RDB
|
|
23
23
|
Add to your Gemfile and run the `bundle` command to install it.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
gem 'neoid', '~> 0.1'
|
26
|
+
gem 'neoid', '~> 0.1.1'
|
27
27
|
```
|
28
28
|
|
29
29
|
**Requires Ruby 1.9.2 or later.**
|
@@ -217,7 +217,7 @@ Neoid::Node.from_hash(Neoid.db.get_node_auto_index(Neoid::UNIQUE_ID_KEY, user.ne
|
|
217
217
|
If Subreferences are enabled, you can get the subref node and then get all attached nodes:
|
218
218
|
|
219
219
|
```ruby
|
220
|
-
Neoid.ref_node.outgoing('users_subref').first.outgoing('
|
220
|
+
Neoid.ref_node.outgoing('users_subref').first.outgoing('users').to_a
|
221
221
|
# => this, according to Neography, returns an array of Neography::Node so no conversion is needed
|
222
222
|
```
|
223
223
|
|
data/lib/neoid/node.rb
CHANGED
@@ -106,7 +106,7 @@ module Neoid
|
|
106
106
|
}
|
107
107
|
} else {
|
108
108
|
node = g.addVertex(node_data);
|
109
|
-
if (enable_subrefs) g.addEdge(g.v(subref_id), node,
|
109
|
+
if (enable_subrefs) g.addEdge(g.v(subref_id), node, neo_subref_node_rel_type);
|
110
110
|
|
111
111
|
if (enable_model_index) g.idx(neo_model_index_name).put('ar_id', node.ar_id, node);
|
112
112
|
}
|
@@ -125,7 +125,7 @@ module Neoid
|
|
125
125
|
if Neoid.config.enable_subrefs
|
126
126
|
script_vars.update(
|
127
127
|
subref_id: self.class.neo_subref_node.neo_id,
|
128
|
-
|
128
|
+
neo_subref_node_rel_type: self.class.neo_subref_node_rel_type
|
129
129
|
)
|
130
130
|
end
|
131
131
|
|
data/lib/neoid/version.rb
CHANGED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neoid::Node do
|
4
|
+
context "create graph nodes" do
|
5
|
+
it "should call neo_save after model creation" do
|
6
|
+
user = User.new(name: "Elad Ossadon")
|
7
|
+
user.should_receive(:neo_save)
|
8
|
+
user.save!
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create a node for user" do
|
12
|
+
user = User.create!(name: "Elad Ossadon", slug: "elado")
|
13
|
+
|
14
|
+
user.neo_node.should_not be_nil
|
15
|
+
|
16
|
+
user.neo_node.ar_id.should == user.id
|
17
|
+
user.neo_node.name.should == user.name
|
18
|
+
user.neo_node.slug.should == user.slug
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create a neo_node for movie" do
|
22
|
+
movie = Movie.create!(name: "Memento", slug: "memento-1999", year: 1999)
|
23
|
+
|
24
|
+
movie.neo_node.should_not be_nil
|
25
|
+
|
26
|
+
movie.neo_node.ar_id.should == movie.id
|
27
|
+
movie.neo_node.name.should == movie.name
|
28
|
+
movie.neo_node.year.should == movie.year
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "update graph nodes" do
|
33
|
+
it "should call neo_save after model update" do
|
34
|
+
user = User.create!(name: "Elad Ossadon")
|
35
|
+
user.should_receive(:neo_save)
|
36
|
+
user.name = "John Doe"
|
37
|
+
user.save!
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should update a node after model update" do
|
41
|
+
user = User.create!(name: "Elad Ossadon")
|
42
|
+
user.neo_node.name.should == "Elad Ossadon"
|
43
|
+
|
44
|
+
user.name = "John Doe"
|
45
|
+
user.save!
|
46
|
+
|
47
|
+
user.neo_node.name.should == "John Doe"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "find by id" do
|
52
|
+
it "should find a neo_node for user" do
|
53
|
+
user = User.create!(name: "Elad Ossadon", slug: "elado")
|
54
|
+
|
55
|
+
user.neo_node.should_not be_nil
|
56
|
+
user.neo_find_by_id.should_not be_nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "no auto_index" do
|
61
|
+
it "should not index a node if option :auto_index is set to false" do
|
62
|
+
model = NoAutoIndexNode.new(name: "Hello")
|
63
|
+
model.should_not_receive(:neo_save)
|
64
|
+
model.save!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "subrefs" do
|
69
|
+
it "should connect subrefs to reference node" do
|
70
|
+
old, Neoid.config.enable_subrefs = Neoid.config.enable_subrefs, true
|
71
|
+
|
72
|
+
Neoid.send(:initialize_subrefs)
|
73
|
+
|
74
|
+
begin
|
75
|
+
Neoid.ref_node.rel(:outgoing, :users_subref).should_not be_nil
|
76
|
+
ensure
|
77
|
+
Neoid.config.enable_subrefs = old
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should create a relationship with a subref node" do
|
82
|
+
old, Neoid.config.enable_subrefs = Neoid.config.enable_subrefs, true
|
83
|
+
|
84
|
+
Neoid.send(:initialize_subrefs)
|
85
|
+
|
86
|
+
begin
|
87
|
+
user = User.create!(name: "Elad")
|
88
|
+
user.neo_node.rel(:incoming, :users).should_not be_nil
|
89
|
+
ensure
|
90
|
+
Neoid.config.enable_subrefs = old
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not create a relationship with a subref node if disabled" do
|
95
|
+
old, Neoid.config.enable_subrefs = Neoid.config.enable_subrefs, false
|
96
|
+
|
97
|
+
begin
|
98
|
+
user = User.create!(name: "Elad")
|
99
|
+
user.neo_node.rel(:incoming, :users_subref).should be_nil
|
100
|
+
ensure
|
101
|
+
Neoid.config.enable_subrefs = old
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "per_model_indexes" do
|
107
|
+
it "should create a relationship with a subref node" do
|
108
|
+
old, Neoid.config.enable_per_model_indexes = Neoid.config.enable_per_model_indexes, true
|
109
|
+
|
110
|
+
Neoid.send(:initialize_per_model_indexes)
|
111
|
+
|
112
|
+
begin
|
113
|
+
user = User.create!(name: "Elad")
|
114
|
+
Neoid.db.get_node_index(User.neo_model_index_name, 'ar_id', user.id).should_not be_nil
|
115
|
+
ensure
|
116
|
+
Neoid.config.enable_per_model_indexes = old
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should not create a relationship with a subref node if disabled" do
|
121
|
+
old, Neoid.config.enable_per_model_indexes = Neoid.config.enable_per_model_indexes, false
|
122
|
+
|
123
|
+
begin
|
124
|
+
user = User.create!(name: "Elad")
|
125
|
+
expect { Neoid.db.get_node_index(User.neo_model_index_name, 'ar_id', user.id) }.to raise_error(Neography::NotFoundException)
|
126
|
+
ensure
|
127
|
+
Neoid.config.enable_per_model_indexes = old
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Neoid::Relationship do
|
4
|
+
let(:user) { User.create!(name: "Elad Ossadon", slug: "elado") }
|
5
|
+
let(:movie) { Movie.create!(name: "Memento", slug: "memento-1999", year: 1999) }
|
6
|
+
|
7
|
+
it "should call neo_save after relationship model creation" do
|
8
|
+
Like.any_instance.should_receive(:neo_save)
|
9
|
+
user.like! movie
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create a neo_relationship for like" do
|
13
|
+
like = user.like! movie
|
14
|
+
like = user.likes.last
|
15
|
+
|
16
|
+
like.neo_find_by_id.should_not be_nil
|
17
|
+
|
18
|
+
like.neo_relationship.should_not be_nil
|
19
|
+
|
20
|
+
like.neo_relationship.start_node.should == user.neo_node
|
21
|
+
like.neo_relationship.end_node.should == movie.neo_node
|
22
|
+
like.neo_relationship.rel_type.should == 'likes'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should delete a relationship on deleting a record" do
|
26
|
+
user.like! movie
|
27
|
+
like = user.likes.last
|
28
|
+
|
29
|
+
relationship_neo_id = like.neo_relationship.neo_id
|
30
|
+
|
31
|
+
Neography::Relationship.load(relationship_neo_id).should_not be_nil
|
32
|
+
|
33
|
+
user.unlike! movie
|
34
|
+
|
35
|
+
expect { Neography::Relationship.load(relationship_neo_id) }.to raise_error(Neography::RelationshipNotFoundException)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should update neo4j on manual set of a collection" do
|
39
|
+
movies = [
|
40
|
+
Movie.create(name: "Memento"),
|
41
|
+
Movie.create(name: "The Prestige"),
|
42
|
+
Movie.create(name: "The Dark Knight"),
|
43
|
+
Movie.create(name: "Spiderman")
|
44
|
+
]
|
45
|
+
|
46
|
+
user.neo_node.outgoing(:likes).length.should == 0
|
47
|
+
|
48
|
+
expect {
|
49
|
+
user.movies = movies
|
50
|
+
}.to change{ user.neo_node.outgoing(:likes).length }.to(movies.length)
|
51
|
+
|
52
|
+
expect { expect {
|
53
|
+
user.movies -= movies[0..1]
|
54
|
+
}.to change{ user.movies.count }.by(-2)
|
55
|
+
}.to change{ user.neo_node.outgoing(:likes).length }.by(-2)
|
56
|
+
|
57
|
+
expect {
|
58
|
+
user.movies = []
|
59
|
+
}.to change{ user.neo_node.outgoing(:likes).length }.to(0)
|
60
|
+
|
61
|
+
expect {
|
62
|
+
user.movie_ids = movies[0...2].collect(&:id)
|
63
|
+
}.to change{ user.neo_node.outgoing(:likes).length }.to(2)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should update a relationship after relationship model update" do
|
67
|
+
like = user.like! movie
|
68
|
+
|
69
|
+
like.neo_relationship.rate.should be_nil
|
70
|
+
|
71
|
+
like.rate = 10
|
72
|
+
like.save!
|
73
|
+
|
74
|
+
like.neo_relationship.rate.should == 10
|
75
|
+
end
|
76
|
+
|
77
|
+
context "polymorphic relationship" do
|
78
|
+
let(:user) { User.create(name: "Elad Ossadon", slug: "elado") }
|
79
|
+
|
80
|
+
it "should create relationships with polymorphic items" do
|
81
|
+
followed = [
|
82
|
+
User.create(name: "Some One", slug: "someone"),
|
83
|
+
Movie.create(name: "The Prestige"),
|
84
|
+
Movie.create(name: "The Dark Knight")
|
85
|
+
]
|
86
|
+
|
87
|
+
expect {
|
88
|
+
followed.each do |item|
|
89
|
+
user.user_follows.create!(item: item)
|
90
|
+
end
|
91
|
+
}.to change{ user.neo_node.outgoing(:follows).length }.to(followed.length)
|
92
|
+
|
93
|
+
expect {
|
94
|
+
user.user_follows = user.user_follows[0...1]
|
95
|
+
}.to change{ user.neo_node.outgoing(:follows).length }.to(1)
|
96
|
+
|
97
|
+
expect {
|
98
|
+
user.user_follows = []
|
99
|
+
}.to change{ user.neo_node.outgoing(:follows).length }.to(0)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -139,8 +139,9 @@ files:
|
|
139
139
|
- neoid.gemspec
|
140
140
|
- spec/neoid/batch_spec.rb
|
141
141
|
- spec/neoid/config_spec.rb
|
142
|
-
- spec/neoid/model_additions_spec.rb
|
143
142
|
- spec/neoid/model_config_spec.rb
|
143
|
+
- spec/neoid/node_spec.rb
|
144
|
+
- spec/neoid/relationship_spec.rb
|
144
145
|
- spec/neoid/search_spec.rb
|
145
146
|
- spec/neoid_spec.rb
|
146
147
|
- spec/spec_helper.rb
|
@@ -174,8 +175,9 @@ summary: Neo4j for ActiveRecord
|
|
174
175
|
test_files:
|
175
176
|
- spec/neoid/batch_spec.rb
|
176
177
|
- spec/neoid/config_spec.rb
|
177
|
-
- spec/neoid/model_additions_spec.rb
|
178
178
|
- spec/neoid/model_config_spec.rb
|
179
|
+
- spec/neoid/node_spec.rb
|
180
|
+
- spec/neoid/relationship_spec.rb
|
179
181
|
- spec/neoid/search_spec.rb
|
180
182
|
- spec/neoid_spec.rb
|
181
183
|
- spec/spec_helper.rb
|
@@ -1,222 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Neoid::ModelAdditions do
|
4
|
-
context "nodes" do
|
5
|
-
context "create graph nodes" do
|
6
|
-
it "should call neo_save after model creation" do
|
7
|
-
user = User.new(name: "Elad Ossadon")
|
8
|
-
user.should_receive(:neo_save)
|
9
|
-
user.save!
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should create a node for user" do
|
13
|
-
user = User.create!(name: "Elad Ossadon", slug: "elado")
|
14
|
-
|
15
|
-
user.neo_node.should_not be_nil
|
16
|
-
|
17
|
-
user.neo_node.ar_id.should == user.id
|
18
|
-
user.neo_node.name.should == user.name
|
19
|
-
user.neo_node.slug.should == user.slug
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should create a neo_node for movie" do
|
23
|
-
movie = Movie.create!(name: "Memento", slug: "memento-1999", year: 1999)
|
24
|
-
|
25
|
-
movie.neo_node.should_not be_nil
|
26
|
-
|
27
|
-
movie.neo_node.ar_id.should == movie.id
|
28
|
-
movie.neo_node.name.should == movie.name
|
29
|
-
movie.neo_node.year.should == movie.year
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "update graph nodes" do
|
34
|
-
it "should call neo_save after model update" do
|
35
|
-
user = User.create!(name: "Elad Ossadon")
|
36
|
-
user.should_receive(:neo_save)
|
37
|
-
user.name = "John Doe"
|
38
|
-
user.save!
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should update a node after model update" do
|
42
|
-
user = User.create!(name: "Elad Ossadon")
|
43
|
-
user.neo_node.name.should == "Elad Ossadon"
|
44
|
-
|
45
|
-
user.name = "John Doe"
|
46
|
-
user.save!
|
47
|
-
|
48
|
-
user.neo_node.name.should == "John Doe"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "find by id" do
|
53
|
-
it "should find a neo_node for user" do
|
54
|
-
user = User.create!(name: "Elad Ossadon", slug: "elado")
|
55
|
-
|
56
|
-
user.neo_node.should_not be_nil
|
57
|
-
user.neo_find_by_id.should_not be_nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "no auto_index" do
|
62
|
-
it "should not index a node if option :auto_index is set to false" do
|
63
|
-
model = NoAutoIndexNode.new(name: "Hello")
|
64
|
-
model.should_not_receive(:neo_save)
|
65
|
-
model.save!
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "subrefs" do
|
70
|
-
it "should create a relationship with a subref node" do
|
71
|
-
old, Neoid.config.enable_subrefs = Neoid.config.enable_subrefs, true
|
72
|
-
|
73
|
-
Neoid.send(:initialize_subrefs)
|
74
|
-
|
75
|
-
begin
|
76
|
-
user = User.create!(name: "Elad")
|
77
|
-
user.neo_node.rel(:incoming, :users_subref).should_not be_nil
|
78
|
-
ensure
|
79
|
-
Neoid.config.enable_subrefs = old
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should not create a relationship with a subref node if disabled" do
|
84
|
-
old, Neoid.config.enable_subrefs = Neoid.config.enable_subrefs, false
|
85
|
-
|
86
|
-
begin
|
87
|
-
user = User.create!(name: "Elad")
|
88
|
-
user.neo_node.rel(:incoming, :users_subref).should be_nil
|
89
|
-
ensure
|
90
|
-
Neoid.config.enable_subrefs = old
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "per_model_indexes" do
|
96
|
-
it "should create a relationship with a subref node" do
|
97
|
-
old, Neoid.config.enable_per_model_indexes = Neoid.config.enable_per_model_indexes, true
|
98
|
-
|
99
|
-
Neoid.send(:initialize_per_model_indexes)
|
100
|
-
|
101
|
-
begin
|
102
|
-
user = User.create!(name: "Elad")
|
103
|
-
Neoid.db.get_node_index(User.neo_model_index_name, 'ar_id', user.id).should_not be_nil
|
104
|
-
ensure
|
105
|
-
Neoid.config.enable_per_model_indexes = old
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should not create a relationship with a subref node if disabled" do
|
110
|
-
old, Neoid.config.enable_per_model_indexes = Neoid.config.enable_per_model_indexes, false
|
111
|
-
|
112
|
-
begin
|
113
|
-
user = User.create!(name: "Elad")
|
114
|
-
expect { Neoid.db.get_node_index(User.neo_model_index_name, 'ar_id', user.id) }.to raise_error(Neography::NotFoundException)
|
115
|
-
ensure
|
116
|
-
Neoid.config.enable_per_model_indexes = old
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "relationships" do
|
123
|
-
let(:user) { User.create!(name: "Elad Ossadon", slug: "elado") }
|
124
|
-
let(:movie) { Movie.create!(name: "Memento", slug: "memento-1999", year: 1999) }
|
125
|
-
|
126
|
-
it "should call neo_save after relationship model creation" do
|
127
|
-
Like.any_instance.should_receive(:neo_save)
|
128
|
-
user.like! movie
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should create a neo_relationship for like" do
|
132
|
-
like = user.like! movie
|
133
|
-
like = user.likes.last
|
134
|
-
|
135
|
-
like.neo_find_by_id.should_not be_nil
|
136
|
-
|
137
|
-
like.neo_relationship.should_not be_nil
|
138
|
-
|
139
|
-
like.neo_relationship.start_node.should == user.neo_node
|
140
|
-
like.neo_relationship.end_node.should == movie.neo_node
|
141
|
-
like.neo_relationship.rel_type.should == 'likes'
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should delete a relationship on deleting a record" do
|
145
|
-
user.like! movie
|
146
|
-
like = user.likes.last
|
147
|
-
|
148
|
-
relationship_neo_id = like.neo_relationship.neo_id
|
149
|
-
|
150
|
-
Neography::Relationship.load(relationship_neo_id).should_not be_nil
|
151
|
-
|
152
|
-
user.unlike! movie
|
153
|
-
|
154
|
-
expect { Neography::Relationship.load(relationship_neo_id) }.to raise_error(Neography::RelationshipNotFoundException)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should update neo4j on manual set of a collection" do
|
158
|
-
movies = [
|
159
|
-
Movie.create(name: "Memento"),
|
160
|
-
Movie.create(name: "The Prestige"),
|
161
|
-
Movie.create(name: "The Dark Knight"),
|
162
|
-
Movie.create(name: "Spiderman")
|
163
|
-
]
|
164
|
-
|
165
|
-
user.neo_node.outgoing(:likes).length.should == 0
|
166
|
-
|
167
|
-
expect {
|
168
|
-
user.movies = movies
|
169
|
-
}.to change{ user.neo_node.outgoing(:likes).length }.to(movies.length)
|
170
|
-
|
171
|
-
expect { expect {
|
172
|
-
user.movies -= movies[0..1]
|
173
|
-
}.to change{ user.movies.count }.by(-2)
|
174
|
-
}.to change{ user.neo_node.outgoing(:likes).length }.by(-2)
|
175
|
-
|
176
|
-
expect {
|
177
|
-
user.movies = []
|
178
|
-
}.to change{ user.neo_node.outgoing(:likes).length }.to(0)
|
179
|
-
|
180
|
-
expect {
|
181
|
-
user.movie_ids = movies[0...2].collect(&:id)
|
182
|
-
}.to change{ user.neo_node.outgoing(:likes).length }.to(2)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should update a relationship after relationship model update" do
|
186
|
-
like = user.like! movie
|
187
|
-
|
188
|
-
like.neo_relationship.rate.should be_nil
|
189
|
-
|
190
|
-
like.rate = 10
|
191
|
-
like.save!
|
192
|
-
|
193
|
-
like.neo_relationship.rate.should == 10
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "polymorphic relationship" do
|
198
|
-
let(:user) { User.create(name: "Elad Ossadon", slug: "elado") }
|
199
|
-
|
200
|
-
it "should create relationships with polymorphic items" do
|
201
|
-
followed = [
|
202
|
-
User.create(name: "Some One", slug: "someone"),
|
203
|
-
Movie.create(name: "The Prestige"),
|
204
|
-
Movie.create(name: "The Dark Knight")
|
205
|
-
]
|
206
|
-
|
207
|
-
expect {
|
208
|
-
followed.each do |item|
|
209
|
-
user.user_follows.create!(item: item)
|
210
|
-
end
|
211
|
-
}.to change{ user.neo_node.outgoing(:follows).length }.to(followed.length)
|
212
|
-
|
213
|
-
expect {
|
214
|
-
user.user_follows = user.user_follows[0...1]
|
215
|
-
}.to change{ user.neo_node.outgoing(:follows).length }.to(1)
|
216
|
-
|
217
|
-
expect {
|
218
|
-
user.user_follows = []
|
219
|
-
}.to change{ user.neo_node.outgoing(:follows).length }.to(0)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|