cequel 0.5.6 → 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cequel.rb +5 -8
  3. data/lib/cequel/errors.rb +1 -0
  4. data/lib/cequel/metal.rb +17 -0
  5. data/lib/cequel/metal/batch.rb +62 -0
  6. data/lib/cequel/metal/cql_row_specification.rb +26 -0
  7. data/lib/cequel/metal/data_set.rb +461 -0
  8. data/lib/cequel/metal/deleter.rb +47 -0
  9. data/lib/cequel/metal/incrementer.rb +35 -0
  10. data/lib/cequel/metal/inserter.rb +53 -0
  11. data/lib/cequel/metal/keyspace.rb +213 -0
  12. data/lib/cequel/metal/row.rb +48 -0
  13. data/lib/cequel/metal/row_specification.rb +37 -0
  14. data/lib/cequel/metal/statement.rb +30 -0
  15. data/lib/cequel/metal/updater.rb +65 -0
  16. data/lib/cequel/metal/writer.rb +73 -0
  17. data/lib/cequel/model.rb +12 -84
  18. data/lib/cequel/model/association_collection.rb +23 -0
  19. data/lib/cequel/model/associations.rb +84 -80
  20. data/lib/cequel/model/base.rb +74 -0
  21. data/lib/cequel/model/belongs_to_association.rb +31 -0
  22. data/lib/cequel/model/callbacks.rb +14 -10
  23. data/lib/cequel/model/collection.rb +255 -0
  24. data/lib/cequel/model/errors.rb +6 -6
  25. data/lib/cequel/model/has_many_association.rb +26 -0
  26. data/lib/cequel/model/mass_assignment.rb +31 -0
  27. data/lib/cequel/model/persistence.rb +119 -115
  28. data/lib/cequel/model/properties.rb +89 -87
  29. data/lib/cequel/model/railtie.rb +21 -14
  30. data/lib/cequel/model/record_set.rb +285 -0
  31. data/lib/cequel/model/schema.rb +33 -0
  32. data/lib/cequel/model/scoped.rb +5 -48
  33. data/lib/cequel/model/validations.rb +18 -18
  34. data/lib/cequel/schema.rb +15 -0
  35. data/lib/cequel/schema/column.rb +135 -0
  36. data/lib/cequel/schema/create_table_dsl.rb +56 -0
  37. data/lib/cequel/schema/keyspace.rb +50 -0
  38. data/lib/cequel/schema/table.rb +120 -0
  39. data/lib/cequel/schema/table_property.rb +67 -0
  40. data/lib/cequel/schema/table_reader.rb +139 -0
  41. data/lib/cequel/schema/table_synchronizer.rb +114 -0
  42. data/lib/cequel/schema/table_updater.rb +83 -0
  43. data/lib/cequel/schema/table_writer.rb +80 -0
  44. data/lib/cequel/schema/update_table_dsl.rb +60 -0
  45. data/lib/cequel/type.rb +232 -0
  46. data/lib/cequel/version.rb +1 -1
  47. data/spec/environment.rb +5 -1
  48. data/spec/examples/metal/data_set_spec.rb +608 -0
  49. data/spec/examples/model/associations_spec.rb +84 -74
  50. data/spec/examples/model/callbacks_spec.rb +66 -59
  51. data/spec/examples/model/list_spec.rb +393 -0
  52. data/spec/examples/model/map_spec.rb +229 -0
  53. data/spec/examples/model/mass_assignment_spec.rb +55 -0
  54. data/spec/examples/model/naming_spec.rb +11 -4
  55. data/spec/examples/model/persistence_spec.rb +140 -150
  56. data/spec/examples/model/properties_spec.rb +122 -75
  57. data/spec/examples/model/record_set_spec.rb +285 -0
  58. data/spec/examples/model/schema_spec.rb +44 -0
  59. data/spec/examples/model/serialization_spec.rb +20 -14
  60. data/spec/examples/model/set_spec.rb +133 -0
  61. data/spec/examples/model/spec_helper.rb +0 -10
  62. data/spec/examples/model/validations_spec.rb +51 -38
  63. data/spec/examples/schema/table_reader_spec.rb +328 -0
  64. data/spec/examples/schema/table_synchronizer_spec.rb +172 -0
  65. data/spec/examples/schema/table_updater_spec.rb +157 -0
  66. data/spec/examples/schema/table_writer_spec.rb +225 -0
  67. data/spec/examples/spec_helper.rb +29 -0
  68. data/spec/examples/type_spec.rb +204 -0
  69. data/spec/support/helpers.rb +67 -8
  70. metadata +121 -152
  71. data/lib/cequel/batch.rb +0 -58
  72. data/lib/cequel/cql_row_specification.rb +0 -22
  73. data/lib/cequel/data_set.rb +0 -371
  74. data/lib/cequel/keyspace.rb +0 -205
  75. data/lib/cequel/model/class_internals.rb +0 -49
  76. data/lib/cequel/model/column.rb +0 -20
  77. data/lib/cequel/model/counter.rb +0 -35
  78. data/lib/cequel/model/dictionary.rb +0 -126
  79. data/lib/cequel/model/dirty.rb +0 -53
  80. data/lib/cequel/model/dynamic.rb +0 -31
  81. data/lib/cequel/model/inheritable.rb +0 -48
  82. data/lib/cequel/model/instance_internals.rb +0 -23
  83. data/lib/cequel/model/local_association.rb +0 -42
  84. data/lib/cequel/model/magic.rb +0 -79
  85. data/lib/cequel/model/mass_assignment_security.rb +0 -21
  86. data/lib/cequel/model/naming.rb +0 -17
  87. data/lib/cequel/model/observer.rb +0 -42
  88. data/lib/cequel/model/readable_dictionary.rb +0 -182
  89. data/lib/cequel/model/remote_association.rb +0 -40
  90. data/lib/cequel/model/scope.rb +0 -362
  91. data/lib/cequel/model/subclass_internals.rb +0 -45
  92. data/lib/cequel/model/timestamps.rb +0 -52
  93. data/lib/cequel/model/translation.rb +0 -17
  94. data/lib/cequel/row_specification.rb +0 -63
  95. data/lib/cequel/statement.rb +0 -23
  96. data/spec/examples/data_set_spec.rb +0 -444
  97. data/spec/examples/keyspace_spec.rb +0 -84
  98. data/spec/examples/model/counter_spec.rb +0 -94
  99. data/spec/examples/model/dictionary_spec.rb +0 -301
  100. data/spec/examples/model/dirty_spec.rb +0 -39
  101. data/spec/examples/model/dynamic_spec.rb +0 -41
  102. data/spec/examples/model/inheritable_spec.rb +0 -45
  103. data/spec/examples/model/magic_spec.rb +0 -199
  104. data/spec/examples/model/mass_assignment_security_spec.rb +0 -13
  105. data/spec/examples/model/observer_spec.rb +0 -86
  106. data/spec/examples/model/scope_spec.rb +0 -677
  107. data/spec/examples/model/timestamps_spec.rb +0 -52
  108. data/spec/examples/model/translation_spec.rb +0 -23
