sessionm-cassandra_object 2.3.9 → 2.4.0

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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3-p327@cassandra_object --create
@@ -19,7 +19,8 @@ module CassandraObject
19
19
 
20
20
  module InstanceMethods
21
21
  def schema_version
22
- Integer(@schema_version || self.class.current_schema_version)
22
+ version = @schema_version || self.class.current_schema_version
23
+ version.nil? ? nil : Integer(version)
23
24
  end
24
25
 
25
26
  def attribute_will_change!(attribute)
@@ -95,7 +95,9 @@ module CassandraObject
95
95
  # don't attempt to encode columns that are nil
96
96
  memo[column_name.to_s] = value.nil? ? '' : model_attributes[column_name].converter.encode(value).force_encoding('ASCII-8BIT')
97
97
  memo
98
- end.merge({"schema_version" => schema_version.to_s})
98
+ end.tap do |hash|
99
+ hash["schema_version"] = schema_version.to_s unless schema_version.nil?
100
+ end
99
101
  end
100
102
 
101
103
  def decode_columns_hash(attributes)
@@ -3,16 +3,21 @@ module CassandraObject
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- attribute :created_at, type: :time#_with_zone
7
- attribute :updated_at, type: :time#_with_zone
6
+ # Derived classes must declare the :created_at and :updated_at attributes.
8
7
 
9
8
  before_create do #|r|
10
- self.created_at ||= Time.current
11
- self.updated_at ||= Time.current
9
+ if attribute_method?(:created_at)
10
+ self.created_at ||= Time.current
11
+ end
12
+ if attribute_method?(:updated_at)
13
+ self.updated_at ||= Time.current
14
+ end
12
15
  end
13
16
 
14
17
  before_update if: :changed? do #|r|
15
- self.updated_at = Time.current
18
+ if attribute_method?(:updated_at)
19
+ self.updated_at = Time.current
20
+ end
16
21
  end
17
22
  end
18
23
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.3.9'
5
+ s.version = '2.4.0'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
data/test/README CHANGED
@@ -2,7 +2,7 @@ To run tests:
2
2
 
3
3
  1) Install gems
4
4
 
5
- $ rvm 1.9.3-p327@cassandra_object --create
5
+ $ cd cassandra_object
6
6
  $ bundle install
7
7
 
8
8
  2) Create keyspace and CFs
@@ -7,11 +7,13 @@ class CassandraObject::AttributesTest < CassandraObject::TestCase
7
7
  end
8
8
 
9
9
  class B < CassandraObject::Base
10
+ attribute :created_at, :type => :time
11
+ attribute :updated_at, :type => :time
10
12
  attribute :b, :type => :integer
11
13
  end
12
14
 
13
15
  test 'model_attributes' do
14
- assert_equal %W[created_at updated_at a], A.model_attributes.keys
16
+ assert_equal %W[a], A.model_attributes.keys
15
17
  assert_equal %W[created_at updated_at b], B.model_attributes.keys
16
18
  end
17
19
 
@@ -36,6 +36,17 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
36
36
  end
37
37
  end
38
38
 
39
+ test 'save! without current schema version' do
40
+ begin
41
+ old_current_schema_version = Issue.current_schema_version
42
+ Issue.current_schema_version = nil
43
+ record = Issue.create!
44
+ assert_equal nil, record.connection.get(Issue.column_family, record.id, 'schema_version')
45
+ ensure
46
+ Issue.current_schema_version = old_current_schema_version
47
+ end
48
+ end
49
+
39
50
  test 'destroy' do
40
51
  issue = Issue.create
41
52
  issue.destroy
data/test/test_helper.rb CHANGED
@@ -7,6 +7,22 @@ require 'rails/test_help'
7
7
  require 'mocha/setup'
8
8
 
9
9
  class Issue < CassandraObject::Base
10
+ key :uuid
11
+ attribute :created_at, :type => :time
12
+ attribute :updated_at, :type => :time
13
+ attribute :description, :type => :string
14
+ attribute :worth, :type => :decimal, :precision => 100
15
+ attribute :name, :type => :string
16
+ before_validation :set_defaults, :on => :create
17
+
18
+ def set_defaults
19
+ self.name ||= 'default name'
20
+ end
21
+ end
22
+
23
+ class IssueWithoutTimestamps < CassandraObject::Base
24
+ self.column_family = 'Issues'
25
+
10
26
  key :uuid
11
27
  attribute :description, :type => :string
12
28
  attribute :worth, :type => :decimal, :precision => 100
@@ -19,6 +35,9 @@ class Issue < CassandraObject::Base
19
35
  end
20
36
 
21
37
  class Counter < CassandraObject::Base
38
+ attribute :created_at, :type => :time
39
+ attribute :updated_at, :type => :time
40
+
22
41
  self.write_consistency = :all
23
42
  end
24
43
 
@@ -24,4 +24,11 @@ class CassandraObject::TimestampsTest < CassandraObject::TestCase
24
24
 
25
25
  assert_equal time, issue.created_at
26
26
  end
27
- end
27
+
28
+ test 'without timestamps' do
29
+ record = IssueWithoutTimestamps.create!
30
+ assert_equal nil, IssueWithoutTimestamps.connection.get(IssueWithoutTimestamps.column_family, record.id, 'created_at')
31
+ assert_equal nil, IssueWithoutTimestamps.connection.get(IssueWithoutTimestamps.column_family, record.id, 'updated_at')
32
+ end
33
+
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.9
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-03 00:00:00.000000000 Z
14
+ date: 2013-04-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -69,6 +69,7 @@ extra_rdoc_files:
69
69
  - README.markdown
70
70
  files:
71
71
  - .gitignore
72
+ - .rvmrc
72
73
  - CHANGELOG
73
74
  - Gemfile
74
75
  - LICENSE