gotime-cassandra_object 4.12.0 → 4.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84be31ff7407fc7ec88e53d411ddbd7ab067fb27
4
- data.tar.gz: b364e2178974653ae11328b7c3b352d24d262a2a
3
+ metadata.gz: 21e6e3bb0dbf786487b89866cc5c57a31e5caf71
4
+ data.tar.gz: c4191773adbef400bd499bcb6fe142dd2b39fcc4
5
5
  SHA512:
6
- metadata.gz: 3397a56b362a21c9a6a9e9480195fdc23334e4ff081f49ef19f84638239f3e562d2e6f81ccb9f1be7c04663f8ec53a298758b8dd44f84c79491d56732922d4b3
7
- data.tar.gz: 123c09faf6d4e07fdd4354619dd8e49bfd97d6f58cf7684a950ffcdf5c474a8579d2ce35fb4abdb7c43d4d072ddfc6bfacf2ba6d62b5e0d7cb447f53830a3968
6
+ metadata.gz: 57223e2269db0a93bec23217e3e8bf48463c9d8366a4ba03b3055df1c6789db33ffe67d2cb9b03f96eb81fa887120c9c4f61bddaec147d73386f7032ca1619a7
7
+ data.tar.gz: af2457981a4ff1102937d5d576e04d7c4dd08bc15a9ab4e9a87e889406ccf766a6c987f7375023145ee92552c0f8f13977d5ddfcdfdf63865ffd9e513c381944
data/Gemfile CHANGED
@@ -2,9 +2,14 @@ source "http://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem 'rake'
5
- gem 'mocha'
6
5
  gem 'thin'
7
6
 
8
- # group :development, :test do
9
- # gem 'pry'
10
- # end
7
+ group :test do
8
+ gem 'rails'
9
+ gem 'mocha', require: false
10
+ end
11
+
12
+ group :hstore do
13
+ gem 'activerecord'
14
+ gem 'pg'
15
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '4.12.0'
5
+ s.version = '4.12.1'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -54,8 +54,9 @@ module CassandraObject
54
54
  end
55
55
 
56
56
  def connection
57
- conf = {:adapter=>"postgresql", :encoding=>"unicode", :database=>"axle_place_test", :pool=>5, :username=>"postgres"}
58
- @connection ||= ActiveRecord::Base.postgresql_connection(conf)
57
+ # conf = {:adapter=>"postgresql", :encoding=>"unicode", :database=>"axle_place_test", :pool=>5, :username=>"postgres"}
58
+ # @connection ||= ActiveRecord::Base.postgresql_connection(conf)
59
+ ActiveRecord::Base.connection
59
60
  # @connection ||= ActiveRecord::Base.postgresql_connection(config)
60
61
  end
61
62
 
@@ -11,7 +11,6 @@ module CassandraObject
11
11
  extend ActiveSupport::DescendantsTracker
12
12
 
13
13
  include Connection
14
- include Consistency
15
14
  include Identity
16
15
  include Inspect
17
16
  include Persistence
@@ -21,8 +21,10 @@ module CassandraObject
21
21
 
22
22
  module ClassMethods
23
23
  def adapter
24
- @@adapter ||= CassandraObject::Adapters::CassandraAdapter.new(config)
25
- # @@adapter ||= CassandraObject::Adapters::HstoreAdapter.new(config)
24
+ @@adapter ||= begin
25
+ CassandraObject::Adapters::CassandraAdapter.new(config)
26
+ # CassandraObject::Adapters::HstoreAdapter.new(config)
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -76,7 +76,6 @@ module CassandraObject
76
76
  extend ActiveSupport::DescendantsTracker
77
77
 
78
78
  include Connection
79
- include Consistency
80
79
  include Identity
81
80
  include Inspect
82
81
  extend Model
@@ -2,7 +2,7 @@ module CassandraObject
2
2
  class Schema
3
3
  module Tasks
4
4
  def dump(io)
5
- column_families.each do |column_family|
5
+ table_names.each do |column_family|
6
6
  io.puts run_command("DESCRIBE COLUMNFAMILY #{column_family}")
7
7
  io.puts
8
8
  end
@@ -23,7 +23,7 @@ module CassandraObject
23
23
  end
24
24
  end
25
25
 
26
- def column_families
26
+ def table_names
27
27
  run_command('DESCRIBE COLUMNFAMILIES').split.sort
28
28
  end
29
29
 
@@ -12,7 +12,6 @@ module CassandraObject
12
12
  autoload :Callbacks
