datastax_rails 2.0.12 → 2.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -5
  3. data/lib/blankslate.rb +8 -11
  4. data/lib/cql-rb_extensions.rb +5 -3
  5. data/lib/datastax_rails/associations/association.rb +93 -101
  6. data/lib/datastax_rails/associations/association_scope.rb +7 -7
  7. data/lib/datastax_rails/associations/belongs_to_association.rb +46 -48
  8. data/lib/datastax_rails/associations/builder/association.rb +32 -31
  9. data/lib/datastax_rails/associations/builder/belongs_to.rb +19 -20
  10. data/lib/datastax_rails/associations/builder/collection_association.rb +32 -32
  11. data/lib/datastax_rails/associations/builder/has_and_belongs_to_many.rb +21 -21
  12. data/lib/datastax_rails/associations/builder/has_many.rb +39 -40
  13. data/lib/datastax_rails/associations/builder/has_one.rb +30 -31
  14. data/lib/datastax_rails/associations/builder/singular_association.rb +31 -33
  15. data/lib/datastax_rails/associations/collection_association.rb +129 -135
  16. data/lib/datastax_rails/associations/collection_proxy.rb +21 -21
  17. data/lib/datastax_rails/associations/has_and_belongs_to_many_association.rb +26 -26
  18. data/lib/datastax_rails/associations/has_many_association.rb +38 -38
  19. data/lib/datastax_rails/associations/has_one_association.rb +31 -32
  20. data/lib/datastax_rails/associations/singular_association.rb +31 -30
  21. data/lib/datastax_rails/associations.rb +27 -24
  22. data/lib/datastax_rails/attribute_assignment.rb +17 -17
  23. data/lib/datastax_rails/attribute_methods/definition.rb +4 -4
  24. data/lib/datastax_rails/attribute_methods/dirty.rb +34 -33
  25. data/lib/datastax_rails/attribute_methods/primary_key.rb +3 -8
  26. data/lib/datastax_rails/attribute_methods/read.rb +10 -12
  27. data/lib/datastax_rails/attribute_methods/typecasting.rb +36 -35
  28. data/lib/datastax_rails/attribute_methods/write.rb +5 -6
  29. data/lib/datastax_rails/attribute_methods.rb +52 -56
  30. data/lib/datastax_rails/base.rb +122 -125
  31. data/lib/datastax_rails/callbacks.rb +15 -9
  32. data/lib/datastax_rails/cassandra_only_model.rb +6 -6
  33. data/lib/datastax_rails/collection.rb +5 -7
  34. data/lib/datastax_rails/column.rb +130 -118
  35. data/lib/datastax_rails/connection/statement_cache.rb +3 -3
  36. data/lib/datastax_rails/connection.rb +42 -33
  37. data/lib/datastax_rails/cql/alter_column_family.rb +19 -21
  38. data/lib/datastax_rails/cql/base.rb +8 -11
  39. data/lib/datastax_rails/cql/column_family.rb +11 -10
  40. data/lib/datastax_rails/cql/consistency.rb +2 -2
  41. data/lib/datastax_rails/cql/create_column_family.rb +15 -15
  42. data/lib/datastax_rails/cql/create_index.rb +5 -5
  43. data/lib/datastax_rails/cql/create_keyspace.rb +7 -7
  44. data/lib/datastax_rails/cql/delete.rb +16 -29
  45. data/lib/datastax_rails/cql/drop_column_family.rb +2 -2
  46. data/lib/datastax_rails/cql/drop_index.rb +2 -2
  47. data/lib/datastax_rails/cql/drop_keyspace.rb +2 -2
  48. data/lib/datastax_rails/cql/insert.rb +10 -16
  49. data/lib/datastax_rails/cql/select.rb +21 -33
  50. data/lib/datastax_rails/cql/truncate.rb +2 -2
  51. data/lib/datastax_rails/cql/update.rb +16 -24
  52. data/lib/datastax_rails/cql/use_keyspace.rb +2 -2
  53. data/lib/datastax_rails/cql.rb +2 -2
  54. data/lib/datastax_rails/dynamic_model.rb +32 -29
  55. data/lib/datastax_rails/errors.rb +6 -6
  56. data/lib/datastax_rails/grouped_collection.rb +3 -3
  57. data/lib/datastax_rails/inheritance.rb +9 -9
  58. data/lib/datastax_rails/payload_model.rb +24 -20
  59. data/lib/datastax_rails/persistence.rb +116 -110
  60. data/lib/datastax_rails/railtie.rb +7 -7
  61. data/lib/datastax_rails/reflection.rb +61 -59
  62. data/lib/datastax_rails/relation/batches.rb +12 -13
  63. data/lib/datastax_rails/relation/facet_methods.rb +44 -33
  64. data/lib/datastax_rails/relation/finder_methods.rb +95 -91
  65. data/lib/datastax_rails/relation/modification_methods.rb +5 -5
  66. data/lib/datastax_rails/relation/search_methods.rb +102 -102
  67. data/lib/datastax_rails/relation/spawn_methods.rb +25 -24
  68. data/lib/datastax_rails/relation/stats_methods.rb +9 -8
  69. data/lib/datastax_rails/relation.rb +165 -170
  70. data/lib/datastax_rails/rsolr_client_wrapper.rb +3 -3
  71. data/lib/datastax_rails/schema/cassandra.rb +44 -43
  72. data/lib/datastax_rails/schema/migrator.rb +52 -52
  73. data/lib/datastax_rails/schema/solr.rb +55 -47
  74. data/lib/datastax_rails/schema_cache.rb +1 -3
  75. data/lib/datastax_rails/scoping/default.rb +2 -3
  76. data/lib/datastax_rails/scoping/named.rb +3 -5
  77. data/lib/datastax_rails/scoping.rb +11 -12
  78. data/lib/datastax_rails/serialization.rb +34 -31
  79. data/lib/datastax_rails/serializers/xml_serializer.rb +178 -175
  80. data/lib/datastax_rails/timestamps.rb +4 -4
  81. data/lib/datastax_rails/types/dirty_collection.rb +57 -57
  82. data/lib/datastax_rails/types/dynamic_list.rb +1 -1
  83. data/lib/datastax_rails/types/dynamic_map.rb +5 -7
  84. data/lib/datastax_rails/types/dynamic_set.rb +2 -2
  85. data/lib/datastax_rails/util/solr_repair.rb +3 -3
  86. data/lib/datastax_rails/validations/associated.rb +8 -6
  87. data/lib/datastax_rails/validations/uniqueness.rb +8 -8
  88. data/lib/datastax_rails/validations.rb +9 -10
  89. data/lib/datastax_rails/version.rb +2 -1
  90. data/lib/datastax_rails/wide_storage_model.rb +6 -6
  91. data/lib/datastax_rails.rb +13 -9
  92. data/lib/schema_migration.rb +3 -3
  93. data/spec/datastax_rails/associations/belongs_to_association_spec.rb +2 -2
  94. data/spec/datastax_rails/associations/collection_association_spec.rb +14 -14
  95. data/spec/datastax_rails/associations/has_many_association_spec.rb +20 -20
  96. data/spec/datastax_rails/associations_spec.rb +11 -11
  97. data/spec/datastax_rails/attribute_methods_spec.rb +25 -25
  98. data/spec/datastax_rails/base_spec.rb +24 -24
  99. data/spec/datastax_rails/callbacks_spec.rb +21 -21
  100. data/spec/datastax_rails/column_spec.rb +133 -132
  101. data/spec/datastax_rails/connection/statement_cache_spec.rb +2 -2
  102. data/spec/datastax_rails/cql/base_spec.rb +4 -4
  103. data/spec/datastax_rails/cql/delete_spec.rb +19 -0
  104. data/spec/datastax_rails/cql/select_spec.rb +8 -8
  105. data/spec/datastax_rails/cql/update_spec.rb +8 -10
  106. data/spec/datastax_rails/dynamic_model_spec.rb +36 -22
  107. data/spec/datastax_rails/inheritance_spec.rb +11 -14
  108. data/spec/datastax_rails/persistence_spec.rb +73 -74
  109. data/spec/datastax_rails/relation/batches_spec.rb +13 -13
  110. data/spec/datastax_rails/relation/facet_methods_spec.rb +43 -35
  111. data/spec/datastax_rails/relation/finder_methods_spec.rb +77 -78
  112. data/spec/datastax_rails/relation/modification_methods_spec.rb +19 -19
  113. data/spec/datastax_rails/relation/search_methods_spec.rb +160 -160
  114. data/spec/datastax_rails/relation/spawn_methods_spec.rb +18 -18
  115. data/spec/datastax_rails/relation_spec.rb +119 -116
  116. data/spec/datastax_rails/schema/migrator_spec.rb +30 -30
  117. data/spec/datastax_rails/schema/solr_spec.rb +15 -15
  118. data/spec/datastax_rails/scoping/default_spec.rb +9 -9
  119. data/spec/datastax_rails/types/dynamic_list_spec.rb +12 -12
  120. data/spec/datastax_rails/types/dynamic_map_spec.rb +10 -10
  121. data/spec/datastax_rails/types/dynamic_set_spec.rb +22 -10
  122. data/spec/datastax_rails/validations/uniqueness_spec.rb +25 -25
  123. data/spec/datastax_rails/wide_storage_model_spec.rb +11 -0
  124. data/spec/datastax_rails_spec.rb +2 -2
  125. data/spec/dummy/config/application.rb +2 -3
  126. data/spec/dummy/config/boot.rb +1 -1
  127. data/spec/dummy/config/environments/development.rb +3 -3
  128. data/spec/dummy/config/environments/test.rb +1 -1
  129. data/spec/dummy/config/initializers/session_store.rb +1 -1
  130. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  131. data/spec/factories/audit_logs.rb +6 -0
  132. data/spec/factories/hobbies.rb +6 -0
  133. data/spec/factories/people.rb +5 -0
  134. data/spec/feature/dynamic_fields_spec.rb +4 -4
  135. data/spec/feature/overloaded_tables_spec.rb +11 -12
  136. data/spec/spec_helper.rb +17 -14
  137. data/spec/support/datastax_test_hook.rb +2 -2
  138. data/spec/support/default_consistency_shared_examples.rb +11 -11
  139. data/spec/support/models.rb +31 -32
  140. metadata +40 -6
  141. data/lib/datastax_rails/attribute_methods/before_type_cast.rb +0 -71
  142. data/lib/datastax_rails/log_subscriber.rb +0 -0
  143. 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, "hobbies")
