ts-datetime-delta 1.0.3 → 2.0.0
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
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1087cb59f57d80d265ea1f197eb5ab703c4a1d3c
|
4
|
+
data.tar.gz: 47e5e40cbd3d6e78956cf4963ccbcf199110e168
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2f7d1406550a8eca218769752b276eae4b762fc61ef1162bcb73b4b21ff71fa3a98e4b757cc5cb8a8fe20ccc1c7a62fb2255868b7281ca31498dae26d50fd8d
|
7
|
+
data.tar.gz: 97b77e7deab112a317769ba3d0d8684291241adfaaac8f6b7d428b9677121643ffa65d82f7d2e3d750a87a2751f0995819cfdb1a1887e6fb018bc31e8aa51972
|
data/README.textile
CHANGED
@@ -2,20 +2,20 @@ h1. Datetime Deltas for Thinking Sphinx
|
|
2
2
|
|
3
3
|
h2. Installation
|
4
4
|
|
5
|
-
You'll need Thinking Sphinx 1.3.0 or later.
|
5
|
+
You'll need Thinking Sphinx 1.3.0 or later (v3 is now supported since the 2.0.0 release of this gem).
|
6
6
|
|
7
7
|
<pre><code>gem install ts-datetime-delta</code></pre>
|
8
8
|
|
9
9
|
In your Gemfile, you can use it like so:
|
10
10
|
|
11
|
-
<pre><code>gem 'ts-datetime-delta', '~>
|
11
|
+
<pre><code>gem 'ts-datetime-delta', '~> 2.0.0',
|
12
12
|
:require => 'thinking_sphinx/deltas/datetime_delta'</code></pre>
|
13
13
|
|
14
14
|
Or if you're still on Rails 2, then put this in your @environment.rb@ file with the rest of your gem dependencies:
|
15
15
|
|
16
16
|
<pre><code>config.gem 'ts-datetime-delta',
|
17
17
|
:lib => 'thinking_sphinx/deltas/datetime_delta'
|
18
|
-
:version => '>=
|
18
|
+
:version => '>= 2.0.0'</code></pre>
|
19
19
|
|
20
20
|
No matter which version of Rails, you'll need to add the following line to the bottom of your @Rakefile@:
|
21
21
|
|
@@ -23,7 +23,16 @@ No matter which version of Rails, you'll need to add the following line to the b
|
|
23
23
|
|
24
24
|
h2. Usage
|
25
25
|
|
26
|
-
For the indexes you want to use this delta approach, make sure you set that up in
|
26
|
+
For the indexes you want to use this delta approach, make sure you set that up in your index definition. For Thinking Sphinx v3, that'll look like this:
|
27
|
+
|
28
|
+
<pre><code>ThinkingSphinx::Index.define(:book,
|
29
|
+
:with => :active_record,
|
30
|
+
:delta => ThinkingSphinx::Deltas::DatetimeDelta
|
31
|
+
) do
|
32
|
+
# ...
|
33
|
+
end</code></pre>
|
34
|
+
|
35
|
+
But for Thinking Sphinx v1/v2, it belongs within your @define_index@ blocks:
|
27
36
|
|
28
37
|
<pre><code>define_index do
|
29
38
|
# ...
|
@@ -33,6 +42,18 @@ end</code></pre>
|
|
33
42
|
|
34
43
|
If you want to use a column other than @updated_at@, you can specify it using the @:delta_column@ option. The same goes for the threshold, which defaults to one day.
|
35
44
|
|
45
|
+
Again, Thinking Sphinx v3 expects these options outside the block:
|
46
|
+
|
47
|
+
<pre><code>ThinkingSphinx::Index.define(:book,
|
48
|
+
:with => :active_record,
|
49
|
+
:delta => ThinkingSphinx::Deltas::DatetimeDelta,
|
50
|
+
:delta_options => {:threshold => 1.hour, :delta_column => :changed_at}
|
51
|
+
) do
|
52
|
+
# ...
|
53
|
+
end</code></pre>
|
54
|
+
|
55
|
+
But Thinking Sphinx v1/v2 it goes within the @define_index@ block:
|
56
|
+
|
36
57
|
<pre><code>set_property :delta => :datetime,
|
37
58
|
:threshold => 1.hour,
|
38
59
|
:delta_column => :changed_at</code></pre>
|
@@ -53,7 +74,9 @@ h2. Contributors
|
|
53
74
|
|
54
75
|
* "W. Andrew Loe III":http://andrewloe.com/ - Environment variable for disabling merging.
|
55
76
|
* "Kirill Maximov":http://kirblog.idetalk.com - Handling nil timestamp column values for toggled checks.
|
77
|
+
* "Timo Virkkala":https://github.com/weetu - Thinking Sphinx v3 compatibility,fix for null timestamps.
|
78
|
+
* "Cedric Maion":https://github.com/cmaion - Fix for keeping custom options persisted.
|
56
79
|
|
57
80
|
h2. Copyright
|
58
81
|
|
59
|
-
Copyright (c) 2009-
|
82
|
+
Copyright (c) 2009-2014 Pat Allan, and released under an MIT Licence.
|
@@ -10,42 +10,49 @@
|
|
10
10
|
#
|
11
11
|
class ThinkingSphinx::Deltas::DatetimeDelta < ThinkingSphinx::Deltas::DefaultDelta
|
12
12
|
attr_accessor :column, :threshold
|
13
|
+
attr_reader :adapter
|
13
14
|
|
14
15
|
def self.index
|
15
|
-
ThinkingSphinx.context
|
16
|
-
model
|
17
|
-
|
18
|
-
model
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
if ThinkingSphinx.respond_to?(:context) # Thinking Sphinx v2
|
17
|
+
ThinkingSphinx.context.indexed_models.collect { |model|
|
18
|
+
model.constantize
|
19
|
+
}.select { |model|
|
20
|
+
model.define_indexes
|
21
|
+
model.delta_indexed_by_sphinx?
|
22
|
+
}.each do |model|
|
23
|
+
model.sphinx_indexes.select { |index|
|
24
|
+
index.delta? && index.delta_object.respond_to?(:delayed_index)
|
25
|
+
}.each { |index|
|
26
|
+
index.delta_object.delayed_index(index.model)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
else # Thinking Sphinx v3
|
30
|
+
configuration = ThinkingSphinx::Configuration.instance
|
31
|
+
configuration.preload_indices
|
32
|
+
configuration.indices.each do |index|
|
33
|
+
if (index.delta?)
|
34
|
+
if (index.delta_processor.respond_to?(:delayed_index))
|
35
|
+
index.delta_processor.delayed_index(index)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|
29
42
|
# Initialises the Delta object for the given index and settings. All handled
|
30
43
|
# by Thinking Sphinx, so you shouldn't need to call this method yourself in
|
31
44
|
# general day-to-day situations.
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# changes for, in seconds. Defaults to one day.
|
44
|
-
#
|
45
|
-
def initialize(index, options = {})
|
46
|
-
@index = index
|
47
|
-
@column = options.delete(:delta_column) || :updated_at
|
48
|
-
@threshold = options.delete(:threshold) || 1.day
|
45
|
+
# @param arg Depending on the version of Thinking Sphinx
|
46
|
+
# For TS v2: the index
|
47
|
+
# For TS v3: the database adapter
|
48
|
+
def initialize(arg, options = {})
|
49
|
+
if ThinkingSphinx.respond_to?(:context) # Thinking Sphinx v2
|
50
|
+
@index = arg
|
51
|
+
else # Thinking Sphinx v3
|
52
|
+
@adapter = arg
|
53
|
+
end
|
54
|
+
@column = options[:column] || :updated_at
|
55
|
+
@threshold = options[:threshold] || 1.day
|
49
56
|
end
|
50
57
|
|
51
58
|
# Does absolutely nothing, beyond returning true. Thinking Sphinx expects
|
@@ -54,37 +61,49 @@ class ThinkingSphinx::Deltas::DatetimeDelta < ThinkingSphinx::Deltas::DefaultDel
|
|
54
61
|
#
|
55
62
|
# All the real indexing logic is done by the delayed_index method.
|
56
63
|
#
|
57
|
-
|
58
|
-
# @param [ActiveRecord::Base] instance the instance of the given model that
|
59
|
-
# has changed. Optional.
|
60
|
-
# @return [Boolean] true
|
61
|
-
# @see #delayed_index
|
62
|
-
#
|
63
|
-
def index(model, instance = nil)
|
64
|
+
def index(arg, instance=nil)
|
64
65
|
# do nothing
|
65
66
|
true
|
66
67
|
end
|
67
68
|
|
68
|
-
# Processes the delta index
|
69
|
+
# Processes the given delta index, and then merges the relevant
|
69
70
|
# core and delta indexes together. By default, the output of these indexer
|
70
71
|
# commands are printed to stdout. If you'd rather it didn't, set
|
71
|
-
#
|
72
|
+
# config.settings['quiet_deltas'] to true.
|
72
73
|
#
|
73
|
-
# @param
|
74
|
+
# @param arg Depending on the version of Thinking Sphinx
|
75
|
+
# For TS v2: the ActiveRecord model to index
|
76
|
+
# For TS v3: the delta index to index
|
74
77
|
# @return [Boolean] true
|
75
78
|
#
|
76
|
-
def delayed_index(
|
79
|
+
def delayed_index(arg)
|
77
80
|
config = ThinkingSphinx::Configuration.instance
|
78
|
-
|
81
|
+
if ThinkingSphinx.respond_to?(:context) # Thinking Sphinx v2
|
82
|
+
model = arg
|
83
|
+
rotate = ThinkingSphinx.sphinx_running? ? " --rotate" : ""
|
84
|
+
output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file}#{rotate} #{model.delta_index_names.join(' ')}`
|
79
85
|
|
80
|
-
|
86
|
+
model.sphinx_indexes.select(&:delta?).each do |index|
|
87
|
+
output += `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file}#{rotate} --merge #{index.core_name} #{index.delta_name} --merge-dst-range sphinx_deleted 0 0`
|
88
|
+
end unless ENV['DISABLE_MERGE'] == 'true'
|
81
89
|
|
90
|
+
puts output unless ThinkingSphinx.suppress_delta_output?
|
91
|
+
else # Thinking Sphinx v3
|
92
|
+
delta_index = arg
|
93
|
+
controller = config.controller
|
94
|
+
output = controller.index(delta_index.name)
|
95
|
+
output = "" unless output.is_a?(String) # Riddle::Controller.index may return true, false, nil or String, depending on its options[:verbose] value
|
96
|
+
rotate = (controller.running? ? ' --rotate' : '')
|
82
97
|
|
83
|
-
|
84
|
-
|
85
|
-
|
98
|
+
unless(ENV['DISABLE_MERGE'] == 'true')
|
99
|
+
core_index = config.indices.select{|idx|idx.reference == delta_index.reference && idx.delta? == false}.first
|
100
|
+
if (core_index)
|
101
|
+
output += `#{controller.bin_path}#{controller.indexer_binary_name} --config #{config.configuration_file}#{rotate} --merge #{core_index.name} #{delta_index.name} --merge-dst-range sphinx_deleted 0 0`
|
102
|
+
end
|
103
|
+
end
|
86
104
|
|
87
|
-
|
105
|
+
puts output unless config.settings['quiet_deltas']
|
106
|
+
end
|
88
107
|
|
89
108
|
true
|
90
109
|
end
|
@@ -106,18 +125,18 @@ class ThinkingSphinx::Deltas::DatetimeDelta < ThinkingSphinx::Deltas::DefaultDel
|
|
106
125
|
# @param [ActiveRecord::Base] instance the instance to check
|
107
126
|
# @return [Boolean] True if within the threshold window, otherwise false.
|
108
127
|
#
|
109
|
-
def toggled(instance)
|
128
|
+
def toggled?(instance)
|
110
129
|
res = instance.send(@column)
|
111
130
|
res && (res > @threshold.ago)
|
112
131
|
end
|
132
|
+
alias_method :toggled, :toggled?
|
113
133
|
|
114
134
|
# Returns the SQL query that resets the model data after a normal index. For
|
115
135
|
# datetime deltas, nothing needs to be done, so this method returns nil.
|
116
136
|
#
|
117
|
-
# @param [Class] model The ActiveRecord model that is requesting the query
|
118
137
|
# @return [NilClass] Always nil
|
119
138
|
#
|
120
|
-
def reset_query(model)
|
139
|
+
def reset_query(model=nil)
|
121
140
|
nil
|
122
141
|
end
|
123
142
|
|
@@ -127,17 +146,28 @@ class ThinkingSphinx::Deltas::DatetimeDelta < ThinkingSphinx::Deltas::DefaultDel
|
|
127
146
|
# delta column being within the threshold. In the latter's case, no condition
|
128
147
|
# is needed, so nil is returned.
|
129
148
|
#
|
130
|
-
# @param
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
# @
|
135
|
-
#
|
136
|
-
#
|
137
|
-
def clause(
|
138
|
-
|
139
|
-
|
140
|
-
|
149
|
+
# @param args Depends on version of Thinking Sphinx:
|
150
|
+
# For ThinkingSphinx v2 this should be: def clause(model, is_delta)
|
151
|
+
# For ThinkingSphinx v3 this should be: def clause(is_delta=false)
|
152
|
+
# @param [Class] model: The ActiveRecord model for which the clause is for
|
153
|
+
# @param [Boolean] is_delta: Whether the clause is for the core or delta index
|
154
|
+
# @return [String, NilClass] The SQL condition if the is_delta is true,
|
155
|
+
# otherwise nil
|
156
|
+
def clause(*args)
|
157
|
+
model = (args.length >= 2 ? args[0] : nil)
|
158
|
+
is_delta = (args.length >= 2 ? args[1] : args[0]) || false
|
159
|
+
|
160
|
+
table_name = (model.nil? ? adapter.quoted_table_name : model.quoted_table_name)
|
161
|
+
column_name = (model.nil? ? adapter.quote(@column.to_s) : model.connection.quote_column_name(@column.to_s))
|
162
|
+
|
163
|
+
if is_delta
|
164
|
+
if adapter.class.name.downcase[/postgres/]
|
165
|
+
"#{table_name}.#{column_name} > current_timestamp - interval '#{@threshold} seconds'"
|
166
|
+
elsif adapter.class.name.downcase[/mysql/]
|
167
|
+
"#{table_name}.#{column_name} > DATE_SUB(NOW(), INTERVAL #{@threshold} SECOND)"
|
168
|
+
else
|
169
|
+
raise 'Unknown adapter type.'
|
170
|
+
end
|
141
171
|
else
|
142
172
|
nil
|
143
173
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
namespace :thinking_sphinx do
|
2
2
|
namespace :index do
|
3
3
|
desc "Index Thinking Sphinx datetime delta indices"
|
4
|
-
task :delta => :app_env do
|
4
|
+
# task :delta => :app_env do
|
5
|
+
task :delta => (
|
6
|
+
(ThinkingSphinx.constants.include?(:Version) and ThinkingSphinx::Version.to_f < 3) \
|
7
|
+
? :app_env
|
8
|
+
: :environment) do
|
5
9
|
ThinkingSphinx::Deltas::DatetimeDelta.index
|
6
10
|
end
|
7
11
|
end
|
@@ -12,4 +16,8 @@ namespace :ts do
|
|
12
16
|
desc "Index Thinking Sphinx datetime delta indices"
|
13
17
|
task :delta => "thinking_sphinx:index:delta"
|
14
18
|
end
|
19
|
+
namespace :index do
|
20
|
+
desc "Index Thinking Sphinx datetime delta indices"
|
21
|
+
task :delta => "thinking_sphinx:index:delta"
|
22
|
+
end
|
15
23
|
end
|
@@ -2,32 +2,36 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Deltas::DatetimeDelta do
|
4
4
|
before :each do
|
5
|
-
@
|
6
|
-
|
7
|
-
|
5
|
+
@sphinx_version = (ThinkingSphinx.constants.include?(:Version) ? ThinkingSphinx::Version : '3.0.0').to_f
|
6
|
+
|
7
|
+
if @sphinx_version < 3
|
8
|
+
@datetime_delta = ThinkingSphinx::Deltas::DatetimeDelta.new(double('index'), {})
|
9
|
+
else
|
10
|
+
@datetime_delta = ThinkingSphinx::Deltas::DatetimeDelta.new(double('adapter'), {})
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
describe '#index' do
|
11
15
|
it "should do nothing to the model" do
|
12
|
-
@datetime_delta.index(
|
16
|
+
@datetime_delta.index(double('model'))
|
13
17
|
end
|
14
18
|
|
15
19
|
it "should do nothing to the instance, if provided" do
|
16
|
-
@datetime_delta.index(
|
20
|
+
@datetime_delta.index(double('model'), double('instance'))
|
17
21
|
end
|
18
22
|
|
19
23
|
it "should make no system calls" do
|
20
|
-
@datetime_delta.stub
|
21
|
-
@datetime_delta.stub
|
24
|
+
@datetime_delta.stub :` => true
|
25
|
+
@datetime_delta.stub :system => true
|
22
26
|
|
23
27
|
@datetime_delta.should_not_receive(:`)
|
24
28
|
@datetime_delta.should_not_receive(:system)
|
25
29
|
|
26
|
-
@datetime_delta.index(
|
30
|
+
@datetime_delta.index(double('model'), double('instance'))
|
27
31
|
end
|
28
32
|
|
29
33
|
it "should return true" do
|
30
|
-
@datetime_delta.index(
|
34
|
+
@datetime_delta.index(double('model')).should be_true
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
@@ -35,45 +39,73 @@ describe ThinkingSphinx::Deltas::DatetimeDelta do
|
|
35
39
|
let(:root) { File.expand_path File.dirname(__FILE__) + '/../../..' }
|
36
40
|
|
37
41
|
before :each do
|
38
|
-
@index =
|
42
|
+
@index = double('index',
|
39
43
|
:delta? => true,
|
44
|
+
:name => 'foo_delta',
|
40
45
|
:core_name => 'foo_core',
|
41
|
-
:delta_name => 'foo_delta'
|
46
|
+
:delta_name => 'foo_delta',
|
47
|
+
:reference => 'foo',
|
42
48
|
)
|
43
|
-
@model =
|
49
|
+
@model = double('foo',
|
44
50
|
:name => 'foo',
|
45
51
|
:source_of_sphinx_index => @model,
|
46
52
|
:delta_index_names => ['foo_delta'],
|
47
|
-
:sphinx_indexes => [@index]
|
53
|
+
:sphinx_indexes => [@index],
|
48
54
|
)
|
49
55
|
|
50
|
-
ThinkingSphinx.suppress_delta_output = false
|
56
|
+
#ThinkingSphinx.suppress_delta_output = false
|
51
57
|
|
52
|
-
@datetime_delta.stub
|
53
|
-
@datetime_delta.stub
|
58
|
+
@datetime_delta.stub :` => ""
|
59
|
+
@datetime_delta.stub :puts => nil
|
60
|
+
|
61
|
+
@controller = ThinkingSphinx::Configuration.instance.controller
|
62
|
+
@controller.stub :` => ""
|
63
|
+
@controller.stub :system => true
|
54
64
|
end
|
55
65
|
|
56
66
|
it "should process the delta index for the given model" do
|
57
|
-
@
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
if @sphinx_version < 3
|
68
|
+
@datetime_delta.should_receive(:`).
|
69
|
+
with("indexer --config /config/development.sphinx.conf foo_delta")
|
70
|
+
|
71
|
+
@datetime_delta.delayed_index(@model)
|
72
|
+
else
|
73
|
+
@controller.stub :index => ""
|
74
|
+
@controller.should_receive(:index).with(@index.name)
|
75
|
+
@datetime_delta.delayed_index(@index)
|
76
|
+
end
|
61
77
|
end
|
62
78
|
|
63
79
|
it "should merge the core and delta indexes for the given model" do
|
64
|
-
@datetime_delta.should_receive(:`).with(
|
65
|
-
|
66
|
-
|
80
|
+
@datetime_delta.should_receive(:`).with(/indexer --config \S+ --merge foo_core foo_delta --merge-dst-range sphinx_deleted 0 0/)
|
81
|
+
if @sphinx_version < 3
|
82
|
+
@datetime_delta.delayed_index(@model)
|
83
|
+
else
|
84
|
+
core_index = double('index',
|
85
|
+
:delta? => false,
|
86
|
+
:name => 'foo_core',
|
87
|
+
:reference => 'foo',
|
88
|
+
)
|
89
|
+
ThinkingSphinx::Configuration.instance.stub :indices => [core_index, @index]
|
90
|
+
@datetime_delta.delayed_index(@index)
|
91
|
+
end
|
67
92
|
end
|
68
93
|
|
69
94
|
it "should include --rotate if Sphinx is running" do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
95
|
+
if @sphinx_version < 3
|
96
|
+
ThinkingSphinx.stub(:sphinx_running? => true)
|
97
|
+
@datetime_delta.should_receive(:`) do |command|
|
98
|
+
command.should match(/\s--rotate\s/)
|
99
|
+
'output'
|
100
|
+
end
|
101
|
+
|
102
|
+
@datetime_delta.delayed_index(@model)
|
103
|
+
else
|
104
|
+
@controller.stub :running? => true
|
105
|
+
@controller.should_receive(:`).with(/indexer.*--rotate/)
|
106
|
+
|
107
|
+
@datetime_delta.delayed_index(@index)
|
74
108
|
end
|
75
|
-
|
76
|
-
@datetime_delta.delayed_index(@model)
|
77
109
|
end
|
78
110
|
|
79
111
|
it "should output the details by default" do
|
@@ -83,7 +115,11 @@ describe ThinkingSphinx::Deltas::DatetimeDelta do
|
|
83
115
|
end
|
84
116
|
|
85
117
|
it "should hide the details if suppressing delta output" do
|
86
|
-
|
118
|
+
if @sphinx_version < 3
|
119
|
+
ThinkingSphinx.suppress_delta_output = true
|
120
|
+
else
|
121
|
+
ThinkingSphinx::Configuration.instance.settings['quiet_deltas'] = true
|
122
|
+
end
|
87
123
|
@datetime_delta.should_not_receive(:puts)
|
88
124
|
|
89
125
|
@datetime_delta.delayed_index(@model)
|
@@ -92,27 +128,27 @@ describe ThinkingSphinx::Deltas::DatetimeDelta do
|
|
92
128
|
|
93
129
|
describe '#toggle' do
|
94
130
|
it "should do nothing to the instance" do
|
95
|
-
@datetime_delta.toggle(
|
131
|
+
@datetime_delta.toggle(double('instance'))
|
96
132
|
end
|
97
133
|
end
|
98
134
|
|
99
135
|
describe '#toggled' do
|
100
136
|
it "should return true if the column value is more recent than the threshold" do
|
101
|
-
instance =
|
137
|
+
instance = double('instance', :updated_at => 20.minutes.ago)
|
102
138
|
@datetime_delta.threshold = 30.minutes
|
103
139
|
|
104
140
|
@datetime_delta.toggled(instance).should be_true
|
105
141
|
end
|
106
142
|
|
107
143
|
it "should return false if the column value is older than the threshold" do
|
108
|
-
instance =
|
144
|
+
instance = double('instance', :updated_at => 30.minutes.ago)
|
109
145
|
@datetime_delta.threshold = 20.minutes
|
110
146
|
|
111
147
|
@datetime_delta.toggled(instance).should be_false
|
112
148
|
end
|
113
149
|
|
114
150
|
it "should return false if the column value is null" do
|
115
|
-
instance =
|
151
|
+
instance = double('instance', :updated_at => nil)
|
116
152
|
@datetime_delta.threshold = 20.minutes
|
117
153
|
|
118
154
|
@datetime_delta.toggled(instance).should be_false
|
@@ -127,12 +163,12 @@ describe ThinkingSphinx::Deltas::DatetimeDelta do
|
|
127
163
|
|
128
164
|
describe '#clause' do
|
129
165
|
before :each do
|
130
|
-
@model =
|
131
|
-
@model.stub
|
132
|
-
@model.connection.stub
|
166
|
+
@model = double('model', :connection => double('connection'))
|
167
|
+
@model.stub(:quoted_table_name => '`foo`')
|
168
|
+
@model.connection.stub(:quote_column_name => '`updated_at`')
|
133
169
|
|
134
|
-
@datetime_delta.stub
|
135
|
-
:adapter =>
|
170
|
+
@datetime_delta.stub(
|
171
|
+
:adapter => double('adapter', :time_difference => 'time_difference')
|
136
172
|
)
|
137
173
|
end
|
138
174
|
|
metadata
CHANGED
@@ -1,141 +1,119 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ts-datetime-delta
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 1.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Pat Allan
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: thinking-sphinx
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 11
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 3
|
32
|
-
- 8
|
18
|
+
- !ruby/object:Gem::Version
|
33
19
|
version: 1.3.8
|
34
20
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rspec
|
38
21
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
42
31
|
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 13
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 2
|
48
|
-
- 9
|
32
|
+
- !ruby/object:Gem::Version
|
49
33
|
version: 1.2.9
|
50
34
|
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: yard
|
54
35
|
prerelease: false
|
55
|
-
|
56
|
-
|
57
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
58
38
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.9
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
64
48
|
type: :development
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: cucumber
|
68
49
|
prerelease: false
|
69
|
-
|
70
|
-
|
71
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cucumber
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
72
59
|
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
78
62
|
type: :development
|
79
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
80
69
|
description: Manage delta indexes via datetime columns for Thinking Sphinx
|
81
70
|
email: pat@freelancing-gods.com
|
82
71
|
executables: []
|
83
|
-
|
84
72
|
extensions: []
|
85
|
-
|
86
|
-
extra_rdoc_files:
|
73
|
+
extra_rdoc_files:
|
87
74
|
- LICENSE
|
88
75
|
- README.textile
|
89
|
-
files:
|
76
|
+
files:
|
90
77
|
- LICENSE
|
91
78
|
- README.textile
|
92
|
-
-
|
93
|
-
- lib/thinking_sphinx/deltas/datetime_delta/tasks.rb
|
79
|
+
- features/datetime_deltas.feature
|
94
80
|
- features/step_definitions/common_steps.rb
|
95
81
|
- features/step_definitions/datetime_delta_steps.rb
|
82
|
+
- features/support/database.example.yml
|
96
83
|
- features/support/db/fixtures/thetas.rb
|
97
84
|
- features/support/db/migrations/create_thetas.rb
|
98
85
|
- features/support/env.rb
|
99
86
|
- features/support/models/theta.rb
|
100
|
-
-
|
101
|
-
-
|
87
|
+
- lib/thinking_sphinx/deltas/datetime_delta.rb
|
88
|
+
- lib/thinking_sphinx/deltas/datetime_delta/tasks.rb
|
102
89
|
- spec/spec.opts
|
103
90
|
- spec/spec_helper.rb
|
104
91
|
- spec/thinking_sphinx/deltas/datetime_delta_spec.rb
|
105
92
|
homepage: http://github.com/freelancing-god/ts-datetime-delta
|
106
|
-
licenses:
|
107
|
-
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
108
96
|
post_install_message:
|
109
97
|
rdoc_options: []
|
110
|
-
|
111
|
-
require_paths:
|
98
|
+
require_paths:
|
112
99
|
- lib
|
113
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
-
|
115
|
-
requirements:
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
116
102
|
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
version: "0"
|
122
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
|
-
requirements:
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
125
107
|
- - ">="
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
version: "0"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
131
110
|
requirements: []
|
132
|
-
|
133
111
|
rubyforge_project:
|
134
|
-
rubygems_version:
|
112
|
+
rubygems_version: 2.3.0
|
135
113
|
signing_key:
|
136
|
-
specification_version:
|
114
|
+
specification_version: 4
|
137
115
|
summary: Thinking Sphinx - Datetime Deltas
|
138
|
-
test_files:
|
116
|
+
test_files:
|
139
117
|
- features/step_definitions/common_steps.rb
|
140
118
|
- features/step_definitions/datetime_delta_steps.rb
|
141
119
|
- features/support/db/fixtures/thetas.rb
|
@@ -147,3 +125,4 @@ test_files:
|
|
147
125
|
- spec/spec.opts
|
148
126
|
- spec/spec_helper.rb
|
149
127
|
- spec/thinking_sphinx/deltas/datetime_delta_spec.rb
|
128
|
+
has_rdoc:
|