gotime-cassandra_object 2.7.8 → 2.7.9
Sign up to get free protection for your applications and to get access to all the features.
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/attribute_methods.rb +4 -0
- data/lib/cassandra_object/base.rb +1 -1
- data/lib/cassandra_object/persistence.rb +8 -7
- data/test/attribute_methods/dirty_test.rb +1 -3
- data/test/attribute_methods_test.rb +11 -0
- data/test/persistence_test.rb +31 -9
- data/test/test_helper.rb +5 -0
- metadata +8 -8
@@ -55,7 +55,7 @@ module CassandraObject
|
|
55
55
|
@attributes = {}
|
56
56
|
self.attributes = attributes
|
57
57
|
attribute_definitions.each do |attr, attribute_definition|
|
58
|
-
unless
|
58
|
+
unless attribute_exists?(attr)
|
59
59
|
write_attribute(attr, attribute_definition.instantiate(self, nil))
|
60
60
|
end
|
61
61
|
end
|
@@ -41,13 +41,14 @@ module CassandraObject
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def encode_attributes(attributes, schema_version)
|
44
|
-
|
45
|
-
|
46
|
-
# expects all strings to be encoded as ascii-8bit.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
44
|
+
encoded = {"schema_version" => schema_version.to_s}
|
45
|
+
attributes.each do |column_name, value|
|
46
|
+
# The ruby thrift gem expects all strings to be encoded as ascii-8bit.
|
47
|
+
unless value.nil?
|
48
|
+
encoded[column_name.to_s] = attribute_definitions[column_name.to_sym].coder.encode(value).force_encoding('ASCII-8BIT')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
encoded
|
51
52
|
end
|
52
53
|
|
53
54
|
def instantiate_attributes(object, attributes)
|
@@ -59,4 +59,15 @@ class CassandraObject::AttributeMethodsTest < CassandraObject::TestCase
|
|
59
59
|
|
60
60
|
assert_equal 'foo', issue.description
|
61
61
|
end
|
62
|
+
|
63
|
+
test 'read and write attributes' do
|
64
|
+
issue = Issue.new
|
65
|
+
assert_nil issue.read_attribute(:description)
|
66
|
+
|
67
|
+
issue.write_attribute(:description, nil)
|
68
|
+
assert_nil issue.read_attribute(:description)
|
69
|
+
|
70
|
+
issue.write_attribute(:description, 'foo')
|
71
|
+
assert_equal 'foo', issue.read_attribute(:description)
|
72
|
+
end
|
62
73
|
end
|
data/test/persistence_test.rb
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
4
|
+
test 'encode_attributes' do
|
5
|
+
klass = temp_object do
|
6
|
+
string :description
|
7
|
+
end
|
8
|
+
|
9
|
+
assert_equal(
|
10
|
+
{'schema_version' => 'foo'},
|
11
|
+
klass.encode_attributes({}, 'foo')
|
12
|
+
)
|
13
|
+
|
14
|
+
assert_equal(
|
15
|
+
{'schema_version' => 'foo'},
|
16
|
+
klass.encode_attributes({description: nil}, 'foo')
|
17
|
+
)
|
18
|
+
|
19
|
+
assert_equal(
|
20
|
+
{'description' => 'lol', 'schema_version' => 'foo'},
|
21
|
+
klass.encode_attributes({description: 'lol'}, 'foo')
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
4
25
|
test 'persistance inquiries' do
|
5
26
|
issue = Issue.new
|
6
27
|
assert issue.new_record?
|
@@ -19,16 +40,17 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
19
40
|
end
|
20
41
|
|
21
42
|
test 'save!' do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
43
|
+
klass = temp_object do
|
44
|
+
string :description
|
45
|
+
validates :description, presence: true
|
46
|
+
end
|
47
|
+
|
48
|
+
record = klass.new(description: 'bad')
|
49
|
+
record.save!
|
27
50
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Issue.reset_callbacks(:validate)
|
51
|
+
assert_raise CassandraObject::RecordInvalid do
|
52
|
+
record = klass.new
|
53
|
+
record.save!
|
32
54
|
end
|
33
55
|
end
|
34
56
|
|
data/test/test_helper.rb
CHANGED
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.7.
|
4
|
+
version: 2.7.9
|
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-09-
|
13
|
+
date: 2011-09-20 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70218458238440 !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: *70218458238440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cassandra
|
28
|
-
requirement: &
|
28
|
+
requirement: &70218458237480 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.12.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70218458237480
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70218458236260 !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: *70218458236260
|
48
48
|
description: Cassandra ActiveModel
|
49
49
|
email: gems@gotime.com
|
50
50
|
executables: []
|