quandl_cassandra 1.0.2 → 1.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: daa4cc9a5d756ff80a50a91316379e7d98c4f91b
4
- data.tar.gz: 22a6937e363c1b387544fba9e6f9a69314045c11
3
+ metadata.gz: f83fe0075114dcd993b31f6b0a0f56799d66bb90
4
+ data.tar.gz: daad90584e0adbf6edd4190ca50fb5f97b8d9eef
5
5
  SHA512:
6
- metadata.gz: b66b468f943f40bfb4c791792a9c21bf9258d75786617663d3bec984d9b43b93aa7844d107e909e56e8f32a6558df527d802b4203c96a084da6628c4471b7212
7
- data.tar.gz: 3835af6152e6fd3e211e72bfdfacf41f348779a37d1f8bceda95064ef4163dcbd77528c3ed9a4d380143136d5e305305ef19864d1f492782cdd1fddec84d84da
6
+ metadata.gz: 5140c4b99eec70768e703a1f1f44305462e518c0e3af9712c17448c11dbf69c4b4736a19f30eb28914136e3d4c021edc69ab5afb56328d430a554274e6542195
7
+ data.tar.gz: ad3c0b11d1657d9f78480dc2fcfd35af61080a4b2bf0e7721ae266dd5de0ae5a7c7f543ba2c2d71d06e52025385088cdef368d87ce997bf729546af06001e7ca
data/UPGRADE.md CHANGED
@@ -1,6 +1,12 @@
1
+ ## 1.0.3
2
+
3
+ * add Base#delete and Base#destroy
4
+ * add persistence specs and creation of test keyspace
5
+
6
+
1
7
  ## 1.0.2
2
8
 
3
- * Dataset .connection, .find should raise Cql::QueryError given missing keyspace
9
+ * Post .connection, .find should raise Cql::QueryError given missing keyspace
4
10
 
5
11
 
6
12
  ## 1.0.0
@@ -67,7 +67,7 @@ module Quandl::Cassandra::Base::Connection
67
67
  hosts: Quandl::Cassandra.configuration.hosts,
68
68
  consistency: Quandl::Cassandra.configuration.consistency )
69
69
  # switch keyspace
70
- c.use( Quandl::Cassandra.configuration.keyspace )
70
+ c.use( Quandl::Cassandra.configuration.keyspace ) if Quandl::Cassandra.configuration.keyspace.present?
71
71
  @@connection = c
72
72
  c
73
73
  end
@@ -42,7 +42,7 @@ module Quandl::Cassandra::Base::Persistence
42
42
  touch
43
43
  save_changes! if self.class.autosave_changes == true
44
44
  cycle_changes!
45
- new_record = false
45
+ self.new_record = false
46
46
  true
47
47
  end
48
48
  end
@@ -52,6 +52,18 @@ module Quandl::Cassandra::Base::Persistence
52
52
  self.updated_at = Time.now if respond_to?(:updated_at=)
53
53
  end
54
54
 
55
+ def destroy
56
+ return false if new_record?
57
+ run_callbacks :destroy do
58
+ self.class.delete(id)
59
+ end
60
+ end
61
+
62
+ def delete
63
+ return false if new_record?
64
+ self.class.delete(id)
65
+ end
66
+
55
67
  def update_attributes(values)
56
68
  values = self.class.sanitize_attributes(values)
57
69
  # add primary key parts to values
@@ -5,10 +5,6 @@ module Quandl::Cassandra::Base::Sanitization
5
5
  module ClassMethods
6
6
 
7
7
  def bind_primary_key(*args)
8
- if args.count > primary_key.count
9
- message = "wrong number of arguments (#{args.count} for 1..#{primary_key.count}) expected: #{primary_key.join(', ')}"
10
- raise(ArgumentError, message)
11
- end
12
8
  attrs = {}
13
9
  primary_key.each_with_index { |k, i| attrs[k] = args[i] if args[i].present? }
14
10
  attrs
@@ -44,12 +44,14 @@ module Quandl::Cassandra::Base::Schema
44
44
  end
45
45
 
46
46
  def column_aliases
47
+ return [] if system_schema.blank?
47
48
  @column_aliases ||= JSON.parse(system_schema['column_aliases']).collect(&:to_sym)
48
49
  rescue JSON::ParserError
49
50
  []
50
51
  end
51
52
 
52
53
  def key_aliases
54
+ return [] if system_schema.blank?
53
55
  @key_aliases ||= JSON.parse(system_schema['key_aliases']).collect(&:to_sym)
54
56
  rescue JSON::ParserError