5
+ @relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
6
6
  end
7
7
 
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')
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'].should == ["skiing", 2, "boating", 1, "fishing", 1]
16
+ expect(@relation.field_facet(:name).all.facets['name']).to eq(['skiing', 2, 'boating', 1, 'fishing', 1])
17
17
  end
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')
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, :prefix => 's').all.facets['name'].should == ["singing", 1, "skiing", 1]
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 "#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)
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'].should == {"counts"=>["1.0", 1, "3.0", 0, "5.0", 1, "7.0", 1, "9.0", 2], "gap"=>2.0, "start"=>1.0, "end"=>11.0}
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 "should allow options to be specified" do
42
- Hobby.create(:complexity => 1.0)
43
- Hobby.create(:complexity => 5.0)
44
- Hobby.create(:complexity => 8.0)
45
- Hobby.create(:complexity => 9.0)
46
- Hobby.create(:complexity => 10.0)
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, :include => 'upper').all.facets['complexity'].should == {"counts"=>["1.0", 0, "3.0", 1, "5.0", 0, "7.0", 2, "9.0", 1], "gap"=>2.0, "start"=>1.0, "end"=>11.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, "hobbies")
5
+ @relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
6
6
  Hobby.commit_solr
7
7
  end
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
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 "raises RecordNotFound for an invalid ID" do
21
- expect{Hobby.find("asdf")}.to raise_exception(DatastaxRails::RecordNotFound)
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 "raises RecordNotFound for a nil ID" do
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 "as an array" do
30
- it "finds the object and returns it as a single-element array" do
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 "with multiple ids" do
37
- it "raises RecordNotFound if any portion of the records could not be found" do
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 "as an array" do
42
- it "finds the objects and returns them as an array" do
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 "as discrete parameters" do
48
- it "finds the objects and returns them as an array" do
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 "#first" do
56
- it "should return the first result if records are already loaded" do
57
- a_record = mock_model(Hobby)
58
- @relation.stub(:loaded? => true)
59
- @relation.instance_variable_set(:@results, [a_record, mock_model(Hobby)])
60
- @relation.first.should == a_record
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 "should look up the first result if records are not already loaded" do
64
- a_record = mock_model(Hobby)
65
- @relation.stub(:loaded? => false)
66
- mock_relation = double(DatastaxRails::Relation, :to_a => [a_record])
67
- @relation.should_receive(:limit).with(1).and_return(mock_relation)
68
- @relation.first.should == a_record
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 "#first!" do
73
- it "should raise RecordNotFound if no record is returned" do
74
- lambda { @relation.first! }.should raise_exception(DatastaxRails::RecordNotFound)
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 "#last" do
79
- it "should return the last result if records are already loaded" do
80
- a_record = mock_model(Hobby)
81
- @relation.stub(:loaded? => true)
82
- @relation.instance_variable_set(:@results, [mock_model(Hobby), a_record])
83
- @relation.last.should == a_record
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 "should look up the last result if records are not already loaded" do
87
- a_record = mock_model(Hobby)
88
- @relation.stub(:loaded? => false)
89
- mock_relation = double(DatastaxRails::Relation, :to_a => [a_record])
90
- @relation.should_receive(:reverse_order).and_return(mock_relation)
91
- mock_relation.should_receive(:limit).with(1).and_return(mock_relation)
92
- @relation.last.should == a_record
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 "#last!" do
97
- it "should raise RecordNotFound if no record is returned" do
98
- lambda { @relation.last! }.should raise_exception(DatastaxRails::RecordNotFound)
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 "#find_by" do
103
- it "finds a record by an attribute" do
104
- Boat.create(:name => 'Spooner')
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').should_not be_nil
105
+ expect(Boat.find_by(name: 'Spooner')).not_to be_nil
107
106
  end
