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.
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
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DatastaxRails::Base do
4
- it "clears the statement cache when a new connection is established" do
5
- DatastaxRails::Base.statement_cache[:a] = 12345
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 "caches prepared statements" do
5
- DatastaxRails::Base.connection.should_receive(:prepare).once.and_return(double("statement", :execute => true))
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(:name => 'John').execute
8
- cql.select(['*']).conditions(:name => 'John').execute
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("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
- cql.to_cql.should == "SELECT * FROM users WHERE \"key\" = ? LIMIT 1 "
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 "default_consistency"
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
- before(:each) do
5
- @model_class = double("Model Class", :column_family => 'users', :default_consistency => DatastaxRails::Cql::Consistency::QUORUM, :primary_key => 'id')
6
- end
7
-
8
- it "should generate valid CQL" do
9
- cql = DatastaxRails::Cql::Update.new(@model_class, 'id' => "12345")
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 "default_consistency"
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 "sets the attribute in the dynamic collection" do
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 "retrieves the attribute from the dynamic collection" do
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 "updates an existing attribute" do
45
+
46
+ it 'updates an existing attribute' do
33
47
  one.save
34
48
  one.name = 'Jim'
35
- expect(one.save).to be_true
49
+ expect(one.save).to be_truthy
36
50
  end
37
-
38
- describe "#solr_field_name" do
39
- it "maps a attribute name to the underlying storage key" do
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 "raises DatastaxRails::UnknownAttributeError if an unknown attribute is mapped without a type" do
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 "maps an undeclared attribute if a type is given" do
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 "Inheritance" do
21
- it "raises NotImplementedError if DatastaxRails::Base is instantiated" do
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 "raises NotImplementedError if an abstract class is instantiated" do
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 "identifies the abstract class as base for direct decendants" do
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 "identifies the abstract class as base for its indirect decendants" do
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 "identifies a child of DatastaxRails::Base as base" do
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 "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
- person.birthdate.should eql(Date.parse("Oct 19, 1980"))
11
- person.nickname.should eql('Jace')
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 "with cql" do
14
+
15
+ describe 'with cql' do
16
16
  before(:each) do
17
17
  Person.storage_method = :cql
18
- @statement = double("prepared statement")
19
- DatastaxRails::Base.connection.stub(:prepare).and_return(@statement)
18
+ @statement = double('prepared statement')
19
+ allow(DatastaxRails::Base.connection).to receive(:prepare).and_return(@statement)
20
20
  end
21
-
22
- describe "#create" do
23
- it "should persist at the given consistency level" do
24
- @statement.should_receive(:execute) do |*args|
25
- expect(args.last).to include(:consistency => :local_quorum)
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({:name => 'Steven'},{:consistency => 'LOCAL_QUORUM'})
27
+ Person.create({ name: 'Steven' }, { consistency: 'LOCAL_QUORUM' })
28
28
  end
29
29
  end
30
-
31
- describe "#save" do
32
- it "should persist at the given consistency level" do
33
- @statement.should_receive(:execute) do |*args|
34
- expect(args.last).to include(:consistency => :local_quorum)
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(:name => 'Steven')
37
- p.save(:consistency => 'LOCAL_QUORUM')
36
+ p = Person.new(name: 'Steven')
37
+ p.save(consistency: 'LOCAL_QUORUM')
38
38
  end
39
39
  end
40
-
41
- describe "#remove" do
42
- it "should remove at the given consistency level" do
43
- @statement.stub(:execute)
44
- p=Person.create(:name => 'Steven')
45
- @statement.should_receive(:execute) do |*args|
46
- expect(args.last).to include(:consistency => :local_quorum)
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(:consistency => :local_quorum)
48
+ p.destroy(consistency: :local_quorum)
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
- describe "with solr" do
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 "#create" do
61
- it "should persist at the given consistency level" do
62
- Person.solr_connection.should_receive(:update).with(hash_including(:params => hash_including({:cl => 'LOCAL_QUORUM'}))).and_return(true)
63
- Person.create({:name => 'Steven'},{:consistency => 'LOCAL_QUORUM'})
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 "#save" do
68
- it "should persist at the given consistency level" do
69
- Person.solr_connection.should_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')
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 "should successfully remove columns that are set to nil" do
75
- pending do
76
- p = 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
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 "#store_file" do
89
- it "should store a file", :slow => true do
90
- file = "abcd"*1.megabyte
91
- CarPayload.create(:digest => 'limo', :payload => file)
92
- CarPayload.find('limo').payload.should == file
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 "should store really large files", :slow => true do
96
- file = IO.read("/dev/zero", 25.megabyte)
97
- CarPayload.create(:digest => 'limo', :payload => file)
98
- CarPayload.find('limo').payload.should == file
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 "should successfully overwrite a larger file with a smaller one", :slow => true do
102
- file = "abcd"*1.megabyte
103
- car = CarPayload.create(:digest => 'limo', :payload => file)
104
- smallfile = "e"*1.kilobyte
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.should == smallfile
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, "hobbies")
5
+ @relation = DatastaxRails::Relation.new(Hobby, 'hobbies')
6
6
  ('a'..'l').each_with_index do |letter, idx|
7
- Hobby.create(:name => letter)
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
- ['cassandra', 'solr'].each do |access_method|
14
- describe "#find_each" do
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(:batch_size => 5) do |hobby|
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.should be_empty
21
+ expect(missed_hobbies).to be_empty
22
22
  end
23
23
  end
24
-
25
- describe "#find_in_batches" do
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(:batch_size => 5) do |batch|
29
- batch.size.should <= 5
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.should == 0
32
+ expect(count).to eq(0)
33
33
  end
34
34
  end
35
35
  end