13
13
  autoload :Config
14
14
  autoload :Connection
15
- autoload :Consistency
16
15
  autoload :Core
17
16
  autoload :CounterBase
18
17
  autoload :Identity
@@ -1,3 +1,21 @@
1
+ CassandraObject::Base.config = {
2
+ keyspace: 'cassandra_object_test',
3
+ servers: '127.0.0.1:9160',
4
+ thrift: {
5
+ timeout: 5
6
+ }
7
+ }
8
+
9
+ begin
10
+ CassandraObject::Schema.drop_keyspace 'cassandra_object_test'
11
+ rescue Exception => e
12
+ end
13
+
14
+ sleep 1
15
+ CassandraObject::Schema.create_keyspace 'cassandra_object_test'
16
+ CassandraObject::Schema.create_column_family 'Issues'
17
+ CassandraObject::Base.adapter.consistency = 'QUORUM'
18
+
1
19
  CassandraObject::Base.class_eval do
2
20
  class_attribute :created_records
3
21
  self.created_records = []
@@ -0,0 +1,46 @@
1
+ Bundler.require :hstore
2
+ require 'active_record'
3
+ CassandraObject::Base.config = {}
4
+ class PGInitializer
5
+ def self.initialize!
6
+ config = {
7
+ 'adapter' => 'postgresql',
8
+ 'encoding' => 'unicode',
9
+ 'database' => 'cassandra_object_test',
10
+ 'pool' => 5,
11
+ 'username' => 'postgres'
12
+ }
13
+
14
+ ActiveRecord::Tasks::DatabaseTasks.drop config
15
+ ActiveRecord::Tasks::DatabaseTasks.create config
16
+ ActiveRecord::Base.establish_connection config
17
+
18
+ ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS hstore'
19
+
20
+ table_names.each { |table_name| create_document_table(table_name) }
21
+ end
22
+
23
+ def self.create_document_table(table_name)
24
+ ActiveRecord::Migration.create_table table_name, id: false do |t|
25
+ t.string :id, null: false
26
+ t.hstore :attribute_store, null: false
27
+ end
28
+ ActiveRecord::Base.connection.execute "ALTER TABLE #{table_name} ADD CONSTRAINT #{table_name}_pkey PRIMARY KEY (id)"
29
+ end
30
+
31
+ def self.table_names
32
+ %w(issues)
33
+ end
34
+ end
35
+
36
+ PGInitializer.initialize!
37
+
38
+ module ActiveSupport
39
+ class TestCase
40
+ teardown do
41
+ PGInitializer.table_names.each do |table_name|
42
+ ActiveRecord::Base.connection.execute "TRUNCATE #{table_name}"
43
+ end
44
+ end
45
+ end
46
+ end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'bundler/setup'
2
- require 'minitest/autorun'
3
2
  Bundler.require(:default, :test)
4
3
 
5
- require 'support/connect'
6
- require 'support/teardown'
4
+ require 'rails/test_help'
5
+ require 'mocha/setup'
6
+
7
+ # require 'support/hstore'
8
+ require 'support/cassandra'
7
9
  require 'support/issue'
8
10
 
9
11
  module CassandraObject
@@ -1,43 +1,43 @@
1
- require 'test_helper'
2
-
3
- class CassandraObject::CounterBaseTest < CassandraObject::TestCase
4
- class AppCounts < CassandraObject::CounterBase
5
- self.column_family = 'AppCounts'
6
- end
7
-
8
- def setup
9
- CassandraObject::Schema.create_column_family 'AppCounts', 'default_validation' => 'CounterColumnType', 'replicate_on_write' => 'true'
10
- end
11
-
12
- def teardown
13
- CassandraObject::Schema.drop_column_family 'AppCounts'
14
- end
15
-
16
- test 'class_loading' do
17
- assert_equal CassandraObject::CounterBase, CassandraObject::CounterBase
18
- end
19
-
20
- test 'single update' do
21
-
22
- AppCounts.update('poop', 'smells', 0)
23
-
24
- assert_equal 0, AppCounts.get("poop", "smells")
25
-
26
- AppCounts.update('poop', 'smells', 60)
27
-
28
- assert_equal 60, AppCounts.get("poop", "smells")
29
-
30
- assert_equal Hash['smells' => 60], AppCounts.get("poop")
31
-
32
- end
33
-
34
- test 'multiple update' do
35
-
36
- AppCounts.update('poop', {'hankey_sightings' => 3, 'christmas_days' => 5})
37
-
38
- assert_equal Hash['hankey_sightings' => 3, 'christmas_days' => 5], AppCounts.get("poop")
39
-
40
- assert_equal 5, AppCounts.get("poop", "christmas_days")
41
- end
42
-
43
- end
1
+ # require 'test_helper'
2
+ #
3
+ # class CassandraObject::CounterBaseTest < CassandraObject::TestCase
4
+ # class AppCounts < CassandraObject::CounterBase
5
+ # self.column_family = 'AppCounts'
6
+ # end
7
+ #
8
+ # def setup
9
+ # CassandraObject::Schema.create_column_family 'AppCounts', 'default_validation' => 'CounterColumnType', 'replicate_on_write' => 'true'
10
+ # end
11
+ #
12
+ # def teardown
13
+ # CassandraObject::Schema.drop_column_family 'AppCounts'
14
+ # end
15
+ #
16
+ # test 'class_loading' do
17
+ # assert_equal CassandraObject::CounterBase, CassandraObject::CounterBase
18
+ # end
19
+ #
20
+ # test 'single update' do
21
+ #
22
+ # AppCounts.update('poop', 'smells', 0)
23
+ #
24
+ # assert_equal 0, AppCounts.get("poop", "smells")
25
+ #
26
+ # AppCounts.update('poop', 'smells', 60)
27
+ #
28
+ # assert_equal 60, AppCounts.get("poop", "smells")
29
+ #
30
+ # assert_equal Hash['smells' => 60], AppCounts.get("poop")
31
+ #
32
+ # end
33
+ #
34
+ # test 'multiple update' do
35
+ #
36
+ # AppCounts.update('poop', {'hankey_sightings' => 3, 'christmas_days' => 5})
37
+ #
38
+ # assert_equal Hash['hankey_sightings' => 3, 'christmas_days' => 5], AppCounts.get("poop")
39
+ #
40
+ # assert_equal 5, AppCounts.get("poop", "christmas_days")
41
+ # end
42
+ #
43
+ # end
@@ -160,19 +160,6 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
160
160
  assert_equal persisted_issue, reloaded_issue
161
161
  end
162
162
 
163
- test 'delete with consistency' do
164
- issue = Issue.create
165
- Issue.with_consistency 'QUORUM' do
166
- issue.destroy
167
- end
168
- end
169
-
170
- test 'insert with consistency' do
171
- Issue.with_consistency 'QUORUM' do
172
- Issue.create
173
- end
174
- end
175
-
176
163
  test 'allow CQL keyword in column name' do
177
164
  assert_nothing_raised do
178
165
  Issue.string :text
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class CassandraObject::Schema::TasksTest < CassandraObject::TestCase
4
- test "column_families" do
5
- assert_equal ['Issues'], CassandraObject::Schema.column_families
4
+ test "table_names" do
5
+ assert_equal ['Issues'], CassandraObject::Schema.table_names
6
6
  end
7
7
 
8
8
  test "dump" do
@@ -18,12 +18,6 @@ class CassandraObject::Scope::QueryMethodsTest < CassandraObject::TestCase
18
18
  assert_equal [foo_issue], Issue.select { |issue| issue.title == 'foo' }
19
19
  end
20
20
 
21
- test "select with consistency" do
22
- Issue.with_consistency 'ONE' do
23
- Issue.all
24
- end
25
- end
26
-
27
21
  test "chaining where with scope" do
28
22
  issue = Issue.create title: 'abc', description: 'def'
29
23
  query = Issue.select(:title).for_key(issue.id)
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: 4.12.0
4
+ version: 4.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Koziarski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-21 00:00:00.000000000 Z
12
+ date: 2014-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -85,7 +85,6 @@ files:
85
85
  - gotime-cassandra_object.gemspec
86
86
  - lib/cassandra_object/adapters/abstract_adapter.rb
87
87
  - lib/cassandra_object/adapters/cassandra_adapter.rb
88
- - lib/cassandra_object/adapters/dynamo_adapter.rb
89
88
  - lib/cassandra_object/adapters/hstore_adapter.rb
90
89
  - lib/cassandra_object/attribute_methods.rb
91
90
  - lib/cassandra_object/attribute_methods/definition.rb
@@ -100,7 +99,6 @@ files:
100
99
  - lib/cassandra_object/callbacks.rb
101
100
  - lib/cassandra_object/config.rb
102
101
  - lib/cassandra_object/connection.rb
103
- - lib/cassandra_object/consistency.rb
104
102
  - lib/cassandra_object/core.rb
105
103
  - lib/cassandra_object/counter_base.rb
106
104
  - lib/cassandra_object/errors.rb
@@ -135,9 +133,9 @@ files:
135
133
  - lib/cassandra_object/types/time_type.rb
136
134
  - lib/cassandra_object/validations.rb
137
135
  - lib/gotime-cassandra_object.rb
138
- - test/support/connect.rb
136
+ - test/support/cassandra.rb
137
+ - test/support/hstore.rb
139
138
  - test/support/issue.rb
140
- - test/support/teardown.rb
141
139
  - test/test_helper.rb
142
140
  - test/unit/active_model_test.rb
143
141
  - test/unit/attribute_methods/definition_test.rb
@@ -151,7 +149,6 @@ files:
151
149
  - test/unit/callbacks_test.rb
152
150
  - test/unit/config_test.rb
153
151
  - test/unit/connection_test.rb
154
- - test/unit/consistency_test.rb
155
152
  - test/unit/core_test.rb
156
153
  - test/unit/counter_base_test.rb
157
154
  - test/unit/identity_test.rb
@@ -1,59 +0,0 @@
1
- module CassandraObject
2
- module Adapters
3
- class DynamoAdapter < AbstractAdapter
4
- def primary_key_column
5
- 'id'
6
- end
7
-
8
- def connection
9
- # self.namespace = spec[:namespace]
10
- @connection ||= AWS::DynamoDB.new(
11
- access_key_id: spec[:access_key_id],
12
- secret_access_key: spec[:secret_access_key]
13
- )
14
- end
15
-
16
- def select(scope)
17
- dynamo_table.items[key_string].attributes.to_h
18
- dynamo_table.batch_get(:all, keys.map(&:to_s))
19
- end
20
-
21
- def insert(table, id, attributes)
22
- attributes = {primary_key => id}.update(attributes)
23
- self.class.dynamo_table.items.create(attributes)
24
- end
25
-
26
- def update(table, id, attributes)
27
- dynamo_db_item = self.class.dynamo_table.items[id]
28
-
29
- dynamo_db_item.attributes.update do |u|
30
- attributes.each do |attr, value|
31
- if value.nil?
32
- u.delete(attr)
33
- else
34
- u.set(attr => value)
35
- end
36
- end
37
- end
38
- end
39
-
40
- def delete(table, ids)
41
- ids.each do |id|
42
- dynamo_table.items[id].delete
43
- end
44
- end
45
-
46
- def dynamo_table_name
47
- "#{namespace}.#{column_family.underscore}"
48
- end
49
-
50
- def dynamo_table
51
- @dynamo_table ||= begin
52
- table = connection.tables[dynamo_table_name]
53
- table.hash_key = [:id, :number]
54
- table
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,22 +0,0 @@
1
- module CassandraObject
2
- module Consistency
3
- extend ActiveSupport::Concern
4
-
5
- module ClassMethods
6
- def with_consistency(consistency)
7
- previous, self.default_consistency = default_consistency, consistency
8
- yield
9
- ensure
10
- self.default_consistency = previous
11
- end
12
-
13
- def default_consistency=(value)
14
- adapter.consistency = value
15
- end
16
-
17
- def default_consistency
18
- adapter.consistency
19
- end
20
- end
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- CassandraObject::Base.config = {
2
- keyspace: 'cassandra_object_test',
3
- servers: '127.0.0.1:9160',
4
- thrift: {
5
- timeout: 5
6
- }
7
- }
8
-
9
- begin
10
- CassandraObject::Schema.drop_keyspace 'cassandra_object_test'
11
- rescue Exception => e
12
- end
13
-
14
- sleep 1
15
- CassandraObject::Schema.create_keyspace 'cassandra_object_test'
16
- CassandraObject::Schema.create_column_family 'Issues'
17
- CassandraObject::Base.default_consistency = 'QUORUM'
@@ -1,13 +0,0 @@
1
- require "test_helper"
2
-
3
- class CassandraObject::ConsistencyTest < CassandraObject::TestCase
4
- test "with_consistency" do
5
- original = CassandraObject::Base.default_consistency
6
-
7
- CassandraObject::Base.with_consistency 'LOL' do
8
- assert_equal 'LOL', CassandraObject::Base.default_consistency
9
- end
10
-
11
- assert_equal original, CassandraObject::Base.default_consistency
12
- end
13
- end