108
107
 
109
- it "finds a record by an attribute with a space in it" do
110
- Boat.create(:name => 'Water Lily')
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').should_not be_nil
111
+ expect(Boat.find_by(name: 'Water Lily')).not_to be_nil
113
112
  end
114
113
 
115
- it "finds a record by an attribute with a colon in it" do
116
- Boat.create(:name => 'Dumb: Name')
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').should_not be_nil
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, "hobbies")
5
+ @relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
6
6
  end
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)
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, "hobbies")
17
- @relation.count.should == 1
16
+ @relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
17
+ expect(@relation.count).to eq(1)
18
18
  end
19
19
  end
20
-
21
- describe "#destroy" do
20
+
21
+ describe '#destroy' do
22
22
  before(:each) do
23
- @h1 = Hobby.create(:name => "biking", :complexity => 1.0)
24
- @h2 = Hobby.create(:name => "skydiving", :complexity => 4.0)
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 "should destroy 1 record by id" do
27
+
28
+ it 'should destroy 1 record by id' do
29
29
  @relation.destroy(@h1.id)
30
30
  @relation.commit_solr
31
- @relation.count.should == 1
31
+ expect(@relation.count).to eq(1)
32
32
  end
33
-
34
- it "should destroy multiple records by id" do
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.should == 0
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, "hobbies")
5
+ @relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
6
6
  end
