toystore 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/.gitignore +1 -2
  2. data/Changelog.md +9 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +71 -0
  5. data/Guardfile +15 -0
  6. data/README.md +28 -0
  7. data/examples/attributes_abbreviation.rb +1 -2
  8. data/examples/attributes_virtual.rb +1 -2
  9. data/examples/identity_map.rb +7 -12
  10. data/examples/memcached.rb +1 -1
  11. data/examples/memory.rb +1 -1
  12. data/examples/mongo.rb +1 -1
  13. data/examples/redis.rb +1 -1
  14. data/examples/riak.rb +1 -1
  15. data/lib/toy.rb +40 -39
  16. data/lib/toy/attribute.rb +1 -6
  17. data/lib/toy/attributes.rb +61 -90
  18. data/lib/toy/caching.rb +11 -13
  19. data/lib/toy/callbacks.rb +12 -31
  20. data/lib/toy/cloneable.rb +20 -0
  21. data/lib/toy/collection.rb +8 -7
  22. data/lib/toy/dirty.rb +17 -36
  23. data/lib/toy/dirty_store.rb +32 -0
  24. data/lib/toy/equality.rb +2 -0
  25. data/lib/toy/extensions/boolean.rb +22 -18
  26. data/lib/toy/identity_map.rb +39 -62
  27. data/lib/toy/list.rb +23 -22
  28. data/lib/toy/logger.rb +2 -17
  29. data/lib/toy/mass_assignment_security.rb +3 -5
  30. data/lib/toy/middleware/identity_map.rb +23 -4
  31. data/lib/toy/object.rb +16 -0
  32. data/lib/toy/persistence.rb +72 -62
  33. data/lib/toy/proxies/list.rb +19 -18
  34. data/lib/toy/proxies/proxy.rb +7 -6
  35. data/lib/toy/querying.rb +2 -4
  36. data/lib/toy/reference.rb +28 -26
  37. data/lib/toy/reloadable.rb +17 -0
  38. data/lib/toy/serialization.rb +25 -25
  39. data/lib/toy/store.rb +3 -11
  40. data/lib/toy/validations.rb +9 -28
  41. data/lib/toy/version.rb +1 -1
  42. data/perf/reads.rb +7 -9
  43. data/perf/writes.rb +6 -8
  44. data/spec/helper.rb +3 -1
  45. data/spec/support/constants.rb +1 -4
  46. data/spec/support/identity_map_matcher.rb +5 -5
  47. data/spec/support/objects.rb +38 -0
  48. data/spec/toy/attribute_spec.rb +1 -1
  49. data/spec/toy/attributes_spec.rb +1 -153
  50. data/spec/toy/callbacks_spec.rb +1 -45
  51. data/spec/toy/cloneable_spec.rb +47 -0
  52. data/spec/toy/dirty_spec.rb +12 -44
  53. data/spec/toy/dirty_store_spec.rb +47 -0
  54. data/spec/toy/equality_spec.rb +5 -19
  55. data/spec/toy/extensions/boolean_spec.rb +2 -0
  56. data/spec/toy/identity/uuid_key_factory_spec.rb +2 -2
  57. data/spec/toy/identity_map_spec.rb +45 -37
  58. data/spec/toy/identity_spec.rb +1 -1
  59. data/spec/toy/inspect_spec.rb +1 -1
  60. data/spec/toy/lists_spec.rb +20 -5
  61. data/spec/toy/logger_spec.rb +1 -29
  62. data/spec/toy/mass_assignment_security_spec.rb +16 -5
  63. data/spec/toy/middleware/identity_map_spec.rb +68 -2
  64. data/spec/toy/persistence_spec.rb +88 -30
  65. data/spec/toy/reference_spec.rb +0 -1
  66. data/spec/toy/references_spec.rb +20 -0
  67. data/spec/toy/reloadable_spec.rb +81 -0
  68. data/spec/toy/serialization_spec.rb +1 -110
  69. data/spec/toy/validations_spec.rb +0 -21
  70. data/spec/toy_spec.rb +4 -5
  71. data/test/lint_test.rb +1 -1
  72. metadata +21 -26
  73. data/.autotest +0 -11
  74. data/LOGGING.rdoc +0 -12
  75. data/README.rdoc +0 -27
  76. data/examples/models.rb +0 -51
  77. data/lib/toy/dolly.rb +0 -30
  78. data/lib/toy/embedded_list.rb +0 -45
  79. data/lib/toy/embedded_lists.rb +0 -68
  80. data/lib/toy/index.rb +0 -74
  81. data/lib/toy/indices.rb +0 -56
  82. data/lib/toy/proxies/embedded_list.rb +0 -79
  83. data/spec/toy/dolly_spec.rb +0 -76
  84. data/spec/toy/embedded_list_spec.rb +0 -607
  85. data/spec/toy/embedded_lists_spec.rb +0 -172
  86. data/spec/toy/index_spec.rb +0 -230
  87. data/spec/toy/indices_spec.rb +0 -141
  88. data/specs.watchr +0 -52
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ describe Toy::Reloadable do
4
+ uses_constants('User', 'Game')
5
+
6
+ describe "#reload" do
7
+ before do
8
+ User.attribute(:name, String)
9
+ @user = User.create(:name => 'John')
10
+ end
11
+ let(:user) { @user }
12
+
13
+ it "reloads id from database" do
14
+ id = user.id
15
+ user.reload
16
+ user.id.should == id
17
+ end
18
+
19
+ it "reloads record from the database" do
20
+ user.name = 'Steve'
21
+ user.reload
22
+ user.name.should == 'John'
23
+ end
24
+
25
+ it "is still persisted" do
26
+ user.should be_persisted
27
+ user.reload
28
+ user.should be_persisted
29
+ end
30
+
31
+ it "returns the record" do
32
+ user.name = 'Steve'
33
+ user.reload.should equal(user)
34
+ end
35
+
36
+ it "resets instance variables" do
37
+ user.instance_variable_set("@foo", true)
38
+ user.reload
39
+ user.instance_variable_get("@foo").should be_nil
40
+ end
41
+
42
+ it "resets lists" do
43
+ User.list(:games)
44
+ game = Game.create
45
+ user.update_attributes(:games => [game])
46
+ user.games = []
47
+ user.games.should == []
48
+ user.reload
49
+ user.games.should == [game]
50
+ end
51
+
52
+ it "resets references" do
53
+ Game.reference(:user)
54
+ game = Game.create(:user => user)
55
+ game.user = nil
56
+ game.user.should be_nil
57
+ game.reload
58
+ game.user.should == user
59
+ end
60
+
61
+ it "raises NotFound if does not exist" do
62
+ user.destroy
63
+ lambda { user.reload }.should raise_error(Toy::NotFound)
64
+ end
65
+
66
+ it "reloads defaults" do
67
+ User.attribute(:skills, Array)
68
+ @user.reload
69
+ @user.skills.should == []
70
+ end
71
+
72
+ it "reloads attributes protected from mass assignment" do
73
+ User.attribute(:admin, Boolean)
74
+ User.attr_accessible(:name)
75
+ user = User.new(:name => 'John')
76
+ user.admin = true
77
+ user.save
78
+ user.reload.admin.should be_true
79
+ end
80
+ end
81
+ end
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Toy::Serialization do
4
- uses_constants('User', 'Game', 'Move', 'Tile')
4
+ uses_constants('User', 'Game', 'Move')
5
5
 
