active_node 2.2.7 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/active_node.gemspec +1 -4
- data/lib/active_node/base.rb +1 -0
- data/lib/active_node/version.rb +1 -1
- data/spec/functional/associations_spec.rb +30 -32
- data/spec/functional/base_spec.rb +3 -5
- data/spec/functional/graph/query_methods_spec.rb +4 -6
- data/spec/functional/graph_spec.rb +19 -21
- data/spec/functional/persistence_spec.rb +40 -32
- data/spec/functional/validations_spec.rb +7 -9
- data/spec/models/address.rb +1 -0
- data/spec/spec_helper.rb +3 -3
- metadata +5 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45501f3e062853d5fe6ccc8c86f421db66c5cff9
|
4
|
+
data.tar.gz: 03cd4becab14827bbef0bac124fd0574d0f34b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bc1bda0941bf238967605fe40083c6ad2b6315d5371b5e28667fbaef5abf01e37dde54c3cacaffbb51aa971316cf7f3c52e4e3a6fe706896b3282deea7622ef
|
7
|
+
data.tar.gz: e39299ad270597c5c36d120056322b3ba8beb8c141210c675cbbd85d127fb525f670057a7fe3f7758d55264f8c4e2bd9fe366d93bc48b7ea218ff34335f234c2
|
data/.rspec
ADDED
data/active_node.gemspec
CHANGED
@@ -20,10 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_dependency "active_attr"
|
22
22
|
s.add_dependency "neography"
|
23
|
-
s.
|
24
|
-
s.add_dependency "activemodel"
|
25
|
-
s.add_development_dependency "rspec", "<= 2.14.1"
|
26
|
-
s.add_development_dependency "net-http-spy", "0.2.1"
|
23
|
+
s.add_development_dependency "rspec"
|
27
24
|
s.add_development_dependency "rake", ">= 0.8.7"
|
28
25
|
s.add_development_dependency "coveralls"
|
29
26
|
s.add_development_dependency "codeclimate-test-reporter"
|
data/lib/active_node/base.rb
CHANGED
data/lib/active_node/version.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe ActiveNode::Associations do
|
4
2
|
describe "#save" do
|
5
3
|
it "should have empty association" do
|
6
4
|
client = Client.new(name: 'a')
|
7
5
|
client.save
|
8
|
-
client.users.
|
6
|
+
expect(client.users).to be_empty
|
9
7
|
end
|
10
8
|
|
11
9
|
it "should not have empty association" do
|
@@ -13,21 +11,21 @@ describe ActiveNode::Associations do
|
|
13
11
|
user.save
|
14
12
|
client = Client.new(name: 'a', users: [user])
|
15
13
|
client.save
|
16
|
-
client.users.
|
14
|
+
expect(client.users).to eq([user])
|
17
15
|
end
|
18
16
|
|
19
17
|
it "can set association by id" do
|
20
18
|
user = NeoUser.create!(name: 'Heinrich')
|
21
19
|
client = Client.create!(name: 'a', user_ids: [user.id])
|
22
|
-
client.users.to_a.
|
23
|
-
client.user_ids.
|
24
|
-
client.users.first.clients.first.
|
20
|
+
expect(client.users.to_a).to eq([user])
|
21
|
+
expect(client.user_ids).to eq([user.id])
|
22
|
+
expect(client.users.first.clients.first).to eq(client)
|
25
23
|
client.user_ids = []
|
26
24
|
client.save
|
27
|
-
Client.find(client.id).users.
|
25
|
+
expect(Client.find(client.id).users).to eq([])
|
28
26
|
client.user_ids = [user.id]
|
29
27
|
client.save
|
30
|
-
Client.find(client.id).users.
|
28
|
+
expect(Client.find(client.id).users).to eq([user])
|
31
29
|
end
|
32
30
|
|
33
31
|
it "can remove associated objects" do
|
@@ -37,18 +35,18 @@ describe ActiveNode::Associations do
|
|
37
35
|
client.save
|
38
36
|
client.user_ids = []
|
39
37
|
client.save
|
40
|
-
client.users.
|
41
|
-
client.user_ids.
|
38
|
+
expect(client.users).to be_empty
|
39
|
+
expect(client.user_ids).to be_empty
|
42
40
|
end
|
43
41
|
|
44
42
|
it "returns nil on a has_one association for a brand spanking new model object" do
|
45
43
|
person = Person.new
|
46
|
-
person.father.
|
44
|
+
expect(person.father).to be_nil
|
47
45
|
end
|
48
46
|
|
49
47
|
it "returns nil on a has_one association where nothing is associated" do
|
50
48
|
person = Person.create!
|
51
|
-
person.father.
|
49
|
+
expect(person.father).to be_nil
|
52
50
|
end
|
53
51
|
|
54
52
|
it "can remove some of the associated objects" do
|
@@ -56,10 +54,10 @@ describe ActiveNode::Associations do
|
|
56
54
|
child2 = Person.create!
|
57
55
|
person = Person.create! child_ids: [child1.id, child2.id]
|
58
56
|
person = Person.find(person.id)
|
59
|
-
person.children.count.
|
57
|
+
expect(person.children.count).to eq(2)
|
60
58
|
person.child_ids = [child2.id]
|
61
59
|
person.save
|
62
|
-
Person.find(person.id).children.
|
60
|
+
expect(Person.find(person.id).children).to eq([child2])
|
63
61
|
end
|
64
62
|
|
65
63
|
it "can remove and add some of the associated objects" do
|
@@ -67,11 +65,11 @@ describe ActiveNode::Associations do
|
|
67
65
|
child2 = Person.create!
|
68
66
|
person = Person.create! child_ids: [child1.id, child2.id]
|
69
67
|
person = Person.find(person.id)
|
70
|
-
person.children.count.
|
68
|
+
expect(person.children.count).to eq(2)
|
71
69
|
child3 = Person.create!
|
72
70
|
person.child_ids = [child2.id, child3.id]
|
73
71
|
person.save
|
74
|
-
Person.find(person.id).children.
|
72
|
+
expect(Person.find(person.id).children).to eq([child2, child3])
|
75
73
|
end
|
76
74
|
|
77
75
|
it 'can handle self referencing' do
|
@@ -80,12 +78,12 @@ describe ActiveNode::Associations do
|
|
80
78
|
person.people = [person]
|
81
79
|
person.save
|
82
80
|
person.people.first == person
|
83
|
-
Person.count.
|
81
|
+
expect(Person.count).to eq(1)
|
84
82
|
end
|
85
83
|
|
86
84
|
it 'can handle reference to the same class' do
|
87
85
|
id = Person.create!(children: [Person.create!, Person.create!]).id
|
88
|
-
Person.find(id).children.size.
|
86
|
+
expect(Person.find(id).children.size).to eq(2)
|
89
87
|
end
|
90
88
|
|
91
89
|
it 'can set has_one relation' do
|
@@ -93,7 +91,7 @@ describe ActiveNode::Associations do
|
|
93
91
|
child = Person.create!
|
94
92
|
child.father = father
|
95
93
|
child.save
|
96
|
-
father.children.
|
94
|
+
expect(father.children).to eq([child])
|
97
95
|
end
|
98
96
|
|
99
97
|
it 'can set has_one relation by id' do
|
@@ -101,19 +99,19 @@ describe ActiveNode::Associations do
|
|
101
99
|
child = Person.create!
|
102
100
|
child.father_id = father.id
|
103
101
|
child.save
|
104
|
-
father.children.
|
102
|
+
expect(father.children).to eq([child])
|
105
103
|
end
|
106
104
|
|
107
105
|
it 'can set has_one relationship by id at creation time' do
|
108
106
|
father = Person.create!
|
109
107
|
child = Person.create! father_id: father.id
|
110
|
-
father.children.
|
108
|
+
expect(father.children).to eq([child])
|
111
109
|
end
|
112
110
|
|
113
111
|
it 'does not set has_one relationship by id if id is blank' do
|
114
112
|
father = Person.create!
|
115
113
|
child = Person.create! father_id: nil
|
116
|
-
father.children.
|
114
|
+
expect(father.children).to be_empty
|
117
115
|
end
|
118
116
|
|
119
117
|
it 'can remove has_one relationship' do
|
@@ -121,7 +119,7 @@ describe ActiveNode::Associations do
|
|
121
119
|
child = Person.create! father: father
|
122
120
|
child.father = nil
|
123
121
|
child.save
|
124
|
-
Person.find(child.id).father.
|
122
|
+
expect(Person.find(child.id).father).to be_nil
|
125
123
|
end
|
126
124
|
|
127
125
|
it 'can read has_one relation by id' do
|
@@ -129,19 +127,19 @@ describe ActiveNode::Associations do
|
|
129
127
|
child = Person.create!
|
130
128
|
child.father = father
|
131
129
|
child.save
|
132
|
-
child.father_id.
|
130
|
+
expect(child.father_id).to eq(father.id)
|
133
131
|
end
|
134
132
|
|
135
133
|
it "can access new association without being saved" do
|
136
134
|
father = Person.create!
|
137
135
|
child = Person.new
|
138
136
|
child.father = father
|
139
|
-
child.father.
|
137
|
+
expect(child.father).to eq(father)
|
140
138
|
end
|
141
139
|
|
142
140
|
it 'can handle has_one reverse relationship' do
|
143
141
|
father = Person.create!(children: [Person.create!])
|
144
|
-
father.children.first.father.
|
142
|
+
expect(father.children.first.father).to eq(father)
|
145
143
|
end
|
146
144
|
|
147
145
|
it 'returns relationships to related nodes' do
|
@@ -150,7 +148,7 @@ describe ActiveNode::Associations do
|
|
150
148
|
person = Person.create! child_ids: [child1.id, child2.id]
|
151
149
|
person.save
|
152
150
|
person = Person.find(person.id)
|
153
|
-
person.child_rels.map(&:other).
|
151
|
+
expect(person.child_rels.map(&:other)).to eq(person.children)
|
154
152
|
end
|
155
153
|
|
156
154
|
it 'relationship should include property' do
|
@@ -158,7 +156,7 @@ describe ActiveNode::Associations do
|
|
158
156
|
client.address_rel=ActiveNode::Relationship.new(Address.create!, address_type: 'home')
|
159
157
|
client.save
|
160
158
|
client = Client.find(client.id)
|
161
|
-
client.address_rel[:address_type].
|
159
|
+
expect(client.address_rel[:address_type]).to eq('home')
|
162
160
|
end
|
163
161
|
|
164
162
|
it 'should save updated property on relationship' do
|
@@ -170,13 +168,13 @@ describe ActiveNode::Associations do
|
|
170
168
|
client.save
|
171
169
|
client=Client.find(client.id)
|
172
170
|
ar=client.address_rel
|
173
|
-
ar[:address_type].
|
171
|
+
expect(ar[:address_type]).to eq('office')
|
174
172
|
end
|
175
173
|
|
176
174
|
it 'should retrieve multiple relationships at once' do
|
177
175
|
address = Address.create!
|
178
176
|
person = Person.create! children: [Person.create!(address: address)]
|
179
|
-
Person.find(person.id).children(:address).first.address.
|
177
|
+
expect(Person.find(person.id).children(:address).first.address).to eq(address)
|
180
178
|
end
|
181
179
|
|
182
180
|
it 'should handle simultaneous updates to father and children' do
|
@@ -186,7 +184,7 @@ describe ActiveNode::Associations do
|
|
186
184
|
father = Person.includes(:children).find(father.id)
|
187
185
|
father.children.first.update_attributes(father: nil)
|
188
186
|
father.update_attributes(name: "John")
|
189
|
-
Person.find(father.id).children.
|
187
|
+
expect(Person.find(father.id).children).to be_empty?
|
190
188
|
end
|
191
189
|
end
|
192
190
|
end
|
@@ -1,18 +1,16 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe ActiveNode::Base do
|
4
2
|
describe ".subclass" do
|
5
3
|
it "should be ActiveNode::Base" do
|
6
|
-
ActiveNode::Base.subclass('Abc').
|
4
|
+
expect(ActiveNode::Base.subclass('Abc')).to be <= ActiveNode::Base
|
7
5
|
end
|
8
6
|
|
9
7
|
it "should have the right label" do
|
10
|
-
ActiveNode::Base.subclass('Abc').label.
|
8
|
+
expect(ActiveNode::Base.subclass('Abc').label).to eq('Abc')
|
11
9
|
end
|
12
10
|
|
13
11
|
it "should find object via subclass" do
|
14
12
|
p = Person.create! name: 'Heinrich'
|
15
|
-
ActiveNode::Base.subclass('Person').find(p.id)[:name].
|
13
|
+
expect(ActiveNode::Base.subclass('Person').find(p.id)[:name]).to eq(p.name)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
@@ -1,13 +1,11 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe ActiveNode::QueryMethods do
|
4
2
|
describe "#order" do
|
5
3
|
it "should order" do
|
6
4
|
p1=Person.create!(name: 'abc')
|
7
5
|
p2=Person.create!(name: 'def')
|
8
|
-
Person.order(:name).
|
9
|
-
Person.order(name: :desc).
|
10
|
-
Person.order('name asc').reverse_order.
|
6
|
+
expect(Person.order(:name)).to eq([p1, p2])
|
7
|
+
expect(Person.order(name: :desc)).to eq([p2, p1])
|
8
|
+
expect(Person.order('name asc').reverse_order).to eq([p2, p1])
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
@@ -15,7 +13,7 @@ describe ActiveNode::QueryMethods do
|
|
15
13
|
it "should limt" do
|
16
14
|
p1=Person.create!(name: 'abc')
|
17
15
|
p2=Person.create!(name: 'def')
|
18
|
-
Person.limit(1).
|
16
|
+
expect(Person.limit(1)).to eq([p1])
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,62 +1,60 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe ActiveNode::Graph do
|
4
2
|
describe "#path" do
|
5
3
|
it "should parse includes" do
|
6
|
-
ActiveNode::Graph.new(Person, :father).send(:query).
|
7
|
-
ActiveNode::Graph.new(Person, :father, :children).send(:query).
|
8
|
-
ActiveNode::Graph.new(Person, children: 2).send(:query).
|
9
|
-
ActiveNode::Graph.new(Person, {children: :address}, :address).send(:query).
|
10
|
-
ActiveNode::Graph.new(Person, children: [:address, :father]).send(:query).
|
11
|
-
ActiveNode::Graph.new(Person, {children: 2} => [:address, :father]).send(:query).
|
12
|
-
ActiveNode::Graph.new(Person, {children: '*'} => [:address, :father]).send(:query).
|
4
|
+
expect(ActiveNode::Graph.new(Person, :father).send(:query)).to eq("optional match (n0)<-[r1:child]-(n1:`Person`)")
|
5
|
+
expect(ActiveNode::Graph.new(Person, :father, :children).send(:query)).to eq("optional match (n0)<-[r1:child]-(n1:`Person`) optional match (n0)-[r2:child]->(n2:`Person`)")
|
6
|
+
expect(ActiveNode::Graph.new(Person, children: 2).send(:query)).to eq("optional match (n0)-[r1:child*1..2]->(n1:`Person`)")
|
7
|
+
expect(ActiveNode::Graph.new(Person, {children: :address}, :address).send(:query)).to eq("optional match (n0)-[r1:child]->(n1:`Person`) optional match (n1)-[r2:address]->(n2:`Address`) optional match (n0)-[r3:address]->(n3:`Address`)")
|
8
|
+
expect(ActiveNode::Graph.new(Person, children: [:address, :father]).send(:query)).to eq("optional match (n0)-[r1:child]->(n1:`Person`) optional match (n1)-[r2:address]->(n2:`Address`) optional match (n1)<-[r3:child]-(n3:`Person`)")
|
9
|
+
expect(ActiveNode::Graph.new(Person, {children: 2} => [:address, :father]).send(:query)).to eq("optional match (n0)-[r1:child*1..2]->(n1:`Person`) optional match (n1)-[r2:address]->(n2:`Address`) optional match (n1)<-[r3:child]-(n3:`Person`)")
|
10
|
+
expect(ActiveNode::Graph.new(Person, {children: '*'} => [:address, :father]).send(:query)).to eq("optional match (n0)-[r1:child*]->(n1:`Person`) optional match (n1)-[r2:address]->(n2:`Address`) optional match (n1)<-[r3:child]-(n3:`Person`)")
|
13
11
|
end
|
14
12
|
|
15
13
|
it "should build graph" do
|
16
14
|
person = Person.create! children: [c1=Person.create!, c2=Person.create!(address: a=Address.create!)]
|
17
15
|
g_person = person.includes!({children: '*'} => [:address, :father])
|
18
16
|
g_person = ActiveNode::Graph.new(Person, {children: '*'} => [:address, :father]).build(person).first
|
19
|
-
g_person.
|
20
|
-
g_person.object_id.
|
21
|
-
ActiveNode::Neo.
|
22
|
-
g_person.children.last.address.
|
17
|
+
expect(g_person).to eq(person)
|
18
|
+
expect(g_person.object_id).to eq(person.object_id)
|
19
|
+
expect(ActiveNode::Neo).not_to receive(:db)
|
20
|
+
expect(g_person.children.last.address).to eq(a)
|
23
21
|
g_person.children.first.father = person
|
24
|
-
g_person.children.
|
22
|
+
expect(g_person.children).to eq([c1, c2])
|
25
23
|
end
|
26
24
|
|
27
25
|
it "should not query db twice" do
|
28
26
|
pending
|
29
27
|
person = Person.create!
|
30
28
|
person.includes! :children
|
31
|
-
ActiveNode::Neo.
|
29
|
+
expect(ActiveNode::Neo).not_to receive(:db)
|
32
30
|
person.children
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
describe '#empty?' do
|
37
35
|
it 'should return true' do
|
38
|
-
Person.all.
|
36
|
+
expect(Person.all).to be_empty
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
40
|
describe '#detect' do
|
43
41
|
it 'should return nil' do
|
44
|
-
Person.all.detect { |p| true }.
|
42
|
+
expect(Person.all.detect { |p| true }).to be_nil
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
46
|
describe '#includes' do
|
49
47
|
it 'should not throw an error' do
|
50
48
|
p = Person.create! father: Person.create!
|
51
|
-
Person.where(id: p.id).includes(:father).first.
|
49
|
+
expect(Person.where(id: p.id).includes(:father).first).to eq(p)
|
52
50
|
end
|
53
51
|
|
54
52
|
it "should return correct associated objects" do
|
55
53
|
child1 = Person.create! children: [Person.create!, Person.create!]
|
56
54
|
person = Person.create! children: [child1]
|
57
|
-
Person.includes(children: :children).find(person.id).children.
|
58
|
-
Person.includes(children: 2).find(person.id).children.
|
59
|
-
Person.includes(children: '*').find(person.id).children.
|
55
|
+
expect(Person.includes(children: :children).find(person.id).children).to eq([child1])
|
56
|
+
expect(Person.includes(children: 2).find(person.id).children).to eq([child1])
|
57
|
+
expect(Person.includes(children: '*').find(person.id).children).to eq([child1])
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
@@ -1,22 +1,20 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe ActiveNode::Persistence do
|
4
2
|
describe "#save" do
|
5
3
|
it "should save an object" do
|
6
4
|
a=Address.create!
|
7
|
-
Address.find(a.id).
|
5
|
+
expect(Address.find(a.id)).to eq(a)
|
8
6
|
end
|
9
7
|
|
10
8
|
it "should not set id property" do
|
11
9
|
a = Address.create!
|
12
|
-
ActiveNode::Neo.db.get_node_properties(a.id).
|
10
|
+
expect(ActiveNode::Neo.db.get_node_properties(a.id)['id']).to be_nil
|
13
11
|
a.save
|
14
|
-
ActiveNode::Neo.db.get_node_properties(a.id).
|
12
|
+
expect(ActiveNode::Neo.db.get_node_properties(a.id)['id']).to be_nil
|
15
13
|
end
|
16
14
|
|
17
15
|
it "should save unconventionally named object" do
|
18
|
-
NeoUser.new(name: 'Heinrich').save.
|
19
|
-
NeoUser.all.map(&:name).
|
16
|
+
expect(NeoUser.new(name: 'Heinrich').save).to be_truthy
|
17
|
+
expect(NeoUser.all.map(&:name)).to eq(['Heinrich'])
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should save object with non attribute properties with a name of a relationship" do
|
@@ -25,44 +23,44 @@ describe ActiveNode::Persistence do
|
|
25
23
|
person[:children] = "Bob"
|
26
24
|
person.save
|
27
25
|
person = Person.find person.id
|
28
|
-
person[:children].
|
29
|
-
person.children.
|
26
|
+
expect(person[:children]).to eq("Bob")
|
27
|
+
expect(person.children).to eq([child])
|
30
28
|
end
|
31
29
|
|
32
30
|
it 'should destroy node' do
|
33
31
|
user = NeoUser.create!(name: 'abc')
|
34
|
-
NeoUser.count.
|
35
|
-
user.destroy.
|
36
|
-
NeoUser.count.
|
32
|
+
expect(NeoUser.count).to eq(1)
|
33
|
+
expect(user.destroy).to be_truthy
|
34
|
+
expect(NeoUser.count).to eq(0)
|
37
35
|
end
|
38
36
|
|
39
37
|
it 'should not destroy node with relationships' do
|
40
38
|
person = Person.create! children: [Person.create!, Person.create!]
|
41
|
-
person.destroy.
|
42
|
-
Person.count.
|
39
|
+
expect(person.destroy).to be_falsey
|
40
|
+
expect(Person.count).to eq(3)
|
43
41
|
end
|
44
42
|
|
45
43
|
it 'should destroy! node with relationships' do
|
46
44
|
person = Person.create! children: [Person.create!, Person.create!]
|
47
|
-
person.destroy
|
48
|
-
Person.count.
|
45
|
+
expect(person.destroy!).to be_truthy
|
46
|
+
expect(Person.count).to eq(2)
|
49
47
|
end
|
50
48
|
|
51
49
|
it 'should record timestamp' do
|
52
50
|
now = Time.now
|
53
51
|
person = Person.create!
|
54
|
-
person.created_at.
|
52
|
+
expect(person.created_at).not_to be_nil
|
55
53
|
person = Person.find(person.id)
|
56
|
-
person.created_at.
|
57
|
-
person.updated_at.
|
54
|
+
expect(person.created_at).not_to be_nil
|
55
|
+
expect(person.updated_at).not_to be_nil
|
58
56
|
allow(Time).to receive(:now) { now + 1.second }
|
59
57
|
person.name = 'abc'
|
60
58
|
person.save
|
61
|
-
(person.created_at < person.updated_at).
|
59
|
+
expect(person.created_at < person.updated_at).to be_truthy
|
62
60
|
end
|
63
61
|
|
64
62
|
it 'should not record timestamp if not specified' do
|
65
|
-
Client.create!(name: 'abc').respond_to?(:created_at).
|
63
|
+
expect(Client.create!(name: 'abc').respond_to?(:created_at)).to be_falsey
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
@@ -82,47 +80,47 @@ describe ActiveNode::Persistence do
|
|
82
80
|
|
83
81
|
describe "#create!" do
|
84
82
|
it "should persist attributes" do
|
85
|
-
Person.create!(name: 'abc').name.
|
83
|
+
expect(Person.create!(name: 'abc').name).to eq('abc')
|
86
84
|
end
|
87
85
|
|
88
86
|
it "should persist array properties" do
|
89
87
|
person = Person.create!(multi: [1, 2, 3])
|
90
|
-
Person.find(person.id).multi.
|
88
|
+
expect(Person.find(person.id).multi).to eq([1, 2, 3])
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
94
92
|
describe "#find" do
|
95
93
|
it 'should find an object by id' do
|
96
94
|
person = Person.create!
|
97
|
-
Person.find(person.id).
|
95
|
+
expect(Person.find(person.id)).to eq(person)
|
98
96
|
end
|
99
97
|
|
100
98
|
it 'should find objects passing multiple ids' do
|
101
99
|
person1 = Person.create!
|
102
100
|
person2 = Person.create!
|
103
|
-
Person.find([person1.id, person2.id]).to_a.
|
101
|
+
expect(Person.find([person1.id, person2.id]).to_a).to eq([person1, person2])
|
104
102
|
end
|
105
103
|
|
106
104
|
it 'should find an object with id of an unknown model' do
|
107
|
-
ActiveNode::Base.find(Person.create!.id).class.
|
105
|
+
expect(ActiveNode::Base.find(Person.create!.id).class).to eq(Person)
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
111
109
|
describe "#attributes" do
|
112
110
|
it "should include id" do
|
113
|
-
Person.create!(name: 'abc').attributes['id'].
|
111
|
+
expect(Person.create!(name: 'abc').attributes['id']).not_to be_nil
|
114
112
|
end
|
115
113
|
end
|
116
114
|
|
117
115
|
describe "#to_param" do
|
118
116
|
it "should return a string version of the id" do
|
119
117
|
person = Person.create!
|
120
|
-
person.to_param.
|
118
|
+
expect(person.to_param).to eq(person.id.to_s)
|
121
119
|
end
|
122
120
|
|
123
121
|
it "should return nil if the id is nil" do
|
124
122
|
person = Person.new
|
125
|
-
person.to_param.
|
123
|
+
expect(person.to_param).to be_nil
|
126
124
|
end
|
127
125
|
end
|
128
126
|
|
@@ -149,7 +147,7 @@ describe ActiveNode::Persistence do
|
|
149
147
|
a = Address.create!
|
150
148
|
p=Person.create!(name: 'abc', address: a)
|
151
149
|
c=Client.create!(name: 'client', address: a)
|
152
|
-
a.incoming(:address).
|
150
|
+
expect(a.incoming(:address)).to include(p, c)
|
153
151
|
end
|
154
152
|
end
|
155
153
|
|
@@ -157,13 +155,23 @@ describe ActiveNode::Persistence do
|
|
157
155
|
it "should update atribute without validation" do
|
158
156
|
client = Client.create!(name: 'abc')
|
159
157
|
client.update_attribute(:name, nil)
|
160
|
-
Client.find(client.id).name.
|
158
|
+
expect(Client.find(client.id).name).to be_nil
|
161
159
|
end
|
162
160
|
end
|
163
161
|
|
164
162
|
describe "#wrap" do
|
165
163
|
it "should wrap nil as nil" do
|
166
|
-
Client.wrap(nil).
|
164
|
+
expect(Client.wrap(nil)).to be_nil
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "default" do
|
169
|
+
it "should default new object" do
|
170
|
+
expect(Address.new.city).to eq "New York"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should default created object" do
|
174
|
+
expect(Address.create!.city).to eq "New York"
|
167
175
|
end
|
168
176
|
end
|
169
177
|
end
|
@@ -1,32 +1,30 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe ActiveNode::Validations do
|
4
2
|
describe "#save" do
|
5
3
|
it "should not save invalid object" do
|
6
|
-
Client.new.save.
|
4
|
+
expect(Client.new.save).to be_falsey
|
7
5
|
end
|
8
6
|
|
9
7
|
it "should save valid object" do
|
10
|
-
Client.new(name: 'abc7').save.
|
11
|
-
Client.all.first.name.
|
8
|
+
expect(Client.new(name: 'abc7').save).to be_truthy
|
9
|
+
expect(Client.all.first.name).to eq('abc7')
|
12
10
|
end
|
13
11
|
|
14
12
|
describe "with uniqueness constraint" do
|
15
13
|
it "should validate uniqueness" do
|
16
14
|
Person.create! name: 'abc'
|
17
|
-
Person.new(name: 'abc').
|
15
|
+
expect(Person.new(name: 'abc')).not_to be_valid
|
18
16
|
end
|
19
17
|
|
20
18
|
it "should still be valid after save" do
|
21
19
|
person = Person.create! name: "abc"
|
22
|
-
person.
|
20
|
+
expect(person).to be_valid
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
24
|
it "should validate presence on has_one" do
|
27
|
-
House.new.
|
25
|
+
expect(House.new).not_to be_valid
|
28
26
|
house = House.create! address_id: Address.create!.id
|
29
|
-
House.find(house.id).
|
27
|
+
expect(House.find(house.id)).to be_valid
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
data/spec/models/address.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -42,12 +42,12 @@ end
|
|
42
42
|
|
43
43
|
def error_response(attributes)
|
44
44
|
request_uri = double()
|
45
|
-
request_uri.
|
45
|
+
allow(request_uri).to receive(:request_uri).and_return("")
|
46
46
|
|
47
47
|
http_header = double()
|
48
|
-
http_header.
|
48
|
+
allow(http_header).to receive(:request_uri).and_return(request_uri)
|
49
49
|
|
50
|
-
|
50
|
+
double(
|
51
51
|
http_header: http_header,
|
52
52
|
code: attributes[:code],
|
53
53
|
body: {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_node
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heinrich Klobuczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|
@@ -39,61 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activemodel
|
42
|
+
name: rspec
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
|
-
type: :
|
48
|
+
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "<="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 2.14.1
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "<="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 2.14.1
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: net-http-spy
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.2.1
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.2.1
|
97
55
|
- !ruby/object:Gem::Dependency
|
98
56
|
name: rake
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +102,7 @@ extensions: []
|
|
144
102
|
extra_rdoc_files: []
|
145
103
|
files:
|
146
104
|
- ".gitignore"
|
105
|
+
- ".rspec"
|
147
106
|
- ".travis.yml"
|
148
107
|
- Gemfile
|
149
108
|
- LICENSE
|