lucid_works 0.6.12 → 0.6.13

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.
@@ -112,5 +112,13 @@ module LucidWorks
112
112
  def t_type
113
113
  I18n.t(type, :scope => 'activemodel.models.lucid_works.datasource.type')
114
114
  end
115
+
116
+ def progress
117
+ return nil if status.stopped?
118
+ return nil unless histories.size > 0
119
+ percent_done = status.elapsed_time.to_f / histories.last.duration
120
+ percent_done = nil if percent_done > 1.0
121
+ percent_done
122
+ end
115
123
  end
116
124
  end
@@ -1,5 +1,5 @@
1
1
  module LucidWorks
2
- VERSION = "0.6.12"
2
+ VERSION = "0.6.13"
3
3
 
4
4
  class Version < Base
5
5
  end
@@ -296,15 +296,50 @@ describe LucidWorks::Datasource do
296
296
  end
297
297
 
298
298
  describe "#progress" do
299
+ before do
300
+ @datasource = LucidWorks::Datasource.new(
301
+ :collection => @collection,
302
+ :crawler => LucidWorks::Datasource::CRAWLERS['file'],
303
+ :type => 'file',
304
+ :name => "datasource we are going to get progress of",
305
+ :path => "/fake_ds_to_test_progress",
306
+ :crawl_depth => 2
307
+ )
308
+ @datasource.should be_valid
309
+ end
310
+
299
311
  context "when the datasource has no prior history" do
300
- it "should return nil"
312
+ it "should return nil" do
313
+ @datasource.progress.should be_nil
314
+ end
301
315
  end
316
+
302
317
  context "when the datasource has history" do
318
+ before do
319
+ mock_history = double("history", :duration => 4000)
320
+ @datasource.stub(:histories) { [mock_history] }
321
+ end
322
+
303
323
  context "and the most last crawl duration was longer then our current crawl duration" do
304
- it "should return the fraction completed (between 0.0 and 1.0)"
324
+ before do
325
+ mock_status = double('status', :stopped? => false, :elapsed_time => 1000)
326
+ @datasource.stub(:status) { mock_status }
327
+ end
328
+
329
+ it "should return the fraction completed (between 0.0 and 1.0)" do
330
+ @datasource.progress.should == 0.25
331
+ end
305
332
  end
306
- context "and the most recent crawl duration was no longer our current duration" do
307
- it "should return nil"
333
+
334
+ context "and the most recent crawl duration was shorter than our current duration" do
335
+ before do
336
+ mock_status = double('status', :stopped? => false, :elapsed_time => 5000)
337
+ @datasource.stub(:status) { mock_status }
338
+ end
339
+
340
+ it "should return nil" do
341
+ @datasource.progress.should be_nil
342
+ end
308
343
  end
309
344
  end
310
345
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lucid_works
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.12
5
+ version: 0.6.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Pierson