active_repository 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/active_repository.gemspec +23 -0
- data/lib/active_repository/associations.rb +102 -0
- data/lib/active_repository/base.rb +266 -0
- data/lib/active_repository/sql_query_executor.rb +123 -0
- data/lib/active_repository/uniqueness.rb +196 -0
- data/lib/active_repository/version.rb +3 -0
- data/lib/active_repository/write_support.rb +76 -0
- data/lib/active_repository.rb +15 -0
- data/spec/active_repository/base_spec.rb +123 -0
- data/spec/active_repository/sql_query_executor_spec.rb +84 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/shared_examples.rb +582 -0
- data/spec/support/sql_query_shared_examples.rb +317 -0
- metadata +164 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
|
|
3
|
+
shared_examples "=" do
|
|
4
|
+
context "when attribute is string" do
|
|
5
|
+
it "matches a record" do
|
|
6
|
+
record = Country.where("name = 'US'")
|
|
7
|
+
record.count.should == 1
|
|
8
|
+
record.first.id.should == 1
|
|
9
|
+
record.first.name.should == 'US'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "doesn't match any record" do
|
|
13
|
+
record = Country.where("name = 'Argentina'")
|
|
14
|
+
record.count.should == 0
|
|
15
|
+
record.should == []
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when attribute is integer" do
|
|
20
|
+
it "matches a record" do
|
|
21
|
+
record = Country.where("id = 1")
|
|
22
|
+
record.count.should == 1
|
|
23
|
+
record.first.id.should == 1
|
|
24
|
+
record.first.name.should == 'US'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "doesn't match any record" do
|
|
28
|
+
record = Country.where("id = 43")
|
|
29
|
+
record.count.should == 0
|
|
30
|
+
record.should == []
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when attribute is datetime" do
|
|
35
|
+
it "matches a record" do
|
|
36
|
+
record = Country.where("founded_at = ?", Time.parse('1500-04-22 13:34:25'))
|
|
37
|
+
record.count.should == 1
|
|
38
|
+
record.first.id.should == 5
|
|
39
|
+
record.first.name.should == 'Brazil'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "doesn't match any record" do
|
|
43
|
+
record = Country.where("id = ?", Time.parse('1500-09-07 13:34:25'))
|
|
44
|
+
record.count.should == 0
|
|
45
|
+
record.should == []
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
shared_examples ">" do
|
|
51
|
+
context "when attribute is a string" do
|
|
52
|
+
it "matches a record" do
|
|
53
|
+
records = Country.where("name > 'T'")
|
|
54
|
+
records.count.should == 2
|
|
55
|
+
records.first.id.should == 1
|
|
56
|
+
records.should == [Country.find(1), Country.find(4)]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "doesn't match any record" do
|
|
60
|
+
record = Country.where("name > 'Z'")
|
|
61
|
+
record.count.should == 0
|
|
62
|
+
record.should == []
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "when attribute is integer" do
|
|
67
|
+
it "matches a record" do
|
|
68
|
+
records = Country.where("id > 3")
|
|
69
|
+
records.count.should == 2
|
|
70
|
+
records.first.id.should == 4
|
|
71
|
+
records.should == [Country.find(4), Country.find(5)]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "doesn't match any record" do
|
|
75
|
+
record = Country.where("id > 5")
|
|
76
|
+
record.count.should == 0
|
|
77
|
+
record.should == []
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "when attribute is datetime" do
|
|
82
|
+
it "matches a record" do
|
|
83
|
+
record = Country.where("founded_at > ?", Time.parse('1500-04-20 13:34:25'))
|
|
84
|
+
record.count.should == 1
|
|
85
|
+
record.first.id.should == 5
|
|
86
|
+
record.first.name.should == 'Brazil'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "doesn't match any record" do
|
|
90
|
+
record = Country.where("founded_at > ?", Time.parse('1500-04-23 13:34:25'))
|
|
91
|
+
record.count.should == 0
|
|
92
|
+
record.should == []
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
shared_examples ">=" do
|
|
98
|
+
context "when attribute is a string" do
|
|
99
|
+
it "matches a record" do
|
|
100
|
+
records = Country.where("name >= 'U'")
|
|
101
|
+
records.count.should == 2
|
|
102
|
+
records.first.id.should == 1
|
|
103
|
+
records.should == [Country.find(1), Country.find(4)]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "doesn't match any record" do
|
|
107
|
+
record = Country.where("name >= 'Z'")
|
|
108
|
+
record.count.should == 0
|
|
109
|
+
record.should == []
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context "when attribute is integer" do
|
|
114
|
+
it "matches a record" do
|
|
115
|
+
records = Country.where("id >= 4")
|
|
116
|
+
records.count.should == 2
|
|
117
|
+
records.first.id.should == 4
|
|
118
|
+
records.should == [Country.find(4), Country.find(5)]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "doesn't match any record" do
|
|
122
|
+
record = Country.where("id >= 6")
|
|
123
|
+
record.count.should == 0
|
|
124
|
+
record.should == []
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
context "when attribute is datetime" do
|
|
129
|
+
it "matches a record" do
|
|
130
|
+
record = Country.where("founded_at >= ?", Time.parse('1500-04-22 13:34:25'))
|
|
131
|
+
record.count.should == 1
|
|
132
|
+
record.first.id.should == 5
|
|
133
|
+
record.first.name.should == 'Brazil'
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "doesn't match any record" do
|
|
137
|
+
record = Country.where("founded_at >= ?", Time.parse('1500-04-23 13:34:25'))
|
|
138
|
+
record.count.should == 0
|
|
139
|
+
record.should == []
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
shared_examples "<" do
|
|
145
|
+
context "when attribute is a string" do
|
|
146
|
+
it "matches a record" do
|
|
147
|
+
records = Country.where("name < 'C'")
|
|
148
|
+
records.count.should == 1
|
|
149
|
+
records.first.id.should == 5
|
|
150
|
+
records.should == [Country.find(5)]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "doesn't match any record" do
|
|
154
|
+
record = Country.where("name < 'B'")
|
|
155
|
+
record.count.should == 0
|
|
156
|
+
record.should == []
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
context "when attribute is integer" do
|
|
161
|
+
it "matches a record" do
|
|
162
|
+
records = Country.where("id < 3")
|
|
163
|
+
records.count.should == 2
|
|
164
|
+
records.first.id.should == 1
|
|
165
|
+
records.should == [Country.find(1), Country.find(2)]
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "doesn't match any record" do
|
|
169
|
+
record = Country.where("id < 1")
|
|
170
|
+
record.count.should == 0
|
|
171
|
+
record.should == []
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
context "when attribute is datetime" do
|
|
176
|
+
it "matches a record" do
|
|
177
|
+
record = Country.where("founded_at < ?", Time.parse('1500-04-22 13:34:26'))
|
|
178
|
+
record.count.should == 1
|
|
179
|
+
record.first.id.should == 5
|
|
180
|
+
record.first.name.should == 'Brazil'
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "doesn't match any record" do
|
|
184
|
+
record = Country.where("founded_at < ?", Time.parse('1500-04-22 13:34:25'))
|
|
185
|
+
record.count.should == 0
|
|
186
|
+
record.should == []
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
shared_examples "<=" do
|
|
192
|
+
context "when attribute is a string" do
|
|
193
|
+
it "matches a record" do
|
|
194
|
+
records = Country.where("name <= 'Brb'")
|
|
195
|
+
records.count.should == 1
|
|
196
|
+
records.first.id.should == 5
|
|
197
|
+
records.should == [Country.find(5)]
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "doesn't match any record" do
|
|
201
|
+
record = Country.where("name <= 'A'")
|
|
202
|
+
record.count.should == 0
|
|
203
|
+
record.should == []
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
context "when attribute is integer" do
|
|
208
|
+
it "matches a record" do
|
|
209
|
+
records = Country.where("id <= 2")
|
|
210
|
+
records.count.should == 2
|
|
211
|
+
records.first.id.should == 1
|
|
212
|
+
records.should == [Country.find(1), Country.find(2)]
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "doesn't match any record" do
|
|
216
|
+
record = Country.where("id <= 0")
|
|
217
|
+
record.count.should == 0
|
|
218
|
+
record.should == []
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
context "when attribute is datetime" do
|
|
223
|
+
it "matches a record" do
|
|
224
|
+
record = Country.where("founded_at <= ?", Time.parse('1500-04-22 13:34:25'))
|
|
225
|
+
record.count.should == 1
|
|
226
|
+
record.first.id.should == 5
|
|
227
|
+
record.first.name.should == 'Brazil'
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "doesn't match any record" do
|
|
231
|
+
record = Country.where("founded_at <= ?", Time.parse('1500-04-22 13:34:24'))
|
|
232
|
+
record.count.should == 0
|
|
233
|
+
record.should == []
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
shared_examples "between" do
|
|
239
|
+
context "when attribute is a string" do
|
|
240
|
+
it "matches a record" do
|
|
241
|
+
records = Country.where("name between 'A' and 'C'")
|
|
242
|
+
records.count.should == 1
|
|
243
|
+
records.first.id.should == 5
|
|
244
|
+
records.should == [Country.find(5)]
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
it "doesn't match any record" do
|
|
248
|
+
record = Country.where("name between 'K' and 'M'")
|
|
249
|
+
record.count.should == 0
|
|
250
|
+
record.should == []
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context "when attribute is integer" do
|
|
255
|
+
it "matches a record" do
|
|
256
|
+
records = Country.where("id between 1 and 2")
|
|
257
|
+
records.count.should == 2
|
|
258
|
+
records.first.id.should == 1
|
|
259
|
+
records.should == [Country.find(1), Country.find(2)]
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it "doesn't match any record" do
|
|
263
|
+
record = Country.where("id between 6 and 10")
|
|
264
|
+
record.count.should == 0
|
|
265
|
+
record.should == []
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
context "when attribute is datetime" do
|
|
270
|
+
it "matches a record" do
|
|
271
|
+
record = Country.where("founded_at between ? and ?", Time.parse('1500-04-22 13:34:24'), Time.parse('1500-04-22 13:34:26'))
|
|
272
|
+
record.count.should == 1
|
|
273
|
+
record.first.id.should == 5
|
|
274
|
+
record.first.name.should == 'Brazil'
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it "doesn't match any record" do
|
|
278
|
+
record = Country.where("founded_at between ? and ?", Time.parse('1500-04-22 13:34:26'), Time.parse('1500-09-22 13:34:25'))
|
|
279
|
+
record.count.should == 0
|
|
280
|
+
record.should == []
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
shared_examples "is" do
|
|
286
|
+
it "attribute is condition" do
|
|
287
|
+
records = Country.where("founded_at is null")
|
|
288
|
+
records.count.should == 4
|
|
289
|
+
records.first.id.should == 1
|
|
290
|
+
records.should == [Country.find(1), Country.find(2), Country.find(3), Country.find(4)]
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "attribute is not condition" do
|
|
294
|
+
records = Country.where("founded_at is not null")
|
|
295
|
+
records.count.should == 1
|
|
296
|
+
records.first.id.should == 5
|
|
297
|
+
records.should == [Country.find(5)]
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
shared_examples "and" do
|
|
302
|
+
it "attribute and condition" do
|
|
303
|
+
records = Country.where("language = 'English' and monarch = 'The Crown of England'")
|
|
304
|
+
records.count.should == 2
|
|
305
|
+
records.first.id.should == 2
|
|
306
|
+
records.should == [Country.find(2), Country.find(4)]
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
shared_examples "or" do
|
|
311
|
+
it "attribute or condition" do
|
|
312
|
+
records = Country.where("language = 'English' or language = 'Spanish'")
|
|
313
|
+
records.count.should == 4
|
|
314
|
+
records.first.id.should == 1
|
|
315
|
+
records.should == [Country.find(1), Country.find(2), Country.find(3), Country.find(4)]
|
|
316
|
+
end
|
|
317
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: active_repository
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Caio Torres
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: active_hash
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.9.12
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.9.12
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: activemodel
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 3.2.6
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 3.2.6
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rspec
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ~>
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 2.2.0
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.2.0
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: sqlite3
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: activerecord
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
type: :development
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: mongoid
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
none: false
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ! '>='
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
description: An implementation of repository pattern that can connect with any ORM
|
|
111
|
+
email:
|
|
112
|
+
- efreesen@gmail.com
|
|
113
|
+
executables: []
|
|
114
|
+
extensions: []
|
|
115
|
+
extra_rdoc_files: []
|
|
116
|
+
files:
|
|
117
|
+
- .gitignore
|
|
118
|
+
- Gemfile
|
|
119
|
+
- LICENSE
|
|
120
|
+
- README.md
|
|
121
|
+
- Rakefile
|
|
122
|
+
- active_repository.gemspec
|
|
123
|
+
- lib/active_repository.rb
|
|
124
|
+
- lib/active_repository/associations.rb
|
|
125
|
+
- lib/active_repository/base.rb
|
|
126
|
+
- lib/active_repository/sql_query_executor.rb
|
|
127
|
+
- lib/active_repository/uniqueness.rb
|
|
128
|
+
- lib/active_repository/version.rb
|
|
129
|
+
- lib/active_repository/write_support.rb
|
|
130
|
+
- spec/active_repository/base_spec.rb
|
|
131
|
+
- spec/active_repository/sql_query_executor_spec.rb
|
|
132
|
+
- spec/spec_helper.rb
|
|
133
|
+
- spec/support/shared_examples.rb
|
|
134
|
+
- spec/support/sql_query_shared_examples.rb
|
|
135
|
+
homepage: http://github.com/efreesen/active_repository
|
|
136
|
+
licenses: []
|
|
137
|
+
post_install_message:
|
|
138
|
+
rdoc_options: []
|
|
139
|
+
require_paths:
|
|
140
|
+
- lib
|
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
|
+
none: false
|
|
143
|
+
requirements:
|
|
144
|
+
- - ! '>='
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '0'
|
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
|
+
none: false
|
|
149
|
+
requirements:
|
|
150
|
+
- - ! '>='
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
requirements: []
|
|
154
|
+
rubyforge_project:
|
|
155
|
+
rubygems_version: 1.8.24
|
|
156
|
+
signing_key:
|
|
157
|
+
specification_version: 3
|
|
158
|
+
summary: An implementation of repository pattern that can connect with any ORM
|
|
159
|
+
test_files:
|
|
160
|
+
- spec/active_repository/base_spec.rb
|
|
161
|
+
- spec/active_repository/sql_query_executor_spec.rb
|
|
162
|
+
- spec/spec_helper.rb
|
|
163
|
+
- spec/support/shared_examples.rb
|
|
164
|
+
- spec/support/sql_query_shared_examples.rb
|