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
data/lib/schema_migration.rb
CHANGED
@@ -4,13 +4,13 @@ class SchemaMigration
|
|
4
4
|
def self.default_consistency
|
5
5
|
DatastaxRails::Base.default_consistency
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
# Returns the name of the column family
|
9
9
|
def self.column_family
|
10
10
|
'schema_migrations'
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def self.primary_key
|
14
14
|
'cf'
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -3,35 +3,35 @@ require 'spec_helper'
|
|
3
3
|
describe DatastaxRails::Base do
|
4
4
|
context 'associations' do
|
5
5
|
context 'collection' do
|
6
|
-
subject {Person.new(name: 'Matthew')}
|
7
|
-
|
8
|
-
describe
|
9
|
-
it
|
6
|
+
subject { Person.new(name: 'Matthew') }
|
7
|
+
|
8
|
+
describe '#size' do
|
9
|
+
it 'reports the total of persisted and non-persisted' do
|
10
10
|
subject.save
|
11
|
-
|
11
|
+
Car.create(person_id: subject.id)
|
12
12
|
car2 = Car.new
|
13
13
|
subject.cars << car2
|
14
14
|
Car.commit_solr
|
15
15
|
expect(subject.cars.size).to be(2)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
describe
|
20
|
-
it
|
18
|
+
|
19
|
+
describe '#empty?' do
|
20
|
+
it 'returns false if a new record exists' do
|
21
21
|
subject.cars << Car.new
|
22
22
|
expect(subject.cars).not_to be_empty
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
describe
|
27
|
-
it
|
25
|
+
|
26
|
+
describe '#any?' do
|
27
|
+
it 'returns true if a new record exists' do
|
28
28
|
subject.cars << Car.new
|
29
29
|
expect(subject.cars).to be_any
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
describe
|
34
|
-
it
|
32
|
+
|
33
|
+
describe '#many?' do
|
34
|
+
it 'returns false if more than one new record exists' do
|
35
35
|
subject.cars << Car.new
|
36
36
|
subject.cars << Car.new
|
37
37
|
expect(subject.cars).to be_many
|
@@ -1,38 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Base do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
p = Person.create(:
|
7
|
-
Car.create(:
|
4
|
+
describe 'HasMany Associations' do
|
5
|
+
it 'should destroy all objects with :dependent => :destroy' do
|
6
|
+
p = Person.create(name: 'jason')
|
7
|
+
Car.create(name: 'Jeep', person_id: p.id)
|
8
8
|
Car.commit_solr
|
9
9
|
p.destroy
|
10
10
|
Car.commit_solr
|
11
11
|
Person.commit_solr
|
12
|
-
Car.count.
|
12
|
+
expect(Car.count).to eq(0)
|
13
13
|
end
|
14
|
-
|
15
|
-
it
|
16
|
-
p = Person.create(:
|
17
|
-
c = Car.create(:
|
14
|
+
|
15
|
+
it 'should retrieve child records' do
|
16
|
+
p = Person.create(name: 'jason')
|
17
|
+
c = Car.create(name: 'Jeep', person_id: p.id)
|
18
18
|
Car.commit_solr
|
19
|
-
p.cars.
|
19
|
+
expect(p.cars).to include(c)
|
20
20
|
end
|
21
|
-
|
22
|
-
it
|
23
|
-
p = Person.create(:
|
24
|
-
c = Car.create(:
|
21
|
+
|
22
|
+
it 'should retrieve only child records' do
|
23
|
+
p = Person.create(name: 'jason')
|
24
|
+
c = Car.create(name: 'Jeep', person_id: '12345')
|
25
25
|
Car.commit_solr
|
26
|
-
p.cars.
|
26
|
+
expect(p.cars).not_to include(c)
|
27
27
|
end
|
28
|
-
|
29
|
-
it
|
28
|
+
|
29
|
+
it 'should create records with the proper foreign key' do
|
30
30
|
Person.commit_solr
|
31
|
-
p = Person.create(:
|
32
|
-
p.cars.create(:
|
31
|
+
p = Person.create(name: 'jason')
|
32
|
+
p.cars.create(name: 'Jeep')
|
33
33
|
Car.commit_solr
|
34
34
|
Person.commit_solr
|
35
|
-
Car.first.person.
|
35
|
+
expect(Car.first.person).to eq(p)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Base do
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
person = Person.create(:
|
8
|
-
job = Job.create(:
|
4
|
+
describe 'Associations' do
|
5
|
+
describe 'belongs_to' do
|
6
|
+
it 'should set the id when setting the object' do
|
7
|
+
person = Person.create(name: 'Jason')
|
8
|
+
job = Job.create(title: 'Developer')
|
9
9
|
Person.commit_solr
|
10
10
|
job.person = person
|
11
|
-
job.person_id.
|
11
|
+
expect(job.person_id).to eq(person.id)
|
12
12
|
end
|
13
|
-
|
14
|
-
it
|
13
|
+
|
14
|
+
it 'should look up the owning model by id' do
|
15
15
|
Job.truncate
|
16
16
|
Job.commit_solr
|
17
|
-
person = Person.create!(:
|
18
|
-
|
17
|
+
person = Person.create!(name: 'John')
|
18
|
+
Job.create!(title: 'Developer', person_id: person.id)
|
19
19
|
Person.commit_solr
|
20
20
|
Job.commit_solr
|
21
|
-
Job.first.person.
|
21
|
+
expect(Job.first.person).to eq(person)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -2,48 +2,48 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class AttributeMethodsTester < DatastaxRails::Base
|
4
4
|
string :test_string
|
5
|
-
string :non_search_string, :
|
6
|
-
end
|
5
|
+
string :non_search_string, solr_index: false
|
6
|
+
end
|
7
7
|
|
8
8
|
class CassandraOnlyTester < DatastaxRails::Base
|
9
9
|
include DatastaxRails::CassandraOnlyModel
|
10
10
|
string :test_string
|
11
|
-
string :test_string2, :
|
11
|
+
string :test_string2, cql_index: true
|
12
12
|
end
|
13
13
|
|
14
14
|
describe DatastaxRails::Base do
|
15
15
|
def tester
|
16
16
|
@tester ||= AttributeMethodsTester.new
|
17
17
|
end
|
18
|
-
|
19
|
-
describe
|
20
|
-
it
|
21
|
-
tester.
|
18
|
+
|
19
|
+
describe 'attribute methods' do
|
20
|
+
it 'should create attribute setter methods' do
|
21
|
+
expect(tester).to respond_to(:test_string=)
|
22
22
|
end
|
23
|
-
|
24
|
-
it
|
25
|
-
tester.
|
23
|
+
|
24
|
+
it 'Should create attribute getter methods' do
|
25
|
+
expect(tester).to respond_to(:test_string)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
|
-
describe
|
30
|
-
context
|
31
|
-
it
|
32
|
-
expect(CassandraOnlyTester.attribute_definitions[:test_string].options[:solr_index]).to
|
33
|
-
expect(CassandraOnlyTester.attribute_definitions[:test_string].options[:cql_index]).to
|
28
|
+
|
29
|
+
describe '#attribute' do
|
30
|
+
context 'Cassandra-only models' do
|
31
|
+
it 'does not index columns by default' do
|
32
|
+
expect(CassandraOnlyTester.attribute_definitions[:test_string].options[:solr_index]).to be_falsey
|
33
|
+
expect(CassandraOnlyTester.attribute_definitions[:test_string].options[:cql_index]).to be_falsey
|
34
34
|
end
|
35
|
-
|
36
|
-
it
|
37
|
-
expect(CassandraOnlyTester.attribute_definitions[:test_string2].options[:solr_index]).to
|
38
|
-
expect(CassandraOnlyTester.attribute_definitions[:test_string2].options[:cql_index]).to
|
35
|
+
|
36
|
+
it 'does not index into solr' do
|
37
|
+
expect(CassandraOnlyTester.attribute_definitions[:test_string2].options[:solr_index]).to be_falsey
|
38
|
+
expect(CassandraOnlyTester.attribute_definitions[:test_string2].options[:cql_index]).to be_truthy
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
context
|
43
|
-
it
|
44
|
-
expect(AttributeMethodsTester.attribute_definitions[:test_string].options[:solr_index]).to
|
41
|
+
|
42
|
+
context 'Normal models' do
|
43
|
+
it 'indexes data into solr by default' do
|
44
|
+
expect(AttributeMethodsTester.attribute_definitions[:test_string].options[:solr_index]).to be_truthy
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
@@ -1,43 +1,43 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Base do
|
4
|
-
it
|
5
|
-
|
4
|
+
it 'should raise RecordNotFound when finding a bogus ID' do
|
5
|
+
expect { Person.find('xyzzy') }.to raise_exception(DatastaxRails::RecordNotFound)
|
6
6
|
end
|
7
|
-
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
p1=Person.new(:
|
11
|
-
p2=Person.new(:
|
7
|
+
|
8
|
+
describe 'equality' do
|
9
|
+
it 'considers new objects to be unequal' do
|
10
|
+
p1 = Person.new(name: 'John')
|
11
|
+
p2 = Person.new(name: 'John')
|
12
12
|
expect(p1).not_to eq(p2)
|
13
13
|
end
|
14
|
-
|
15
|
-
it
|
16
|
-
p1=Person.create!(:
|
17
|
-
p2=Person.new(:
|
14
|
+
|
15
|
+
it 'considers a new object to be unequal to a saved object' do
|
16
|
+
p1 = Person.create!(name: 'Mike')
|
17
|
+
p2 = Person.new(name: 'Mike')
|
18
18
|
expect(p1).not_to eq(p2)
|
19
19
|
end
|
20
|
-
|
21
|
-
it
|
20
|
+
|
21
|
+
it 'considers two new objects to be unequal' do
|
22
22
|
expect(Person.new).not_to eq(Person.new)
|
23
23
|
end
|
24
|
-
|
25
|
-
it
|
26
|
-
p=Person.new
|
24
|
+
|
25
|
+
it 'considers the same object equal to itself' do
|
26
|
+
p = Person.new
|
27
27
|
expect(p).to eq(p)
|
28
28
|
end
|
29
|
-
|
30
|
-
it
|
29
|
+
|
30
|
+
it 'considers two persisted objects to be equal if their primary keys are equal' do
|
31
31
|
Person.commit_solr
|
32
|
-
p1=Person.create!(:
|
33
|
-
p2=Person.find(p1.id)
|
32
|
+
p1 = Person.create!(name: 'Jim')
|
33
|
+
p2 = Person.find(p1.id)
|
34
34
|
expect(p1).to eq(p2)
|
35
35
|
end
|
36
|
-
|
37
|
-
it
|
36
|
+
|
37
|
+
it 'considers two persisted objects to be unequal if they have different primary keys' do
|
38
38
|
Person.commit_solr
|
39
|
-
p1=Person.create!(:
|
40
|
-
p2=Person.create!(:
|
39
|
+
p1 = Person.create!(name: 'Kirk')
|
40
|
+
p2 = Person.create!(name: 'Tiberious')
|
41
41
|
expect(p1).not_to eq(p2)
|
42
42
|
end
|
43
43
|
end
|
@@ -1,48 +1,48 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class CallbackTester < Hobby
|
4
|
-
self.column_family =
|
4
|
+
self.column_family = 'hobbies'
|
5
5
|
attr_accessor :after_find_called, :after_initialize_called
|
6
|
-
|
6
|
+
|
7
7
|
after_find { self.after_find_called = true }
|
8
8
|
after_initialize { self.after_initialize_called = true }
|
9
|
-
|
10
|
-
%w
|
11
|
-
after_touch before_destroy after_destroy
|
12
|
-
|
13
|
-
define_method(callback+
|
9
|
+
|
10
|
+
%w(before_save before_create after_save after_create before_validation after_validation
|
11
|
+
after_touch before_destroy after_destroy).each do |callback|
|
12
|
+
send(callback, callback + '_callback') # after_save 'after_save_callback'
|
13
|
+
define_method(callback + '_callback') do
|
14
14
|
true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe DatastaxRails::Base do
|
20
|
-
describe
|
20
|
+
describe 'callbacks' do
|
21
21
|
subject { CallbackTester.new }
|
22
|
-
|
23
|
-
%w
|
22
|
+
|
23
|
+
%w(before_save before_create after_save after_create before_validation after_validation).each do |callback|
|
24
24
|
it "runs #{callback}" do
|
25
|
-
expect(subject).to receive(callback+
|
25
|
+
expect(subject).to receive(callback + '_callback')
|
26
26
|
subject.save
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
%w
|
29
|
+
|
30
|
+
%w(after_destroy before_destroy).each do |callback|
|
31
31
|
it "runs #{callback}" do
|
32
32
|
subject.save
|
33
|
-
expect(subject).to receive(callback+
|
33
|
+
expect(subject).to receive(callback + '_callback')
|
34
34
|
subject.destroy
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
it
|
37
|
+
|
38
|
+
it 'runs after_find' do
|
39
39
|
subject.save
|
40
|
-
ct=CallbackTester.find(subject.id)
|
41
|
-
expect(ct.after_find_called).to
|
40
|
+
ct = CallbackTester.find(subject.id)
|
41
|
+
expect(ct.after_find_called).to be_truthy
|
42
42
|
end
|
43
|
-
|
44
|
-
it
|
45
|
-
expect(subject.after_initialize_called).to
|
43
|
+
|
44
|
+
it 'runs after_initialize' do
|
45
|
+
expect(subject.after_initialize_called).to be_truthy
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,246 +1,247 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Column do
|
4
|
-
describe
|
5
|
-
let(:record) {double(Person, :
|
6
|
-
|
7
|
-
describe
|
8
|
-
let(:c) {DatastaxRails::Column.new(
|
9
|
-
|
10
|
-
describe
|
11
|
-
it "casts '' to nil" do
|
4
|
+
describe 'type casting' do
|
5
|
+
let(:record) { double(Person, changed_attributes: {}, attributes: {}) }
|
6
|
+
|
7
|
+
describe 'boolean' do
|
8
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'boolean') }
|
9
|
+
|
10
|
+
describe 'to ruby' do
|
11
|
+
it "casts '' to nil" do
|
12
12
|
expect(c.type_cast('')).to be_nil
|
13
13
|
end
|
14
|
-
|
15
|
-
it
|
14
|
+
|
15
|
+
it 'casts nil to nil' do
|
16
16
|
expect(c.type_cast(nil)).to be_nil
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
[true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].each do |val|
|
20
20
|
it "casts #{val.inspect} to true" do
|
21
21
|
expect(c.type_cast(val)).to eq(true)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', ' ', "\u3000\r\n", "\u0000", 'SOMETHING RANDOM'].each do |val|
|
26
26
|
it "casts #{val.inspect} to false" do
|
27
27
|
expect(c.type_cast(val)).to eq(false)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
describe
|
33
|
-
it
|
34
|
-
expect(c.type_cast_for_cql3(false)).to
|
31
|
+
|
32
|
+
describe 'to cql3' do
|
33
|
+
it 'casts false to false' do
|
34
|
+
expect(c.type_cast_for_cql3(false)).to be_falsey
|
35
35
|
end
|
36
|
-
|
37
|
-
it
|
38
|
-
expect(c.type_cast_for_cql3(true)).to
|
36
|
+
|
37
|
+
it 'casts true to true' do
|
38
|
+
expect(c.type_cast_for_cql3(true)).to be_truthy
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
describe
|
41
|
+
|
42
|
+
describe 'to solr' do
|
43
43
|
it "casts false to 'false'" do
|
44
44
|
expect(c.type_cast_for_solr(false)).to eq('false')
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "casts true to 'true'" do
|
48
48
|
expect(c.type_cast_for_solr(true)).to eq('true')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
53
|
-
describe
|
54
|
-
let(:c) {DatastaxRails::Column.new(
|
55
|
-
|
56
|
-
describe
|
57
|
-
[1,'1','1ignore','1.7',true].each do |val|
|
52
|
+
|
53
|
+
describe 'integer' do
|
54
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'integer') }
|
55
|
+
|
56
|
+
describe 'to ruby' do
|
57
|
+
[1, '1', '1ignore', '1.7', true].each do |val|
|
58
58
|
it "casts #{val.inspect} to true" do
|
59
59
|
expect(c.type_cast(val)).to eq(1)
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
|
-
['bad1','bad',false].each do |val|
|
62
|
+
|
63
|
+
['bad1', 'bad', false].each do |val|
|
64
64
|
it "casts #{val.inspect} to 0" do
|
65
65
|
expect(c.type_cast(val)).to eq(0)
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
69
|
-
[nil,[1,2],{1 => 2},(1..2),Object.new,Float::NAN,(1.0/0.0)].each do |val|
|
68
|
+
|
69
|
+
[nil, [1, 2], { 1 => 2 }, (1..2), Object.new, Float::NAN, (1.0 / 0.0)].each do |val|
|
70
70
|
it "casts #{val.inspect} to nil" do
|
71
71
|
expect(c.type_cast(val)).to be_nil
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
|
-
it
|
74
|
+
|
75
|
+
it 'casts a duration to an integer' do
|
76
76
|
expect(c.type_cast(30.minutes)).to be(1800)
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
80
|
-
describe
|
81
|
-
it
|
79
|
+
|
80
|
+
describe 'to cql3' do
|
81
|
+
it 'casts 1 to 1' do
|
82
82
|
expect(c.type_cast_for_cql3(1)).to be(1)
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
86
|
-
describe
|
87
|
-
it
|
85
|
+
|
86
|
+
describe 'to solr' do
|
87
|
+
it 'casts 1 to 1' do
|
88
88
|
expect(c.type_cast_for_solr(1)).to be(1)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
93
|
-
describe
|
94
|
-
let(:c) {DatastaxRails::Column.new(
|
95
|
-
|
96
|
-
describe
|
97
|
-
[nil,'ABC',''].each do |val|
|
92
|
+
|
93
|
+
describe 'time' do
|
94
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'time') }
|
95
|
+
|
96
|
+
describe 'to ruby' do
|
97
|
+
[nil, 'ABC', ''].each do |val|
|
98
98
|
it "casts #{val.inspect} to nil" do
|
99
99
|
expect(c.type_cast(val)).to be_nil
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
103
|
-
it
|
104
|
-
time_string = Time.now.utc.strftime(
|
105
|
-
expect(c.type_cast(time_string).strftime(
|
102
|
+
|
103
|
+
it 'casts a time string to Time' do
|
104
|
+
time_string = Time.now.utc.strftime('%T')
|
105
|
+
expect(c.type_cast(time_string).strftime('%T')).to eq(time_string)
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
109
|
-
describe
|
110
|
-
it
|
108
|
+
|
109
|
+
describe 'to cql3' do
|
110
|
+
it 'casts a Time object to a Time object' do
|
111
111
|
time = Time.parse('1980-10-19 17:55:00')
|
112
112
|
expect(c.type_cast_for_cql3(time)).to eq(time)
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
116
|
-
describe
|
117
|
-
it
|
115
|
+
|
116
|
+
describe 'to solr' do
|
117
|
+
it 'casts a Time object to a solr formatted time string' do
|
118
118
|
time = Time.parse('1980-10-19 17:55:00')
|
119
119
|
expect(c.type_cast_for_solr(time)).to eq('1980-10-19T17:55:00Z')
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
124
|
-
describe
|
125
|
-
let(:c) {DatastaxRails::Column.new(
|
126
|
-
|
127
|
-
describe
|
128
|
-
[nil,'',' ', 'ABC'].each do |val|
|
123
|
+
|
124
|
+
describe 'timestamp' do
|
125
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'timestamp') }
|
126
|
+
|
127
|
+
describe 'to ruby' do
|
128
|
+
[nil, '', ' ', 'ABC'].each do |val|
|
129
129
|
it "casts #{val.inspect} to nil" do
|
130
130
|
expect(c.type_cast(val)).to be_nil
|
131
131
|
end
|
132
132
|
end
|
133
|
-
|
134
|
-
it
|
135
|
-
datetime_string = Time.now.utc.strftime(
|
136
|
-
expect(c.type_cast(datetime_string).strftime(
|
133
|
+
|
134
|
+
it 'casts a datetime string to Time' do
|
135
|
+
datetime_string = Time.now.utc.strftime('%FT%T')
|
136
|
+
expect(c.type_cast(datetime_string).strftime('%FT%T')).to eq(datetime_string)
|
137
137
|
end
|
138
|
-
|
139
|
-
it
|
138
|
+
|
139
|
+
it 'casts a datetime string with timezone to Time' do
|
140
|
+
pending 'How do we handle other time zones?'
|
140
141
|
begin
|
141
142
|
old = DatastaxRails::Base.default_timezone
|
142
143
|
[:utc, :local].each do |zone|
|
143
144
|
DatastaxRails::Base.default_timezone = zone
|
144
|
-
datetime_string =
|
145
|
-
expect(c.type_cast(
|
145
|
+
datetime_string = 'Wed, 04 Sep 2013 03:00:00 EDT'
|
146
|
+
expect(c.type_cast(datetime_string)).to eq(Time.utc(2013, 9, 4, 0, 0, 0))
|
146
147
|
end
|
147
148
|
rescue
|
148
149
|
DatastaxRails::Base.default_timezone = old
|
149
150
|
end
|
150
151
|
end
|
151
152
|
end
|
152
|
-
|
153
|
-
describe
|
154
|
-
it
|
153
|
+
|
154
|
+
describe 'to cql3' do
|
155
|
+
it 'casts a Time object to a Time object' do
|
155
156
|
time = Time.parse('1980-10-19 17:55:00')
|
156
157
|
expect(c.type_cast_for_cql3(time)).to eq(time)
|
157
158
|
end
|
158
159
|
end
|
159
|
-
|
160
|
-
describe
|
161
|
-
it
|
160
|
+
|
161
|
+
describe 'to solr' do
|
162
|
+
it 'casts a Time object to a solr formatted time string' do
|
162
163
|
time = Time.parse('1980-10-19 17:55:00')
|
163
164
|
expect(c.type_cast_for_solr(time)).to eq('1980-10-19T17:55:00Z')
|
164
165
|
end
|
165
166
|
end
|
166
167
|
end
|
167
|
-
|
168
|
-
describe
|
169
|
-
let(:c) {DatastaxRails::Column.new(
|
170
|
-
|
171
|
-
[nil,'',' ', 'ABC'].each do |val|
|
168
|
+
|
169
|
+
describe 'date' do
|
170
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'date') }
|
171
|
+
|
172
|
+
[nil, '', ' ', 'ABC'].each do |val|
|
172
173
|
it "casts #{val.inspect} to nil" do
|
173
174
|
expect(c.type_cast(val)).to be_nil
|
174
175
|
end
|
175
176
|
end
|
176
|
-
|
177
|
-
it
|
178
|
-
date_string = Time.now.utc.strftime(
|
179
|
-
expect(c.type_cast(date_string).strftime(
|
177
|
+
|
178
|
+
it 'casts a date string to Date' do
|
179
|
+
date_string = Time.now.utc.strftime('%F')
|
180
|
+
expect(c.type_cast(date_string).strftime('%F')).to eq(date_string)
|
180
181
|
end
|
181
|
-
|
182
|
-
describe
|
183
|
-
it
|
182
|
+
|
183
|
+
describe 'to cql3' do
|
184
|
+
it 'casts a Date object to a Time object' do
|
184
185
|
time = Time.parse('1980-10-19 00:00:00')
|
185
186
|
date = Date.parse('1980-10-19')
|
186
187
|
expect(c.type_cast_for_cql3(date)).to eq(time)
|
187
188
|
end
|
188
189
|
end
|
189
|
-
|
190
|
-
describe
|
191
|
-
it
|
190
|
+
|
191
|
+
describe 'to solr' do
|
192
|
+
it 'casts a Date object to a solr formatted time string' do
|
192
193
|
date = Date.parse('1980-10-19')
|
193
194
|
expect(c.type_cast_for_solr(date)).to eq('1980-10-19T00:00:00Z')
|
194
195
|
end
|
195
196
|
end
|
196
197
|
end
|
197
|
-
|
198
|
-
describe
|
199
|
-
let(:c) {DatastaxRails::Column.new(
|
200
|
-
let(:dc) {DatastaxRails::Column.new(
|
201
|
-
|
202
|
-
it
|
203
|
-
expect(c.type_cast({:
|
204
|
-
end
|
205
|
-
|
206
|
-
it
|
207
|
-
expect(c.type_cast({'field_key' => '7'}, record)).to eq(
|
208
|
-
end
|
209
|
-
|
210
|
-
it
|
211
|
-
expect(c.type_cast({'field_key' => '7'}, record)).to be_a(DatastaxRails::Types::DynamicMap)
|
212
|
-
end
|
213
|
-
|
214
|
-
describe
|
215
|
-
it
|
216
|
-
date = Date.parse(
|
217
|
-
time = Time.parse(
|
218
|
-
expect(dc.type_cast_for_cql3(
|
198
|
+
|
199
|
+
describe 'map' do
|
200
|
+
let(:c) { DatastaxRails::Column.new('field_', nil, 'map', holds: :integer) }
|
201
|
+
let(:dc) { DatastaxRails::Column.new('field_', nil, 'map', holds: :date) }
|
202
|
+
|
203
|
+
it 'casts map keys to strings' do
|
204
|
+
expect(c.type_cast({ field_key: 7 }, record)).to eq('field_key' => 7)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'casts map values to the type specified in the options' do
|
208
|
+
expect(c.type_cast({ 'field_key' => '7' }, record)).to eq('field_key' => 7)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'wraps map values in a DynamicMap' do
|
212
|
+
expect(c.type_cast({ 'field_key' => '7' }, record)).to be_a(DatastaxRails::Types::DynamicMap)
|
213
|
+
end
|
214
|
+
|
215
|
+
describe 'to cql' do
|
216
|
+
it 'casts map values to the appropriate type' do
|
217
|
+
date = Date.parse('1980-10-19')
|
218
|
+
time = Time.parse('1980-10-19 00:00:00 +0000')
|
219
|
+
expect(dc.type_cast_for_cql3(field_key: date)).to eq(field_key: time)
|
219
220
|
end
|
220
221
|
end
|
221
222
|
end
|
222
|
-
|
223
|
-
describe
|
224
|
-
let(:c) {DatastaxRails::Column.new(
|
225
|
-
|
226
|
-
it
|
227
|
-
expect(c.type_cast([1,
|
223
|
+
|
224
|
+
describe 'list' do
|
225
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'list', holds: :integer) }
|
226
|
+
|
227
|
+
it 'casts list values to the type specified in the options' do
|
228
|
+
expect(c.type_cast([1, '2', 6.minutes], record)).to eq([1, 2, 360])
|
228
229
|
end
|
229
|
-
|
230
|
-
it
|
231
|
-
expect(c.type_cast([1,
|
230
|
+
|
231
|
+
it 'wraps list values in a DynamicList' do
|
232
|
+
expect(c.type_cast([1, '2', 6.minutes], record)).to be_a(DatastaxRails::Types::DynamicList)
|
232
233
|
end
|
233
234
|
end
|
234
|
-
|
235
|
-
describe
|
236
|
-
let(:c) {DatastaxRails::Column.new(
|
237
|
-
|
238
|
-
it
|
239
|
-
expect(c.type_cast([1,
|
240
|
-
end
|
241
|
-
|
242
|
-
it
|
243
|
-
expect(c.type_cast([1,
|
235
|
+
|
236
|
+
describe 'set' do
|
237
|
+
let(:c) { DatastaxRails::Column.new('field', nil, 'set', holds: :integer) }
|
238
|
+
|
239
|
+
it 'casts list values to the type specified in the options' do
|
240
|
+
expect(c.type_cast([1, '2', 6.minutes, 2], record)).to eq(Set.new([1, 2, 360]))
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'wraps list values in a DynamicSet' do
|
244
|
+
expect(c.type_cast([1, '2', 6.minutes, 2], record)).to be_a(DatastaxRails::Types::DynamicSet)
|
244
245
|
end
|
245
246
|
end
|
246
247
|
end
|