sessionm-cassandra_object 2.3.6 → 2.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
+
4
+ gem "mocha", :require => false
@@ -18,7 +18,7 @@ module CassandraObject
18
18
  def establish_connection(config)
19
19
  spec = config.reverse_merge(DEFAULT_OPTIONS)
20
20
 
21
- spec[:thrift] = (spec[:thrift] || {}).reverse_merge(DEFAULT_THRIFT_OPTIONS)
21
+ spec[:thrift] = (spec[:thrift].try(:symbolize_keys) || {}).reverse_merge(DEFAULT_THRIFT_OPTIONS)
22
22
  spec[:thrift][:exception_class_overrides] = spec[:thrift][:exception_class_overrides].map(&:constantize)
23
23
 
24
24
  self.connection = Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift])
@@ -20,8 +20,8 @@ module CassandraObject
20
20
  :write_default => :quorum,
21
21
  }
22
22
 
23
- @@default_read_consistency
24
- @@default_write_consistency
23
+ @@default_read_consistency = DEFAULT_OPTIONS[:read_default]
24
+ @@default_write_consistency = DEFAULT_OPTIONS[:write_default]
25
25
  def set_default_consistencies(config)
26
26
  config = (config[:consistency] || {}).reverse_merge(DEFAULT_OPTIONS)
27
27
  @@default_read_consistency = config[:read_default].to_sym
@@ -4,17 +4,17 @@ module CassandraObject
4
4
 
5
5
  module ClassMethods
6
6
  def add(key, value, *columns_and_options)
7
- defaults = Cassandra::WRITE_DEFAULTS.merge(:consistency => Cassandra::Consistency::QUORUM)
8
-
9
- column_family, column, sub_column, options = connection.extract_and_validate_params(self.column_family, key, columns_and_options, defaults)
7
+ column_family, column, sub_column, options = connection.extract_and_validate_params(self.column_family, key, columns_and_options, {})
8
+ # the options are removed, leaving just columns
9
+ columns = columns_and_options
10
10
 
11
11
  ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
12
- connection.add(column_family, key, value, *columns_and_options)
12
+ connection.add(column_family, key, value, *columns, :consistency => thrift_write_consistency)
13
13
  end
14
14
  end
15
15
 
16
16
  def remove(key)
17
- ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
17
+ ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
18
18
  connection.remove(column_family, key.to_s, consistency: thrift_write_consistency)
19
19
  end
20
20
  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.6'
5
+ s.version = '2.3.8'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
data/test/README ADDED
@@ -0,0 +1,18 @@
1
+ To run tests:
2
+
3
+ 1) Install gems
4
+
5
+ $ rvm 1.9.3-p327@cassandra_object --create
6
+ $ bundle install
7
+
8
+ 2) Create keyspace and CFs
9
+
10
+ $ cassandra-cli
11
+ ] create keyspace place_directory_development;
12
+ ] use place_directory_development;
13
+ ] create column family Issues;
14
+ ] create column family Counters with default_validation_class=CounterColumnType and comparator=UTF8Type;
15
+
16
+ 3) Run tests
17
+
18
+ $ rake test
@@ -45,6 +45,35 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
45
45
  assert !issue.new_record?
46
46
  end
47
47
 
48
+ test 'add should work' do
49
+ assert_equal nil, Counter.connection.get(Counter.column_family, 'key', 'column')
50
+
51
+ Counter.add('key', 1, 'column')
52
+ assert_equal 1, Counter.connection.get(Counter.column_family, 'key', 'column')
53
+
54
+ Counter.add('key', -1, 'column')
55
+ assert_equal 0, Counter.connection.get(Counter.column_family, 'key', 'column')
56
+ end
57
+
58
+ test 'add should respect default and class consistency option' do
59
+ begin
60
+ old_default_write_cl = CassandraObject::Consistency::ClassMethods.class_variable_get(:@@default_read_consistency)
61
+ old_class_write_cl = Counter.write_consistency
62
+ CassandraObject::Consistency::ClassMethods.class_variable_set(:@@default_read_consistency, :quorum)
63
+ Counter.write_consistency = nil
64
+
65
+ Counter.connection.expects(:add).with(Counter.column_family, 'key', 2, 'column', :consistency => Cassandra::Consistency::QUORUM)
66
+ Counter.add('key', 2, 'column')
67
+
68
+ Counter.write_consistency = :local_quorum
69
+ Counter.connection.expects(:add).with(Counter.column_family, 'key', 2, 'column', :consistency => Cassandra::Consistency::LOCAL_QUORUM)
70
+ Counter.add('key', 2, 'column')
71
+ ensure
72
+ CassandraObject::Consistency::ClassMethods.class_variable_set(:@@default_read_consistency, old_class_write_cl)
73
+ Counter.write_consistency = old_class_write_cl
74
+ end
75
+ end
76
+
48
77
  test 'update_attribute' do
