datastax_rails 2.0.15 → 2.0.16
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/lib/datastax_rails/base.rb +1 -1
- data/lib/datastax_rails/collection.rb +2 -1
- data/lib/datastax_rails/column.rb +1 -1
- data/lib/datastax_rails/relation/stats_methods.rb +2 -1
- data/lib/datastax_rails/relation.rb +2 -1
- data/lib/datastax_rails/version.rb +1 -1
- data/spec/datastax_rails/attribute_methods/typecasting_spec.rb +25 -0
- data/spec/datastax_rails/relation/stats_methods_spec.rb +72 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/models.rb +10 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 132b266af9a95c9c39cf2ebd31070736456203a9
|
4
|
+
data.tar.gz: 456554a5b9f107ceb7766f8dc8d80b9e842ef53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f91a8dcaba63be7244c3d58621fab35a9677e7cf1c93e9763f6adf9ef25b203a6883531100c7a357082b60e980435c1f7a276eab0f87ed35758be4701a3debe5
|
7
|
+
data.tar.gz: 773c2de70abae6deae8ba0119873c760b61cb14e0992c88e39975446136a82856f1fc177802b23a78e378ece41b075942adef07d5b13f2af891d49967c31f3c1
|
data/lib/datastax_rails/base.rb
CHANGED
@@ -467,7 +467,7 @@ module DatastaxRails #:nodoc:
|
|
467
467
|
# won't get written unless they get marked as changed
|
468
468
|
self.class.columns.each do |c|
|
469
469
|
attr, orig_value = c.name, c.default
|
470
|
-
@changed_attributes[attr] =
|
470
|
+
@changed_attributes[attr] = nil if _field_changed?(attr, orig_value, @attributes[attr])
|
471
471
|
end
|
472
472
|
end
|
473
473
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module DatastaxRails
|
2
|
+
# Holds a collection of DatastaxRails::Base objects.
|
2
3
|
class Collection < Array
|
3
4
|
# @!attribute [r] total_entries
|
4
5
|
# @return [Fixnum] the total number of entries that match the search
|
@@ -11,7 +12,7 @@ module DatastaxRails
|
|
11
12
|
attr_accessor :total_entries, :per_page, :current_page, :facets, :highlights
|
12
13
|
|
13
14
|
def inspect
|
14
|
-
"<DatastaxRails::Collection##{object_id} contents: #{super}
|
15
|
+
"<DatastaxRails::Collection##{object_id} contents: #{super}>"
|
15
16
|
end
|
16
17
|
|
17
18
|
def total_pages
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module DatastaxRails
|
2
|
+
# Methods for computing statistics (sum, maximum, minimum, average, and stddev)
|
2
3
|
module StatsMethods
|
3
4
|
STATS_FIELDS = { 'sum' => 'sum', 'maximum' => 'max', 'minimum' => 'min', 'average' => 'mean', 'stddev' => 'stddev' }
|
4
5
|
|
@@ -63,7 +64,7 @@ module DatastaxRails
|
|
63
64
|
|
64
65
|
def calculate_stats(field)
|
65
66
|
unless @stats[field]
|
66
|
-
@stats[field] = limit(1).compute_stats(field).stats[field]
|
67
|
+
@stats[field] = with_solr.limit(1).compute_stats(field).stats[field]
|
67
68
|
end
|
68
69
|
end
|
69
70
|
end
|
@@ -2,6 +2,7 @@ require 'rsolr'
|
|
2
2
|
require 'pp' if ENV['DEBUG_SOLR'] == 'true'
|
3
3
|
# TODO: Move functionality into modules
|
4
4
|
module DatastaxRails
|
5
|
+
# = DatastaxRails Relation
|
5
6
|
class Relation # rubocop:disable Style/ClassLength
|
6
7
|
MULTI_VALUE_METHODS = %i(order where where_not fulltext greater_than less_than select stats field_facet
|
7
8
|
range_facet slow_order)
|
@@ -493,7 +494,7 @@ module DatastaxRails
|
|
493
494
|
@stats_values.flatten.each do |sv|
|
494
495
|
params['stats.field'] = sv
|
495
496
|
end
|
496
|
-
|
497
|
+
params['stats.facet'] = @group_value
|
497
498
|
end
|
498
499
|
solr_response = nil
|
499
500
|
if @group_value
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DatastaxRails::Base do
|
4
|
+
context 'attribute methods' do
|
5
|
+
context 'default values' do
|
6
|
+
subject { Default.new }
|
7
|
+
|
8
|
+
its(:str) { is_expected.to eq('string') }
|
9
|
+
its(:bool) { is_expected.to be(true) }
|
10
|
+
its(:bool2) { is_expected.to be(false) }
|
11
|
+
its(:bool3) { is_expected.to be_nil }
|
12
|
+
its(:changed_attributes) { is_expected.to include('str') }
|
13
|
+
its(:changed_attributes) { is_expected.to include('bool') }
|
14
|
+
its(:changed_attributes) { is_expected.to include('bool2') }
|
15
|
+
its(:changed_attributes) { is_expected.not_to include('bool3') }
|
16
|
+
|
17
|
+
context 'setting the attribute to the default' do
|
18
|
+
before { subject.bool = true }
|
19
|
+
|
20
|
+
its(:bool) { is_expected.to be(true) }
|
21
|
+
its(:changed_attributes) { is_expected.to include('bool') }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DatastaxRails::Relation do
|
4
|
+
context 'stats methods' do
|
5
|
+
before(:all) do
|
6
|
+
DatastaxRails::Base.recorded_classes = {}
|
7
|
+
Hobby.create(name: 'Knitting', complexity: 1.0)
|
8
|
+
Hobby.create(name: 'Walking', complexity: 2.0)
|
9
|
+
Hobby.create(name: 'Skydiving', complexity: 10.0)
|
10
|
+
Hobby.create(name: 'Flying', complexity: 50.0)
|
11
|
+
Hobby.commit_solr
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) { Hobby.truncate }
|
15
|
+
|
16
|
+
subject { Hobby }
|
17
|
+
|
18
|
+
context('#sum') do
|
19
|
+
subject { super().sum(:complexity) }
|
20
|
+
it { is_expected.to eq(63.0) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context('#average') do
|
24
|
+
subject { super().average(:complexity) }
|
25
|
+
it { is_expected.to eq(15.75) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context('#maximum') do
|
29
|
+
subject { super().maximum(:complexity) }
|
30
|
+
it { is_expected.to eq(50.0) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context('#minimum') do
|
34
|
+
subject { super().minimum(:complexity) }
|
35
|
+
it { is_expected.to eq(1.0) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context('#stddev') do
|
39
|
+
subject { super().stddev(:complexity) }
|
40
|
+
it { is_expected.to be_within(0.001).of(23.185) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context('grouped') do
|
44
|
+
subject { super().group(:name) }
|
45
|
+
|
46
|
+
context('#sum') do
|
47
|
+
subject { super().grouped_sum(:complexity) }
|
48
|
+
it { is_expected.to eq('knitting' => 1.0, 'walking' => 2.0, 'skydiving' => 10.0, 'flying' => 50.0) }
|
49
|
+
end
|
50
|
+
|
51
|
+
context('#average') do
|
52
|
+
subject { super().grouped_average(:complexity) }
|
53
|
+
it { is_expected.to eq('knitting' => 1.0, 'walking' => 2.0, 'skydiving' => 10.0, 'flying' => 50.0) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context('#maximum') do
|
57
|
+
subject { super().grouped_maximum(:complexity) }
|
58
|
+
it { is_expected.to eq('knitting' => 1.0, 'walking' => 2.0, 'skydiving' => 10.0, 'flying' => 50.0) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context('#minimum') do
|
62
|
+
subject { super().grouped_minimum(:complexity) }
|
63
|
+
it { is_expected.to eq('knitting' => 1.0, 'walking' => 2.0, 'skydiving' => 10.0, 'flying' => 50.0) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context('#stddev') do
|
67
|
+
subject { super().grouped_stddev(:complexity) }
|
68
|
+
it { is_expected.to eq('knitting' => 0.0, 'walking' => 0.0, 'skydiving' => 0.0, 'flying' => 0.0) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/models.rb
CHANGED
@@ -86,6 +86,16 @@ class Hobby < DatastaxRails::Base
|
|
86
86
|
timestamps
|
87
87
|
end
|
88
88
|
|
89
|
+
class Default < DatastaxRails::Base
|
90
|
+
self.column_family = 'defaults'
|
91
|
+
|
92
|
+
uuid :id
|
93
|
+
string :str, default: 'string'
|
94
|
+
boolean :bool, default: true
|
95
|
+
boolean :bool2, default: false
|
96
|
+
boolean :bool3
|
97
|
+
end
|
98
|
+
|
89
99
|
class CoreMetadata < DatastaxRails::DynamicModel
|
90
100
|
self.grouping = 'core'
|
91
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datastax_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason M. Kusar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -270,6 +270,7 @@ files:
|
|
270
270
|
- spec/datastax_rails/associations/collection_association_spec.rb
|
271
271
|
- spec/datastax_rails/associations/has_many_association_spec.rb
|
272
272
|
- spec/datastax_rails/associations_spec.rb
|
273
|
+
- spec/datastax_rails/attribute_methods/typecasting_spec.rb
|
273
274
|
- spec/datastax_rails/attribute_methods_spec.rb
|
274
275
|
- spec/datastax_rails/base_spec.rb
|
275
276
|
- spec/datastax_rails/callbacks_spec.rb
|
@@ -288,6 +289,7 @@ files:
|
|
288
289
|
- spec/datastax_rails/relation/modification_methods_spec.rb
|
289
290
|
- spec/datastax_rails/relation/search_methods_spec.rb
|
290
291
|
- spec/datastax_rails/relation/spawn_methods_spec.rb
|
292
|
+
- spec/datastax_rails/relation/stats_methods_spec.rb
|
291
293
|
- spec/datastax_rails/relation_spec.rb
|
292
294
|
- spec/datastax_rails/schema/migrator_spec.rb
|
293
295
|
- spec/datastax_rails/schema/solr_spec.rb
|
@@ -386,11 +388,13 @@ test_files:
|
|
386
388
|
- spec/datastax_rails/schema/migrator_spec.rb
|
387
389
|
- spec/datastax_rails/schema/solr_spec.rb
|
388
390
|
- spec/datastax_rails/validations/uniqueness_spec.rb
|
391
|
+
- spec/datastax_rails/attribute_methods/typecasting_spec.rb
|
389
392
|
- spec/datastax_rails/cql/delete_spec.rb
|
390
393
|
- spec/datastax_rails/cql/update_spec.rb
|
391
394
|
- spec/datastax_rails/cql/base_spec.rb
|
392
395
|
- spec/datastax_rails/cql/select_spec.rb
|
393
396
|
- spec/datastax_rails/persistence_spec.rb
|
397
|
+
- spec/datastax_rails/relation/stats_methods_spec.rb
|
394
398
|
- spec/datastax_rails/relation/spawn_methods_spec.rb
|
395
399
|
- spec/datastax_rails/relation/facet_methods_spec.rb
|
396
400
|
- spec/datastax_rails/relation/finder_methods_spec.rb
|