dpickett-workling_delta_indexer 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :minor: 1
@@ -0,0 +1,10 @@
1
+ module WorklingDelta
2
+ class Indexer < ThinkingSphinx::Deltas::DefaultDelta
3
+ def do_index(model, instance = nil)
4
+ doc_id = instance ? instance.sphinx_document_id : nil
5
+ WorklingDelta::Worker.async_index(:index_name => delta_index_name(model), :document_id => doc_id)
6
+
7
+ true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class WorklingDelta::Worker < Workling::Base
2
+ def index(options = {})
3
+ ThinkingSphinx::Deltas::DeltaJob.new(options[:index_name]).perform
4
+
5
+ if options[:document_id]
6
+ ThinkingSphinx::Deltas::FlagAsDeletedJob.new(options[:index_name],
7
+ options[:document_id]).perform
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ class WorklingDelta::IndexerTest < Test::Unit::TestCase
4
+ context "an indexer" do
5
+ should "spawn a worker with the delta index name when an index is triggered" do
6
+ mock(WorklingDelta::Worker).async_index(:index_name => "test_model_delta", :document_id => nil)
7
+
8
+ WorklingDelta::Indexer.new(ThinkingSphinx::Index.new(TestModel), {}).do_index(TestModel)
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ class TestModel < ActiveRecord::Base
15
+ define_index do
16
+ indexes :id
17
+ end
18
+ end
19
+
20
+
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+
3
+ class WorklingDelta::WorkerTest < Test::Unit::TestCase
4
+ context "a worker" do
5
+ setup do
6
+ @index_name = "the_delta_index"
7
+ @document_id = 1
8
+
9
+ @job = mock(Object)
10
+ mock(ThinkingSphinx::Deltas::DeltaJob).new(@index_name) { @job }
11
+ @job.perform
12
+ end
13
+
14
+ context "that doesn't receive a document id" do
15
+
16
+ should "perform a TS delta job with the index name" do
17
+ invoke_worker(:index_name => @index_name)
18
+ end
19
+
20
+ should "not perform a flag as deleted job if I don't pass a document id" do
21
+ dont_allow(ThinkingSphinx::Deltas::FlagAsDeletedJob).new(
22
+ anything, anything)
23
+
24
+ invoke_worker(:index_name => @index_name)
25
+ end
26
+
27
+ end
28
+
29
+ context "that receives a document id" do
30
+ should "trigger a flag as deleted job if I pass a document id" do
31
+ delete_job = mock(Object)
32
+ mock(ThinkingSphinx::Deltas::FlagAsDeletedJob).new(
33
+ @index_name, @document_id) { delete_job }
34
+ delete_job.perform
35
+
36
+ invoke_worker(:index_name => @index_name, :document_id => @document_id)
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ private
43
+ def invoke_worker(options = {})
44
+ WorklingDelta::Worker.new.index(options)
45
+ end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpickett-workling_delta_indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
@@ -24,9 +24,15 @@ extra_rdoc_files:
24
24
  - LICENSE
25
25
  files:
26
26
  - README.rdoc
27
+ - VERSION.yml
28
+ - lib/workling_delta
29
+ - lib/workling_delta/indexer.rb
30
+ - lib/workling_delta/worker.rb
27
31
  - lib/workling_delta_indexer.rb
28
32
  - test/test_helper.rb
29
- - test/workling_delta_indexer_test.rb
33
+ - test/workling_delta
34
+ - test/workling_delta/indexer_test.rb
35
+ - test/workling_delta/worker_test.rb
30
36
  - LICENSE
31
37
  has_rdoc: true
32
38
  homepage: http://github.com/dpickett/workling_delta_indexer