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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.7.8'
5
+ s.version = '2.7.9'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -72,6 +72,10 @@ module CassandraObject
72
72
  @attributes[name.to_s]
73
73
  end
74
74
 
75
+ def attribute_exists?(name)
76
+ @attributes.key?(name.to_s)
77
+ end
78
+
75
79
  def attributes=(attributes)
76
80
  attributes.each do |(name, value)|
77
81
  send("#{name}=", value)
@@ -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 read_attribute(attr)
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
- attributes.inject({}) do |memo, (column_name, value)|
45
- # cassandra stores bytes, not strings, so it has no concept of encodings. The ruby thrift gem
46
- # expects all strings to be encoded as ascii-8bit.
47
- # don't attempt to encode columns that are nil
48
- memo[column_name.to_s] = value.nil? ? '' : attribute_definitions[column_name.to_sym].coder.encode(value).force_encoding('ASCII-8BIT')
49
- memo
50
- end.merge({"schema_version" => schema_version.to_s})
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)
@@ -42,9 +42,7 @@ class CassandraObject::AttributeMethods::DirtyTest < CassandraObject::TestCase
42
42
  record = temp_object do
43
43
  boolean :awesome
44
44
  end.create(awesome: false)
45
-
46
- p record.changes
47
-
45
+
48
46
  record.awesome = false
49
47
  assert !record.changed?
50
48
 
@@ -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
@@ -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
- begin
23
- Issue.validates(:description, presence: true)
24
-
25
- issue = Issue.new(description: 'bad')
26
- issue.save!
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
- issue = Issue.new
29
- assert_raise(CassandraObject::RecordInvalid) { issue.save! }
30
- ensure
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
@@ -28,6 +28,11 @@ module CassandraObject
28
28
  Class.new(CassandraObject::Base) do
29
29
  key :uuid
30
30
  self.column_family = 'Issues'
31
+
32
+ def self.name
33
+ 'Issue'
34
+ end
35
+
31
36
  instance_eval(&block)
32
37
  end
33
38
  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.7.8
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-08 00:00:00.000000000Z
13
+ date: 2011-09-20 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &70102740233680 !ruby/object:Gem::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: *70102740233680
25
+ version_requirements: *70218458238440
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &70102740233220 !ruby/object:Gem::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: *70102740233220
36
+ version_requirements: *70218458237480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70102740232720 !ruby/object:Gem::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: *70102740232720
47
+ version_requirements: *70218458236260
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []