datastax_rails 2.0.9 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cql-rb_extensions.rb +6 -1
- data/lib/datastax_rails/associations/collection_association.rb +25 -1
- data/lib/datastax_rails/associations/has_many_association.rb +1 -0
- data/lib/datastax_rails/base.rb +4 -4
- data/lib/datastax_rails/column.rb +1 -0
- data/lib/datastax_rails/connection/statement_cache.rb +17 -0
- data/lib/datastax_rails/connection.rb +1 -0
- data/lib/datastax_rails/cql/base.rb +4 -3
- data/lib/datastax_rails/log_subscriber.rb +0 -0
- data/lib/datastax_rails/version.rb +1 -1
- data/lib/datastax_rails.rb +5 -0
- data/spec/datastax_rails/associations/collection_association_spec.rb +42 -0
- data/spec/datastax_rails/connection/statement_cache_spec.rb +9 -0
- data/spec/datastax_rails/cql/base_spec.rb +10 -0
- data/spec/datastax_rails/cql/select_spec.rb +2 -4
- data/spec/datastax_rails/relation/finder_methods_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/default_consistency_shared_examples.rb +8 -5
- data/spec/support/models.rb +1 -0
- metadata +14 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 98234dcb77c32791b630e27d4a9e4deb0be11068
         | 
| 4 | 
            +
              data.tar.gz: 0faf451aa7dfb597651ef4195d0849731ac43b7e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6b0ca26bcaedfe88407c54badf618eb8968aa2cdbda4aac273c7d0422be89d79ce2b806af36d0bdebb41e8ad40a67a86c806065bec014ceb3d39ecf7a9ade7bf
         | 
| 7 | 
            +
              data.tar.gz: 9a502e20649c2e627bf4256e4e175860ef3004cd3fe6d418a0506c343ca2c8cb6eee8702a19aeef75d1cd10a7ed6b616f48e138bc933c24bbb002890cce95d78
         | 
    
        data/lib/cql-rb_extensions.rb
    CHANGED
    
    | @@ -1,3 +1,8 @@ | |
| 1 | 
            +
            # By default, cql-rb grabs a random connection for each request. This is great for
         | 
| 2 | 
            +
            # keeping load distributed across the cluster. Unfortunately, it plays havoc with
         | 
| 3 | 
            +
            # the Solr integration where we often need to ensure that we're talking to the
         | 
| 4 | 
            +
            # Solr and Cassandra on the same node. For that reason, we cause the current
         | 
| 5 | 
            +
            # connection in use to stay fixed for 500 requests before rolling to the another.
         | 
| 1 6 | 
             
            require 'cql'
         | 
| 2 7 | 
             
            require 'cql/client/connection_manager'
         | 
| 3 8 |  | 
| @@ -18,7 +23,7 @@ Cql::Client::ConnectionManager.class_eval do | |
| 18 23 | 
             
              end
         | 
| 19 24 | 
             
            end
         | 
| 20 25 |  | 
| 21 | 
            -
            require 'cql/client/ | 
| 26 | 
            +
            require 'cql/client/client'
         | 
| 22 27 |  | 
| 23 28 | 
             
            Cql::Client::SynchronousClient.class_eval do
         | 
| 24 29 | 
             
              def current_connection
         | 
| @@ -18,13 +18,37 @@ module DatastaxRails | |
| 18 18 | 
             
                class CollectionAssociation < Association #:nodoc:
         | 
| 19 19 | 
             
                  attr_reader :proxy
         | 
| 20 20 |  | 
| 21 | 
            -
                  delegate : | 
| 21 | 
            +
                  delegate :first, :last, :to => :scoped
         | 
| 22 22 |  | 
| 23 23 | 
             
                  def initialize(owner, reflection)
         | 
| 24 24 | 
             
                    super
         | 
| 25 25 | 
             
                    @proxy = CollectionProxy.new(self)
         | 
| 26 26 | 
             
                  end
         | 
| 27 27 |  | 
| 28 | 
            +
                  def size
         | 