55
57
  []
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassandra
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ # set host
2
+ Quandl::Cassandra.configure do |c|
3
+ c.hosts = ['localhost','192.168.33.10']
4
+ c.consistency = :one
5
+ end
6
+
7
+ # reset keyspace
8
+ keyspace_exists = Quandl::Cassandra::Base.execute("SELECT * FROM system.schema_keyspaces WHERE keyspace_name = 'quandl_cassandra_test';")
9
+ Quandl::Cassandra::Base.execute("DROP KEYSPACE quandl_cassandra_test;") if keyspace_exists.present?
10
+
11
+ # create keyspace
12
+ Quandl::Cassandra::Base.execute("CREATE KEYSPACE quandl_cassandra_test WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor': 3};")
13
+
14
+ # reconnect to keyspace
15
+ Quandl::Cassandra.configuration.keyspace = 'quandl_cassandra_test'
16
+ Quandl::Cassandra::Base.reset_connection
17
+
18
+ # create posts table
19
+ Quandl::Cassandra::Base.execute("CREATE TABLE posts (
20
+ id uuid PRIMARY KEY,
21
+ content text,
22
+ author varchar,
23
+ updated_at timestamp );")
24
+
25
+ class Post < Quandl::Cassandra::Base; end
@@ -0,0 +1,6 @@
1
+
2
+ logger = Logger.new( 'log/test.log', 2, 52428800 )
3
+ logger.formatter = proc do |severity, datetime, progname, msg|
4
+ "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}]: #{msg}\n"
5
+ end
6
+ Quandl::Logger.use(logger)
@@ -1,23 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestModel < Quandl::Cassandra::Base; end
4
-
5
3
  describe Quandl::Cassandra::Base::Connection do
6
- before(:all){ Quandl::Cassandra.configuration.keyspace = 'missing_keyspace' }
7
-
8
- subject{ TestModel }
9
4
 
10
- describe ".connection" do
5
+ describe ".reset_connection" do
11
6
  it "should raise Cql::QueryError" do
12
- expect{ TestModel.connection }.to raise_error(Cql::QueryError)
7
+ Quandl::Cassandra.configuration.keyspace = 'missing_keyspace'
8
+ expect{ Post.reset_connection }.to raise_error(Cql::QueryError)
13
9
  end
14
10
  end
15
11
 
16
12
  describe ".find" do
17
13
  it "should raise Cql::QueryError" do
18
- expect{ TestModel.find(1) }.to raise_error(Cql::QueryError)
14
+ expect{ Post.find(1) }.to raise_error(Cql::QueryError)
19
15
  end
20
16
  end
21
17
 
22
- after(:all){ Quandl::Cassandra.configuration.keyspace = 'wikiposit' }
18
+ after(:all) do
19
+ Quandl::Cassandra.configuration.keyspace = 'quandl_cassandra_test'
20
+ Quandl::Cassandra::Base.reset_connection
21
+ end
23
22
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Quandl::Cassandra::Base::Persistence do
4
+
5
+ let(:id){ Cql::Uuid.new(SecureRandom.uuid) }
6
+
7
+ subject{ Post.new }
8
+
9
+ it{ should respond_to :id }
10
+ it{ should respond_to :content }
11
+ it{ should respond_to :author }
12
+ it{ should respond_to :updated_at }
13
+
14
+ its(:new_record?){ should be_true }
15
+
16
+ describe ".create" do
17
+
18
+ let(:post){ Post.create( id: id, content: 'test content', author: "quandl" ) }
19
+ subject{ post }
20
+
21
+ its(:new_record?){ should be_false }
22
+
23
+ describe ".find" do
24
+ subject{ Post.find(post.id) }
25
+
26
+ its(:id){ should eq id }
27
+ its(:content){ should eq 'test content' }
28
+ its(:author){ should eq 'quandl' }
29
+ its(:new_record?){ should be_false }
30
+ end
31
+
32
+ describe ".destroy" do
33
+ before(:each){ post.destroy }
34
+ it "should not find the post" do
35
+ Post.find(post.id).should be_nil
36
+ end
37
+ end
38
+
39
+ describe ".delete" do
40
+ before(:each){ post.delete }
41
+ it "should not find the post" do
42
+ Post.find(post.id).should be_nil
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestModel < Quandl::Cassandra::Base; end
4
-
5
3
  describe Quandl::Cassandra::Base::Sanitization do
6
4
 
7
5
  end
@@ -1,46 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestModel < Quandl::Cassandra::Base; end
4
-
5
3
  describe Quandl::Cassandra::Base::Scoping do
6
4
 
7
- subject{ TestModel }
5
+ subject{ Post }
8
6
 
9
7
  [:where, :select, :limit, :order].each do |name|
10
8
  it{ should respond_to name }
11
9
  end
12
10
 
13
- its(:scope_names){ should eq TestModel.scope.scope_names }
14
- #
15
- # describe ".find_or_build" do
16
- # it "given nil should be a new record" do
17
- # TestModel.find_or_build(nil).new_record?.should be_true
18
- # end
19
- # it "given empty sting should be a new record" do
20
- # TestModel.find_or_build('').new_record?.should be_true
21
- # end
22
- # end
23
- #
11
+ let(:id){ SecureRandom.uuid }
12
+
13
+ its(:scope_names){ should eq Post.scope.scope_names }
14
+
15
+ describe ".find_or_build" do
16
+ it "given nil should be a new record" do
17
+ Post.find_or_build(nil).new_record?.should be_true
18
+ end
19
+ it "given empty sting should be a new record" do
20
+ Post.find_or_build('').new_record?.should be_true
21
+ end
22
+ end
23
+
24
24
  describe ".to_cql" do
25
25
 