7
-
8
- describe "#consistency" do
9
- it "should throw an ArgumentError for invalid consistency levels" do
10
- lambda { @relation.consistency(:foo) }.should raise_exception(ArgumentError)
11
- end
12
-
13
- it "should not raise an exception for a valid consistency level" do
14
- lambda { @relation.consistency(:local_quorum) }.should_not raise_exception
15
- end
16
-
17
- it "should call cassandra to enforce consistency" do
18
- h=Hobby.create(:name => 'swimming')
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.stub_chain(:with_cassandra,:consistency).and_return(@relation)
21
- @relation.should_receive(:find_by_id).with(h.id)
22
- @relation.consistency(:all).where(:name => 'swimming').all
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 "#limit" do
27
- it "should limit the page size" do
28
- "a".upto("l") do |letter|
29
- Hobby.create(:name => letter)
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.should == 7
32
+ expect(@relation.limit(7).all.size).to eq(7)
33
33
  end
34
34
  end
35
-
36
- describe "#page" do
37
- it "should get a particular page" do
38
- "a".upto("l") do |letter|
39
- Hobby.create(:name => letter)
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.should == "d"
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 "#group" do
47
-
45
+
46
+ describe '#group' do
47
+
48
48
  end
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)
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).collect {|h| h.name}.should == %w[boating chess fishing hiking jogging swimming]
56
+ expect(@relation.order(:name).map { |h| h.name }).to eq(%w(boating chess fishing hiking jogging swimming))
57
57
  end
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)
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(:name => :desc).collect {|h| h.name}.should == %w[swimming jogging hiking fishing chess boating]
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 "#select" do
69
- it "returns maps from solr automatically" do
70
- Hobby.create!(:name => "legos", :components => {'squares' => 4, 'rectangles' => 6})
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
- res = @relation.select(:components).with_solr.first.components.should have_key('squares')
72
+ expect(@relation.select(:components).with_solr.first.components).to have_key('squares')
73
73
  end
74
74
  end
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')
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(:user => :asc).collect {|log| log.user}.should == %w[billy jason jim john michael phil tony]
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 "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')
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(:user => :desc).collect {|log| log.user}.should == %w[tony phil michael john jim jason billy]
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 "#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)
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(:name => nil).should_not be_empty
97
+ expect(@relation.where(name: nil)).not_to be_empty
98
98
  end
