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
@@ -2,51 +2,59 @@ 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
|
end
|
7
7
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
it
|
11
|
-
Hobby.create(:
|
12
|
-
Hobby.create(:
|
13
|
-
Hobby.create(:
|
14
|
-
Hobby.create(:
|
8
|
+
describe '#field_facet' do
|
9
|
+
|
10
|
+
it 'should return facets on a field' do
|
11
|
+
Hobby.create(name: 'skiing')
|
12
|
+
Hobby.create(name: 'boating')
|
13
|
+
Hobby.create(name: 'fishing')
|
14
|
+
Hobby.create(name: 'skiing')
|
15
15
|
Hobby.commit_solr
|
16
|
-
@relation.field_facet(:name).all.facets['name'].
|
16
|
+
expect(@relation.field_facet(:name).all.facets['name']).to eq(['skiing', 2, 'boating', 1, 'fishing', 1])
|
17
17
|
end
|
18
|
-
|
19
|
-
it
|
20
|
-
Hobby.create(:
|
21
|
-
Hobby.create(:
|
22
|
-
Hobby.create(:
|
18
|
+
|
19
|
+
it 'should allow options to be specified' do
|
20
|
+
Hobby.create(name: 'skiing')
|
21
|
+
Hobby.create(name: 'singing')
|
22
|
+
Hobby.create(name: 'reading')
|
23
23
|
Hobby.commit_solr
|
24
|
-
@relation.field_facet(:name, :
|
24
|
+
expect(@relation.field_facet(:name, prefix: 's').all.facets['name']).to eq(['singing', 1, 'skiing', 1])
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
30
|
-
|
31
|
-
it
|
32
|
-
Hobby.create(:
|
33
|
-
Hobby.create(:
|
34
|
-
Hobby.create(:
|
35
|
-
Hobby.create(:
|
36
|
-
Hobby.create(:
|
29
|
+
describe '#range_facet' do
|
30
|
+
|
31
|
+
it 'should return facets on a field' do
|
32
|
+
Hobby.create(complexity: 1.0)
|
33
|
+
Hobby.create(complexity: 5.0)
|
34
|
+
Hobby.create(complexity: 8.0)
|
35
|
+
Hobby.create(complexity: 9.0)
|
36
|
+
Hobby.create(complexity: 10.0)
|
37
37
|
Hobby.commit_solr
|
38
|
-
@relation.range_facet(:complexity, 1.0, 10.0, 2.0).all.facets['complexity']
|
38
|
+
expect(@relation.range_facet(:complexity, 1.0, 10.0, 2.0).all.facets['complexity'])
|
39
|
+
.to eq('counts' => ['1.0', 1, '3.0', 0, '5.0', 1, '7.0', 1, '9.0', 2],
|
40
|
+
'gap' => 2.0,
|
41
|
+
'start' => 1.0,
|
42
|
+
'end' => 11.0)
|
39
43
|
end
|
40
44
|
|
41
|
-
it
|
42
|
-
Hobby.create(:
|
43
|
-
Hobby.create(:
|
44
|
-
Hobby.create(:
|
45
|
-
Hobby.create(:
|
46
|
-
Hobby.create(:
|
45
|
+
it 'should allow options to be specified' do
|
46
|
+
Hobby.create(complexity: 1.0)
|
47
|
+
Hobby.create(complexity: 5.0)
|
48
|
+
Hobby.create(complexity: 8.0)
|
49
|
+
Hobby.create(complexity: 9.0)
|
50
|
+
Hobby.create(complexity: 10.0)
|
47
51
|
Hobby.commit_solr
|
48
|
-
@relation.range_facet(:complexity, 1.0, 10.0, 2.0, :
|
52
|
+
expect(@relation.range_facet(:complexity, 1.0, 10.0, 2.0, include: 'upper').all.facets['complexity'])
|
53
|
+
.to eq('counts' => ['1.0', 0, '3.0', 1, '5.0', 0, '7.0', 2, '9.0', 1],
|
54
|
+
'gap' => 2.0,
|
55
|
+
'start' => 1.0,
|
56
|
+
'end' => 11.0)
|
49
57
|
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -2,120 +2,119 @@ 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
|
Hobby.commit_solr
|
7
7
|
end
|
8
|
-
|
9
|
-
describe
|
10
|
-
let(:h) {Hobby.create}
|
11
|
-
let(:i) {Hobby.create}
|
12
|
-
|
13
|
-
context
|
14
|
-
context
|
15
|
-
it
|
16
|
-
|
8
|
+
|
9
|
+
describe '#find' do
|
10
|
+
let(:h) { Hobby.create }
|
11
|
+
let(:i) { Hobby.create }
|
12
|
+
|
13
|
+
context 'with a single id' do
|
14
|
+
context 'as a scalar' do
|
15
|
+
it 'finds the object and returns it as an object' do
|
17
16
|
expect(Hobby.find(h.id)).to eq(h)
|
18
17
|
end
|
19
|
-
|
20
|
-
it
|
21
|
-
expect{Hobby.find(
|
18
|
+
|
19
|
+
it 'raises RecordNotFound for an invalid ID' do
|
20
|
+
expect { Hobby.find('asdf') }.to raise_exception(DatastaxRails::RecordNotFound)
|
22
21
|
end
|
23
|
-
|
24
|
-
it
|
25
|
-
expect{Hobby.find(nil)}.to raise_exception(DatastaxRails::RecordNotFound)
|
22
|
+
|
23
|
+
it 'raises RecordNotFound for a nil ID' do
|
24
|
+
expect { Hobby.find(nil) }.to raise_exception(DatastaxRails::RecordNotFound)
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
29
|
-
context
|
30
|
-
it
|
27
|
+
|
28
|
+
context 'as an array' do
|
29
|
+
it 'finds the object and returns it as a single-element array' do
|
31
30
|
expect(Hobby.find([h.id])).to eq([h])
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
|
-
context
|
37
|
-
it
|
38
|
-
expect{Hobby.find(h.id, ::Cql::TimeUuid::Generator.new.next)}.to raise_exception(DatastaxRails::RecordNotFound)
|
34
|
+
|
35
|
+
context 'with multiple ids' do
|
36
|
+
it 'raises RecordNotFound if any portion of the records could not be found' do
|
37
|
+
expect { Hobby.find(h.id, ::Cql::TimeUuid::Generator.new.next) }.to raise_exception(DatastaxRails::RecordNotFound)
|
39
38
|
end
|
40
|
-
|
41
|
-
context
|
42
|
-
it
|
43
|
-
expect(Hobby.find([h.id, i.id])).to eq([h,i])
|
39
|
+
|
40
|
+
context 'as an array' do
|
41
|
+
it 'finds the objects and returns them as an array' do
|
42
|
+
expect(Hobby.find([h.id, i.id])).to eq([h, i])
|
44
43
|
end
|
45
44
|
end
|
46
|
-
|
47
|
-
context
|
48
|
-
it
|
49
|
-
expect(Hobby.find(h.id, i.id)).to eq([h,i])
|
45
|
+
|
46
|
+
context 'as discrete parameters' do
|
47
|
+
it 'finds the objects and returns them as an array' do
|
48
|
+
expect(Hobby.find(h.id, i.id)).to eq([h, i])
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
54
|
-
|
55
|
-
describe
|
56
|
-
it
|
57
|
-
a_record =
|
58
|
-
@relation.
|
59
|
-
@relation.instance_variable_set(:@results, [a_record,
|
60
|
-
@relation.first.
|
53
|
+
|
54
|
+
describe '#first' do
|
55
|
+
it 'should return the first result if records are already loaded' do
|
56
|
+
a_record = build_stubbed(:hobby)
|
57
|
+
allow(@relation).to receive(:loaded?).and_return(true)
|
58
|
+
@relation.instance_variable_set(:@results, [a_record, build_stubbed(:hobby)])
|
59
|
+
expect(@relation.first).to eq(a_record)
|
61
60
|
end
|
62
|
-
|
63
|
-
it
|
64
|
-
a_record =
|
65
|
-
@relation.
|
66
|
-
mock_relation = double(DatastaxRails::Relation, :
|
67
|
-
@relation.
|
68
|
-
@relation.first.
|
61
|
+
|
62
|
+
it 'should look up the first result if records are not already loaded' do
|
63
|
+
a_record = build_stubbed(:hobby)
|
64
|
+
allow(@relation).to receive(:loaded?).and_return(false)
|
65
|
+
mock_relation = double(DatastaxRails::Relation, to_a: [a_record])
|
66
|
+
expect(@relation).to receive(:limit).with(1).and_return(mock_relation)
|
67
|
+
expect(@relation.first).to eq(a_record)
|
69
68
|
end
|
70
69
|
end
|
71
|
-
|
72
|
-
describe
|
73
|
-
it
|
74
|
-
|
70
|
+
|
71
|
+
describe '#first!' do
|
72
|
+
it 'should raise RecordNotFound if no record is returned' do
|
73
|
+
expect { @relation.first! }.to raise_exception(DatastaxRails::RecordNotFound)
|
75
74
|
end
|
76
75
|
end
|
77
|
-
|
78
|
-
describe
|
79
|
-
it
|
80
|
-
a_record =
|
81
|
-
@relation.
|
82
|
-
@relation.instance_variable_set(:@results, [
|
83
|
-
@relation.last.
|
76
|
+
|
77
|
+
describe '#last' do
|
78
|
+
it 'should return the last result if records are already loaded' do
|
79
|
+
a_record = build_stubbed(:hobby)
|
80
|
+
allow(@relation).to receive(:loaded?).and_return(true)
|
81
|
+
@relation.instance_variable_set(:@results, [build_stubbed(:hobby), a_record])
|
82
|
+
expect(@relation.last).to eq(a_record)
|
84
83
|
end
|
85
|
-
|
86
|
-
it
|
87
|
-
a_record =
|
88
|
-
@relation.
|
89
|
-
mock_relation = double(DatastaxRails::Relation, :
|
90
|
-
@relation.
|
91
|
-
mock_relation.
|
92
|
-
@relation.last.
|
84
|
+
|
85
|
+
it 'should look up the last result if records are not already loaded' do
|
86
|
+
a_record = build_stubbed(:hobby)
|
87
|
+
allow(@relation).to receive(:loaded?).and_return(false)
|
88
|
+
mock_relation = double(DatastaxRails::Relation, to_a: [a_record])
|
89
|
+
expect(@relation).to receive(:reverse_order).and_return(mock_relation)
|
90
|
+
expect(mock_relation).to receive(:limit).with(1).and_return(mock_relation)
|
91
|
+
expect(@relation.last).to eq(a_record)
|
93
92
|
end
|
94
93
|
end
|
95
|
-
|
96
|
-
describe
|
97
|
-
it
|
98
|
-
|
94
|
+
|
95
|
+
describe '#last!' do
|
96
|
+
it 'should raise RecordNotFound if no record is returned' do
|
97
|
+
expect { @relation.last! }.to raise_exception(DatastaxRails::RecordNotFound)
|
99
98
|
end
|
100
99
|
end
|
101
100
|
|
102
|
-
describe
|
103
|
-
it
|
104
|
-
Boat.create(:
|
101
|
+
describe '#find_by' do
|
102
|
+
it 'finds a record by an attribute' do
|
103
|
+
Boat.create(name: 'Spooner')
|
105
104
|
Boat.commit_solr
|
106
|
-
Boat.find_by(name: 'Spooner').
|
105
|
+
expect(Boat.find_by(name: 'Spooner')).not_to be_nil
|
107
106
|
end
|
108
107
|
|
109
|
-
it
|
110
|
-
Boat.create(:
|
108
|
+
it 'finds a record by an attribute with a space in it' do
|
109
|
+
Boat.create(name: 'Water Lily')
|
111
110
|
Boat.commit_solr
|
112
|
-
Boat.find_by(name: 'Water Lily').
|
111
|
+
expect(Boat.find_by(name: 'Water Lily')).not_to be_nil
|
113
112
|
end
|
114
113
|
|
115
|
-
it
|
116
|
-
Boat.create(:
|
114
|
+
it 'finds a record by an attribute with a colon in it' do
|
115
|
+
Boat.create(name: 'Dumb: Name')
|
117
116
|
Boat.commit_solr
|
118
|
-
Boat.find_by(name: 'Dumb: Name').
|
117
|
+
expect(Boat.find_by(name: 'Dumb: Name')).not_to be_nil
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
@@ -2,39 +2,39 @@ 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
|
end
|
7
|
-
|
8
|
-
describe
|
9
|
-
describe
|
10
|
-
it
|
11
|
-
Hobby.create(:
|
12
|
-
Hobby.create(:
|
7
|
+
|
8
|
+
describe 'Modification Methods' do
|
9
|
+
describe '#destroy_all' do
|
10
|
+
it 'should destroy all matching records' do
|
11
|
+
Hobby.create(name: 'biking', complexity: 1.0)
|
12
|
+
Hobby.create(name: 'skydiving', complexity: 4.0)
|
13
13
|
@relation.commit_solr
|
14
14
|
@relation.where(:complexity).greater_than(2.0).destroy_all
|
15
15
|
@relation.commit_solr
|
16
|
-
@relation = DatastaxRails::Relation.new(Hobby,
|
17
|
-
@relation.count.
|
16
|
+
@relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
|
17
|
+
expect(@relation.count).to eq(1)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
describe
|
20
|
+
|
21
|
+
describe '#destroy' do
|
22
22
|
before(:each) do
|
23
|
-
@h1 = Hobby.create(:
|
24
|
-
@h2 = Hobby.create(:
|
23
|
+
@h1 = Hobby.create(name: 'biking', complexity: 1.0)
|
24
|
+
@h2 = Hobby.create(name: 'skydiving', complexity: 4.0)
|
25
25
|
@relation.commit_solr
|
26
26
|
end
|
27
|
-
|
28
|
-
it
|
27
|
+
|
28
|
+
it 'should destroy 1 record by id' do
|
29
29
|
@relation.destroy(@h1.id)
|
30
30
|
@relation.commit_solr
|
31
|
-
@relation.count.
|
31
|
+
expect(@relation.count).to eq(1)
|
32
32
|
end
|
33
|
-
|
34
|
-
it
|
33
|
+
|
34
|
+
it 'should destroy multiple records by id' do
|
35
35
|
@relation.destroy([@h1.id, @h2.id])
|
36
36
|
@relation.commit_solr
|
37
|
-
@relation.count.
|
37
|
+
expect(@relation.count).to eq(0)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -2,249 +2,249 @@ 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
|
end
|
7
|
-
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
it
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
it
|
18
|
-
h=Hobby.create(:
|
7
|
+
|
8
|
+
describe '#consistency' do
|
9
|
+
it 'should throw an ArgumentError for invalid consistency levels' do
|
10
|
+
expect { @relation.consistency(:foo) }.to raise_exception(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should not raise an exception for a valid consistency level' do
|
14
|
+
expect { @relation.consistency(:local_quorum) }.not_to raise_exception
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should call cassandra to enforce consistency' do
|
18
|
+
h = Hobby.create(name: 'swimming')
|
19
19
|
Hobby.commit_solr
|
20
|
-
Hobby.
|
21
|
-
@relation.
|
22
|
-
@relation.consistency(:all).where(:
|
20
|
+
allow(Hobby).to receive_message_chain(:with_cassandra, :consistency).and_return(@relation)
|
21
|
+
expect(@relation).to receive(:find_by_id).with(h.id)
|
22
|
+
@relation.consistency(:all).where(name: 'swimming').all
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
|
29
|
-
Hobby.create(:
|
25
|
+
|
26
|
+
describe '#limit' do
|
27
|
+
it 'should limit the page size' do
|
28
|
+
'a'.upto('l') do |letter|
|
29
|
+
Hobby.create(name: letter)
|
30
30
|
end
|
31
31
|
Hobby.commit_solr
|
32
|
-
@relation.limit(7).all.size.
|
32
|
+
expect(@relation.limit(7).all.size).to eq(7)
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
36
|
-
describe
|
37
|
-
it
|
38
|
-
|
39
|
-
Hobby.create(:
|
35
|
+
|
36
|
+
describe '#page' do
|
37
|
+
it 'should get a particular page' do
|
38
|
+
'a'.upto('l') do |letter|
|
39
|
+
Hobby.create(name: letter)
|
40
40
|
end
|
41
41
|
Hobby.commit_solr
|
42
|
-
@relation.per_page(3).page(2).order(:name).all.first.name.
|
42
|
+
expect(@relation.per_page(3).page(2).order(:name).all.first.name).to eq('d')
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
describe
|
47
|
-
|
45
|
+
|
46
|
+
describe '#group' do
|
47
|
+
|
48
48
|
end
|
49
|
-
|
50
|
-
describe
|
51
|
-
it
|
52
|
-
%w
|
53
|
-
Hobby.create(:
|
49
|
+
|
50
|
+
describe '#order' do
|
51
|
+
it 'should return items in ascending order' do
|
52
|
+
%w(fishing hiking boating jogging swimming chess).each do |word|
|
53
|
+
Hobby.create(name: word)
|
54
54
|
end
|
55
55
|
@relation.commit_solr
|
56
|
-
@relation.order(:name).
|
56
|
+
expect(@relation.order(:name).map { |h| h.name }).to eq(%w(boating chess fishing hiking jogging swimming))
|
57
57
|
end
|
58
|
-
|
59
|
-
it
|
60
|
-
%w
|
61
|
-
Hobby.create!(:
|
58
|
+
|
59
|
+
it 'should return items in descending order' do
|
60
|
+
%w(fishing hiking boating jogging swimming chess).each do |word|
|
61
|
+
Hobby.create!(name: word)
|
62
62
|
end
|
63
63
|
@relation.commit_solr
|
64
|
-
@relation.order(:
|
64
|
+
expect(@relation.order(name: :desc).map { |h| h.name }).to eq(%w(swimming jogging hiking fishing chess boating))
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
68
|
-
describe
|
69
|
-
it
|
70
|
-
Hobby.create!(:
|
67
|
+
|
68
|
+
describe '#select' do
|
69
|
+
it 'returns maps from solr automatically' do
|
70
|
+
Hobby.create!(name: 'legos', components: { 'squares' => 4, 'rectangles' => 6 })
|
71
71
|
@relation.commit_solr
|
72
|
-
|
72
|
+
expect(@relation.select(:components).with_solr.first.components).to have_key('squares')
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
76
|
-
describe
|
77
|
-
it
|
78
|
-
%w
|
79
|
-
AuditLog.create!(:
|
75
|
+
|
76
|
+
describe '#slow_order' do
|
77
|
+
it 'should manually order items coming from Cassandra' do
|
78
|
+
%w(john jason michael tony billy jim phil).each_with_index do |name, i|
|
79
|
+
AuditLog.create!(uuid: "c1401540-f092-11e2-9001-6a5ab73a986#{i}", user: name, message: 'changed')
|
80
80
|
end
|
81
|
-
AuditLog.unscoped.slow_order(:
|
81
|
+
expect(AuditLog.unscoped.slow_order(user: :asc).map { |log| log.user }).to eq(%w(billy jason jim john michael phil tony))
|
82
82
|
end
|
83
|
-
|
84
|
-
it
|
85
|
-
%w
|
86
|
-
AuditLog.create!(:
|
83
|
+
|
84
|
+
it 'should manually order items coming from Cassandra in descending order' do
|
85
|
+
%w(john jason michael tony billy jim phil).each_with_index do |name, i|
|
86
|
+
AuditLog.create!(uuid: "c1401540-f092-11e2-9001-6a5ab73a986#{i}", user: name, message: 'changed')
|
87
87
|
end
|
88
|
-
AuditLog.unscoped.slow_order(:
|
88
|
+
expect(AuditLog.unscoped.slow_order(user: :desc).map { |log| log.user }).to eq(%w(tony phil michael john jim jason billy))
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
92
|
-
describe
|
93
|
-
it
|
94
|
-
Hobby.create(:
|
95
|
-
Hobby.create(:
|
91
|
+
|
92
|
+
describe '#where' do
|
93
|
+
it 'should return documents where a field is nil (does not exist)' do
|
94
|
+
Hobby.create(name: 'Swimming')
|
95
|
+
Hobby.create(name: nil)
|
96
96
|
@relation.commit_solr
|
97
|
-
@relation.where(:
|
97
|
+
expect(@relation.where(name: nil)).not_to be_empty
|
98
98
|
end
|
99
|
-
|
100
|
-
it
|
101
|
-
Hobby.create(:
|
99
|
+
|
100
|
+
it 'should return documents where a value is greater than the given value' do
|
101
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
102
102
|
@relation.commit_solr
|
103
|
-
@relation.where(:complexity).greater_than(1.0).
|
103
|
+
expect(@relation.where(:complexity).greater_than(1.0)).not_to be_empty
|
104
104
|
end
|
105
|
-
|
106
|
-
it
|
107
|
-
Hobby.create(:
|
105
|
+
|
106
|
+
it 'should allow :greater_than to be specified in a single call' do
|
107
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
108
108
|
@relation.commit_solr
|
109
|
-
@relation.where(:
|
109
|
+
expect(@relation.where(complexity: { greater_than: 1.0 })).not_to be_empty
|
110
110
|
end
|
111
|
-
|
112
|
-
it
|
113
|
-
Hobby.create(:
|
111
|
+
|
112
|
+
it 'should return documents where a value is less than the given value' do
|
113
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
114
114
|
@relation.commit_solr
|
115
|
-
@relation.where(:complexity).less_than(2.0).
|
115
|
+
expect(@relation.where(:complexity).less_than(2.0)).not_to be_empty
|
116
116
|
end
|
117
|
-
|
118
|
-
it
|
119
|
-
Hobby.create(:
|
117
|
+
|
118
|
+
it 'should allow :less_than to be specified in a single call' do
|
119
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
120
120
|
@relation.commit_solr
|
121
|
-
@relation.where(:
|
121
|
+
expect(@relation.where(complexity: { less_than: 2.0 })).not_to be_empty
|
122
122
|
end
|
123
|
-
|
124
|
-
it
|
125
|
-
%w
|
126
|
-
Hobby.create(:
|
123
|
+
|
124
|
+
it 'should allow arrays to be passed as OR queries' do
|
125
|
+
%w(fishing hiking boating jogging swimming chess).each do |word|
|
126
|
+
Hobby.create(name: word)
|
127
127
|
end
|
128
128
|
@relation.commit_solr
|
129
|
-
@relation.where(:
|
129
|
+
expect(@relation.where(name: %w(boating jogging chess skydiving)).size).to eq(3)
|
130
130
|
end
|
131
|
-
|
132
|
-
it
|
133
|
-
Hobby.create(:
|
131
|
+
|
132
|
+
it 'should handle negative numbers without breaking' do
|
133
|
+
Hobby.create(name: 'jogging', complexity: -1.2)
|
134
134
|
@relation.commit_solr
|
135
|
-
@relation.where(:complexity).less_than(-1).
|
135
|
+
expect(@relation.where(:complexity).less_than(-1)).not_to be_empty
|
136
136
|
end
|
137
|
-
|
138
|
-
it
|
139
|
-
Hobby.create(:
|
137
|
+
|
138
|
+
it 'should not tokenize where queries on spaces' do
|
139
|
+
Hobby.create(name: 'horseback riding')
|
140
140
|
@relation.commit_solr
|
141
|
-
@relation.where(:
|
142
|
-
@relation.where(:
|
143
|
-
@relation.where(:
|
141
|
+
expect(@relation.where(name: 'horseback')).to be_empty
|
142
|
+
expect(@relation.where(name: 'horseback riding')).not_to be_empty
|
143
|
+
expect(@relation.where(name: 'horseback ri*')).not_to be_empty
|
144
144
|
end
|
145
|
-
|
146
|
-
it
|
147
|
-
Hobby.create(:
|
145
|
+
|
146
|
+
it 'should not tokenize where queries on spaces inside arrays' do
|
147
|
+
Hobby.create(name: 'horseback riding')
|
148
148
|
@relation.commit_solr
|
149
|
-
@relation.where(:
|
149
|
+
expect(@relation.where(name: ['horseback riding', 'some other hobby'])).not_to be_empty
|
150
150
|
end
|
151
|
-
|
152
|
-
it
|
153
|
-
Hobby.create(:
|
151
|
+
|
152
|
+
it 'should search for values within a range' do
|
153
|
+
Hobby.create(name: 'jogging', complexity: 1.2)
|
154
154
|
@relation.commit_solr
|
155
|
-
@relation.where(:
|
156
|
-
@relation.where(:
|
155
|
+
expect(@relation.where(complexity: 1..2)).not_to be_empty
|
156
|
+
expect(@relation.where(complexity: 2..3)).to be_empty
|
157
157
|
end
|
158
158
|
end
|
159
|
-
|
160
|
-
describe
|
161
|
-
it
|
162
|
-
Hobby.create(:
|
159
|
+
|
160
|
+
describe '#where_not' do
|
161
|
+
it 'should return documents where a field has any value' do
|
162
|
+
Hobby.create(name: 'Swimming')
|
163
163
|
@relation.commit_solr
|
164
|
-
@relation.where_not(:
|
164
|
+
expect(@relation.where_not(name: nil)).not_to be_empty
|
165
165
|
end
|
166
|
-
|
167
|
-
it
|
168
|
-
Hobby.create(:
|
169
|
-
Hobby.create(:
|
166
|
+
|
167
|
+
it 'should return documents where none of the options are present' do
|
168
|
+
Hobby.create(name: 'Swimming')
|
169
|
+
Hobby.create(name: 'Biking')
|
170
170
|
@relation.commit_solr
|
171
|
-
@relation.where_not(:
|
171
|
+
expect(@relation.where_not(name: %w(Swimming Biking))).to be_empty
|
172
172
|
end
|
173
|
-
|
174
|
-
it
|
175
|
-
Hobby.create(:
|
173
|
+
|
174
|
+
it 'should return documents where a value is not greater than the given value' do
|
175
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
176
176
|
@relation.commit_solr
|
177
|
-
@relation.where_not(:complexity).greater_than(2.0).
|
177
|
+
expect(@relation.where_not(:complexity).greater_than(2.0)).not_to be_empty
|
178
178
|
end
|
179
|
-
|
180
|
-
it
|
181
|
-
Hobby.create(:
|
179
|
+
|
180
|
+
it 'should allow :greater_than to be specified in a single call' do
|
181
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
182
182
|
@relation.commit_solr
|
183
|
-
@relation.where_not(:
|
183
|
+
expect(@relation.where_not(complexity: { greater_than: 2.0 })).not_to be_empty
|
184
184
|
end
|
185
|
-
|
186
|
-
it
|
187
|
-
Hobby.create(:
|
185
|
+
|
186
|
+
it 'should return documents where a value is not less than the given value' do
|
187
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
188
188
|
@relation.commit_solr
|
189
|
-
@relation.where_not(:complexity).less_than(1.0).
|
189
|
+
expect(@relation.where_not(:complexity).less_than(1.0)).not_to be_empty
|
190
190
|
end
|
191
|
-
|
192
|
-
it
|
193
|
-
Hobby.create(:
|
191
|
+
|
192
|
+
it 'should allow :less_than to be specified in a single call' do
|
193
|
+
Hobby.create(name: 'Swimming', complexity: 1.1)
|
194
194
|
@relation.commit_solr
|
195
|
-
@relation.where_not(:
|
195
|
+
expect(@relation.where_not(complexity: { less_than: 1.0 })).not_to be_empty
|
196
196
|
end
|
197
|
-
|
198
|
-
it
|
199
|
-
Hobby.create(:
|
197
|
+
|
198
|
+
it 'should search for values outside a range' do
|
199
|
+
Hobby.create(name: 'jogging', complexity: 1.2)
|
200
200
|
@relation.commit_solr
|
201
|
-
@relation.where_not(:
|
202
|
-
@relation.where_not(:
|
201
|
+
expect(@relation.where_not(complexity: 1..2)).to be_empty
|
202
|
+
expect(@relation.where_not(complexity: 2..3)).not_to be_empty
|
203
203
|
end
|
204
204
|
end
|
205
|
-
|
206
|
-
describe
|
207
|
-
it
|
208
|
-
Hobby.create(:
|
205
|
+
|
206
|
+
describe '#fulltext' do
|
207
|
+
it 'should allow case-insensitive wildcard searches' do
|
208
|
+
Hobby.create(name: 'Swimming')
|
209
209
|
@relation.commit_solr
|
210
|
-
@relation.fulltext(
|
210
|
+
expect(@relation.fulltext('swimming')).not_to be_empty
|
211
211
|
end
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
describe '#highlight' do
|
215
|
-
let(:hl) { @relation.highlight(:name, :description, :
|
216
|
-
|
215
|
+
let(:hl) { @relation.highlight(:name, :description, snippet: 3, fragsize: 200) }
|
216
|
+
|
217
217
|
it { expect(hl.highlight_options[:fields]).to eq [:name, :description] }
|
218
218
|
it { expect(hl.highlight_options[:snippet]).to eq 3 }
|
219
219
|
it { expect(hl.highlight_options[:fragsize]).to eq 200 }
|
220
|
-
|
220
|
+
|
221
221
|
context 'with duplicate fields' do
|
222
222
|
let(:hl) { @relation.highlight(:name, :description, :name) }
|
223
|
-
|
223
|
+
|
224
224
|
it { expect(hl.highlight_options[:fields]).to eq [:name, :description] }
|
225
225
|
end
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
describe '#solr_format' do
|
229
229
|
context 'when formatting Time' do
|
230
|
-
let(:time) { Time.new 2011, 10, 9, 8, 7, 6,
|
231
|
-
let(:c) {DatastaxRails::Column.new(
|
232
|
-
|
233
|
-
it { expect(@relation.solr_format(c,time)).to eq '2011-10-09T13:07:06Z' }
|
230
|
+
let(:time) { Time.new 2011, 10, 9, 8, 7, 6, '-05:00' }
|
231
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'time') }
|
232
|
+
|
233
|
+
it { expect(@relation.solr_format(c, time)).to eq '2011-10-09T13:07:06Z' }
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
context 'when formatting Date' do
|
237
237
|
let(:date) { Date.new 2001, 2, 3 }
|
238
|
-
let(:c) {DatastaxRails::Column.new(
|
239
|
-
|
240
|
-
it { expect(@relation.solr_format(c,date)).to eq '2001-02-03T00:00:00Z' }
|
238
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'date') }
|
239
|
+
|
240
|
+
it { expect(@relation.solr_format(c, date)).to eq '2001-02-03T00:00:00Z' }
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
context 'when formatting DateTime' do
|
244
|
-
let(:datetime) { DateTime.new 2001, 2, 3, 4, 5, 6,
|
245
|
-
let(:c) {DatastaxRails::Column.new(
|
246
|
-
|
247
|
-
it { expect(@relation.solr_format(c,datetime)).to eq '2001-02-03T11:05:06Z' }
|
244
|
+
let(:datetime) { DateTime.new 2001, 2, 3, 4, 5, 6, '-07:00' }
|
245
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'timestamp') }
|
246
|
+
|
247
|
+
it { expect(@relation.solr_format(c, datetime)).to eq '2001-02-03T11:05:06Z' }
|
248
248
|
end
|
249
249
|
end
|
250
|
-
end
|
250
|
+
end
|