6
6
  before do
7
7
  User.attribute :name, String
@@ -65,57 +65,6 @@ describe Toy::Serialization do
65
65
  ActiveSupport::JSON.decode(json)['user'].should_not have_key('id')
66
66
  end
67
67
 
68
- describe "serializing with embedded documents" do
69
- before do
70
- Game.reference(:creator, User)
71
-
72
- Move.attribute(:index, Integer)
73
- Move.attribute(:points, Integer)
74
- Move.attribute(:words, Array)
75
-
76
- Tile.attribute(:row, Integer)
77
- Tile.attribute(:column, Integer)
78
- Tile.attribute(:index, Integer)
79
-
80
- Game.embedded_list(:moves)
81
- Move.embedded_list(:tiles)
82
-
83
- @user = User.create
84
- @game = Game.create!(:creator => @user, :move_attributes => [
85
- :index => 0,
86
- :points => 15,
87
- :tile_attributes => [
88
- {:column => 7, :row => 7, :index => 23},
89
- {:column => 8, :row => 7, :index => 24},
90
- ],
91
- ])
92
- end
93
-
94
- it "includes all embedded attributes by default" do
95
- move = @game.moves.first
96
- tile1 = move.tiles[0]
97
- tile2 = move.tiles[1]
98
- ActiveSupport::JSON.decode(@game.to_json).should == {
99
- 'game' => {
100
- 'id' => @game.id,
101
- 'creator_id' => @user.id,
102
- 'moves' => [
103
- {
104
- 'id' => move.id,
105
- 'index' => 0,
106
- 'points' => 15,
107
- 'words' => [],
108
- 'tiles' => [
109
- {'id' => tile1.id, 'column' => 7, 'row' => 7, 'index' => 23},
110
- {'id' => tile2.id, 'column' => 8, 'row' => 7, 'index' => 24},
111
- ]
112
- },
113
- ],
114
- }
115
- }
116
- end
117
- end
118
-
119
68
  describe "serializing relationships" do
