gotime-cassandra_object 2.2.0 → 2.2.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/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
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::ConsistencyTest < CassandraObject::TestCase
|
4
|
+
class TestModel < CassandraObject::Base
|
5
|
+
end
|
6
|
+
|
7
|
+
test 'consistency_levels' do
|
8
|
+
assert_equal [:one, :quorum, :all].to_set, TestModel.consistency_levels.to_set
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'thrift_write_consistency' do
|
12
|
+
TestModel.write_consistency = :all
|
13
|
+
assert_equal Cassandra::Consistency::ALL, TestModel.thrift_write_consistency
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'thrift_read_consistency' do
|
17
|
+
TestModel.read_consistency = :all
|
18
|
+
assert_equal Cassandra::Consistency::ALL, TestModel.thrift_read_consistency
|
19
|
+
end
|
20
|
+
end
|
data/test/identity_test.rb
CHANGED
@@ -2,7 +2,6 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class CassandraObject::IdentityTest < CassandraObject::TestCase
|
4
4
|
test 'parse_key' do
|
5
|
-
# p "Issue.parse_key('bb4cbbbc-b7c7-11e0-9ca2-732604ff41fe') = #{Issue.parse_key('bb4cbbbc-b7c7-11e0-9ca2-732604ff41fe').class}"
|
6
5
|
assert_kind_of(
|
7
6
|
CassandraObject::Identity::UUIDKeyFactory::UUID,
|
8
7
|
Issue.parse_key('bb4cbbbc-b7c7-11e0-9ca2-732604ff41fe')
|
@@ -11,6 +10,12 @@ class CassandraObject::IdentityTest < CassandraObject::TestCase
|
|
11
10
|
assert_nil Issue.parse_key('fail')
|
12
11
|
end
|
13
12
|
|
13
|
+
test 'id' do
|
14
|
+
issue = Issue.create
|
15
|
+
|
16
|
+
assert_equal issue.key.to_s, issue.id
|
17
|
+
end
|
18
|
+
|
14
19
|
test 'equality of new records' do
|
15
20
|
assert_not_equal Issue.new, Issue.new
|
16
21
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::ValidationsTest < CassandraObject::TestCase
|
4
|
+
test 'create!' do
|
5
|
+
begin
|
6
|
+
Issue.validates(:description, presence: true)
|
7
|
+
|
8
|
+
Issue.create!(description: 'lol')
|
9
|
+
|
10
|
+
assert_raise(CassandraObject::RecordInvalid) { Issue.create!(description: '') }
|
11
|
+
ensure
|
12
|
+
Issue.reset_callbacks(:validate)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-27 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &2165601520 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2165601520
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cassandra
|
28
|
-
requirement: &
|
28
|
+
requirement: &2165601060 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.11.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2165601060
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &2165600600 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2165600600
|
48
48
|
description: Cassandra ActiveModel
|
49
49
|
email: gems@gotime.com
|
50
50
|
executables: []
|
@@ -91,7 +91,6 @@ files:
|
|
91
91
|
- lib/cassandra_object/migrations/migration.rb
|
92
92
|
- lib/cassandra_object/mocking.rb
|
93
93
|
- lib/cassandra_object/persistence.rb
|
94
|
-
- lib/cassandra_object/primary_key.rb
|
95
94
|
- lib/cassandra_object/railtie.rb
|
96
95
|
- lib/cassandra_object/schema.rb
|
97
96
|
- lib/cassandra_object/schema/migration.rb
|
@@ -115,36 +114,15 @@ files:
|
|
115
114
|
- lib/cassandra_object/types/time_type.rb
|
116
115
|
- lib/cassandra_object/types/time_with_zone_type.rb
|
117
116
|
- lib/cassandra_object/types/utf8_string_type.rb
|
118
|
-
- lib/cassandra_object/
|
119
|
-
- test
|
120
|
-
- test-old/base_test.rb
|
121
|
-
- test-old/basic_scenarios_test.rb
|
122
|
-
- test-old/callbacks_test.rb
|
123
|
-
- test-old/config/cassandra.in.sh
|
124
|
-
- test-old/config/log4j.properties
|
125
|
-
- test-old/config/storage-conf.xml
|
126
|
-
- test-old/connection.rb
|
127
|
-
- test-old/cursor_test.rb
|
128
|
-
- test-old/dirty_test.rb
|
129
|
-
- test-old/fixture_models.rb
|
130
|
-
- test-old/identity/natural_key_factory_test.rb
|
131
|
-
- test-old/index_test.rb
|
132
|
-
- test-old/legacy/test_helper.rb
|
133
|
-
- test-old/migration_test.rb
|
134
|
-
- test-old/one_to_many_associations_test.rb
|
135
|
-
- test-old/test_case.rb
|
136
|
-
- test-old/test_helper.rb
|
137
|
-
- test-old/time_test.rb
|
138
|
-
- test-old/types_test.rb
|
139
|
-
- test-old/validation_test.rb
|
140
|
-
- test-old/z_mock_test.rb
|
117
|
+
- lib/cassandra_object/validations.rb
|
118
|
+
- test/active_model_test.rb
|
141
119
|
- test/base_test.rb
|
142
120
|
- test/batches_test.rb
|
143
121
|
- test/connection_test.rb
|
122
|
+
- test/consistency_test.rb
|
144
123
|
- test/finder_methods_test.rb
|
145
124
|
- test/identity_test.rb
|
146
125
|
- test/persistence_test.rb
|
147
|
-
- test/primary_key_test.rb
|
148
126
|
- test/test_helper.rb
|
149
127
|
- test/timestamps_test.rb
|
150
128
|
- test/types/array_type_test.rb
|
@@ -157,6 +135,7 @@ files:
|
|
157
135
|
- test/types/string_type_test.rb
|
158
136
|
- test/types/time_type_test.rb
|
159
137
|
- test/types/utf8_string_type_test.rb
|
138
|
+
- test/validations_test.rb
|
160
139
|
homepage: http://github.com/gotime/cassandra_object
|
161
140
|
licenses: []
|
162
141
|
post_install_message:
|
@@ -182,13 +161,14 @@ signing_key:
|
|
182
161
|
specification_version: 3
|
183
162
|
summary: Cassandra ActiveModel
|
184
163
|
test_files:
|
164
|
+
- test/active_model_test.rb
|
185
165
|
- test/base_test.rb
|
186
166
|
- test/batches_test.rb
|
187
167
|
- test/connection_test.rb
|
168
|
+
- test/consistency_test.rb
|
188
169
|
- test/finder_methods_test.rb
|
189
170
|
- test/identity_test.rb
|
190
171
|
- test/persistence_test.rb
|
191
|
-
- test/primary_key_test.rb
|
192
172
|
- test/test_helper.rb
|
193
173
|
- test/timestamps_test.rb
|
194
174
|
- test/types/array_type_test.rb
|
@@ -201,3 +181,4 @@ test_files:
|
|
201
181
|
- test/types/string_type_test.rb
|
202
182
|
- test/types/time_type_test.rb
|
203
183
|
- test/types/utf8_string_type_test.rb
|
184
|
+
- test/validations_test.rb
|
data/test-old/base_test.rb
DELETED
@@ -1,243 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class BasicScenariosTest < CassandraObjectTestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
@customer = Customer.create :first_name => "Michael",
|
7
|
-
:last_name => "Koziarski",
|
8
|
-
:date_of_birth => Date.parse("1980/08/15")
|
9
|
-
@customer_key = @customer.key.to_s
|
10
|
-
|
11
|
-
assert @customer.valid?
|
12
|
-
end
|
13
|
-
|
14
|
-
test "get on a non-existent key returns nil" do
|
15
|
-
assert_nil Customer.get("THIS IS NOT A KEY")
|
16
|
-
end
|
17
|
-
|
18
|
-
test "a new object can be retrieved by key" do
|
19
|
-
other_customer = Customer.get(@customer_key)
|
20
|
-
assert_equal @customer, other_customer
|
21
|
-
|
22
|
-
assert_equal "Michael", other_customer.first_name
|
23
|
-
assert_equal "Koziarski", other_customer.last_name
|
24
|
-
assert_equal Date.parse("1980-08-15"), other_customer.date_of_birth
|
25
|
-
end
|
26
|
-
|
27
|
-
test "a new object is included in Model.all" do
|
28
|
-
assert Customer.all.include?(@customer)
|
29
|
-
end
|
30
|
-
|
31
|
-
test "date_of_birth is a date" do
|
32
|
-
assert @customer.date_of_birth.is_a?(Date)
|
33
|
-
end
|
34
|
-
|
35
|
-
test "should not let you assign junk to a date column" do
|
36
|
-
assert_raise(ArgumentError) do
|
37
|
-
@customer.date_of_birth = 24.5
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
test "should return nil for attributes without a value" do
|
42
|
-
assert_nil @customer.preferences
|
43
|
-
end
|
44
|
-
|
45
|
-
test "should let a user set a Hash valued attribute" do
|
46
|
-
val = {"a"=>"b"}
|
47
|
-
@customer.preferences = val
|
48
|
-
assert_equal val, @customer.preferences
|
49
|
-
@customer.save
|
50
|
-
|
51
|
-
other_customer = Customer.get(@customer_key)
|
52
|
-
assert_equal val, other_customer.preferences
|
53
|
-
end
|
54
|
-
|
55
|
-
test "should validate strings passed to a typed column" do
|
56
|
-
assert_raises(ArgumentError){
|
57
|
-
@customer.date_of_birth = "35345908"
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
test "should have a schema version of 0" do
|
62
|
-
assert_equal 0, @customer.schema_version
|
63
|
-
end
|
64
|
-
|
65
|
-
test "multiget" do
|
66
|
-
custs = Customer.multi_get([@customer_key, "This is not a key either"])
|
67
|
-
customer, nothing = custs.values
|
68
|
-
|
69
|
-
assert_equal @customer, customer
|
70
|
-
assert_nil nothing
|
71
|
-
end
|
72
|
-
|
73
|
-
test "creating a new record starts with the right version" do
|
74
|
-
@invoice = mock_invoice
|
75
|
-
|
76
|
-
raw_result = Invoice.connection.get("Invoices", @invoice.key.to_s)
|
77
|
-
assert_equal Invoice.current_schema_version, ActiveSupport::JSON.decode(raw_result["schema_version"])
|
78
|
-
end
|
79
|
-
|
80
|
-
test "to_param works" do
|
81
|
-
invoice = mock_invoice
|
82
|
-
param = invoice.to_param
|
83
|
-
assert_match /[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}/, param
|
84
|
-
assert_equal invoice.key, Invoice.parse_key(param)
|
85
|
-
end
|
86
|
-
|
87
|
-
test "setting a column_family" do
|
88
|
-
class Foo < CassandraObject::Base
|
89
|
-
self.column_family = 'Bar'
|
90
|
-
end
|
91
|
-
assert_equal 'Bar', Foo.column_family
|
92
|
-
end
|
93
|
-
|
94
|
-
context "destroying a customer with invoices" do
|
95
|
-
setup do
|
96
|
-
@invoice = mock_invoice
|
97
|
-
@customer.invoices << @invoice
|
98
|
-
|
99
|
-
@customer.destroy
|
100
|
-
end
|
101
|
-
|
102
|
-
should "Have removed the customer" do
|
103
|
-
assert Customer.connection.get("Customers", @customer.key.to_s).empty?
|
104
|
-
end
|
105
|
-
|
106
|
-
should "Have removed the associations too" do
|
107
|
-
assert_equal Hash.new, Customer.connection.get("CustomerRelationships", @customer.key.to_s)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "An object with a natural key" do
|
112
|
-
setup do
|
113
|
-
@payment = Payment.new :reference_number => "12345",
|
114
|
-
:amount => 1001
|
115
|
-
@payment.save!
|
116
|
-
end
|
117
|
-
|
118
|
-
should "create a natural key based on that attr" do
|
119
|
-
assert_equal "12345", @payment.key.to_s
|
120
|
-
end
|
121
|
-
|
122
|
-
should "have a key equal to another object with that key" do
|
123
|
-
p = Payment.new(:reference_number => "12345",
|
124
|
-
:amount => 1001)
|
125
|
-
p.save
|
126
|
-
|
127
|
-
assert_equal @payment.key, p.key
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context "Model with no attributes" do
|
132
|
-
setup do
|
133
|
-
class Empty < CassandraObject::Base
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
should "work" do
|
138
|
-
e = Empty.new
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "A model that allows nils" do
|
143
|
-
setup do
|
144
|
-
class Nilable < CassandraObject::Base
|
145
|
-
attribute :user_id, :type => Integer, :allow_nil => true
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
should "should be valid with a nil" do
|
150
|
-
n = Nilable.new
|
151
|
-
assert n.valid?
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "A janky custom key factory" do
|
156
|
-
setup do
|
157
|
-
class JankyKeys
|
158
|
-
def next_key(object)
|
159
|
-
nil
|
160
|
-
end
|
161
|
-
end
|
162
|
-
class JankyObject < CassandraObject::Base
|
163
|
-
key JankyKeys.new
|
164
|
-
end
|
165
|
-
@object = JankyObject.new
|
166
|
-
end
|
167
|
-
|
168
|
-
should "raise an error on nil key" do
|
169
|
-
assert_raises(RuntimeError) do
|
170
|
-
@object.save
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
test "updating columns" do
|
176
|
-
appt = Appointment.new(:start_time => Time.now, :title => 'emergency meeting')
|
177
|
-
appt.save!
|
178
|
-
appt = Appointment.get(appt.key)
|
179
|
-
appt.start_time = Time.now + 1.hour
|
180
|
-
appt.end_time = Time.now.utc + 5.hours
|
181
|
-
appt.save!
|
182
|
-
assert appt.reload.end_time.is_a?(ActiveSupport::TimeWithZone)
|
183
|
-
end
|
184
|
-
|
185
|
-
test "Saving a class with custom attributes uses the custom converter" do
|
186
|
-
@customer.custom_storage = "hello"
|
187
|
-
@customer.save
|
188
|
-
|
189
|
-
raw_result = Customer.connection.get("Customers", @customer.key.to_s)
|
190
|
-
|
191
|
-
assert_equal "olleh", raw_result["custom_storage"]
|
192
|
-
assert_equal "hello", @customer.reload.custom_storage
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
context "setting valid consistency levels" do
|
197
|
-
setup do
|
198
|
-
class Senate < CassandraObject::Base
|
199
|
-
consistency_levels :write => :quorum, :read => :quorum
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
should "should have the settings" do
|
204
|
-
assert_equal :quorum, Senate.write_consistency
|
205
|
-
assert_equal :quorum, Senate.read_consistency
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context "setting invalid consistency levels" do
|
210
|
-
context "invalid write consistency" do
|
211
|
-
should "raise an error" do
|
212
|
-
assert_raises(ArgumentError) do
|
213
|
-
class BadWriter < CassandraObject::Base
|
214
|
-
consistency_levels :write => :foo, :read => :quorum
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
context "invalid read consistency" do
|
221
|
-
should "raise an error" do
|
222
|
-
assert_raises(ArgumentError) do
|
223
|
-
class BadReader < CassandraObject::Base
|
224
|
-
consistency_levels :write => :quorum, :read => :foo
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
test "ignoring columns we don't know about" do
|
232
|
-
# if there's a column in the row that's not configured as an attribute, it should be ignored with no errors
|
233
|
-
|
234
|
-
payment = Payment.new(:reference_number => 'abc123', :amount => 26)
|
235
|
-
payment.save
|
236
|
-
|
237
|
-
Payment.connection.insert(Payment.column_family, payment.key.to_s, {"bogus" => 'very bogus', "schema_version" => payment.schema_version.to_s}, :consistency => Payment.send(:write_consistency_for_thrift))
|
238
|
-
|
239
|
-
assert_nothing_raised do
|
240
|
-
Payment.get(payment.key)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|