thingtank 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -22
- data/Rakefile +1 -6
- data/VERSION +1 -1
- data/examples/bear_julius.rb +7 -7
- data/examples/first_marriage.rb +4 -4
- data/examples/immortal_julius.rb +2 -2
- data/examples/marriage_improvement.rb +11 -11
- data/examples/second_marriage.rb +2 -2
- data/lib/couchrest/extensions/view.rb +3 -3
- data/lib/thingtank/callbacks.rb +1 -1
- data/lib/thingtank/{role.rb → character.rb} +21 -21
- data/lib/thingtank/character_handling.rb +198 -0
- data/lib/thingtank/dependencies.rb +16 -16
- data/lib/thingtank/fakebase.rb +17 -17
- data/lib/thingtank/shared_methods.rb +19 -19
- data/lib/thingtank/shortcuts.rb +6 -6
- data/lib/thingtank/thingtank.rb +2 -2
- data/lib/thingtank.rb +9 -4
- data/test/test_fakebase.rb +115 -115
- data/test/test_helper.rb +4 -4
- data/test/test_thingtank.rb +17 -17
- data/test/test_views.rb +6 -6
- metadata +29 -29
- data/lib/thingtank/role_handling.rb +0 -198
data/test/test_fakebase.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
describe "should
|
3
|
+
describe "should character a CouchRest::Database" do
|
4
4
|
|
5
5
|
it "create a couchrest doc" do
|
6
6
|
|
@@ -14,20 +14,20 @@ describe "should role a CouchRest::Database" do
|
|
14
14
|
assert !doc.new?
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should
|
17
|
+
it "should character" do
|
18
18
|
doc = create :a => 'A', :b => 'B'
|
19
|
-
|
20
|
-
assert_equal "pong",
|
21
|
-
assert_equal "A",
|
22
|
-
assert_equal "A",
|
19
|
+
character = doc.to_character(Check)
|
20
|
+
assert_equal "pong", character.ping
|
21
|
+
assert_equal "A", character.a
|
22
|
+
assert_equal "A", character["a"]
|
23
23
|
end
|
24
24
|
|
25
|
-
it "should update a
|
26
|
-
doc = create :a => 'A', :b => 'B', :
|
27
|
-
|
28
|
-
assert_equal false,
|
29
|
-
|
30
|
-
|
25
|
+
it "should update a character" do
|
26
|
+
doc = create :a => 'A', :b => 'B', :characters => ['Check']
|
27
|
+
character = doc.to_character(Check)
|
28
|
+
assert_equal false, character.new?
|
29
|
+
character.c = "C"
|
30
|
+
character.save
|
31
31
|
doc.reload
|
32
32
|
assert_equal "ThingTank", doc["type"]
|
33
33
|
assert_equal "B", doc["b"]
|
@@ -37,11 +37,11 @@ describe "should role a CouchRest::Database" do
|
|
37
37
|
assert doc["check_created"].nil?
|
38
38
|
end
|
39
39
|
|
40
|
-
it "should create a
|
40
|
+
it "should create a character, based on doc that did not have this character" do
|
41
41
|
doc = create :a => 'A', :b => 'B'
|
42
|
-
|
43
|
-
assert
|
44
|
-
|
42
|
+
character = doc.add_character(Check)
|
43
|
+
assert character.new?, "character should be new when freshly added"
|
44
|
+
character.c = "C"
|
45
45
|
doc.save
|
46
46
|
doc.reload
|
47
47
|
assert_equal "ThingTank", doc["type"]
|
@@ -52,17 +52,17 @@ describe "should role a CouchRest::Database" do
|
|
52
52
|
assert doc["check_updated"].nil?
|
53
53
|
|
54
54
|
doc.reload
|
55
|
-
|
56
|
-
assert_equal false,
|
55
|
+
character = doc.to_character(Check)
|
56
|
+
assert_equal false, character.new?
|
57
57
|
end
|
58
58
|
|
59
|
-
it "should create a
|
60
|
-
doc = new :a => 'A', :b => 'B', :
|
61
|
-
|
62
|
-
assert
|
63
|
-
|
64
|
-
|
65
|
-
assert_equal false,
|
59
|
+
it "should create a character, based on a new doc" do
|
60
|
+
doc = new :a => 'A', :b => 'B', :characters => ['Check']
|
61
|
+
character = doc.to_character(Check)
|
62
|
+
assert character.new?
|
63
|
+
character.c = "C"
|
64
|
+
character.save
|
65
|
+
assert_equal false, character.changed?
|
66
66
|
doc.reload
|
67
67
|
assert_equal "ThingTank", doc["type"]
|
68
68
|
assert_equal "B", doc["b"]
|
@@ -72,83 +72,83 @@ describe "should role a CouchRest::Database" do
|
|
72
72
|
assert doc["check_updated"].nil?
|
73
73
|
|
74
74
|
doc.reload
|
75
|
-
|
76
|
-
assert_equal false,
|
77
|
-
assert_equal false,
|
75
|
+
character = doc.to_character(Check)
|
76
|
+
assert_equal false, character.new?
|
77
|
+
assert_equal false, character.changed?
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should not be valid if the requirements aren't met" do
|
81
81
|
doc = new
|
82
|
-
|
83
|
-
assert !
|
82
|
+
character = doc.to_character(Check)
|
83
|
+
assert !character.valid?
|
84
84
|
end
|
85
85
|
|
86
|
-
it "should be able to access other
|
86
|
+
it "should be able to access other characters and autosave the accessed characters if they are not saved by themselves" do
|
87
87
|
doc = new :a => 'A'
|
88
|
-
|
89
|
-
|
88
|
+
character = doc.to_character(Check)
|
89
|
+
character.access_other_character
|
90
90
|
doc.save
|
91
91
|
doc.reload
|
92
92
|
assert_equal "I was here", doc["checker1"]
|
93
|
-
assert_equal true, doc["
|
94
|
-
assert_equal true, doc["
|
93
|
+
assert_equal true, doc["characters"].include?(Checker.to_s)
|
94
|
+
assert_equal true, doc["characters"].include?(Check.to_s)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should not be able to save properties we don't have" do
|
98
98
|
doc = new :a => 'A'
|
99
|
-
|
100
|
-
|
99
|
+
character = doc.to_character(Check)
|
100
|
+
character.set_properties_we_don_t_have
|
101
101
|
|
102
102
|
assert_raises RuntimeError do
|
103
|
-
|
103
|
+
character.save
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should be able to save properties of the doc" do
|
108
108
|
doc = new :a => 'A'
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
character = doc.to_character(Check)
|
110
|
+
character.set_properties_of_doc
|
111
|
+
character.save
|
112
112
|
doc.reload
|
113
113
|
assert_equal "got it", doc["ooops"]
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should only destroy it's own properties" do
|
117
|
-
doc = create :a => 'A', :c => 'C', :b => 'B', :shared => 'keep me too', :checker1 => 'keep me!', :
|
118
|
-
|
117
|
+
doc = create :a => 'A', :c => 'C', :b => 'B', :shared => 'keep me too', :checker1 => 'keep me!', :characters => ['Check', 'Checker']
|
118
|
+
character = doc.to_character(Check)
|
119
119
|
doc.save
|
120
120
|
doc.reload
|
121
121
|
assert 'A', doc["a"]
|
122
122
|
assert 'C', doc["c"]
|
123
123
|
assert_equal "keep me!", doc["checker1"]
|
124
124
|
assert_equal "keep me too", doc["shared"]
|
125
|
-
assert doc["
|
125
|
+
assert doc["characters"].include?(Check.to_s)
|
126
126
|
|
127
127
|
# now destroy Check
|
128
|
-
|
129
|
-
|
128
|
+
character = doc.to_character(Check)
|
129
|
+
character.destroy
|
130
130
|
doc.save
|
131
131
|
doc.reload
|
132
|
-
assert_equal ['Checker'], doc["
|
132
|
+
assert_equal ['Checker'], doc["characters"]
|
133
133
|
assert_equal "B", doc["b"]
|
134
134
|
assert_equal "keep me!", doc["checker1"]
|
135
135
|
assert_equal "keep me too", doc["shared"]
|
136
136
|
assert doc["a"].nil?
|
137
137
|
end
|
138
138
|
|
139
|
-
it "should trying to make a
|
140
|
-
doc = create :simple => { :a => 'A', :c => 'C', :b => 'B', :
|
141
|
-
|
142
|
-
|
139
|
+
it "should trying to make a character from a property" do
|
140
|
+
doc = create :simple => { :a => 'A', :c => 'C', :b => 'B', :characters => ['Check']}, :checker1 => 'keep me!', :characters => ['Checker']
|
141
|
+
character = doc.to_character(Check,'simple')
|
142
|
+
character.c = "BC"
|
143
143
|
doc.save
|
144
144
|
assert_equal "BC", doc["simple"]["c"]
|
145
145
|
assert doc["simple"]["check_saved"]
|
146
146
|
end
|
147
147
|
|
148
|
-
it "should trying to make a array of
|
149
|
-
doc = create :simple => [{ :a => 'A1', :c => 'C1', :b => 'B1', :
|
150
|
-
|
151
|
-
|
148
|
+
it "should trying to make a array of characters from a property" do
|
149
|
+
doc = create :simple => [{ :a => 'A1', :c => 'C1', :b => 'B1', :characters => ['Check']}, { :a => 'A2', :c => 'C2', :b => 'B2', :characters => ['Check']}], :checker1 => 'keep me!', :characters => ['Checker']
|
150
|
+
characters = doc.to_character(Check, 'simple')
|
151
|
+
characters.each do |fk|
|
152
152
|
fk.c = fk.c.downcase
|
153
153
|
end
|
154
154
|
|
@@ -160,12 +160,12 @@ describe "should role a CouchRest::Database" do
|
|
160
160
|
end
|
161
161
|
|
162
162
|
|
163
|
-
it "should also possible to use a
|
164
|
-
checks = [{ :a => 'A1', :c => 'C1', :b => 'B1', :
|
165
|
-
doc = create :checker1 => checks, :
|
166
|
-
|
163
|
+
it "should also possible to use a character as property of a character" do
|
164
|
+
checks = [{ :a => 'A1', :c => 'C1', :b => 'B1', :characters => ['Check']}, { :a => 'A2', :c => 'C2', :b => 'B2', :characters => ['Check']}]
|
165
|
+
doc = create :checker1 => checks, :characters => ['Checker']
|
166
|
+
character = doc.to_character(Checker)
|
167
167
|
|
168
|
-
|
168
|
+
character.to_character(Check, 'checker1').each do |fk|
|
169
169
|
fk.c = fk.c.downcase
|
170
170
|
end
|
171
171
|
|
@@ -174,20 +174,20 @@ describe "should role a CouchRest::Database" do
|
|
174
174
|
assert_equal "c2", doc["checker1"].last["c"]
|
175
175
|
end
|
176
176
|
|
177
|
-
it "should also possible to use a
|
178
|
-
doc = create :simple => { :a => 'AAAA', :c => {:checker1 => 'modify me!!!!!', :
|
179
|
-
|
180
|
-
|
181
|
-
|
177
|
+
it "should also possible to use a character as property of anotherone" do
|
178
|
+
doc = create :simple => { :a => 'AAAA', :c => {:checker1 => 'modify me!!!!!', :characters => ['Checker']}, :b => 'B', :characters => ['Check']}
|
179
|
+
character1 = doc.to_character(Check, 'simple')
|
180
|
+
character2 = character1.to_character(Checker, 'c')
|
181
|
+
character2.checker1 = "modified!!!!"
|
182
182
|
doc.save
|
183
183
|
assert_equal "modified!!!!", doc["simple"]["c"]["checker1"]
|
184
184
|
end
|
185
185
|
|
186
|
-
it "should also possible to use a
|
187
|
-
doc = create :simple => { :a => 'AAAA', :c => [{:checker1 => 'mod1', :
|
188
|
-
|
189
|
-
|
190
|
-
|
186
|
+
it "should also possible to use a character as property of anotherone (array)" do
|
187
|
+
doc = create :simple => { :a => 'AAAA', :c => [{:checker1 => 'mod1', :characters => ['Checker']},{:checker1 => 'mod2', :characters => ['Checker']}], :b => 'B', :characters => ['Check']}
|
188
|
+
character1 = doc.to_character(Check, 'simple')
|
189
|
+
characters = character1.to_character(Checker, 'c')
|
190
|
+
characters.each do |fk|
|
191
191
|
fk.checker1 = fk.checker1.upcase
|
192
192
|
end
|
193
193
|
|
@@ -196,16 +196,16 @@ describe "should role a CouchRest::Database" do
|
|
196
196
|
assert_equal "MOD2", doc["simple"]["c"].last["checker1"]
|
197
197
|
end
|
198
198
|
|
199
|
-
it "should also possible to use a
|
200
|
-
doc = create :simple => { :a => 'AAAA', :c => [{:checker1 => 'mod1', :
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
it "should also possible to use a character as property of anotherone (array.save)" do
|
200
|
+
doc = create :simple => { :a => 'AAAA', :c => [{:checker1 => 'mod1', :characters => ['Checker']},{:checker1 => 'mod2', :characters => ['Checker']}], :b => 'B', :characters => ['Check']}
|
201
|
+
character1 = doc.to_character(Check, 'simple')
|
202
|
+
characters = character1.to_character(Checker, 'c')
|
203
|
+
characters.each do |fk|
|
204
204
|
fk.checker1 = fk.checker1.upcase
|
205
205
|
end
|
206
206
|
|
207
207
|
# saves only the first
|
208
|
-
|
208
|
+
characters.first.save
|
209
209
|
assert_equal "MOD1", doc["simple"]["c"].first["checker1"]
|
210
210
|
assert_equal "mod2", doc["simple"]["c"].last["checker1"]
|
211
211
|
|
@@ -215,21 +215,21 @@ describe "should role a CouchRest::Database" do
|
|
215
215
|
assert_equal "MOD2", doc["simple"]["c"].last["checker1"]
|
216
216
|
end
|
217
217
|
|
218
|
-
it "should also possible to use a
|
219
|
-
doc = create :simple => { :a => 'AAAA', :c => {:checker1 => 'modify me!!!!!', :
|
220
|
-
|
221
|
-
|
222
|
-
|
218
|
+
it "should also possible to use a character as property of anotherone (destroy hook)" do
|
219
|
+
doc = create :simple => { :a => 'AAAA', :c => {:checker1 => 'modify me!!!!!', :characters => ['Checker'], :a => 'A'}, :b => 'B', :characters => ['Check', 'Checker']}
|
220
|
+
character1 = doc.to_character(Check, 'simple')
|
221
|
+
character2 = character1.to_character(Checker, 'c')
|
222
|
+
character2.destroy
|
223
223
|
doc.save
|
224
224
|
assert_equal 'A', doc["simple"]["c"]["a"]
|
225
225
|
assert doc["simple"]["c"]["checker1"].nil?
|
226
226
|
end
|
227
227
|
|
228
228
|
|
229
|
-
it "should also possible to use a
|
230
|
-
doc = create :simple => { :a => 'AAAA', :c => [{:checker1 => 'mod1', :a => 'A', :
|
231
|
-
|
232
|
-
f =
|
229
|
+
it "should also possible to use a character as property of anotherone (array. trigger destroy hook)" do
|
230
|
+
doc = create :simple => { :a => 'AAAA', :c => [{:checker1 => 'mod1', :a => 'A', :characters => ['Checker']},{:checker1 => 'mod2', :characters => ['Checker']}], :b => 'B', :characters => ['Check']}
|
231
|
+
character1 = doc.to_character(Check, 'simple')
|
232
|
+
f = character1.first_character(Checker, 'c')
|
233
233
|
|
234
234
|
assert_equal 'mod1', doc["simple"]["c"].first["checker1"]
|
235
235
|
assert_equal 'A', doc["simple"]["c"].first["a"]
|
@@ -238,7 +238,7 @@ describe "should role a CouchRest::Database" do
|
|
238
238
|
assert_equal 'mod1', f.checker1
|
239
239
|
f.destroy
|
240
240
|
assert_equal nil, f.checker1
|
241
|
-
assert_equal 'A', f.
|
241
|
+
assert_equal 'A', f._character_doc["a"]
|
242
242
|
doc.save
|
243
243
|
doc.reload
|
244
244
|
|
@@ -247,24 +247,24 @@ describe "should role a CouchRest::Database" do
|
|
247
247
|
end
|
248
248
|
|
249
249
|
|
250
|
-
it "should allow adding of a
|
250
|
+
it "should allow adding of a character as property with properties directly set" do
|
251
251
|
doc = create
|
252
|
-
doc.
|
252
|
+
doc.add_character(Check, 'check') do |c|
|
253
253
|
c.a = 'A'
|
254
254
|
end
|
255
255
|
|
256
256
|
assert_equal 'A', doc["check"]["a"]
|
257
257
|
end
|
258
258
|
|
259
|
-
it "should allow adding of a
|
259
|
+
it "should allow adding of a character as property without properties directly set" do
|
260
260
|
doc = create
|
261
|
-
doc.
|
261
|
+
doc.add_character(Check, 'check')
|
262
262
|
|
263
|
-
doc.
|
263
|
+
doc.last_character(Check, 'check') do |c|
|
264
264
|
c.a = 'A'
|
265
265
|
end
|
266
266
|
|
267
|
-
doc.
|
267
|
+
doc.last_character(Check, 'check') do |c|
|
268
268
|
c.c = 'C'
|
269
269
|
end
|
270
270
|
|
@@ -273,19 +273,19 @@ describe "should role a CouchRest::Database" do
|
|
273
273
|
assert_equal 'C', doc["check"]["c"]
|
274
274
|
end
|
275
275
|
|
276
|
-
it "should allow adding of a
|
276
|
+
it "should allow adding of a character as property multiple times transforming into an array by the way" do
|
277
277
|
doc = create
|
278
|
-
doc.
|
278
|
+
doc.add_character(Check, 'check') do |c|
|
279
279
|
c.a = 'A1'
|
280
280
|
end
|
281
281
|
|
282
282
|
assert_equal 'A1', doc["check"]["a"]
|
283
283
|
|
284
|
-
doc.
|
284
|
+
doc.add_character(Check, 'check') do |c|
|
285
285
|
c.a = 'A2'
|
286
286
|
end
|
287
287
|
|
288
|
-
doc.
|
288
|
+
doc.add_character(Check, 'check') do |c|
|
289
289
|
c.a = 'A3'
|
290
290
|
end
|
291
291
|
|
@@ -294,21 +294,21 @@ describe "should role a CouchRest::Database" do
|
|
294
294
|
assert_equal 'A3', doc["check"].last["a"]
|
295
295
|
end
|
296
296
|
|
297
|
-
it "should allow adding of a
|
297
|
+
it "should allow adding of a character of a character as property with properties directly set 1" do
|
298
298
|
doc = create
|
299
|
-
doc.
|
299
|
+
doc.add_character(Check, 'check') do |c|
|
300
300
|
c.a = 'A'
|
301
301
|
end
|
302
302
|
|
303
|
-
|
303
|
+
character = doc.to_character(Check, 'check')
|
304
304
|
|
305
|
-
|
305
|
+
character.add_character(Checker, 'sub') do |ck|
|
306
306
|
ck.checker1 = 'hiho'
|
307
307
|
end
|
308
308
|
|
309
309
|
assert_equal 'hiho', doc["check"]["sub"]["checker1"]
|
310
310
|
|
311
|
-
|
311
|
+
character.add_character(Checker, 'sub') do |ck|
|
312
312
|
ck.checker1 = 'hoho'
|
313
313
|
end
|
314
314
|
|
@@ -319,38 +319,38 @@ describe "should role a CouchRest::Database" do
|
|
319
319
|
end
|
320
320
|
|
321
321
|
|
322
|
-
it "should allow adding of a
|
322
|
+
it "should allow adding of a character of a character as property with properties directly set 2" do
|
323
323
|
doc = create
|
324
|
-
doc.
|
324
|
+
doc.add_character(Check, 'check') do |c|
|
325
325
|
c.a = 'A1'
|
326
326
|
end
|
327
327
|
|
328
|
-
doc.
|
328
|
+
doc.add_character(Check, 'check') do |c|
|
329
329
|
c.a = 'A2'
|
330
330
|
end
|
331
331
|
|
332
332
|
|
333
|
-
|
333
|
+
character1 = doc.first_character(Check, 'check')
|
334
334
|
|
335
|
-
|
335
|
+
character1.add_character(Checker, 'sub') do |ck|
|
336
336
|
ck.checker1 = 'A1sub1'
|
337
337
|
end
|
338
338
|
|
339
339
|
assert_equal 'A1sub1', doc["check"].first["sub"]["checker1"]
|
340
340
|
|
341
|
-
|
341
|
+
character1.add_character(Checker, 'sub') do |ck|
|
342
342
|
ck.checker1 = 'A1sub2'
|
343
343
|
end
|
344
344
|
|
345
|
-
|
345
|
+
character2 = doc.last_character(Check, 'check')
|
346
346
|
|
347
|
-
|
347
|
+
character2.add_character(Checker, 'sub') do |ck|
|
348
348
|
ck.checker1 = 'A2sub1'
|
349
349
|
end
|
350
350
|
|
351
351
|
assert_equal 'A2sub1', doc["check"].last["sub"]["checker1"]
|
352
352
|
|
353
|
-
|
353
|
+
character2.add_character(Checker, 'sub') do |ck|
|
354
354
|
ck.checker1 = 'A2sub2'
|
355
355
|
end
|
356
356
|
|
@@ -366,17 +366,17 @@ describe "should role a CouchRest::Database" do
|
|
366
366
|
end
|
367
367
|
|
368
368
|
|
369
|
-
it "should allow adding of a
|
369
|
+
it "should allow adding of a character as property without properties directly set" do
|
370
370
|
doc = create
|
371
|
-
doc.
|
371
|
+
doc.add_character(Check, 'check') do |c|
|
372
372
|
c.a = 'A'
|
373
373
|
end
|
374
374
|
|
375
|
-
|
375
|
+
character1 = doc.last_character(Check, 'check')
|
376
376
|
|
377
|
-
|
377
|
+
character1.add_character(Checker, 'sub')
|
378
378
|
|
379
|
-
|
379
|
+
character1.last_character(Checker, 'sub') do |ck|
|
380
380
|
ck.checker1 = 'A1sub1'
|
381
381
|
end
|
382
382
|
|
data/test/test_helper.rb
CHANGED
@@ -49,7 +49,7 @@ def db_load(id)
|
|
49
49
|
ThingTank.get id
|
50
50
|
end
|
51
51
|
|
52
|
-
class Check < ThingTank::
|
52
|
+
class Check < ThingTank::Character
|
53
53
|
property :a
|
54
54
|
property :c
|
55
55
|
property :check_saved
|
@@ -62,8 +62,8 @@ class Check < ThingTank::Role
|
|
62
62
|
"pong"
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
checker = database.
|
65
|
+
def access_other_character
|
66
|
+
checker = database.to_character(Checker)
|
67
67
|
checker["checker1"] = "I was here"
|
68
68
|
end
|
69
69
|
|
@@ -96,7 +96,7 @@ class Check < ThingTank::Role
|
|
96
96
|
validates_presence_of :a
|
97
97
|
end
|
98
98
|
|
99
|
-
class Checker < ThingTank::
|
99
|
+
class Checker < ThingTank::Character
|
100
100
|
property :shared
|
101
101
|
property :checker1
|
102
102
|
|
data/test/test_thingtank.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class DrivingLicense < ThingTank::
|
3
|
+
class DrivingLicense < ThingTank::Character
|
4
4
|
property :date_of_driving_license, String
|
5
5
|
property :driving_license_state
|
6
6
|
property :tester
|
@@ -17,7 +17,7 @@ class DrivingLicense < ThingTank::Role
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
class Car < ThingTank::
|
20
|
+
class Car < ThingTank::Character
|
21
21
|
property :color, String
|
22
22
|
property :model, String
|
23
23
|
|
@@ -38,13 +38,13 @@ describe "a general test" do
|
|
38
38
|
reset_test_db!
|
39
39
|
end
|
40
40
|
|
41
|
-
it "should add a
|
41
|
+
it "should add a character if set by is but not if just asked if it could be a character" do
|
42
42
|
doc1 = create
|
43
43
|
doc1.is(DrivingLicense)
|
44
44
|
could_it = doc1.could_be?(Car)
|
45
45
|
doc1.save
|
46
46
|
assert_equal false, could_it
|
47
|
-
assert_equal ["DrivingLicense"], db_load(doc1.id)["
|
47
|
+
assert_equal ["DrivingLicense"], db_load(doc1.id)["characters"]
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should work with with" do
|
@@ -133,7 +133,7 @@ describe "a general test" do
|
|
133
133
|
|
134
134
|
|
135
135
|
it "make the changed test" do
|
136
|
-
doc = create :a => "A", :
|
136
|
+
doc = create :a => "A", :characters => ["Check"]
|
137
137
|
assert doc.is? Check
|
138
138
|
assert !doc.as(Check).changed?
|
139
139
|
chk = doc.as(Check) do |c|
|
@@ -177,22 +177,22 @@ describe "a general test" do
|
|
177
177
|
assert_equal({ "hi" => "ho" }, doc["thingie"])
|
178
178
|
end
|
179
179
|
|
180
|
-
it "
|
181
|
-
doc = create :color => 'black', :model => 'Carrera', :
|
180
|
+
it "is a car" do
|
181
|
+
doc = create :color => 'black', :model => 'Carrera', :characters => ['Car']
|
182
182
|
assert_equal true, doc.is?(Car)
|
183
183
|
end
|
184
184
|
|
185
185
|
it "cannot be a car" do
|
186
186
|
doc = create :model => 'Carrera'
|
187
|
-
doc["
|
187
|
+
doc["characters"] = ['Car']
|
188
188
|
assert_equal false, doc.is?(Car)
|
189
|
-
assert_equal ["Car"], doc.
|
189
|
+
assert_equal ["Car"], doc.invalid_characters
|
190
190
|
#assert_raises RuntimeError do
|
191
191
|
# doc.save
|
192
192
|
#end
|
193
193
|
doc["color"] = 'blue'
|
194
194
|
assert_equal true, doc.is?(Car)
|
195
|
-
assert_equal [], doc.
|
195
|
+
assert_equal [], doc.invalid_characters
|
196
196
|
doc.save
|
197
197
|
doc.reload
|
198
198
|
assert_equal true, doc.is?(Car)
|
@@ -253,22 +253,22 @@ describe "a thingtank" do
|
|
253
253
|
it "should be able to change the name of a property" do
|
254
254
|
end
|
255
255
|
|
256
|
-
it "should be able to share properties with different
|
256
|
+
it "should be able to share properties with different characters" do
|
257
257
|
end
|
258
258
|
|
259
|
-
it "should trigger all affected callbacks when a property is shared between
|
259
|
+
it "should trigger all affected callbacks when a property is shared between characters" do
|
260
260
|
end
|
261
261
|
|
262
|
-
it "should allow an alias for a property if the property needs disambiguation between the different meanings for the different
|
262
|
+
it "should allow an alias for a property if the property needs disambiguation between the different meanings for the different characters" do
|
263
263
|
end
|
264
264
|
|
265
|
-
it "should allow general handlers for
|
265
|
+
it "should allow general handlers for characters that only are affected if a doc fits to a character and ignore the docs otherwise" do
|
266
266
|
end
|
267
267
|
|
268
|
-
it "should allow views that handle only the chosen
|
268
|
+
it "should allow views that handle only the chosen characters" do
|
269
269
|
end
|
270
270
|
|
271
|
-
it "should recommend interesting new
|
271
|
+
it "should recommend interesting new characters" do
|
272
272
|
end
|
273
273
|
|
274
274
|
it "should validate with validatable" do
|
@@ -280,7 +280,7 @@ describe "a thingtank" do
|
|
280
280
|
it "should handle pagination" do
|
281
281
|
end
|
282
282
|
|
283
|
-
it "should have
|
283
|
+
it "should have characters" do
|
284
284
|
end
|
285
285
|
|
286
286
|
end
|
data/test/test_views.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'pp'
|
3
3
|
|
4
|
-
class Car < ThingTank::
|
4
|
+
class Car < ThingTank::Character
|
5
5
|
property :name
|
6
6
|
end
|
7
7
|
|
8
|
-
class House < ThingTank::
|
8
|
+
class House < ThingTank::Character
|
9
9
|
property :name
|
10
10
|
end
|
11
11
|
|
12
|
-
class Ship < ThingTank::
|
12
|
+
class Ship < ThingTank::Character
|
13
13
|
property :name
|
14
14
|
property :weight
|
15
15
|
end
|
@@ -18,9 +18,9 @@ end
|
|
18
18
|
class Tanker < ThingTank
|
19
19
|
|
20
20
|
design do
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
character_view Car, :by_name, :by => ['name']
|
22
|
+
character_view House, :by_name, :by => ['name']
|
23
|
+
character_view Ship, :by_name, :by => ['name']
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|