| 29 | 
            +
                    if !find_target? || loaded?
         | 
| 30 | 
            +
                      target.size
         | 
| 31 | 
            +
                    elsif !loaded? && target.is_a?(Array)
         | 
| 32 | 
            +
                      unsaved_records = target.select { |r| r.new_record? }
         | 
| 33 | 
            +
                      unsaved_records.size + scoped.count
         | 
| 34 | 
            +
                    else
         | 
| 35 | 
            +
                      scoped.count
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                  alias_method :count, :size
         | 
| 39 | 
            +
                  
         | 
| 40 | 
            +
                  def empty?
         | 
| 41 | 
            +
                    size == 0
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                  
         | 
| 44 | 
            +
                  def any?
         | 
| 45 | 
            +
                    size > 0
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                  
         | 
| 48 | 
            +
                  def many?
         | 
| 49 | 
            +
                    size > 1
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                  
         | 
| 28 52 | 
             
                  # Implements the reader method, e.g. foo.items for Foo.has_many :items
         | 
| 29 53 | 
             
                  def reader(force_reload = false)
         | 
| 30 54 | 
             
                    if force_reload || stale_target?
         | 
    
        data/lib/datastax_rails/base.rb
    CHANGED
    
    | @@ -491,10 +491,10 @@ module DatastaxRails #:nodoc: | |
| 491 491 | 
             
                end
         | 
| 492 492 |  | 
| 493 493 | 
             
                def ==(comparison_object)
         | 
| 494 | 
            -
                   | 
| 495 | 
            -
                     | 
| 496 | 
            -
             | 
| 497 | 
            -
             | 
| 494 | 
            +
                  super ||
         | 
| 495 | 
            +
                    comparison_object.instance_of?(self.class) &&
         | 
| 496 | 
            +
                    id.present? &&
         | 
| 497 | 
            +
                    comparison_object.id.eql?(id)
         | 
| 498 498 | 
             
                end
         | 
| 499 499 |  | 
| 500 500 | 
             
                def eql?(comparison_object)
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            module DatastaxRails
         | 
| 2 | 
            +
              module StatementCache
         | 
| 3 | 
            +
                extend ActiveSupport::Concern
         | 
| 4 | 
            +
                
         | 
| 5 | 
            +
                included do
         | 
| 6 | 
            +
                  class_attribute :statement_cache
         | 
| 7 | 
            +
                  self.statement_cache = {}
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                
         | 
| 10 | 
            +
                module ClassMethods
         | 
| 11 | 
            +
                  def establish_connection(spec)
         | 
| 12 | 
            +
                    self.statement_cache = {}
         | 
| 13 | 
            +
                    super
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| @@ -29,11 +29,12 @@ module DatastaxRails | |
| 29 29 | 
             
                    cql = self.to_cql
         | 
| 30 30 | 
             
                    puts cql if ENV['DEBUG_CQL'] == 'true'
         | 
| 31 31 | 
             
                    pp @values if ENV['DEBUG_CQL'] == 'true'
         | 
| 32 | 
            -
                     | 
| 33 | 
            -
             | 
| 32 | 
            +
                    digest = Digest::MD5.digest cql
         | 
| 33 | 
            +
                    stmt = DatastaxRails::Base.statement_cache[digest] ||= DatastaxRails::Base.connection.prepare(cql)
         | 
| 34 | 
            +
                    if @consistency
         | 
| 34 35 | 
             
                      stmt.execute(*@values, :consistency => @consistency)
         | 
| 35 36 | 
             
                    else
         | 
| 36 | 
            -
                       | 
| 37 | 
            +
                      stmt.execute(*@values)
         | 
| 37 38 | 
             
                    end
         | 
| 38 39 | 
             
                  end
         | 
| 39 40 | 
             
                end
         | 
| 
            File without changes
         | 
    
        data/lib/datastax_rails.rb
    CHANGED
    
    
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe DatastaxRails::Base do
         | 
| 4 | 
            +
              context 'associations' do
         | 
| 5 | 
            +
                context 'collection' do
         | 