49
78
  issue = Issue.create
50
79
  issue.update_attribute(:description, 'lol')
data/test/test_helper.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'cassandra/0.8'
5
5
  require 'cassandra_object'
6
6
  require 'rails/test_help'
7
+ require 'mocha/setup'
7
8
 
8
9
  class Issue < CassandraObject::Base
9
10
  key :uuid
@@ -17,6 +18,10 @@ class Issue < CassandraObject::Base
17
18
  end
18
19
  end
19
20
 
21
+ class Counter < CassandraObject::Base
22
+ self.write_consistency = :all
23
+ end
24
+
20
25
  module CassandraObject
21
26
  class TestCase < ActiveSupport::TestCase
22
27
  TEST_KEYSPACE = 'place_directory_development'
@@ -31,6 +36,7 @@ module CassandraObject
31
36
 
32
37
  teardown do
33
38
  Issue.delete_all
39
+ Counter.delete_all
34
40
  end
35
41
 
36
42
  def connection
metadata CHANGED
@@ -1,75 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 3
8
- - 6
9
- version: 2.3.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.3.8
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Michael Koziarski
13
9
  - gotime
14
10
  - sessionm
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2013-03-18 00:00:00 -04:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
14
+ date: 2013-03-27 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
23
17
  name: rails
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- requirements:
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
27
21
  - - ~>
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 3
31
- - 0
32
- - 9
22
+ - !ruby/object:Gem::Version
33
23
  version: 3.0.9
34
24
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: cassandra
38
25
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 11
46
- - 3
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: 3.0.9
32
+ - !ruby/object:Gem::Dependency
33
+ name: cassandra
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
47
39
  version: 0.11.3
48
40
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: bundler
52
41
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 0
60
- - 0
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.3
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
61
55
  version: 1.0.0
62
56
  type: :development
63
- version_requirements: *id003
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 1.0.0
64
64
  description: Cassandra ActiveModel
65
65
  email: klange@sessionm.com
66
66
  executables: []
67
-
68
67
  extensions: []
69
-
70
- extra_rdoc_files:
68
+ extra_rdoc_files:
71
69
  - README.markdown
72
- files:
70
+ files:
73
71
  - .gitignore
74
72
  - CHANGELOG
75
73
  - Gemfile
@@ -136,6 +134,7 @@ files:
136
134
  - lib/cassandra_object/types/utf8_string_type.rb
137
135
  - lib/cassandra_object/validations.rb
138
136
  - sessionm-cassandra_object.gemspec
137
+ - test/README
139
138
  - test/active_model_test.rb
140
139
  - test/attributes_test.rb
141
140
  - test/base_test.rb
@@ -160,41 +159,32 @@ files:
160
159
  - test/types/time_type_test.rb
161
160
  - test/types/utf8_string_type_test.rb
162
161
  - test/validations_test.rb
163
- has_rdoc: true
164
162
  homepage: http://github.com/sessionm/cassandra_object
165
163
  licenses: []
166
-
167
164
  post_install_message:
168
165
  rdoc_options: []
169
-
170
- require_paths:
166
+ require_paths:
171
167
  - lib
172
- required_ruby_version: !ruby/object:Gem::Requirement
173
- requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- segments:
177
- - 1
178
- - 9
179
- - 2
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
180
173
  version: 1.9.2
181
- required_rubygems_version: !ruby/object:Gem::Requirement
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- segments:
186
- - 1
187
- - 3
188
- - 5
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
189
179
  version: 1.3.5
190
180
  requirements: []
191
-
192
181
  rubyforge_project:
193
- rubygems_version: 1.3.6
182
+ rubygems_version: 1.8.25
194
183
  signing_key:
195
184
  specification_version: 3
196
185
  summary: Cassandra ActiveModel
197
- test_files:
186
+ test_files:
187
+ - test/README
198
188
  - test/active_model_test.rb
199
189
  - test/attributes_test.rb
200
190
  - test/base_test.rb