gotime-cassandra_object 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object.rb +1 -2
- data/lib/cassandra_object/associations.rb +3 -4
- data/lib/cassandra_object/associations/one_to_many.rb +2 -10
- data/lib/cassandra_object/associations/one_to_one.rb +1 -1
- data/lib/cassandra_object/base.rb +20 -4
- data/lib/cassandra_object/consistency.rb +21 -20
- data/lib/cassandra_object/cursor.rb +6 -7
- data/lib/cassandra_object/finder_methods.rb +4 -10
- data/lib/cassandra_object/identity.rb +8 -26
- data/lib/cassandra_object/persistence.rb +5 -30
- data/lib/cassandra_object/{validation.rb → validations.rb} +6 -8
- data/{test-old → test}/active_model_test.rb +2 -2
- data/test/base_test.rb +10 -0
- data/test/consistency_test.rb +20 -0
- data/test/identity_test.rb +6 -1
- data/test/validations_test.rb +15 -0
- metadata +15 -34
- data/lib/cassandra_object/primary_key.rb +0 -12
- data/test-old/base_test.rb +0 -4
- data/test-old/basic_scenarios_test.rb +0 -243
- data/test-old/callbacks_test.rb +0 -19
- data/test-old/config/cassandra.in.sh +0 -53
- data/test-old/config/log4j.properties +0 -38
- data/test-old/config/storage-conf.xml +0 -221
- data/test-old/connection.rb +0 -25
- data/test-old/cursor_test.rb +0 -66
- data/test-old/dirty_test.rb +0 -34
- data/test-old/fixture_models.rb +0 -90
- data/test-old/identity/natural_key_factory_test.rb +0 -94
- data/test-old/index_test.rb +0 -69
- data/test-old/legacy/test_helper.rb +0 -18
- data/test-old/migration_test.rb +0 -21
- data/test-old/one_to_many_associations_test.rb +0 -163
- data/test-old/test_case.rb +0 -28
- data/test-old/test_helper.rb +0 -16
- data/test-old/time_test.rb +0 -32
- data/test-old/types_test.rb +0 -252
- data/test-old/validation_test.rb +0 -25
- data/test-old/z_mock_test.rb +0 -36
- data/test/primary_key_test.rb +0 -9
data/test-old/test_case.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
|
2
|
-
class CassandraObjectTestCase < ActiveSupport::TestCase
|
3
|
-
def teardown
|
4
|
-
CassandraObject::Base.connection.clear_keyspace!
|
5
|
-
end
|
6
|
-
|
7
|
-
def mock_invoice
|
8
|
-
Invoice.create :number=>Time.now.to_i*(rand(5)), :total=>Time.now.to_f
|
9
|
-
end
|
10
|
-
|
11
|
-
def connection
|
12
|
-
CassandraObject::Base.connection
|
13
|
-
end
|
14
|
-
|
15
|
-
def assert_ordered(expected_object_order, actual_order, to_s_before_comparing = true)
|
16
|
-
# don't use map! so we don't go changing user's arguments
|
17
|
-
if to_s_before_comparing
|
18
|
-
expected_object_order = expected_object_order.map(&:to_s)
|
19
|
-
actual_order = actual_order.map(&:to_s)
|
20
|
-
end
|
21
|
-
|
22
|
-
assert_equal Set.new(expected_object_order), Set.new(actual_order), "Collections weren't equal"
|
23
|
-
actual_indexes = actual_order.map do |e|
|
24
|
-
expected_object_order.index(e)
|
25
|
-
end
|
26
|
-
assert_equal expected_object_order, actual_order, "Collection was ordered incorrectly: #{actual_indexes.inspect}"
|
27
|
-
end
|
28
|
-
end
|
data/test-old/test_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
|
4
|
-
Bundler.setup
|
5
|
-
|
6
|
-
require 'cassandra_object'
|
7
|
-
require 'connection'
|
8
|
-
|
9
|
-
require 'test/unit'
|
10
|
-
require 'active_support/test_case'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
require 'fixture_models'
|
14
|
-
require 'pp'
|
15
|
-
|
16
|
-
require 'test_case'
|
data/test-old/time_test.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TimeTest < CassandraObjectTestCase
|
4
|
-
|
5
|
-
test "new raises an error" do
|
6
|
-
begin
|
7
|
-
appt = Appointment.new :start_time => 1
|
8
|
-
flunk "Should have failed to save"
|
9
|
-
rescue ArgumentError => e
|
10
|
-
assert_equal "CassandraObject::TimeType requires a Time", e.message
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
test "the attribute writer raises an error" do
|
15
|
-
begin
|
16
|
-
appt = Appointment.new
|
17
|
-
appt.start_time = 1
|
18
|
-
flunk "Should have failed to save"
|
19
|
-
rescue ArgumentError => e
|
20
|
-
assert_equal "CassandraObject::TimeType requires a Time", e.message
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
test "Time's should be round-trip-able" do
|
25
|
-
appt = Appointment.new :start_time => (t = Time.now.utc), :title => "team meeting"
|
26
|
-
appt.save!
|
27
|
-
appt2 = Appointment.get(appt.key)
|
28
|
-
|
29
|
-
assert_equal appt.start_time.class, appt2.start_time.class
|
30
|
-
assert_equal appt.start_time, appt2.start_time
|
31
|
-
end
|
32
|
-
end
|
data/test-old/types_test.rb
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TypeTest < CassandraObjectTestCase
|
4
|
-
context "IntegerType" do
|
5
|
-
context "encode" do
|
6
|
-
|
7
|
-
should "return an int with no errors" do
|
8
|
-
assert_nothing_raised {
|
9
|
-
i = 12
|
10
|
-
assert_equal i.to_s, CassandraObject::IntegerType.encode(i)
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
should "raises an error on non-Integer input" do
|
15
|
-
assert_raises(ArgumentError) { CassandraObject::IntegerType::encode('')}
|
16
|
-
end
|
17
|
-
|
18
|
-
should "work with Bignums" do
|
19
|
-
assert_nothing_raised {
|
20
|
-
i = 2**32
|
21
|
-
assert_equal i.to_s, CassandraObject::IntegerType.encode(i)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
should "work with Fixnums" do
|
26
|
-
assert_nothing_raised {
|
27
|
-
i = 2**16
|
28
|
-
assert_equal Fixnum, i.class
|
29
|
-
assert_equal i.to_s, CassandraObject::IntegerType.encode(i)
|
30
|
-
}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "decode" do
|
35
|
-
should "work with an int" do
|
36
|
-
assert_nothing_raised {
|
37
|
-
assert_equal 12, CassandraObject::IntegerType.decode('12')
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
should "work with Bignums" do
|
42
|
-
assert_nothing_raised {
|
43
|
-
assert_equal 2**32, CassandraObject::IntegerType.decode((2**32).to_s)
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
should "reject trash" do
|
48
|
-
assert_raises(ArgumentError) {
|
49
|
-
CassandraObject::IntegerType.decode('asdf')
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
should "work on a negative number" do
|
54
|
-
assert_equal -1, CassandraObject::IntegerType.decode('-1')
|
55
|
-
end
|
56
|
-
|
57
|
-
should "work with a leading +" do
|
58
|
-
assert_equal 1, CassandraObject::IntegerType.decode('+1')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "FloatType" do
|
64
|
-
context "encode" do
|
65
|
-
should "should reject an Integer" do
|
66
|
-
assert_raises(ArgumentError) {
|
67
|
-
CassandraObject::FloatType.encode(1)
|
68
|
-
}
|
69
|
-
end
|
70
|
-
|
71
|
-
should "reject a string" do
|
72
|
-
assert_raises(ArgumentError) {
|
73
|
-
CassandraObject::FloatType.encode('asdf')
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
should "return a string" do
|
78
|
-
assert_equal '1.0', CassandraObject::FloatType.encode(1.0)
|
79
|
-
end
|
80
|
-
|
81
|
-
should "accept a negative number" do
|
82
|
-
assert_equal '-1.0', CassandraObject::FloatType.encode(-1.0)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "decode" do
|
87
|
-
should "reject a non-float" do
|
88
|
-
assert_raises(ArgumentError) {
|
89
|
-
CassandraObject::FloatType.decode('asdf')
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
should "work on a float" do
|
94
|
-
assert_equal 1.2, CassandraObject::FloatType.decode('1.2')
|
95
|
-
end
|
96
|
-
|
97
|
-
should "work on a negative number" do
|
98
|
-
assert_equal -1.2, CassandraObject::FloatType.decode('-1.2')
|
99
|
-
end
|
100
|
-
|
101
|
-
should "work with a leading +" do
|
102
|
-
assert_equal 1.2, CassandraObject::FloatType.decode('+1.2')
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "DateType" do
|
108
|
-
context "encode" do
|
109
|
-
should "accept a valid Date object" do
|
110
|
-
assert_nothing_raised {
|
111
|
-
CassandraObject::DateType.encode(Date.today)
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
should "reject a String, even if it looks like a date" do
|
116
|
-
assert_raises(ArgumentError) { CassandraObject::DateType.encode('2009-10-31') }
|
117
|
-
end
|
118
|
-
|
119
|
-
should "reject an Integer" do
|
120
|
-
assert_raises(ArgumentError) { CassandraObject::DateType.encode(12) }
|
121
|
-
end
|
122
|
-
|
123
|
-
should "return a properly formatted string" do
|
124
|
-
str = '2009-10-31'
|
125
|
-
date = Date.strptime(str)
|
126
|
-
assert_equal str, CassandraObject::DateType.encode(date)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context "decode" do
|
131
|
-
should "work on a properly formatted string" do
|
132
|
-
s = '2009-10-31'
|
133
|
-
assert_equal Date.strptime(s), CassandraObject::DateType.decode(s)
|
134
|
-
end
|
135
|
-
|
136
|
-
should "reject a badly formatted string" do
|
137
|
-
assert_raises(ArgumentError) {
|
138
|
-
CassandraObject::DateType.decode('asdf')
|
139
|
-
}
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "TimeType" do
|
145
|
-
context "#encode" do
|
146
|
-
should "accept a Time" do
|
147
|
-
assert_nothing_raised {CassandraObject::TimeType.encode(Time.now)}
|
148
|
-
end
|
149
|
-
|
150
|
-
should "return a properly formated string for a legit time" do
|
151
|
-
t = Time.now
|
152
|
-
formatted = t.xmlschema(6)
|
153
|
-
assert_equal(formatted, CassandraObject::TimeType.encode(t))
|
154
|
-
end
|
155
|
-
|
156
|
-
should "reject things other than Time" do
|
157
|
-
assert_raises(ArgumentError) {
|
158
|
-
CassandraObject::TimeType.encode(1)
|
159
|
-
}
|
160
|
-
assert_raises(ArgumentError) {
|
161
|
-
CassandraObject::TimeType.encode('asdf')
|
162
|
-
}
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "#decode" do
|
167
|
-
should "parse a valid string and return a Time (with timezone)" do
|
168
|
-
time = Time.xmlschema(str = "2009-11-05T13:24:07-08:00")
|
169
|
-
assert_nothing_raised {
|
170
|
-
assert_equal time, CassandraObject::TimeType.decode(str)
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
should "parse a valid string and return a Time (with UTC)" do
|
175
|
-
time = Time.xmlschema(str = "2009-11-05T13:24:07Z")
|
176
|
-
assert_nothing_raised {
|
177
|
-
assert_equal time, CassandraObject::TimeType.decode(str)
|
178
|
-
}
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "HashType" do
|
184
|
-
context "encode" do
|
185
|
-
should "handle an empty Hash" do
|
186
|
-
assert_nothing_raised {
|
187
|
-
assert_equal(ActiveSupport::JSON.encode({}), CassandraObject::HashType.encode({}))
|
188
|
-
}
|
189
|
-
end
|
190
|
-
|
191
|
-
should "handle string keys" do
|
192
|
-
assert_nothing_raised {
|
193
|
-
h = {'foo' => 'bar'}
|
194
|
-
assert_equal(ActiveSupport::JSON.encode(h), CassandraObject::HashType.encode(h))
|
195
|
-
}
|
196
|
-
end
|
197
|
-
|
198
|
-
should "handle symbol keys" do
|
199
|
-
assert_nothing_raised {
|
200
|
-
h = {:foo => 'bar'}
|
201
|
-
assert_equal(ActiveSupport::JSON.encode(h), CassandraObject::HashType.encode(h))
|
202
|
-
}
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
context "BooleanType" do
|
208
|
-
context "encode" do
|
209
|
-
should "handle true" do
|
210
|
-
assert_nothing_raised {
|
211
|
-
assert_equal '1', CassandraObject::BooleanType.encode(true)
|
212
|
-
}
|
213
|
-
end
|
214
|
-
|
215
|
-
should "handle false" do
|
216
|
-
assert_nothing_raised {
|
217
|
-
assert_equal '0', CassandraObject::BooleanType.encode(false)
|
218
|
-
}
|
219
|
-
end
|
220
|
-
|
221
|
-
should "handle nil" do
|
222
|
-
assert_nothing_raised {
|
223
|
-
assert_equal '0', CassandraObject::BooleanType.encode(nil)
|
224
|
-
}
|
225
|
-
end
|
226
|
-
|
227
|
-
should "not handle normal objects" do
|
228
|
-
assert_raises(ArgumentError) {
|
229
|
-
assert_equal '1', CassandraObject::BooleanType.encode(Object.new)
|
230
|
-
}
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context "decode" do
|
235
|
-
should "handle true" do
|
236
|
-
assert_nothing_raised {
|
237
|
-
assert_equal true, CassandraObject::BooleanType.decode('1')
|
238
|
-
}
|
239
|
-
end
|
240
|
-
|
241
|
-
should "handle false" do
|
242
|
-
assert_nothing_raised {
|
243
|
-
assert_equal false, CassandraObject::BooleanType.decode('0')
|
244
|
-
}
|
245
|
-
end
|
246
|
-
|
247
|
-
should "handle bad data as false" do
|
248
|
-
assert_equal false, CassandraObject::BooleanType.decode('')
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
data/test-old/validation_test.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ValidationTest < CassandraObjectTestCase
|
4
|
-
|
5
|
-
test "save! raises an error" do
|
6
|
-
begin
|
7
|
-
customer = Customer.new :first_name=>"steve", :date_of_birth=>Date.parse("1979/12/25")
|
8
|
-
customer.save!
|
9
|
-
flunk "Should have failed to save"
|
10
|
-
rescue CassandraObject::Validation::RecordInvalid => e
|
11
|
-
assert_equal customer, e.record
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
test "create! raises an error" do
|
16
|
-
begin
|
17
|
-
customer = Customer.create! :first_name=>"steve", :date_of_birth=>Date.parse("1979/12/25")
|
18
|
-
flunk "Should have failed to create!"
|
19
|
-
rescue CassandraObject::Validation::RecordInvalid => e
|
20
|
-
assert_kind_of Customer, e.record
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
end
|
data/test-old/z_mock_test.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# The filename is so that this test gets loaded last, since it depends on all the other tests.
|
2
|
-
# Suggestions of less janky ways to do this would be appreciated. -rk
|
3
|
-
|
4
|
-
require 'test_helper'
|
5
|
-
|
6
|
-
class MockTest < CassandraObjectTestCase
|
7
|
-
context CassandraObject::Base do
|
8
|
-
should "respond to use_mock!" do
|
9
|
-
assert CassandraObject::Base.respond_to?(:use_mock!)
|
10
|
-
end
|
11
|
-
context "use_mock!" do
|
12
|
-
should "set the connection_class" do
|
13
|
-
CassandraObject::Base.use_mock!
|
14
|
-
assert_equal Cassandra::Mock, CassandraObject::Base.connection_class
|
15
|
-
CassandraObject::Base.use_mock!(false)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module MockTestMixin
|
22
|
-
def setup
|
23
|
-
CassandraObject::Base.use_mock!
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
def teardown
|
28
|
-
CassandraObject::Base.use_mock!(false)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
%w[BasicScenarios Cursor Dirty Index Migration OneToManyAssociations Time Types Validation].each do |test|
|
33
|
-
klass = Class.new(Kernel.const_get(test + 'Test'))
|
34
|
-
klass.send(:include, MockTestMixin)
|
35
|
-
Kernel.const_set(test + 'WithMockTest', klass)
|
36
|
-
end
|