| 6 | 
            +
                  subject {Person.new(name: 'Matthew')}
         | 
| 7 | 
            +
                  
         | 
| 8 | 
            +
                  describe "#size" do
         | 
| 9 | 
            +
                    it "reports the total of persisted and non-persisted" do
         | 
| 10 | 
            +
                      subject.save
         | 
| 11 | 
            +
                      car1 = Car.create(:person_id => subject.id)
         | 
| 12 | 
            +
                      car2 = Car.new
         | 
| 13 | 
            +
                      subject.cars << car2
         | 
| 14 | 
            +
                      Car.commit_solr
         | 
| 15 | 
            +
                      expect(subject.cars.size).to be(2)
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  
         | 
| 19 | 
            +
                  describe "#empty?" do
         | 
| 20 | 
            +
                    it "returns false if a new record exists" do
         | 
| 21 | 
            +
                      subject.cars << Car.new
         | 
| 22 | 
            +
                      expect(subject.cars).not_to be_empty
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                  
         | 
| 26 | 
            +
                  describe "#any?" do
         | 
| 27 | 
            +
                    it "returns true if a new record exists" do
         | 
| 28 | 
            +
                      subject.cars << Car.new
         | 
| 29 | 
            +
                      expect(subject.cars).to be_any
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                  
         | 
| 33 | 
            +
                  describe "#many?" do
         | 
| 34 | 
            +
                    it "returns false if more than one new record exists" do
         | 
| 35 | 
            +
                      subject.cars << Car.new
         | 
| 36 | 
            +
                      subject.cars << Car.new
         | 
| 37 | 
            +
                      expect(subject.cars).to be_many
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe DatastaxRails::Base do
         | 
| 4 | 
            +
              it "clears the statement cache when a new connection is established" do
         | 
| 5 | 
            +
                DatastaxRails::Base.statement_cache[:a] = 12345
         | 
| 6 | 
            +
                DatastaxRails::Base.establish_connection(DatastaxRails::Base.config)
         | 
| 7 | 
            +
                expect(DatastaxRails::Base.statement_cache).to be_empty
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
            end
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe DatastaxRails::Cql::Base do
         | 
| 4 | 
            +
              it "caches prepared statements" do
         | 
| 5 | 
            +
                DatastaxRails::Base.connection.should_receive(:prepare).once.and_return(double("statement", :execute => true))
         | 
| 6 | 
            +
                cql = DatastaxRails::Cql::ColumnFamily.new(Person)
         | 
| 7 | 
            +
                cql.select(['*']).conditions(:name => 'John').execute
         | 
| 8 | 
            +
                cql.select(['*']).conditions(:name => 'John').execute
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| @@ -1,12 +1,10 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe DatastaxRails::Cql::Select do
         | 
| 4 | 
            -
               | 
| 5 | 
            -
                @model_class = double("Model Class", :column_family => 'users', :default_consistency => DatastaxRails::Cql::Consistency::QUORUM)
         | 
| 6 | 
            -
              end
         | 
| 4 | 
            +
              let(:model_class) { double("Model Class", :column_family => 'users', :default_consistency => DatastaxRails::Cql::Consistency::QUORUM) }
         | 
| 7 5 |  | 
| 8 6 | 
             
              it "should generate valid CQL" do
         | 
