sessionm-cassandra_object 2.2.46 → 2.2.47

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,9 +36,9 @@ module CassandraObject
36
36
  include Identity
37
37
  include Attributes
38
38
  include Persistence
39
- include Callbacks
40
39
  include Dirty
41
40
  include Validations
41
+ include Callbacks
42
42
  include Associations
43
43
  include Batches
44
44
  include FinderMethods
@@ -1,27 +1,37 @@
1
+ require 'active_support/core_ext/array/wrap'
2
+
1
3
  module CassandraObject
2
4
  module Callbacks
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  included do
6
8
  extend ActiveModel::Callbacks
7
- define_model_callbacks :save, :create, :destroy, :update
9
+ include ActiveModel::Validations::Callbacks
10
+
11
+ define_model_callbacks :initialize, :find, :touch, :only => :after
12
+ define_model_callbacks :save, :create, :update, :destroy
8
13
  end
9
14
 
10
15
  def destroy #:nodoc:
11
16
  _run_destroy_callbacks { super }
12
17
  end
13
18
 
14
- private
15
- def create_or_update #:nodoc:
16
- _run_save_callbacks { super }
17
- end
19
+ def touch(*) #:nodoc:
20
+ _run_touch_callbacks { super }
21
+ end
22
+
23
+ private
18
24
 
19
- def create #:nodoc:
20
- _run_create_callbacks { super }
21
- end
25
+ def create_or_update #:nodoc:
26
+ _run_save_callbacks { super }
27
+ end
28
+
29
+ def create #:nodoc:
30
+ _run_create_callbacks { super }
31
+ end
22
32
 
23
- def update(*) #:nodoc:
24
- _run_update_callbacks { super }
25
- end
33
+ def update(*) #:nodoc:
34
+ _run_update_callbacks { super }
35
+ end
26
36
  end
27
- end
37
+ end
@@ -11,11 +11,6 @@ module CassandraObject
11
11
  extend ActiveSupport::Concern
12
12
  include ActiveModel::Validations
13
13
 
14
- included do
15
- define_model_callbacks :validation
16
- define_callbacks :validate, :scope => :name
17
- end
18
-
19
14
  module ClassMethods
20
15
  def create!(attributes = {})
21
16
  new(attributes).tap do |object|
@@ -26,9 +21,7 @@ module CassandraObject
26
21
 
27
22
  def valid?(context=nil)
28
23
  context ||= (new_record? ? :create : :update)
29
- run_callbacks :validation do
30
- super context
31
- end
24
+ super(context)
32
25
  end
33
26
 
34
27
  def save(options={})
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.2.46'
5
+ s.version = '2.2.47'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -18,9 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_runtime_dependency('rails', "~> 3.0")
21
+ s.add_runtime_dependency('rails', "~> 3.0.9")
22
22
  s.add_runtime_dependency('cassandra', ">= 0.11.3")
23
23
 
24
- s.add_development_dependency('bundler', "~> 1.0.0")
24
+ s.add_development_dependency('bundler', ">= 1.0.0")
25
25
  end
26
26
 
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class CassandraObject::CallbacksTest < CassandraObject::TestCase
4
+
5
+ test 'before_validation respects :on' do
6
+ issue = Issue.new
7
+ issue.save
8
+ assert_equal 'default name', issue.name
9
+
10
+ # make sure :on => :create is respected
11
+ issue.name = nil
12
+ issue.save
13
+ assert_equal nil, issue.name
14
+ end
15
+
16
+ end
data/test/test_helper.rb CHANGED
@@ -9,6 +9,12 @@ class Issue < CassandraObject::Base
9
9
  key :uuid
10
10
  attribute :description, :type => :string
11
11
  attribute :worth, :type => :decimal, :precision => 100
12
+ attribute :name, :type => :string
13
+ before_validation :set_defaults, :on => :create
14
+
15
+ def set_defaults
16
+ self.name ||= 'default name'
17
+ end
12
18
  end
13
19
 
14
20
  module CassandraObject
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.2.46
4
+ version: 2.2.47
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,22 +11,27 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-05 00:00:00.000000000Z
14
+ date: 2012-04-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &70206110473260 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: '3.0'
23
+ version: 3.0.9
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70206110473260
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: 3.0.9
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: cassandra
29
- requirement: &70206110472600 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,18 +39,28 @@ dependencies:
34
39
  version: 0.11.3
35
40
  type: :runtime
36
41
  prerelease: false
37
- version_requirements: *70206110472600
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.3
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: bundler
40
- requirement: &70206110472040 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
- - - ~>
53
+ - - ! '>='
44
54
  - !ruby/object:Gem::Version
45
55
  version: 1.0.0
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *70206110472040
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 1.0.0
49
64
  description: Cassandra ActiveModel
50
65
  email: klange@sessionm.com
51
66
  executables: []
@@ -121,6 +136,7 @@ files:
121
136
  - test/attributes_test.rb
122
137
  - test/base_test.rb
123
138
  - test/batches_test.rb
139
+ - test/callbacks_test.rb
124
140
  - test/connection_test.rb
125
141
  - test/consistency_test.rb
126
142
  - test/finder_methods_test.rb
@@ -160,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
176
  version: 1.3.5
161
177
  requirements: []
162
178
  rubyforge_project:
163
- rubygems_version: 1.8.6
179
+ rubygems_version: 1.8.22
164
180
  signing_key:
165
181
  specification_version: 3
166
182
  summary: Cassandra ActiveModel
@@ -169,6 +185,7 @@ test_files:
169
185
  - test/attributes_test.rb
170
186
  - test/base_test.rb
171
187
  - test/batches_test.rb
188
+ - test/callbacks_test.rb
172
189
  - test/connection_test.rb
173
190
  - test/consistency_test.rb
174
191
  - test/finder_methods_test.rb