120
69
  before do
121
70
  User.list :games, :inverse_of => :user
@@ -209,30 +158,6 @@ describe Toy::Serialization do
209
158
  end
210
159
  end
211
160
 
212
- describe "serializing parent relationships" do
213
- before do
214
- Game.embedded_list :moves
215
- Move.parent_reference :game
216
- end
217
-
218
- it "should include references" do
219
- game = Game.create
220
- move = game.moves.create
221
-
222
- ActiveSupport::JSON.decode(move.to_json(:include => [:game])).should == {
223
- 'move' => {
224
- 'id' => move.id,
225
- 'game' => {
226
- 'id' => game.id,
227
- 'moves' => [{
228
- 'id' => move.id
229
- }]
230
- }
231
- }
232
- }
233
- end
234
- end
235
-
236
161
  describe "serializing specific attributes" do
237
162
  before do
238
163
  Move.attribute(:index, Integer)
@@ -301,40 +226,6 @@ describe Toy::Serialization do
301
226
  end
302
227
 
303
228
  describe "#serializable_hash" do
304
- context "with embedded list" do
305
- before do
306
- Game.embedded_list :moves
307
- Move.parent_reference :game
308
-
309
- @game = Game.create
310
- @move = game.moves.create
311
- end
312
- let(:game) { @game }
313
-
314
- it "returns a hash the whole way through" do
315
- game.serializable_hash.should == {
316
- 'id' => game.id,
317
- 'moves' => [
318
- {'id' => game.moves.first.id}
319
- ]
320
- }
321
- end
322
-
323
- it "allows using only with embedded" do
324
- game.serializable_hash(:only => :moves).should == {
325
- 'moves' => [
326
- {'id' => game.moves.first.id}
327
- ]
328
- }
329
- end
330
-
331
- it "allows using except to not include embedded" do
332
- game.serializable_hash(:except => :moves).should == {
333
- 'id' => game.id,
334
- }
335
- end
336
- end
337
-
338
229
  context "with method that is another toystore object" do
339
230
  before do
340
231
  Game.reference(:creator, User)
@@ -147,25 +147,4 @@ describe Toy::Validations do
147
147
  end
148
148
  end
149
149
  end
150
-
151
- describe ".validates_embedded" do
152
- before do
153
- Game.embedded_list(:moves)
154
- Move.attribute(:index, Integer)
155
- Move.validates_presence_of(:index)
156
- Game.validates_embedded(:moves)
157
- end
158
-
159
- it "adds errors if any of the embedded are invalid" do
160
- game = Game.new(:moves => [Move.new])
161
- game.valid?
162
- game.errors[:moves].should include('is invalid')
163
- end
164
-
165
- it "does not have errors if all embedded are valid" do
166
- game = Game.new(:moves => [Move.new(:index => 1)])
167
- game.valid?
168
- game.errors[:moves].should_not include('is invalid')
169
- end
170
- end
171
150
  end
data/spec/toy_spec.rb CHANGED
@@ -1,19 +1,18 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Toy do
4
- uses_constants('User', 'Game', 'Move')
4
+ uses_constants('User', 'Game')
5
5
 
