outoftime-sunspot 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :minor: 7
@@ -19,6 +19,7 @@ module Sunspot
19
19
  @config = config
20
20
  yield(@config) if block_given?
21
21
  @connection = connection
22
+ @updates = 0
22
23
  end
23
24
 
24
25
  #
@@ -34,6 +35,7 @@ module Sunspot
34
35
  #
35
36
  def index(*objects)
36
37
  objects.flatten!
38
+ @updates += objects.length
37
39
  for object in objects
38
40
  setup_for(object).indexer(connection).add(object)
39
41
  end
@@ -51,6 +53,7 @@ module Sunspot
51
53
  # See Sunspot.commit!
52
54
  #
53
55
  def commit
56
+ @updates = 0
54
57
  connection.commit
55
58
  end
56
59
 
@@ -59,6 +62,7 @@ module Sunspot
59
62
  #
60
63
  def remove(*objects)
61
64
  objects.flatten!
65
+ @updates += objects.length
62
66
  for object in objects
63
67
  setup_for(object).indexer(connection).remove(object)
64
68
  end
@@ -70,14 +74,30 @@ module Sunspot
70
74
  def remove_all(*classes)
71
75
  classes.flatten!
72
76
  if classes.empty?
77
+ @updates += 1
73
78
  Indexer.remove_all(connection)
74
79
  else
80
+ @updates += classes.length
75
81
  for clazz in classes
76
82
  Setup.for(clazz).indexer(connection).remove_all
77
83
  end
78
84
  end
79
85
  end
80
86
 
87
+ #
88
+ # See Sunspot.dirty?
89
+ #
90
+ def dirty?
91
+ @updates > 0
92
+ end
93
+
94
+ #
95
+ # See Sunspot.commit_if_dirty
96
+ #
97
+ def commit_if_dirty
98
+ commit if dirty?
99
+ end
100
+
81
101
  private
82
102
 
83
103
  #
data/lib/sunspot.rb CHANGED
@@ -243,6 +243,25 @@ module Sunspot
243
243
  session.remove_all(*classes)
244
244
  end
245
245
 
246
+ #
247
+ # True if documents have been added, updated, or removed since the last
248
+ # commit.
249
+ #
250
+ # ==== Returns
251
+ #
252
+ # Boolean:: Whether there have been any updates since the last commit
253
+ #
254
+ def dirty?
255
+ session.dirty?
256
+ end
257
+
258
+ #
259
+ # Sends a commit if the session is dirty (see #dirty?).
260
+ #
261
+ def commit_if_dirty
262
+ session.commit_if_dirty
263
+ end
264
+
246
265
  # Returns the configuration associated with the singleton session. See
247
266
  # Sunspot::Configuration for details.
248
267
  #
@@ -46,6 +46,56 @@ describe 'Session' do
46
46
  end
47
47
  end
48
48
 
49
+ context 'dirty sessions' do
50
+ before :each do
51
+ connection.stub!(:add)
52
+ connection.stub!(:commit)
53
+ Solr::Connection.stub!(:new).and_return(connection)
54
+ @session = Sunspot::Session.new
55
+ end
56
+
57
+ it 'should start out not dirty' do
58
+ @session.dirty?.should be_false
59
+ end
60
+
61
+ it 'should be dirty after adding an item' do
62
+ @session.index(Post.new)
63
+ @session.dirty?.should be_true
64
+ end
65
+
66
+ it 'should be dirty after deleting an item' do
67
+ @session.remove(Post.new)
68
+ @session.dirty?.should be_true
69
+ end
70
+
71
+ it 'should be dirty after a remove_all for a class' do
72
+ @session.remove_all(Post)
73
+ @session.dirty?.should be_true
74
+ end
75
+
76
+ it 'should be dirty after a global remove_all' do
77
+ @session.remove_all
78
+ @session.dirty?.should be_true
79
+ end
80
+
81
+ it 'should not be dirty after a commit' do
82
+ @session.index(Post.new)
83
+ @session.commit
84
+ @session.dirty?.should be_false
85
+ end
86
+
87
+ it 'should not commit when commit_if_dirty called on clean session' do
88
+ connection.should_not_receive(:commit)
89
+ @session.commit_if_dirty
90
+ end
91
+
92
+ it 'should commit when commit_if_dirty called on dirty session' do
93
+ connection.should_receive(:commit)
94
+ @session.index(Post.new)
95
+ @session.commit_if_dirty
96
+ end
97
+ end
98
+
49
99
  def connection
50
100
  @connection ||= mock('Connection').as_null_object
51
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outoftime-sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown