sessionm-cassandra_object 4.0.2 → 4.0.3

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: 3e1cdbe60a0e5d0445c81ca4a2cbbfe124392c1f
4
- data.tar.gz: 8dbd7771413345f0477fdd98d8ae2198bdb6d26f
3
+ metadata.gz: 1cc26d22e02e21c2be4d61d54240bafffa24d411
4
+ data.tar.gz: a0d6ff6c258975e3eb271a374ca62ca91e7fabe6
5
5
  SHA512:
6
- metadata.gz: 47dc210f1595a73cbd8a900021facd42bfae16e81292d2b079f9ffb053e7f6dc72ad6864ccfe832110167f566c77540c417b4e75457e48347eabacac639a7c9a
7
- data.tar.gz: 580fc7a117c73831b5b4cc6857a714e2cffdfb89187c741f0838afea11c701eec968b4f63f17b11985e6b52a4e73b9b70a201f8d74e4d4f13ad5d8bca861c4b6
6
+ metadata.gz: 13a8276f70d0a89537081a60577afd044e9f514f06bc1033a4d7f70db9ade605a4610e8a08d3545c48a43bac013c26278b8d7525eb6000738f2a58d0bff69fe2
7
+ data.tar.gz: e3f44b48c7f076a2ba30899b9ae551e9236a3a0b1e634b9575170bf0becc8bce0b1778fd3b9b6fbd60dfc429b3c359f0b17139b33bb6de3537d005eea1fa8309
data/Gemfile CHANGED
@@ -1,12 +1,14 @@
1
- source 'http://gems.prod.sessionm.com'
1
+ source "http://rubygems.org"
2
2
 
3
3
  gem 'activesupport', :require => 'active_support/all'
4
4
  gem 'activerecord', :require => 'active_record'
5
5
 
6
6
  gem 'simple_uuid', '0.2.2'
7
7
  gem 'cassandra-driver', :require => 'cassandra'
8
+ gem 'mysql2'
8
9
 
9
10
  group :test, :spec do
10
11
  gem 'rspec'
11
12
  gem "mocha"
13
+ gem "database_cleaner"
12
14
  end
data/Gemfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  GEM
2
- remote: http://gems.prod.sessionm.com/
2
+ remote: http://rubygems.org/
3
3
  specs:
4
4
  activemodel (4.2.1)
5
5
  activesupport (= 4.2.1)
@@ -18,6 +18,7 @@ GEM
18
18
  builder (3.2.2)
19
19
  cassandra-driver (2.1.3)
20
20
  ione (~> 1.2)
21
+ database_cleaner (1.4.1)
21
22
  diff-lcs (1.2.5)
22
23
  i18n (0.7.0)
23
24
  ione (1.2.0)
@@ -28,6 +29,7 @@ GEM
28
29
  minitest (5.6.1)
29
30
  mocha (1.1.0)
30
31
  metaclass (~> 0.0.1)
32
+ mysql2 (0.3.18)
31
33
  rspec (3.2.0)
32
34
  rspec-core (~> 3.2.0)
33
35
  rspec-expectations (~> 3.2.0)
@@ -55,6 +57,8 @@ DEPENDENCIES
55
57
  activerecord
56
58
  activesupport
57
59
  cassandra-driver
60
+ database_cleaner
58
61
  mocha
62
+ mysql2
59
63
  rspec
60
64
  simple_uuid (= 0.2.2)
@@ -0,0 +1,6 @@
1
+ test:
2
+ encoding: utf8
3
+ adapter: mysql2
4
+ database: cassandra_object_test
5
+ username: root
6
+ host: localhost
@@ -28,6 +28,7 @@ module CassandraObject
28
28
  autoload :RowTTL
29
29
  autoload :NestedAttributes
30
30
  autoload :Adapters
31
+ autoload :Arel
31
32
 
32
33
  module Tasks
33
34
  extend ActiveSupport::Autoload
@@ -0,0 +1,16 @@
1
+ # adds arel_table support for belongs_to relationships in ActiveRecord models
2
+ module CassandraObject
3
+ module Arel
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ def arel_table
8
+ @arel_table ||= ::Arel::Table.new(column_family, arel_engine)
9
+ end
10
+
11
+ def arel_engine
12
+ self
13
+ end
14
+ end
15
+ end
16
+ end
@@ -69,6 +69,8 @@ module CassandraObject
69
69
  @attributes[name.to_s]
70
70
  end
71
71
 
72
+ alias _read_attribute read_attribute
73
+
72
74
  def attributes=(attributes)
73
75
  attributes.each do |(name, value)|
74
76
  send("#{name}=", value)
@@ -23,12 +23,15 @@ module CassandraObject
23
23
  klass
24
24
  end
25
25
 
26
- delegate :compute_type, :to => 'ActiveRecord::Base'
26
+ def compute_type(*args)
27
+ ActiveRecord::Base.send :compute_type, *args
28
+ end
27
29
  end
28
30
 
29
31
  extend ActiveModel::Naming
30
32
  include ActiveModel::Conversion
31
33
  extend ActiveSupport::DescendantsTracker
34
+ extend ActiveRecord::Delegation::DelegateCache
32
35
 
33
36
  include Configuration
34
37
  include Connection
@@ -45,6 +48,7 @@ module CassandraObject
45
48
  include FinderMethods
46
49
  include Timestamps
47
50
  include NestedAttributes
51
+ include Arel
48
52
 
49
53
  attr_accessor :key, :schema_version, :association_cache
50
54
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '4.0.2'
5
+ s.version = '4.0.3'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe CassandraObject::Associations do
4
+ context "belongs_to" do
5
+ it "should fetch the user record from the belongs_to relationship from a cassandra object" do
6
+ user = User.create! :position => 1
7
+ issue = Issue.create! :description => 'web site not working', :worth => 1.5, :user_id => user.id
8
+ expect(issue.user.id).to eq user.id
9
+ end
10
+
11
+ it "should fetch the cassandra object from the belongs_to relationship from an active record object" do
12
+ issue = Issue.create! :description => 'web site not working', :worth => 1.5
13
+ user = User.create! :position => 1, :issue_id => issue.id
14
+ expect(user.issue.id).to eq issue.id
15
+ end
16
+ end
17
+ end
@@ -27,4 +27,10 @@ describe CassandraObject::Base do
27
27
  issue3 = Issue.create! :description => 'button is disabled', :worth => 0.2
28
28
  expect(Issue.find_with_ids(issue1.id, issue2.id).map(&:id).sort).to eq [issue1.id, issue2.id].sort
29
29
  end
30
+
31
+ it "should be able to get all issues" do
32
+ issue1 = Issue.create! :description => 'web site not working', :worth => 1.5
33
+ issue2 = Issue.create! :description => 'button is disabled', :worth => 0.2
34
+ expect(Issue.find_with_ids([issue1.id, issue2.id]).map(&:id).sort).to eq [issue1.id, issue2.id].sort
35
+ end
30
36
  end
data/spec/spec_helper.rb CHANGED
@@ -6,8 +6,6 @@ require File.expand_path('../../config/environment', __FILE__)
6
6
 
7
7
  Bundler.require :default, :test
8
8
 
9
- Dir[BASE_DIR.join("spec/support/**/*.rb")].each { |f| require f }
10
-
11
9
  KEYSPACE = 'cassandra_object_test'
12
10
 
13
11
  CassandraObject::Adapters::CassandraDriver.new(CassandraObject::Base.connection_spec).cluster.tap do |cluster|
@@ -43,6 +41,13 @@ CQL
43
41
  cluster.close
44
42
  end
45
43
 
44
+ ActiveRecord::Base.configurations = YAML.load_file('config/database.yml')
45
+ ActiveRecord::Base.establish_connection ENV["RAILS_ENV"]
46
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
47
+ ActiveRecord::Migrator.migrate('spec/support/db/migrate')
48
+
49
+ Dir[BASE_DIR.join("spec/support/**/*.rb")].each { |f| require f }
50
+
46
51
  RSpec.configure do |config|
47
52
 
48
53
  config.before(:each) do
@@ -0,0 +1,12 @@
1
+ class CreateTestTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :issue_id
5
+ t.integer :position
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :users
11
+ end
12
+ end
@@ -1,10 +1,13 @@
1
1
  class Issue < CassandraObject::Base
2
2
  key :uuid
3
+ attribute :user_id, :type => :integer
3
4
  attribute :description, :type => :string
4
5
  attribute :worth, :type => :decimal, :precision => 100
5
6
  attribute :name, :type => :string
6
7
  before_validation :set_defaults, :on => :create
7
8
 
9
+ belongs_to :user
10
+
8
11
  def set_defaults
9
12
  self.name ||= 'default name'
10
13
  end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ belongs_to :issue
3
+ 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: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Koziarski
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-05-11 00:00:00.000000000 Z
13
+ date: 2015-05-21 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Cassandra ActiveModel
16
16
  email: doug@sessionm.com
@@ -31,10 +31,12 @@ files:
31
31
  - Rakefile
32
32
  - config/boot.rb
33
33
  - config/cassandra.yml
34
+ - config/database.yml
34
35
  - config/environment.rb
35
36
  - lib/cassandra_object.rb
36
37
  - lib/cassandra_object/adapters.rb
37
38
  - lib/cassandra_object/adapters/cassandra_driver.rb
39
+ - lib/cassandra_object/arel.rb
38
40
  - lib/cassandra_object/associations.rb
39
41
  - lib/cassandra_object/associations/one_to_many.rb
40
42
  - lib/cassandra_object/associations/one_to_one.rb
@@ -93,11 +95,14 @@ files:
93
95
  - lib/cassandra_object/validations.rb
94
96
  - script/console.rb
95
97
  - sessionm-cassandra_object.gemspec
98
+ - spec/cassandra_object/associations_spec.rb
96
99
  - spec/cassandra_object/base_spec.rb
97
100
  - spec/spec_helper.rb
98
101
  - spec/support/cassandra.rb
102
+ - spec/support/db/migrate/001_create_test_tables.rb
99
103
  - spec/support/models/counter.rb
100
104
  - spec/support/models/issue.rb
105
+ - spec/support/models/user.rb
101
106
  - test/README
102
107
  - test/active_model_test.rb
103
108
  - test/attributes_test.rb
@@ -147,11 +152,14 @@ signing_key:
147
152
  specification_version: 4
148
153
  summary: Cassandra ActiveModel
149
154
  test_files:
155
+ - spec/cassandra_object/associations_spec.rb
150
156
  - spec/cassandra_object/base_spec.rb
151
157
  - spec/spec_helper.rb
152
158
  - spec/support/cassandra.rb
159
+ - spec/support/db/migrate/001_create_test_tables.rb
153
160
  - spec/support/models/counter.rb
154
161
  - spec/support/models/issue.rb
162
+ - spec/support/models/user.rb
155
163
  - test/README
156
164
  - test/active_model_test.rb
157
165
  - test/attributes_test.rb