| 9 | 
            -
                cql = DatastaxRails::Cql::Select.new( | 
| 7 | 
            +
                cql = DatastaxRails::Cql::Select.new(model_class, ["*"])
         | 
| 10 8 | 
             
                cql.using(DatastaxRails::Cql::Consistency::QUORUM).conditions(:key => '12345').limit(1)
         | 
| 11 9 | 
             
                cql.to_cql.should == "SELECT * FROM users WHERE \"key\" = ? LIMIT 1 "
         | 
| 12 10 | 
             
              end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
| @@ -1,16 +1,19 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            shared_examples_for 'default_consistency' do
         | 
| 4 | 
            +
              let(:prepared_statement) {double("PreparedStatement")}
         | 
| 5 | 
            +
              before { DatastaxRails::Base.connection.stub(:prepare => prepared_statement)}
         | 
| 6 | 
            +
              
         | 
| 4 7 | 
             
              it "should default to QUORUM" do
         | 
| 5 | 
            -
                cql = DatastaxRails::Cql::Select.new( | 
| 6 | 
            -
                DatastaxRails::Base.connection.should_receive(:execute).with( | 
| 8 | 
            +
                cql = DatastaxRails::Cql::Select.new(model_class, ["*"])
         | 
| 9 | 
            +
                DatastaxRails::Base.connection.should_receive(:execute).with(prepared_statement, :consistency => :quorum)
         | 
| 7 10 | 
             
                cql.execute
         | 
| 8 11 | 
             
              end
         | 
| 9 12 |  | 
| 10 13 | 
             
              it "should default to level specified by model class" do
         | 
| 11 | 
            -
                 | 
| 12 | 
            -
                cql = DatastaxRails::Cql::Select.new( | 
| 13 | 
            -
                DatastaxRails::Base.connection.should_receive(:execute).with( | 
| 14 | 
            +
                model_class.stub(:default_consistency => 'LOCAL_QUORUM')
         | 
| 15 | 
            +
                cql = DatastaxRails::Cql::Select.new(model_class, ["*"])
         | 
| 16 | 
            +
                DatastaxRails::Base.connection.should_receive(:execute).with(prepared_statement, :consistency => :local_quorum)
         | 
| 14 17 | 
             
                cql.execute
         | 
| 15 18 | 
             
              end
         | 
| 16 19 | 
             
            end
         | 
    
        data/spec/support/models.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: datastax_rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.0. | 
| 4 | 
            +
              version: 2.0.12
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jason M. Kusar
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-07-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| @@ -36,20 +36,20 @@ dependencies: | |
| 36 36 | 
             
                requirements:
         | 
| 37 37 | 
             
                - - ~>
         | 
| 38 38 | 
             
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            -
                    version: ' | 
| 39 | 
            +
                    version: '2.0'
         | 
| 40 40 | 
             
                - - '>='
         | 
| 41 41 | 
             
                  - !ruby/object:Gem::Version
         | 
| 42 | 
            -
                    version:  | 
| 42 | 
            +
                    version: 2.0.0
         | 
| 43 43 | 
             
              type: :runtime
         | 
| 44 44 | 
             
              prerelease: false
         | 
| 45 45 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 46 46 | 
             
                requirements:
         | 
| 47 47 | 
             
                - - ~>
         | 
| 48 48 | 
             
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            -
                    version: ' | 
| 49 | 
            +
                    version: '2.0'
         | 
| 50 50 | 
             
                - - '>='
         | 
| 51 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 52 | 
            -
                    version:  | 
| 52 | 
            +
                    version: 2.0.0
         | 
| 53 53 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 54 54 | 
             
              name: rsolr
         | 
| 55 55 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -181,6 +181,7 @@ files: | |
| 181 181 | 
             
            - lib/datastax_rails/collection.rb
         | 
| 182 182 | 
             
            - lib/datastax_rails/column.rb
         | 
| 183 183 | 
             
            - lib/datastax_rails/connection.rb
         | 
| 184 | 
            +
            - lib/datastax_rails/connection/statement_cache.rb
         | 
| 184 185 | 
             
            - lib/datastax_rails/cql.rb
         | 
| 185 186 | 
             
            - lib/datastax_rails/cql/alter_column_family.rb
         | 
| 186 187 | 
             
            - lib/datastax_rails/cql/base.rb
         | 
| @@ -202,6 +203,7 @@ files: | |
| 202 203 | 
             
            - lib/datastax_rails/errors.rb
         | 
| 203 204 | 
             
            - lib/datastax_rails/grouped_collection.rb
         | 
| 204 205 | 
             
            - lib/datastax_rails/inheritance.rb
         | 
| 206 | 
            +
            - lib/datastax_rails/log_subscriber.rb
         | 
| 205 207 | 
             
            - lib/datastax_rails/payload_model.rb
         | 
| 206 208 | 
             
            - lib/datastax_rails/persistence.rb
         | 
| 207 209 | 
             
            - lib/datastax_rails/railtie.rb
         | 
| @@ -239,12 +241,15 @@ files: | |
| 239 241 | 
             
            - lib/datastax_rails/wide_storage_model.rb
         | 
| 240 242 | 
             
            - lib/schema_migration.rb
         | 
| 241 243 | 
             
            - spec/datastax_rails/associations/belongs_to_association_spec.rb
         | 
| 244 | 
            +
            - spec/datastax_rails/associations/collection_association_spec.rb
         | 
| 242 245 | 
             
            - spec/datastax_rails/associations/has_many_association_spec.rb
         | 
| 243 246 | 
             
            - spec/datastax_rails/associations_spec.rb
         | 
| 244 247 | 
             
            - spec/datastax_rails/attribute_methods_spec.rb
         | 
| 245 248 | 
             
            - spec/datastax_rails/base_spec.rb
         | 
| 246 249 | 
             
            - spec/datastax_rails/callbacks_spec.rb
         | 
| 247 250 | 
             
            - spec/datastax_rails/column_spec.rb
         | 
| 251 | 
            +
            - spec/datastax_rails/connection/statement_cache_spec.rb
         | 
| 252 | 
            +
            - spec/datastax_rails/cql/base_spec.rb
         | 
| 248 253 | 
             
            - spec/datastax_rails/cql/select_spec.rb
         | 
| 249 254 | 
             
            - spec/datastax_rails/cql/update_spec.rb
         | 
| 250 255 | 
             
            - spec/datastax_rails/dynamic_model_spec.rb
         | 
| @@ -342,6 +347,7 @@ test_files: | |
| 342 347 | 
             
            - spec/datastax_rails/attribute_methods_spec.rb
         | 
| 343 348 | 
             
            - spec/datastax_rails/scoping/default_spec.rb
         | 
| 344 349 | 
             
            - spec/datastax_rails/associations_spec.rb
         | 
| 350 | 
            +
            - spec/datastax_rails/connection/statement_cache_spec.rb
         | 
| 345 351 | 
             
            - spec/datastax_rails/types/dynamic_list_spec.rb
         | 
| 346 352 | 
             
            - spec/datastax_rails/types/dynamic_set_spec.rb
         | 
| 347 353 | 
             
            - spec/datastax_rails/types/dynamic_map_spec.rb
         | 
| @@ -350,6 +356,7 @@ test_files: | |
| 350 356 | 
             
            - spec/datastax_rails/schema/solr_spec.rb
         | 
| 351 357 | 
             
            - spec/datastax_rails/validations/uniqueness_spec.rb
         | 
| 352 358 | 
             
            - spec/datastax_rails/cql/update_spec.rb
         | 
| 359 | 
            +
            - spec/datastax_rails/cql/base_spec.rb
         | 
| 353 360 | 
             
            - spec/datastax_rails/cql/select_spec.rb
         | 
| 354 361 | 
             
            - spec/datastax_rails/persistence_spec.rb
         | 
| 355 362 | 
             
            - spec/datastax_rails/relation/spawn_methods_spec.rb
         | 
| @@ -362,6 +369,7 @@ test_files: | |
| 362 369 | 
             
            - spec/datastax_rails/base_spec.rb
         | 
| 363 370 | 
             
            - spec/datastax_rails/inheritance_spec.rb
         | 
| 364 371 | 
             
            - spec/datastax_rails/associations/has_many_association_spec.rb
         | 
| 372 | 
            +
            - spec/datastax_rails/associations/collection_association_spec.rb
         | 
| 365 373 | 
             
            - spec/datastax_rails/associations/belongs_to_association_spec.rb
         | 
| 366 374 | 
             
            - spec/datastax_rails/callbacks_spec.rb
         | 
| 367 375 | 
             
            - spec/feature/dynamic_fields_spec.rb
         |