26
- let(:scope) { TestModel.scope.new }
26
+ let(:scope) { Post.scope.new }
27
27
  subject{ scope.to_cql }
28
28
 
29
29
  describe "#where" do
30
- before(:each){ scope.where( id: 1 ) }
31
- it{ should eq "SELECT * FROM test_models WHERE id = 1" }
30
+ before(:each){ scope.where( id: id ) }
31
+ it{ should eq "SELECT * FROM posts WHERE id = #{id}" }
32
32
 
33
33
  describe "#limit" do
34
34
  before(:each){ scope.limit( 10 ) }
35
- it{ should eq "SELECT * FROM test_models WHERE id = 1 LIMIT 10" }
35
+ it{ should eq "SELECT * FROM posts WHERE id = #{id} LIMIT 10" }
36
36
 
37
37
  describe "#select" do
38
38
  before(:each){ scope.select( :name, :value ) }
39
- it{ should eq "SELECT name,value FROM test_models WHERE id = 1 LIMIT 10" }
39
+ it{ should eq "SELECT name,value FROM posts WHERE id = #{id} LIMIT 10" }
40
40
 
41
41
  describe "#order" do
42
42
  before(:each){ scope.order("name DESC") }
43
- it{ should eq "SELECT name,value FROM test_models WHERE id = 1 ORDER BY name DESC LIMIT 10" }
43
+ it{ should eq "SELECT name,value FROM posts WHERE id = #{id} ORDER BY name DESC LIMIT 10" }
44
44
  end
45
45
 
46
46
  end
@@ -6,7 +6,7 @@ describe Quandl::Cassandra do
6
6
  subject{ Quandl::Cassandra.configuration }
7
7
  its(:hosts){ should be_present }
8
8
  its(:consistency){ should eq :one }
9
- its(:keyspace){ should eq 'wikiposit' }
9
+ its(:keyspace){ should eq 'quandl_cassandra_test' }
10
10
  end
11
11
 
12
12
  end
data/spec/spec_helper.rb CHANGED
@@ -5,10 +5,14 @@ QUANDL_LOGGER = true
5
5
  require "rspec"
6
6
  require 'factory_girl'
7
7
  require 'pry'
8
+ require 'securerandom'
8
9
 
9
10
  require "quandl/cassandra"
10
11
  require "quandl/fabricate"
11
12
 
13
+ # require config
14
+ Dir.glob( File.join( File.dirname(__FILE__), 'config/**/*.rb' ) ).each{|f| require(f) }
15
+
12
16
  # require expectations
13
17
  require 'rspec/expectations'
14
18
  Dir.glob( File.join( File.dirname(__FILE__), 'expectations/**/*.rb' ) ).each{|f| require(f) }
@@ -16,20 +20,6 @@ Dir.glob( File.join( File.dirname(__FILE__), 'expectations/**/*.rb' ) ).each{|f|
16
20
  # require factories
17
21
  Dir.glob( File.join( File.dirname(__FILE__), 'factories/**/*.rb' ) ).each{|f| require(f) }
18
22
 
19
- include Quandl::Cassandra
20
-
21
- logger = Logger.new( 'log/test.log', 2, 52428800 )
22
- logger.formatter = proc do |severity, datetime, progname, msg|
23
- "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}]: #{msg}\n"
24
- end
25
- Quandl::Logger.use(logger)
26
-
27
- Quandl::Cassandra.configure do |c|
28
- c.hosts = ['192.168.33.10']
29
- c.keyspace = 'wikiposit'
30
- c.consistency = :one
31
- end
32
-
33
23
  RSpec.configure do |config|
34
24
  config.include FactoryGirl::Syntax::Methods
35
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassandra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -235,9 +235,12 @@ files:
235
235
  - lib/quandl/cassandra/version.rb
236
236
  - lib/quandl/strategy.rb
237
237
  - quandl_cassandra.gemspec
238
+ - spec/config/cassandra.rb
239
+ - spec/config/logger.rb
238
240
  - spec/expectations/string.rb
239
241
  - spec/expectations/time.rb
240
242
  - spec/lib/quandl/cassandra/base/connection_spec.rb
243
+ - spec/lib/quandl/cassandra/base/persistence_spec.rb
241
244
  - spec/lib/quandl/cassandra/base/sanitization_spec.rb
242
245
  - spec/lib/quandl/cassandra/base/scoping_spec.rb
243
246
  - spec/lib/quandl/cassandra_spec.rb
@@ -267,9 +270,12 @@ signing_key:
267
270
  specification_version: 4
268
271
  summary: Quandl cassandra interface.
269
272
  test_files:
273
+ - spec/config/cassandra.rb
274
+ - spec/config/logger.rb
270
275
  - spec/expectations/string.rb
271
276
  - spec/expectations/time.rb
272
277
  - spec/lib/quandl/cassandra/base/connection_spec.rb
278
+ - spec/lib/quandl/cassandra/base/persistence_spec.rb
273
279
  - spec/lib/quandl/cassandra/base/sanitization_spec.rb
274
280
  - spec/lib/quandl/cassandra/base/scoping_spec.rb
275
281
  - spec/lib/quandl/cassandra_spec.rb