/
query_spec.rb
205 lines (150 loc) · 4.42 KB
/
query_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
require 'spec_helper'
class Person
include Neo4j::ActiveNode
property :name, type: String
property :age, type: Integer
end
describe 'Neo4j::ActiveNode queries' do
# Copied from http://guides.rubyonrails.org/active_record_querying.html
# http://guides.rubyonrails.org/active_record_querying.html#retrieving-a-single-object
describe '1.1 Retrieving a Single Object' do
before(:each) { delete_db }
shared_context "people" do |attribute_list|
let(:people) do
attribute_list.each do |attributes|
Person.create(attributes)
end
end
end
describe 'Using a Primary Key' do
describe 'find' do
subject { Person.find(id) }
let(:id) { people.first.id }
include_context 'people', [] do
let(:id) { 0 }
it { should == nil }
end
include_context 'people', [{}] do
it { should == people.first }
end
include_context 'people', [{},{}] do
it { should == people.first }
end
end
describe 'take' do
subject { Person.take }
include_context 'people', [] do
it { should == nil }
end
include_context 'people', [{}] do
it { should == people.first }
end
include_context 'people', [{},{}] do
it { should == people.first }
end
end
describe 'first' do
subject { Person.first }
include_context 'people', [] do
it { should == nil }
end
include_context 'people', [{}] do
it { should == people.first }
end
include_context 'people', [{},{}] do
it { should == people.first }
end
end
describe 'last' do
subject { Person.last }
include_context 'people', [] do
it { should == nil }
end
include_context 'people', [{}] do
it { should == people.last }
end
include_context 'people', [{},{}] do
it { should == people.last }
end
end
describe 'find_by' do
subject { Person.find_by name: 'Brian' }
include_context 'people', [{name: 'Brian'}, {name: 'Andreas'}] do
it { should == people.first }
end
include_context 'people', [{name: 'Andreas'}, {name: 'Brian'}] do
it { should == nil }
end
include_context 'people', [{name: 'Brian!'}, {name: 'Andreas'}] do
it { should == nil }
end
end
# ...
end
end
describe '1.2 Retrieving Multiple Objects' do
describe 'Using Multiple Primary Keys' do
describe 'Client.find([1, 10])' do
it 'finds the clients with primary keys 1 and 10'
end
end
end
describe '1.3 Retrieving Multiple Objects in Batches' do
describe 'User.all' do
end
# ...
end
describe '2.1 Pure String Conditions' do
describe %q[Client.where("orders_count = '2'")] do
end
end
describe '2.2 Array Conditions' do
describe 'Client.where("orders_count = {orders}", orders: params[:orders])' do
end
end
describe '2.3 Hash Conditions' do
end
describe '3 Ordering' do
describe 'Client.order(:created_at)'
describe 'Client.order("created_at")'
describe 'Client.order(created_at: :desc)'
# ...
end
describe '4 Selecting Specific Fields' do
describe 'Client.select("viewable_by, locked")'
describe 'Client.select(:name).distinct'
end
describe '5 Limit and Offset' do
describe 'Client.limit(5)'
describe 'Client.limit(5).offset(30)'
end
describe '6 Group' do
# Not sure we can or should do this
# http://docs.neo4j.org/chunked/stable/query-aggregation.html
end
describe '7 Having' do
# not sure we should do this,
# http://stackoverflow.com/questions/18138752/can-neo4j-cypher-query-do-similar-thing-as-having-in-sql
end
# Scope ?
# 15 Dynamic Finders
describe '15 Dynamic Finders'
describe '16 Find or Build a New Object'
describe '18 Existence of Objects'
describe '19 Calculations' do
describe '19.1 Count' do
describe 'Client.count'
describe %q[Client.where(first_name: 'Ryan').count']
end
describe '19.2 Average'
describe '19.3 Minimum' do
describe 'Client.minimum("age")'
end
describe '19.4 Maximum' do
describe 'Client.maximum("age")'
end
describe '19.5 Sum' do
describe 'Client.sum("orders_count")'
end
end
end