datastax_rails 2.0.12 → 2.0.15
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/Rakefile +5 -5
- data/lib/blankslate.rb +8 -11
- data/lib/cql-rb_extensions.rb +5 -3
- data/lib/datastax_rails/associations/association.rb +93 -101
- data/lib/datastax_rails/associations/association_scope.rb +7 -7
- data/lib/datastax_rails/associations/belongs_to_association.rb +46 -48
- data/lib/datastax_rails/associations/builder/association.rb +32 -31
- data/lib/datastax_rails/associations/builder/belongs_to.rb +19 -20
- data/lib/datastax_rails/associations/builder/collection_association.rb +32 -32
- data/lib/datastax_rails/associations/builder/has_and_belongs_to_many.rb +21 -21
- data/lib/datastax_rails/associations/builder/has_many.rb +39 -40
- data/lib/datastax_rails/associations/builder/has_one.rb +30 -31
- data/lib/datastax_rails/associations/builder/singular_association.rb +31 -33
- data/lib/datastax_rails/associations/collection_association.rb +129 -135
- data/lib/datastax_rails/associations/collection_proxy.rb +21 -21
- data/lib/datastax_rails/associations/has_and_belongs_to_many_association.rb +26 -26
- data/lib/datastax_rails/associations/has_many_association.rb +38 -38
- data/lib/datastax_rails/associations/has_one_association.rb +31 -32
- data/lib/datastax_rails/associations/singular_association.rb +31 -30
- data/lib/datastax_rails/associations.rb +27 -24
- data/lib/datastax_rails/attribute_assignment.rb +17 -17
- data/lib/datastax_rails/attribute_methods/definition.rb +4 -4
- data/lib/datastax_rails/attribute_methods/dirty.rb +34 -33
- data/lib/datastax_rails/attribute_methods/primary_key.rb +3 -8
- data/lib/datastax_rails/attribute_methods/read.rb +10 -12
- data/lib/datastax_rails/attribute_methods/typecasting.rb +36 -35
- data/lib/datastax_rails/attribute_methods/write.rb +5 -6
- data/lib/datastax_rails/attribute_methods.rb +52 -56
- data/lib/datastax_rails/base.rb +122 -125
- data/lib/datastax_rails/callbacks.rb +15 -9
- data/lib/datastax_rails/cassandra_only_model.rb +6 -6
- data/lib/datastax_rails/collection.rb +5 -7
- data/lib/datastax_rails/column.rb +130 -118
- data/lib/datastax_rails/connection/statement_cache.rb +3 -3
- data/lib/datastax_rails/connection.rb +42 -33
- data/lib/datastax_rails/cql/alter_column_family.rb +19 -21
- data/lib/datastax_rails/cql/base.rb +8 -11
- data/lib/datastax_rails/cql/column_family.rb +11 -10
- data/lib/datastax_rails/cql/consistency.rb +2 -2
- data/lib/datastax_rails/cql/create_column_family.rb +15 -15
- data/lib/datastax_rails/cql/create_index.rb +5 -5
- data/lib/datastax_rails/cql/create_keyspace.rb +7 -7
- data/lib/datastax_rails/cql/delete.rb +16 -29
- data/lib/datastax_rails/cql/drop_column_family.rb +2 -2
- data/lib/datastax_rails/cql/drop_index.rb +2 -2
- data/lib/datastax_rails/cql/drop_keyspace.rb +2 -2
- data/lib/datastax_rails/cql/insert.rb +10 -16
- data/lib/datastax_rails/cql/select.rb +21 -33
- data/lib/datastax_rails/cql/truncate.rb +2 -2
- data/lib/datastax_rails/cql/update.rb +16 -24
- data/lib/datastax_rails/cql/use_keyspace.rb +2 -2
- data/lib/datastax_rails/cql.rb +2 -2
- data/lib/datastax_rails/dynamic_model.rb +32 -29
- data/lib/datastax_rails/errors.rb +6 -6
- data/lib/datastax_rails/grouped_collection.rb +3 -3
- data/lib/datastax_rails/inheritance.rb +9 -9
- data/lib/datastax_rails/payload_model.rb +24 -20
- data/lib/datastax_rails/persistence.rb +116 -110
- data/lib/datastax_rails/railtie.rb +7 -7
- data/lib/datastax_rails/reflection.rb +61 -59
- data/lib/datastax_rails/relation/batches.rb +12 -13
- data/lib/datastax_rails/relation/facet_methods.rb +44 -33
- data/lib/datastax_rails/relation/finder_methods.rb +95 -91
- data/lib/datastax_rails/relation/modification_methods.rb +5 -5
- data/lib/datastax_rails/relation/search_methods.rb +102 -102
- data/lib/datastax_rails/relation/spawn_methods.rb +25 -24
- data/lib/datastax_rails/relation/stats_methods.rb +9 -8
- data/lib/datastax_rails/relation.rb +165 -170
- data/lib/datastax_rails/rsolr_client_wrapper.rb +3 -3
- data/lib/datastax_rails/schema/cassandra.rb +44 -43
- data/lib/datastax_rails/schema/migrator.rb +52 -52
- data/lib/datastax_rails/schema/solr.rb +55 -47
- data/lib/datastax_rails/schema_cache.rb +1 -3
- data/lib/datastax_rails/scoping/default.rb +2 -3
- data/lib/datastax_rails/scoping/named.rb +3 -5
- data/lib/datastax_rails/scoping.rb +11 -12
- data/lib/datastax_rails/serialization.rb +34 -31
- data/lib/datastax_rails/serializers/xml_serializer.rb +178 -175
- data/lib/datastax_rails/timestamps.rb +4 -4
- data/lib/datastax_rails/types/dirty_collection.rb +57 -57
- data/lib/datastax_rails/types/dynamic_list.rb +1 -1
- data/lib/datastax_rails/types/dynamic_map.rb +5 -7
- data/lib/datastax_rails/types/dynamic_set.rb +2 -2
- data/lib/datastax_rails/util/solr_repair.rb +3 -3
- data/lib/datastax_rails/validations/associated.rb +8 -6
- data/lib/datastax_rails/validations/uniqueness.rb +8 -8
- data/lib/datastax_rails/validations.rb +9 -10
- data/lib/datastax_rails/version.rb +2 -1
- data/lib/datastax_rails/wide_storage_model.rb +6 -6
- data/lib/datastax_rails.rb +13 -9
- data/lib/schema_migration.rb +3 -3
- data/spec/datastax_rails/associations/belongs_to_association_spec.rb +2 -2
- data/spec/datastax_rails/associations/collection_association_spec.rb +14 -14
- data/spec/datastax_rails/associations/has_many_association_spec.rb +20 -20
- data/spec/datastax_rails/associations_spec.rb +11 -11
- data/spec/datastax_rails/attribute_methods_spec.rb +25 -25
- data/spec/datastax_rails/base_spec.rb +24 -24
- data/spec/datastax_rails/callbacks_spec.rb +21 -21
- data/spec/datastax_rails/column_spec.rb +133 -132
- data/spec/datastax_rails/connection/statement_cache_spec.rb +2 -2
- data/spec/datastax_rails/cql/base_spec.rb +4 -4
- data/spec/datastax_rails/cql/delete_spec.rb +19 -0
- data/spec/datastax_rails/cql/select_spec.rb +8 -8
- data/spec/datastax_rails/cql/update_spec.rb +8 -10
- data/spec/datastax_rails/dynamic_model_spec.rb +36 -22
- data/spec/datastax_rails/inheritance_spec.rb +11 -14
- data/spec/datastax_rails/persistence_spec.rb +73 -74
- data/spec/datastax_rails/relation/batches_spec.rb +13 -13
- data/spec/datastax_rails/relation/facet_methods_spec.rb +43 -35
- data/spec/datastax_rails/relation/finder_methods_spec.rb +77 -78
- data/spec/datastax_rails/relation/modification_methods_spec.rb +19 -19
- data/spec/datastax_rails/relation/search_methods_spec.rb +160 -160
- data/spec/datastax_rails/relation/spawn_methods_spec.rb +18 -18
- data/spec/datastax_rails/relation_spec.rb +119 -116
- data/spec/datastax_rails/schema/migrator_spec.rb +30 -30
- data/spec/datastax_rails/schema/solr_spec.rb +15 -15
- data/spec/datastax_rails/scoping/default_spec.rb +9 -9
- data/spec/datastax_rails/types/dynamic_list_spec.rb +12 -12
- data/spec/datastax_rails/types/dynamic_map_spec.rb +10 -10
- data/spec/datastax_rails/types/dynamic_set_spec.rb +22 -10
- data/spec/datastax_rails/validations/uniqueness_spec.rb +25 -25
- data/spec/datastax_rails/wide_storage_model_spec.rb +11 -0
- data/spec/datastax_rails_spec.rb +2 -2
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/factories/audit_logs.rb +6 -0
- data/spec/factories/hobbies.rb +6 -0
- data/spec/factories/people.rb +5 -0
- data/spec/feature/dynamic_fields_spec.rb +4 -4
- data/spec/feature/overloaded_tables_spec.rb +11 -12
- data/spec/spec_helper.rb +17 -14
- data/spec/support/datastax_test_hook.rb +2 -2
- data/spec/support/default_consistency_shared_examples.rb +11 -11
- data/spec/support/models.rb +31 -32
- metadata +40 -6
- data/lib/datastax_rails/attribute_methods/before_type_cast.rb +0 -71
- data/lib/datastax_rails/log_subscriber.rb +0 -0
- data/spec/dummy/ks/migrate/20111117224534_models.rb +0 -20
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Base do
|
4
|
-
it
|
5
|
-
DatastaxRails::Base.statement_cache[:a] =
|
4
|
+
it 'clears the statement cache when a new connection is established' do
|
5
|
+
DatastaxRails::Base.statement_cache[:a] = 12_345
|
6
6
|
DatastaxRails::Base.establish_connection(DatastaxRails::Base.config)
|
7
7
|
expect(DatastaxRails::Base.statement_cache).to be_empty
|
8
8
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Cql::Base do
|
4
|
-
it
|
5
|
-
DatastaxRails::Base.connection.
|
4
|
+
it 'caches prepared statements' do
|
5
|
+
expect(DatastaxRails::Base.connection).to receive(:prepare).once.and_return(double('statement', execute: true))
|
6
6
|
cql = DatastaxRails::Cql::ColumnFamily.new(Person)
|
7
|
-
cql.select(['*']).conditions(:
|
8
|
-
cql.select(['*']).conditions(:
|
7
|
+
cql.select(['*']).conditions(name: 'John').execute
|
8
|
+
cql.select(['*']).conditions(name: 'John').execute
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DatastaxRails::Cql::Delete do
|
4
|
+
context 'with single primary key' do
|
5
|
+
it 'should generate valid CQL' do
|
6
|
+
cql = DatastaxRails::Cql::Delete.new(Person, id: '12345')
|
7
|
+
expect(cql.to_cql).to match(/DELETE\s+FROM people WHERE "id" = \?/)
|
8
|
+
expect(cql.instance_variable_get(:@values)).to eq(['12345'])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with compound primary key' do
|
13
|
+
it 'should generate valid CQL' do
|
14
|
+
cql = DatastaxRails::Cql::Delete.new(CoreMetadata, id: '12345', group: 'core')
|
15
|
+
expect(cql.to_cql).to match(/DELETE\s+FROM dynamic_model WHERE "id" = \? AND "group" = \?/)
|
16
|
+
expect(cql.instance_variable_get(:@values)).to eq(%w(12345 core))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Cql::Select do
|
4
|
-
let(:model_class) { double(
|
5
|
-
|
6
|
-
it
|
7
|
-
cql = DatastaxRails::Cql::Select.new(model_class, [
|
8
|
-
cql.using(DatastaxRails::Cql::Consistency::QUORUM).conditions(:
|
9
|
-
cql.to_cql.
|
4
|
+
let(:model_class) { double('Model Class', column_family: 'users', default_consistency: DatastaxRails::Cql::Consistency::QUORUM) }
|
5
|
+
|
6
|
+
it 'should generate valid CQL' do
|
7
|
+
cql = DatastaxRails::Cql::Select.new(model_class, ['*'])
|
8
|
+
cql.using(DatastaxRails::Cql::Consistency::QUORUM).conditions(key: '12345').limit(1)
|
9
|
+
expect(cql.to_cql).to eq("SELECT * FROM users WHERE \"key\" = ? LIMIT 1 ")
|
10
10
|
end
|
11
|
-
|
12
|
-
it_has_behavior
|
11
|
+
|
12
|
+
it_has_behavior 'default_consistency'
|
13
13
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Cql::Update do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
cql
|
10
|
-
cql.using(DatastaxRails::Cql::Consistency::QUORUM).columns(:name => 'John', :age => '23')
|
11
|
-
cql.to_cql.should match(/update users SET ("name" = \?, "age" = \?|"age" = \?, "name" = \?) WHERE "id" = \?/)
|
4
|
+
let(:model_class) { double('Model Class', column_family: 'users', default_consistency: DatastaxRails::Cql::Consistency::QUORUM, primary_key: 'id') }
|
5
|
+
|
6
|
+
it 'should generate valid CQL' do
|
7
|
+
cql = DatastaxRails::Cql::Update.new(model_class, 'id' => '12345')
|
8
|
+
cql.using(DatastaxRails::Cql::Consistency::QUORUM).columns(name: 'John', age: '23')
|
9
|
+
expect(cql.to_cql).to match(/update users SET ("name" = \?, "age" = \?|"age" = \?, "name" = \?) WHERE "id" = \?/)
|
12
10
|
end
|
13
|
-
|
14
|
-
it_has_behavior
|
11
|
+
|
12
|
+
it_has_behavior 'default_consistency'
|
15
13
|
end
|
@@ -8,43 +8,57 @@ end
|
|
8
8
|
|
9
9
|
class DynamicTestModel2 < DatastaxRails::DynamicModel
|
10
10
|
self.grouping = 'test2'
|
11
|
+
integer :age
|
11
12
|
end
|
12
13
|
|
13
14
|
describe DatastaxRails::DynamicModel do
|
14
|
-
let(:one) {DynamicTestModel1.new}
|
15
|
-
let(:two) {DynamicTestModel2.new}
|
16
|
-
|
17
|
-
it {expect(one).to respond_to(:created_at)}
|
18
|
-
it {expect(one).to respond_to(:created_at=)}
|
19
|
-
it {expect(two).not_to respond_to(:created_at)}
|
20
|
-
it {expect(two).not_to respond_to(:created_at=)}
|
21
|
-
|
22
|
-
it
|
15
|
+
let(:one) { DynamicTestModel1.new }
|
16
|
+
let(:two) { DynamicTestModel2.new }
|
17
|
+
|
18
|
+
it { expect(one).to respond_to(:created_at) }
|
19
|
+
it { expect(one).to respond_to(:created_at=) }
|
20
|
+
it { expect(two).not_to respond_to(:created_at) }
|
21
|
+
it { expect(two).not_to respond_to(:created_at=) }
|
22
|
+
|
23
|
+
it 'sets the attribute in the dynamic collection' do
|
23
24
|
one.name = 'John'
|
24
25
|
expect(one.s_).to eq('s_name' => 'John')
|
25
26
|
end
|
26
|
-
|
27
|
-
it
|
27
|
+
|
28
|
+
it 'deletes a dynamic record' do
|
29
|
+
one.name = 'John'
|
30
|
+
one.save
|
31
|
+
two.age = 27
|
32
|
+
two.id = one.id # Make sure they're in the same C* row
|
33
|
+
two.save
|
34
|
+
one.destroy
|
35
|
+
DynamicTestModel1.commit_solr
|
36
|
+
expect(DynamicTestModel1.count).to be(0)
|
37
|
+
DynamicTestModel2.commit_solr
|
38
|
+
expect(DynamicTestModel2.count).to be(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'retrieves the attribute from the dynamic collection' do
|
28
42
|
one.strings[:name] = 'John'
|
29
43
|
expect(one.name).to eq('John')
|
30
44
|
end
|
31
|
-
|
32
|
-
it
|
45
|
+
|
46
|
+
it 'updates an existing attribute' do
|
33
47
|
one.save
|
34
48
|
one.name = 'Jim'
|
35
|
-
expect(one.save).to
|
49
|
+
expect(one.save).to be_truthy
|
36
50
|
end
|
37
|
-
|
38
|
-
describe
|
39
|
-
it
|
51
|
+
|
52
|
+
describe '#solr_field_name' do
|
53
|
+
it 'maps a attribute name to the underlying storage key' do
|
40
54
|
expect(one.solr_field_name(:name)).to eq('s_name')
|
41
55
|
end
|
42
|
-
|
43
|
-
it
|
44
|
-
expect{two.solr_field_name(:name)}.to raise_exception(DatastaxRails::UnknownAttributeError)
|
56
|
+
|
57
|
+
it 'raises DatastaxRails::UnknownAttributeError if an unknown attribute is mapped without a type' do
|
58
|
+
expect { two.solr_field_name(:name) }.to raise_exception(DatastaxRails::UnknownAttributeError)
|
45
59
|
end
|
46
|
-
|
47
|
-
it
|
60
|
+
|
61
|
+
it 'maps an undeclared attribute if a type is given' do
|
48
62
|
expect(one.solr_field_name(:birthdate, :date)).to eq('d_birthdate')
|
49
63
|
end
|
50
64
|
end
|
@@ -5,36 +5,33 @@ class InheritanceTesterBase < DatastaxRails::Base
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class InheritanceTesterChild < InheritanceTesterBase
|
8
|
-
|
9
8
|
end
|
10
9
|
|
11
10
|
class InheritanceTesterGrandChild < InheritanceTesterChild
|
12
|
-
|
13
11
|
end
|
14
12
|
|
15
13
|
class InheritanceTesterNonAbstract < DatastaxRails::Base
|
16
|
-
|
17
14
|
end
|
18
15
|
|
19
16
|
describe DatastaxRails::Base do
|
20
|
-
context
|
21
|
-
it
|
17
|
+
context 'Inheritance' do
|
18
|
+
it 'raises NotImplementedError if DatastaxRails::Base is instantiated' do
|
22
19
|
expect { DatastaxRails::Base.new }.to raise_error(NotImplementedError)
|
23
20
|
end
|
24
|
-
|
25
|
-
it
|
21
|
+
|
22
|
+
it 'raises NotImplementedError if an abstract class is instantiated' do
|
26
23
|
expect { InheritanceTesterBase.new }.to raise_error(NotImplementedError)
|
27
24
|
end
|
28
|
-
|
29
|
-
it
|
25
|
+
|
26
|
+
it 'identifies the abstract class as base for direct decendants' do
|
30
27
|
expect(InheritanceTesterChild.base_class).to eq(InheritanceTesterBase)
|
31
28
|
end
|
32
|
-
|
33
|
-
it
|
29
|
+
|
30
|
+
it 'identifies the abstract class as base for its indirect decendants' do
|
34
31
|
expect(InheritanceTesterGrandChild.base_class).to eq(InheritanceTesterBase)
|
35
|
-
end
|
36
|
-
|
37
|
-
it
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'identifies a child of DatastaxRails::Base as base' do
|
38
35
|
expect(InheritanceTesterNonAbstract.base_class).to eq(InheritanceTesterNonAbstract)
|
39
36
|
end
|
40
37
|
end
|
@@ -1,110 +1,109 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
person = Person.create(:
|
8
|
-
person.birthdate = Date.parse(
|
9
|
-
person.update_attributes(:
|
10
|
-
person.birthdate.
|
11
|
-
person.nickname.
|
3
|
+
describe 'DatastaxRails::Base' do
|
4
|
+
describe 'persistence' do
|
5
|
+
describe '#update_attributes' do
|
6
|
+
it 'only overwrites attributes that are passed in as part of the hash' do
|
7
|
+
person = Person.create(name: 'Jason', birthdate: Date.parse('Oct 19, 1981'), nickname: 'Jas')
|
8
|
+
person.birthdate = Date.parse('Oct 19, 1980')
|
9
|
+
person.update_attributes(nickname: 'Jace')
|
10
|
+
expect(person.birthdate).to eql(Date.parse('Oct 19, 1980'))
|
11
|
+
expect(person.nickname).to eql('Jace')
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
15
|
-
describe
|
14
|
+
|
15
|
+
describe 'with cql' do
|
16
16
|
before(:each) do
|
17
17
|
Person.storage_method = :cql
|
18
|
-
@statement = double(
|
19
|
-
DatastaxRails::Base.connection.
|
18
|
+
@statement = double('prepared statement')
|
19
|
+
allow(DatastaxRails::Base.connection).to receive(:prepare).and_return(@statement)
|
20
20
|
end
|
21
|
-
|
22
|
-
describe
|
23
|
-
it
|
24
|
-
@statement.
|
25
|
-
expect(args.last).to include(:
|
21
|
+
|
22
|
+
describe '#create' do
|
23
|
+
it 'should persist at the given consistency level' do
|
24
|
+
expect(@statement).to receive(:execute) do |*args|
|
25
|
+
expect(args.last).to include(consistency: :local_quorum)
|
26
26
|
end
|
27
|
-
Person.create({:
|
27
|
+
Person.create({ name: 'Steven' }, { consistency: 'LOCAL_QUORUM' })
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
31
|
-
describe
|
32
|
-
it
|
33
|
-
@statement.
|
34
|
-
expect(args.last).to include(:
|
30
|
+
|
31
|
+
describe '#save' do
|
32
|
+
it 'should persist at the given consistency level' do
|
33
|
+
expect(@statement).to receive(:execute) do |*args|
|
34
|
+
expect(args.last).to include(consistency: :local_quorum)
|
35
35
|
end
|
36
|
-
p=Person.new(:
|
37
|
-
p.save(:
|
36
|
+
p = Person.new(name: 'Steven')
|
37
|
+
p.save(consistency: 'LOCAL_QUORUM')
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
describe
|
42
|
-
it
|
43
|
-
@statement.
|
44
|
-
p=Person.create(:
|
45
|
-
@statement.
|
46
|
-
expect(args.last).to include(:
|
40
|
+
|
41
|
+
describe '#remove' do
|
42
|
+
it 'should remove at the given consistency level' do
|
43
|
+
allow(@statement).to receive(:execute)
|
44
|
+
p = Person.create(name: 'Steven')
|
45
|
+
expect(@statement).to receive(:execute) do |*args|
|
46
|
+
expect(args.last).to include(consistency: :local_quorum)
|
47
47
|
end
|
48
|
-
p.destroy(:
|
48
|
+
p.destroy(consistency: :local_quorum)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
53
|
+
describe 'with solr' do
|
54
54
|
around(:each) do |example|
|
55
55
|
Person.storage_method = :solr
|
56
56
|
example.run
|
57
57
|
Person.storage_method = :cql
|
58
58
|
end
|
59
|
-
|
60
|
-
describe
|
61
|
-
it
|
62
|
-
Person.solr_connection.
|
63
|
-
Person.create({:
|
59
|
+
|
60
|
+
describe '#create' do
|
61
|
+
it 'should persist at the given consistency level' do
|
62
|
+
expect(Person.solr_connection).to receive(:update).with(hash_including(params: hash_including(cl: 'LOCAL_QUORUM'))).and_return(true)
|
63
|
+
Person.create({ name: 'Steven' }, { consistency: 'LOCAL_QUORUM' })
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
|
-
describe
|
68
|
-
it
|
69
|
-
Person.solr_connection.
|
70
|
-
p=Person.new(:
|
71
|
-
p.save(:
|
66
|
+
|
67
|
+
describe '#save' do
|
68
|
+
it 'should persist at the given consistency level' do
|
69
|
+
expect(Person.solr_connection).to receive(:update).with(hash_including(params: hash_including(cl: 'LOCAL_QUORUM'))).and_return(true)
|
70
|
+
p = Person.new(name: 'Steven')
|
71
|
+
p.save(consistency: 'LOCAL_QUORUM')
|
72
72
|
end
|
73
|
-
|
74
|
-
it
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
73
|
+
|
74
|
+
it 'should successfully remove columns that are set to nil' do
|
75
|
+
skip
|
76
|
+
Person.create!(name: 'Steven', birthdate: Date.today)
|
77
|
+
Person.commit_solr
|
78
|
+
p = Person.find_by_name('Steven')
|
79
|
+
p.birthdate = nil
|
80
|
+
p.save
|
81
|
+
Person.commit_solr
|
82
|
+
Person.find by_name('Steven').birthdate.should be_nil
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
87
|
-
|
88
|
-
describe
|
89
|
-
it
|
90
|
-
file =
|
91
|
-
CarPayload.create(:
|
92
|
-
CarPayload.find('limo').payload.
|
86
|
+
|
87
|
+
describe '#store_file' do
|
88
|
+
it 'should store a file', slow: true do
|
89
|
+
file = 'abcd' * 1.megabyte
|
90
|
+
CarPayload.create(digest: 'limo', payload: file)
|
91
|
+
expect(CarPayload.find('limo').payload).to eq(file)
|
93
92
|
end
|
94
|
-
|
95
|
-
it
|
96
|
-
file = IO.read(
|
97
|
-
CarPayload.create(:
|
98
|
-
CarPayload.find('limo').payload.
|
93
|
+
|
94
|
+
it 'should store really large files', slow: true do
|
95
|
+
file = IO.read('/dev/zero', 25.megabyte)
|
96
|
+
CarPayload.create(digest: 'limo', payload: file)
|
97
|
+
expect(CarPayload.find('limo').payload).to eq(file)
|
99
98
|
end
|
100
|
-
|
101
|
-
it
|
102
|
-
file =
|
103
|
-
car = CarPayload.create(:
|
104
|
-
smallfile =
|
99
|
+
|
100
|
+
it 'should successfully overwrite a larger file with a smaller one', slow: true do
|
101
|
+
file = 'abcd' * 1.megabyte
|
102
|
+
car = CarPayload.create(digest: 'limo', payload: file)
|
103
|
+
smallfile = 'e' * 1.kilobyte
|
105
104
|
car.payload = smallfile
|
106
105
|
car.save
|
107
|
-
CarPayload.find('limo').payload.
|
106
|
+
expect(CarPayload.find('limo').payload).to eq(smallfile)
|
108
107
|
end
|
109
108
|
end
|
110
109
|
end
|
@@ -2,34 +2,34 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DatastaxRails::Relation do
|
4
4
|
before(:each) do
|
5
|
-
@relation = DatastaxRails::Relation.new(Hobby,
|
5
|
+
@relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
|
6
6
|
('a'..'l').each_with_index do |letter, idx|
|
7
|
-
Hobby.create(:
|
7
|
+
Hobby.create(name: letter)
|
8
8
|
sleep(1) if idx % 5 == 4 # Performance hack
|
9
9
|
end
|
10
10
|
Hobby.commit_solr
|
11
11
|
end
|
12
|
-
|
13
|
-
|
14
|
-
describe
|
12
|
+
|
13
|
+
%w(cassandra solr).each do |access_method|
|
14
|
+
describe '#find_each' do
|
15
15
|
it "returns each record one at a time with #{access_method}" do
|
16
16
|
sleep(1)
|
17
17
|
missed_hobbies = ('a'..'l').to_a
|
18
|
-
@relation.send('with_'+access_method).find_each(:
|
19
|
-
missed_hobbies.delete_if {|h| h == hobby.name}
|
18
|
+
@relation.send('with_' + access_method).find_each(batch_size: 5) do |hobby|
|
19
|
+
missed_hobbies.delete_if { |h| h == hobby.name }
|
20
20
|
end
|
21
|
-
missed_hobbies.
|
21
|
+
expect(missed_hobbies).to be_empty
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
describe
|
24
|
+
|
25
|
+
describe '#find_in_batches' do
|
26
26
|
it "returns records in batches of the given size with #{access_method}" do
|
27
27
|
count = 12
|
28
|
-
@relation.send('with_'+access_method).find_in_batches(:
|
29
|
-
batch.size.
|
28
|
+
@relation.send('with_' + access_method).find_in_batches(batch_size: 5) do |batch|
|
29
|
+
expect(batch.size).to be <= 5
|
30
30
|
count -= batch.size
|
31
31
|
end
|
32
|
-
count.
|
32
|
+
expect(count).to eq(0)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|