@@ -1,84 +0,0 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
- require 'stringio'
3
- require 'logger'
4
-
5
- describe Cequel::Keyspace do
6
- describe '::batch' do
7
- it 'should send enclosed write statements in bulk' do
8
- connection.should_receive(:execute).with(<<CQL, [:id, :title], [1, 'Hey'], :body, 'Body')
9
- BEGIN BATCH
10
- INSERT INTO posts (?) VALUES (?)
11
- UPDATE posts SET ? = ?
12
- DELETE FROM posts
13
- APPLY BATCH
14
- CQL
15
- cequel.batch do
16
- cequel[:posts].insert(:id => 1, :title => 'Hey')
17
- cequel[:posts].update(:body => 'Body')
18
- cequel[:posts].delete
19
- end
20
- end
21
-
22
- it 'should auto-apply if option given' do
23
- connection.should_receive(:execute).with(<<CQL, [:id, :title], [1, 'Hey'], :body, 'Body')
24
- BEGIN BATCH
25
- INSERT INTO posts (?) VALUES (?)
26
- UPDATE posts SET ? = ?
27
- APPLY BATCH
28
- CQL
29
- connection.should_receive(:execute).with(<<CQL)
30
- BEGIN BATCH
31
- DELETE FROM posts
32
- APPLY BATCH
33
- CQL
34
-
35
- cequel.batch(:auto_apply => 2) do
36
- cequel[:posts].insert(:id => 1, :title => 'Hey')
37
- cequel[:posts].update(:body => 'Body')
38
- cequel[:posts].delete
39
- end
40
- end
41
-
42
- it 'should do nothing if no statements executed in batch' do
43
- expect { cequel.batch {} }.to_not raise_error
44
- end
45
- end
46
-
47
- describe '::connection_pool' do
48
- it 'should use connection pool if pool specified' do
49
- #NOTE: called one time per pool entry
50
- Cequel::Keyspace.any_instance.should_receive(:build_connection).once.and_return(connection)
51
- Cequel::Keyspace.any_instance.should_receive(:connection).never
52
- keyspace = Cequel::Keyspace.new(:pool => 1)
53
-
54
- keyspace.with_connection { |conn| }
55
- keyspace.with_connection { |conn| }
56
- keyspace.with_connection { |conn| }
57
- end
58
-
59
- it 'should not use connection pool if no pool specified' do
60
- Cequel::Keyspace.any_instance.should_receive(:connection).exactly(3).times.and_return(connection)
61
- keyspace = Cequel::Keyspace.new({})
62
-
63
- keyspace.with_connection { |conn| }
64
- keyspace.with_connection { |conn| }
65
- keyspace.with_connection { |conn| }
66
- end
67
- end
68
-
69
- describe '::logger=' do
70
- let(:io) { StringIO.new }
71
- let(:logger) { Logger.new(io) }
72
-
73
- before do
74
- logger.level = Logger::DEBUG
75
- cequel.logger = logger
76
- end
77
-
78
- it 'should log queries with bind variables resolved' do
79
- connection.stub(:execute).with("SELECT ? FROM posts", [:id, :title]).and_return result_stub
80
- cequel[:posts].select(:id, :title).to_a
81
- io.string.should =~ /CQL \(\d+ms\) SELECT 'id','title' FROM posts/
82
- end
83
- end
84
- end
@@ -1,94 +0,0 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- describe Cequel::Model::Counter do
4
- let(:counter) { CommentCounts[1] }
5
- let(:dictionary) { counter }
6
- let(:uuid1) { CassandraCQL::UUID.new }
7
- let(:uuid2) { CassandraCQL::UUID.new }
8
-
9
- it_behaves_like 'readable dictionary'
10
-
11
- describe '#increment' do
12
- it 'should increment single column by default 1' do
13
- connection.should_receive(:execute).with(
14
- 'UPDATE comment_counts SET ? = ? + ? WHERE ? = ?',
15
- uuid1, uuid1, 1, :blog_id, 1
16
- )
17
- dictionary.increment(uuid1)
18
- end
19
-
20
- it 'should increment single column by given value' do
21
- connection.should_receive(:execute).with(
22
- 'UPDATE comment_counts SET ? = ? + ? WHERE ? = ?',
23
- uuid1, uuid1, 4, :blog_id, 1
24
- )
25
- dictionary.increment(uuid1, 4)
26
- end
27
-
28
- it 'should increment multiple columns by default value' do
29
- connection.should_receive(:execute).with(
30
- 'UPDATE comment_counts SET ? = ? + ?, ? = ? + ? WHERE ? = ?',
31
- uuid1, uuid1, 1, uuid2, uuid2, 1, :blog_id, 1
32
- )
33
- dictionary.increment([uuid1, uuid2])
34
- end
35
-
36
- it 'should increment multiple columns by given value' do
37
- connection.should_receive(:execute).with(
38
- 'UPDATE comment_counts SET ? = ? + ?, ? = ? + ? WHERE ? = ?',
39
- uuid1, uuid1, 4, uuid2, uuid2, 4, :blog_id, 1
40
- )
41
- dictionary.increment([uuid1, uuid2], 4)
42
- end
43
-
44
- it 'should increment multiple columns by given deltas' do
45
- connection.should_receive(:execute).with(
46
- 'UPDATE comment_counts SET ? = ? + ?, ? = ? + ? WHERE ? = ?',
47
- uuid1, uuid1, 4, uuid2, uuid2, 2, :blog_id, 1
48
- )
49
- dictionary.increment(uuid1 => 4, uuid2 => 2)
50
- end
51
- end
52
-
53
- describe '#decrement' do
54
- it 'should increment single column by default 1' do
55
- connection.should_receive(:execute).with(
56
- 'UPDATE comment_counts SET ? = ? - ? WHERE ? = ?',
57
- uuid1, uuid1, 1, :blog_id, 1
58
- )
59
- dictionary.decrement(uuid1)
60
- end
61
-
62
- it 'should increment single column by given value' do
63
- connection.should_receive(:execute).with(
64
- 'UPDATE comment_counts SET ? = ? - ? WHERE ? = ?',
65
- uuid1, uuid1, 4, :blog_id, 1
66
- )
67
- dictionary.decrement(uuid1, 4)
68
- end
69
-
70
- it 'should increment multiple columns by default value' do
71
- connection.should_receive(:execute).with(
72
- 'UPDATE comment_counts SET ? = ? - ?, ? = ? - ? WHERE ? = ?',
73
- uuid1, uuid1, 1, uuid2, uuid2, 1, :blog_id, 1
74
- )
75
- dictionary.decrement([uuid1, uuid2])
76
- end
77
-
78
- it 'should increment multiple columns by given value' do
79
- connection.should_receive(:execute).with(
80
- 'UPDATE comment_counts SET ? = ? - ?, ? = ? - ? WHERE ? = ?',
81
- uuid1, uuid1, 4, uuid2, uuid2, 4, :blog_id, 1
82
- )
83
- dictionary.decrement([uuid1, uuid2], 4)
84
- end
85
-
86
- it 'should increment multiple columns by given deltas' do
87
- connection.should_receive(:execute).with(
88
- 'UPDATE comment_counts SET ? = ? - ?, ? = ? - ? WHERE ? = ?',
89
- uuid1, uuid1, 4, uuid2, uuid2, 2, :blog_id, 1
90
- )
91
- dictionary.decrement(uuid1 => 4, uuid2 => 2)
92
- end
93
- end
94
- end
@@ -1,301 +0,0 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- describe Cequel::Model::Dictionary do
4
- let(:uuid1) { uuid }
5
- let(:uuid2) { uuid }
6
- let(:uuid3) { uuid }
7
- let(:dictionary) { BlogPosts[1] }
8
-
9
- it_behaves_like 'readable dictionary'
10
-
11
- describe '#save' do
12
- before do
13
- connection.stub(:execute).
14
- with('SELECT FIRST 2 * FROM blog_posts WHERE ? = ? LIMIT 1', :blog_id, 1).
15
- and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
16
- connection.stub(:execute).
17
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid2, '', :blog_id, 1).
18
- and_return result_stub('blog_id' => 1)
19
- end
20
-
21
- it 'should write to row' do
22
- dictionary[uuid1] = 1
23
- dictionary[uuid2] = 2
24
- connection.should_receive(:execute).
25
- with('UPDATE blog_posts SET ? = ?, ? = ? WHERE ? = ?', uuid1, 1, uuid2, 2, :blog_id, 1)
26
- dictionary.save
27
- end
28
-
29
- it 'should update changed columns' do
30
- dictionary.load
31
- dictionary[uuid1] = 2
32
- connection.should_receive(:execute).
33
- with('UPDATE blog_posts SET ? = ? WHERE ? = ?', uuid1, 2, :blog_id, 1)
34
- dictionary.save
35
- end
36
-
37
- it 'should write new columns' do
38
- dictionary.load
39
- dictionary[uuid3] = 3
40
- connection.should_receive(:execute).
41
- with('UPDATE blog_posts SET ? = ? WHERE ? = ?', uuid3, 3, :blog_id, 1)
42
- dictionary.save
43
- end
44
-
45
- it 'should delete removed columns' do
46
- dictionary.load
47
- dictionary[uuid1] = nil
48
- connection.should_receive(:execute).
49
- with('DELETE ? FROM blog_posts WHERE ? = ?', [uuid1], :blog_id, 1)
50
- dictionary.save
51
- end
52
-
53
- it 'should not update a row if it should be deleted' do
54
- dictionary.load
55
- dictionary[uuid1] = 1
56
- dictionary[uuid1] = nil
57
- connection.should_receive(:execute).once.
58
- with('DELETE ? FROM blog_posts WHERE ? = ?', [uuid1], :blog_id, 1)
59
- dictionary.save
60
- end
61
-
62
- it 'should not delete a row if it was subsequently updated' do
63
- dictionary.load
64
- dictionary[uuid1] = nil
65
- dictionary[uuid1] = 1
66
- connection.should_receive(:execute).once.
67
- with('UPDATE blog_posts SET ? = ? WHERE ? = ?', uuid1, 1, :blog_id, 1)
68
- dictionary.save
69
- end
70
-
71
- it 'should not save columns that have been saved previously' do
72
- dictionary.load
73
- dictionary[uuid3] = 3
74
- connection.should_receive(:execute).once.
75
- with('UPDATE blog_posts SET ? = ? WHERE ? = ?', uuid3, 3, :blog_id, 1)
76
- 2.times { dictionary.save }
77
- end
78
-
79
- it 'should not delete columns that have been deleted previously' do
80
- dictionary.load
81
- dictionary[uuid1] = nil
82
- connection.should_receive(:execute).once.
83
- with('DELETE ? FROM blog_posts WHERE ? = ?', [uuid1], :blog_id, 1)
84
- 2.times { dictionary.save }
85
- end
86
-
87
- end
88
-
89
- describe '#destroy' do
90
- before do
91
- connection.stub(:execute).
92
- with('SELECT FIRST 2 * FROM blog_posts WHERE ? = ? LIMIT 1', :blog_id, 1).
93
- and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
94
- connection.stub(:execute).
95
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid2, '', :blog_id, 1).
96
- and_return result_stub({'blog_id' => 1})
97
-
98
- dictionary.load
99
- connection.should_receive(:execute).
100
- with('DELETE FROM blog_posts WHERE ? = ?', :blog_id, 1)
101
- end
102
-
103
- it 'should delete row from cassandra' do
104
- dictionary.destroy
105
- end
106
-
107
- it 'should remove all properties from memory' do
108
- dictionary.destroy
109
- connection.stub(:execute).
110
- with('SELECT ? FROM blog_posts WHERE ? = ? LIMIT 1', [uuid1], :blog_id, 1).
111
- and_return result_stub({})
112
- dictionary[uuid1].should be_nil
113
- end
114
-
115
- it 'should not save previously updated properties when saved' do
116
- dictionary[uuid1] = 5
117
- dictionary.destroy
118
- connection.should_not_receive(:execute)
119
- dictionary.save
120
- end
121
-
122
- it 'should not delete previously deleted properties when saved' do
123
- dictionary[uuid1] = nil
124
- dictionary.destroy
125
- connection.should_not_receive(:execute)
126
- dictionary.save
127
- end
128
- end
129
-
130
- context 'with data modified but not loaded in memory' do
131
- let(:uuid4) { uuid }
132
-
133
- before do
134
- dictionary[uuid1] = -1
135
- dictionary[uuid3] = nil
136
- dictionary[uuid4] = 4
137
- end
138
-
139
- describe '#each_pair' do
140
- it 'should override persisted data with unsaved changes' do
141
- connection.stub(:execute).
142
- with('SELECT FIRST 2 * FROM blog_posts WHERE ? = ? LIMIT 1', :blog_id, 1).
143
- and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
144
- connection.stub(:execute).
145
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid2, '', :blog_id, 1).
146
- and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
147
- connection.stub(:execute).
148
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid3, '', :blog_id, 1).
149
- and_return result_stub({'blog_id' => 1})
150
- hash = {}
151
- dictionary.each_pair do |key, value|
152
- hash[key] = value
153
- end
154
- hash.should == {uuid1 => -1, uuid2 => 2, uuid4 => 4}
155
- end
156
- end
157
-
158
- describe '#[]' do
159
- it 'should return unsaved changed value' do
160
- dictionary[uuid1].should == -1
161
- end
162
-
163
- it 'should return nil if value removed' do
164
- dictionary[uuid3].should be_nil
165
- end
166
-
167
- it 'should return unsaved new value' do
168
- dictionary[uuid4].should == 4
169
- end
170
- end
171
-
172
- describe '#slice' do
173
- it 'should override loaded slice with unsaved data in memory' do
174
- connection.stub(:execute).
175
- with('SELECT ? FROM blog_posts WHERE ? = ? LIMIT 1', [uuid1,uuid2,uuid3,uuid4], :blog_id, 1).
176
- and_return result_stub(uuid1 => 1, uuid2 => 2, uuid3 => 3)
177
- dictionary.slice(uuid1, uuid2, uuid3, uuid4).should ==
178
- {uuid1 => -1, uuid2 => 2, uuid4 => 4}
179
- end
180
- end
181
-
182
- describe '#keys' do
183
- it 'should override keys that have been added or removed' do
184
- connection.should_receive(:execute).
185
- with('SELECT FIRST 2 * FROM blog_posts WHERE ? = ? LIMIT 1', :blog_id, 1).
186
- and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
187
- connection.should_receive(:execute).
188
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid2, '', :blog_id, 1).
189
- and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
190
- connection.should_receive(:execute).
191
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid3, '', :blog_id, 1).
192
- and_return result_stub({'blog_id' => 1})
193
- dictionary.keys.should == [uuid1, uuid2, uuid4]
194
- end
195
- end
196
-
197
- describe '#values' do
198
- it 'should override values that have been added or removed' do
199
- connection.should_receive(:execute).
200
- with('SELECT FIRST 2 * FROM blog_posts WHERE ? = ? LIMIT 1', :blog_id, 1).
201
- and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
202
- connection.should_receive(:execute).
203
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid2, '', :blog_id, 1).
204
- and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
205
- connection.should_receive(:execute).
206
- with('SELECT FIRST 2 ?..? FROM blog_posts WHERE ? = ? LIMIT 1', uuid3, '', :blog_id, 1).
207
- and_return result_stub({'blog_id' => 1})
208
- dictionary.values.should == [-1, 2, 4]
209
- end
210
- end
211
- end
212
-
213
- context 'with serializer/deserializer defined' do
214
- let(:dictionary) { PostComments[1] }
215
- let(:comment) { {'user' => 'Mat Brown', 'comment' => 'I like big data.'} }
216
-
217
- describe '#save' do
218
- it 'should serialize data' do
219
- dictionary[4] = comment
220
- connection.should_receive(:execute).
221
- with(
222
- 'UPDATE post_comments SET ? = ? WHERE ? = ?',
223
- 4, comment.to_json, :post_id, 1
224
- )
225
- dictionary.save
226
- end
227
- end
228
-
229
- describe '#[]' do
230
- it 'should return deserialized data' do
231
- connection.stub(:execute).with(
232
- 'SELECT ? FROM post_comments WHERE ? = ? LIMIT 1',
233
- [4], :post_id, 1
234
- ).and_return result_stub(4 => comment.to_json)
235
- dictionary[4].should == comment
236
- end
237
- end
238
-
239
- describe '#slice' do
240
- it 'should return deserialized values' do
241
- connection.stub(:execute).with(
242
- 'SELECT ? FROM post_comments WHERE ? = ? LIMIT 1',
243
- [4, 5], :post_id, 1
244
- ).and_return result_stub(4 => comment.to_json)
245
- dictionary.slice(4, 5).should == {4 => comment}
246
- end
247
- end
248
-
249
- describe '#load' do
250
- it 'should retain deserialized values in memory' do
251
- connection.stub(:execute).with(
252
- 'SELECT FIRST 1000 * FROM post_comments WHERE ? = ? LIMIT 1',
253
- :post_id, 1
254
- ).and_return result_stub(4 => comment.to_json)
255
- dictionary.load
256
- connection.should_not_receive(:execute)
257
- dictionary[4].should == comment
258
- end
259
-
260
- it 'should be a no-op if already loaded' do
261
- connection.stub(:execute).with(
262
- 'SELECT FIRST 1000 * FROM post_comments WHERE ? = ? LIMIT 1',
263
- :post_id, 1
264
- ).and_return result_stub(4 => comment.to_json)
265
- dictionary.load
266
- connection.should_not_receive(:execute)
267
- dictionary.load
268
- dictionary[4].should == comment
269
- end
270
- end
271
-
272
- describe '#each_pair' do
273
- it 'should yield deserialized values' do
274
- connection.stub(:execute).
275
- with(
276
- 'SELECT FIRST 1000 * FROM post_comments WHERE ? = ? LIMIT 1',
277
- :post_id, 1
278
- ).and_return result_stub('post_id' => 1, 4 => comment.to_json)
279
- dictionary.each_pair.map { |column, comment| comment }.first.
280
- should == comment
281
- end
282
- end
283
-
284
- describe '#values' do
285
- it 'should return deserialized values' do
286
- connection.stub(:execute).
287
- with(
288
- 'SELECT FIRST 1000 * FROM post_comments WHERE ? = ? LIMIT 1',
289
- :post_id, 1
290
- ).and_return result_stub('post_id' => 1, 4 => comment.to_json)
291
- dictionary.values.should == [comment]
292
- end
293
- end
294
- end
295
-
296
- private
297
-
298
- def uuid
299
- SimpleUUID::UUID.new.to_guid
300
- end
301
- end