6
6
  describe ".clear" do
7
- it "can clear all the stores in one magical moment" do
8
- Game.embedded_list(:moves)
7
+ it "can clear all the adapters in one magical moment" do
9
8
  user = User.create!
10
- game = Game.create!(:moves => [Move.new])
9
+ game = Game.create!
11
10
  Toy.clear
12
11
  User.get(user.id).should be_nil
13
12
  Game.get(game.id).should be_nil
14
13
  end
15
14
 
16
- it "does not raise error when no default store set" do
15
+ it "does not raise error when no default adapter set" do
17
16
  klass = Class.new { include Toy::Store }
18
17
  lambda { Toy.clear }.should_not raise_error
19
18
  end
data/test/lint_test.rb CHANGED
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  class User
30
30
  include Toy::Store
31
- store :memory, {}
31
+ adapter :memory, {}
32
32
  end
33
33
 
34
34
  class LintTest < ActiveModel::TestCase
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
9
- - 3
10
- version: 0.8.3
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoffrey Dagley
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-02-09 00:00:00 Z
19
+ date: 2012-03-14 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: adapter
@@ -105,19 +105,19 @@ extensions: []
105
105
  extra_rdoc_files: []
106
106
 
107
107
  files:
108
- - .autotest
109
108
  - .gitignore
109
+ - Changelog.md
110
110
  - Gemfile
111
+ - Gemfile.lock
112
+ - Guardfile
111
113
  - LICENSE
112
- - LOGGING.rdoc
113
- - README.rdoc
114
+ - README.md
114
115
  - Rakefile
115
116
  - examples/attributes_abbreviation.rb
116
117
  - examples/attributes_virtual.rb
117
118
  - examples/identity_map.rb
118
119
  - examples/memcached.rb
119
120
  - examples/memory.rb
120
- - examples/models.rb
121
121
  - examples/mongo.rb
122
122
  - examples/namespacing_keys.rb
123
123
  - examples/redis.rb
@@ -127,11 +127,10 @@ files:
127
127
  - lib/toy/attributes.rb
128
128
  - lib/toy/caching.rb
129
129
  - lib/toy/callbacks.rb
130
+ - lib/toy/cloneable.rb
130
131
  - lib/toy/collection.rb
131
132
  - lib/toy/dirty.rb
132
- - lib/toy/dolly.rb
133
- - lib/toy/embedded_list.rb
134
- - lib/toy/embedded_lists.rb
133
+ - lib/toy/dirty_store.rb
135
134
  - lib/toy/equality.rb
136
135
  - lib/toy/exceptions.rb
137
136
  - lib/toy/extensions/array.rb
@@ -149,22 +148,21 @@ files:
149
148
  - lib/toy/identity/abstract_key_factory.rb
150
149
  - lib/toy/identity/uuid_key_factory.rb
151
150
  - lib/toy/identity_map.rb
152
- - lib/toy/index.rb
153
- - lib/toy/indices.rb
154
151
  - lib/toy/inspect.rb
155
152
  - lib/toy/list.rb
156
153
  - lib/toy/lists.rb
157
154
  - lib/toy/logger.rb
158
155
  - lib/toy/mass_assignment_security.rb
159
156
  - lib/toy/middleware/identity_map.rb
157
+ - lib/toy/object.rb
160
158
  - lib/toy/persistence.rb
161
159
  - lib/toy/plugins.rb
162
- - lib/toy/proxies/embedded_list.rb
163
160
  - lib/toy/proxies/list.rb
164
161
  - lib/toy/proxies/proxy.rb
165
162
  - lib/toy/querying.rb
166
163
  - lib/toy/reference.rb
167
164
  - lib/toy/references.rb
165
+ - lib/toy/reloadable.rb
168
166
  - lib/toy/serialization.rb
169
167
  - lib/toy/store.rb
170
168
  - lib/toy/timestamps.rb
@@ -178,14 +176,14 @@ files:
178
176
  - spec/support/constants.rb
179
177
  - spec/support/identity_map_matcher.rb
180
178
  - spec/support/name_and_number_key_factory.rb
179
+ - spec/support/objects.rb
181
180
  - spec/toy/attribute_spec.rb