99
-
100
- it "should return documents where a value is greater than the given value" do
101
- Hobby.create(:name => 'Swimming', :complexity => 1.1)
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).should_not be_empty
103
+ expect(@relation.where(:complexity).greater_than(1.0)).not_to be_empty
104
104
  end
105
-
106
- it "should allow :greater_than to be specified in a single call" do
107
- Hobby.create(:name => 'Swimming', :complexity => 1.1)
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(:complexity => {:greater_than => 1.0}).should_not be_empty
109
+ expect(@relation.where(complexity: { greater_than: 1.0 })).not_to be_empty
110
110
  end
111
-
112
- it "should return documents where a value is less than the given value" do
113
- Hobby.create(:name => 'Swimming', :complexity => 1.1)
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).should_not be_empty
115
+ expect(@relation.where(:complexity).less_than(2.0)).not_to be_empty
116
116
  end
117
-
118
- it "should allow :less_than to be specified in a single call" do
119
- Hobby.create(:name => 'Swimming', :complexity => 1.1)
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(:complexity => {:less_than => 2.0}).should_not be_empty
121
+ expect(@relation.where(complexity: { less_than: 2.0 })).not_to be_empty
122
122
  end
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)
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(:name => ['boating', 'jogging', 'chess', 'skydiving']).size.should == 3
129
+ expect(@relation.where(name: %w(boating jogging chess skydiving)).size).to eq(3)
130
130
  end
131
-
132
- it "should handle negative numbers without breaking" do
133
- Hobby.create(:name => 'jogging', :complexity => -1.2)
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).should_not be_empty
135
+ expect(@relation.where(:complexity).less_than(-1)).not_to be_empty
136
136
  end
137
-
138
- it "should not tokenize where queries on spaces" do
139
- Hobby.create(:name => 'horseback riding')
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(:name => 'horseback').should be_empty
142
- @relation.where(:name => 'horseback riding').should_not be_empty
143
- @relation.where(:name => 'horseback ri*').should_not be_empty
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 "should not tokenize where queries on spaces inside arrays" do
147
- Hobby.create(:name => 'horseback riding')
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(:name => ['horseback riding', 'some other hobby']).should_not be_empty
149
+ expect(@relation.where(name: ['horseback riding', 'some other hobby'])).not_to be_empty
150
150
  end
151
-
152
- it "should search for values within a range" do
153
- Hobby.create(:name => 'jogging', :complexity => 1.2)
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(:complexity => 1..2).should_not be_empty
156
- @relation.where(:complexity => 2..3).should be_empty
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 "#where_not" do
161
- it "should return documents where a field has any value" do
162
- Hobby.create(:name => 'Swimming')
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(:name => nil).should_not be_empty
164
+ expect(@relation.where_not(name: nil)).not_to be_empty
165
165
  end
166
-
167
- it "should return documents where none of the options are present" do
168
- Hobby.create(:name => 'Swimming')
169
- Hobby.create(:name => 'Biking')
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(:name => ['Swimming','Biking']).should be_empty
171
+ expect(@relation.where_not(name: %w(Swimming Biking))).to be_empty
172
172
  end
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)
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).should_not be_empty
177
+ expect(@relation.where_not(:complexity).greater_than(2.0)).not_to be_empty
178
178
  end
179
-
180
- it "should allow :greater_than to be specified in a single call" do
181
- Hobby.create(:name => 'Swimming', :complexity => 1.1)
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(:complexity => {:greater_than => 2.0}).should_not be_empty
183
+ expect(@relation.where_not(complexity: { greater_than: 2.0 })).not_to be_empty
184
184
  end
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)
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).should_not be_empty
189
+ expect(@relation.where_not(:complexity).less_than(1.0)).not_to be_empty
190
190
  end
191
-
192
- it "should allow :less_than to be specified in a single call" do
193
- Hobby.create(:name => 'Swimming', :complexity => 1.1)
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(:complexity => {:less_than => 1.0}).should_not be_empty
195
+ expect(@relation.where_not(complexity: { less_than: 1.0 })).not_to be_empty
196
196
  end
197
-
198
- it "should search for values outside a range" do
199
- Hobby.create(:name => 'jogging', :complexity => 1.2)
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(:complexity => 1..2).should be_empty
202
- @relation.where_not(:complexity => 2..3).should_not be_empty
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 "#fulltext" do
207
- it "should allow case-insensitive wildcard searches" do
208
- Hobby.create(:name => "Swimming")
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("swimming").should_not be_empty
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, :snippet => 3, :fragsize => 200) }
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, "-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' }
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("field", nil, "date")}
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, "-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' }
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