182
181
  - spec/toy/attributes_spec.rb
183
182
  - spec/toy/caching_spec.rb
184
183
  - spec/toy/callbacks_spec.rb
184
+ - spec/toy/cloneable_spec.rb
185
185
  - spec/toy/dirty_spec.rb
186
- - spec/toy/dolly_spec.rb
187
- - spec/toy/embedded_list_spec.rb
188
- - spec/toy/embedded_lists_spec.rb
186
+ - spec/toy/dirty_store_spec.rb
189
187
  - spec/toy/equality_spec.rb
190
188
  - spec/toy/exceptions_spec.rb
191
189
  - spec/toy/extensions/array_spec.rb
@@ -202,8 +200,6 @@ files:
202
200
  - spec/toy/identity/uuid_key_factory_spec.rb
203
201
  - spec/toy/identity_map_spec.rb
204
202
  - spec/toy/identity_spec.rb
205
- - spec/toy/index_spec.rb
206
- - spec/toy/indices_spec.rb
207
203
  - spec/toy/inspect_spec.rb
208
204
  - spec/toy/list_spec.rb
209
205
  - spec/toy/lists_spec.rb
@@ -215,12 +211,12 @@ files:
215
211
  - spec/toy/querying_spec.rb
216
212
  - spec/toy/reference_spec.rb
217
213
  - spec/toy/references_spec.rb
214
+ - spec/toy/reloadable_spec.rb
218
215
  - spec/toy/serialization_spec.rb
219
216
  - spec/toy/store_spec.rb
220
217
  - spec/toy/timestamps_spec.rb
221
218
  - spec/toy/validations_spec.rb
222
219
  - spec/toy_spec.rb
223
- - specs.watchr
224
220
  - test/lint_test.rb
225
221
  - toystore.gemspec
226
222
  homepage: http://github.com/newtoy/toystore
@@ -262,14 +258,14 @@ test_files:
262
258
  - spec/support/constants.rb
263
259
  - spec/support/identity_map_matcher.rb
264
260
  - spec/support/name_and_number_key_factory.rb
261
+ - spec/support/objects.rb
265
262
  - spec/toy/attribute_spec.rb
266
263
  - spec/toy/attributes_spec.rb
267
264
  - spec/toy/caching_spec.rb
268
265
  - spec/toy/callbacks_spec.rb
266
+ - spec/toy/cloneable_spec.rb
269
267
  - spec/toy/dirty_spec.rb
270
- - spec/toy/dolly_spec.rb
271
- - spec/toy/embedded_list_spec.rb
272
- - spec/toy/embedded_lists_spec.rb
268
+ - spec/toy/dirty_store_spec.rb
273
269
  - spec/toy/equality_spec.rb
274
270
  - spec/toy/exceptions_spec.rb
275
271
  - spec/toy/extensions/array_spec.rb
@@ -286,8 +282,6 @@ test_files:
286
282
  - spec/toy/identity/uuid_key_factory_spec.rb
287
283
  - spec/toy/identity_map_spec.rb
288
284
  - spec/toy/identity_spec.rb
289
- - spec/toy/index_spec.rb
290
- - spec/toy/indices_spec.rb
291
285
  - spec/toy/inspect_spec.rb
292
286
  - spec/toy/list_spec.rb
293
287
  - spec/toy/lists_spec.rb
@@ -299,6 +293,7 @@ test_files:
299
293
  - spec/toy/querying_spec.rb
300
294
  - spec/toy/reference_spec.rb
301
295
  - spec/toy/references_spec.rb
296
+ - spec/toy/reloadable_spec.rb
302
297
  - spec/toy/serialization_spec.rb
303
298
  - spec/toy/store_spec.rb
304
299
  - spec/toy/timestamps_spec.rb
data/.autotest DELETED
@@ -1,11 +0,0 @@
1
- require 'autotest/growl'
2
-
3
- Autotest.add_hook(:initialize) {|at|
4
- at.add_exception %r{^\.git} # ignore Version Control System
5
- at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
6
- # at.clear_mappings # take out the default (test/test*rb)
7
- at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
8
- Dir['spec/**/*.rb']
9
- }
10
- nil
11
- }