lucid_works 0.3.9 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/README.rdoc +33 -3
  2. data/config/locales/en.yml +21 -12
  3. data/lib/lucid_works.rb +10 -0
  4. data/lib/lucid_works/associations.rb +14 -12
  5. data/lib/lucid_works/base.rb +13 -13
  6. data/lib/lucid_works/collection.rb +65 -5
  7. data/lib/lucid_works/collection/activity.rb +33 -0
  8. data/lib/lucid_works/collection/activity/history.rb +20 -0
  9. data/lib/lucid_works/collection/activity/status.rb +14 -0
  10. data/lib/lucid_works/collection/settings.rb +28 -8
  11. data/lib/lucid_works/crawler.rb +3 -3
  12. data/lib/lucid_works/datasource.rb +29 -3
  13. data/lib/lucid_works/datasource/job.rb +9 -0
  14. data/lib/lucid_works/datasource/status.rb +6 -11
  15. data/lib/lucid_works/patch_time.rb +13 -0
  16. data/lib/lucid_works/schema.rb +36 -8
  17. data/lib/lucid_works/utils.rb +22 -0
  18. data/lib/lucid_works/version.rb +1 -1
  19. data/lucid_works.gemspec +2 -0
  20. data/spec/lib/lucid_works/associations_spec.rb +12 -1
  21. data/spec/lib/lucid_works/base_spec.rb +26 -10
  22. data/spec/lib/lucid_works/collection/activity/history_spec.rb +33 -0
  23. data/spec/lib/lucid_works/collection/activity/status_spec.rb +20 -0
  24. data/spec/lib/lucid_works/collection/activity_spec.rb +88 -0
  25. data/spec/lib/lucid_works/collection/prime_activities_spec.rb +86 -0
  26. data/spec/lib/lucid_works/collection_spec.rb +140 -1
  27. data/spec/lib/lucid_works/datasource/history_spec.rb +11 -7
  28. data/spec/lib/lucid_works/datasource/status_spec.rb +64 -32
  29. data/spec/lib/lucid_works/datasource_spec.rb +48 -13
  30. data/spec/lib/lucid_works/schema_spec.rb +56 -4
  31. data/spec/lib/lucid_works/utils_spec.rb +62 -0
  32. data/spec/spec_helper.rb +17 -14
  33. metadata +41 -3
@@ -4,7 +4,7 @@ describe LucidWorks::Datasource do
4
4
  before :all do
5
5
  @server = connect_to_live_server
6
6
  @server.reset_collections!
7
- @collection = @server.collections.first
7
+ @collection = @server.collections!.first
8
8
  end
9
9
 
10
10
  describe "CRUD" do
@@ -222,7 +222,7 @@ describe LucidWorks::Datasource do
222
222
  end
223
223
  end
224
224
 
225
- describe "#build_index" do
225
+ describe "#index" do
226
226
  it "should return a new LucidWorks::Datasource::Index for this datasource" do
227
227
  @datasource = LucidWorks::Datasource.create(
228
228
  :collection => @collection,
@@ -240,9 +240,44 @@ describe LucidWorks::Datasource do
240
240
  end
241
241
  end
242
242
 
243
+ describe "job control" do
244
+ before :all do
245
+ @datasource = LucidWorks::Datasource.create(
246
+ :collection => @collection,
247
+ :crawler => LucidWorks::Datasource::CRAWLERS['file'],
248
+ :type => 'file',
249
+ :name => "datasource we are going to mess with job of",
250
+ :path => "/fake_ds_to_mess_with_job_of",
251
+ :crawl_depth => 2
252
+ )
253
+ @datasource.should be_valid
254
+ end
255
+
256
+ describe "#job" do
257
+ it "should return a new LucidWorks::Datasource::Job for this datasource" do
258
+ job = @datasource.job
259
+ job.should be_a(LucidWorks::Datasource::Job)
260
+ job.should be_persisted # special case - singletons are always considered persisted
261
+ end
262
+ end
263
+
264
+ describe "#start_crawl!" do
265
+ it "should PUT /api/collections/<collection_id>/datasources/<datasource_id>/job" do
266
+ RestClient.should_receive(:put).with("#{@datasource.uri}/job", "{}", {:content_type => :json})
267
+ @datasource.start_crawl!
268
+ end
269
+ end
270
+
271
+ describe "#stop_crawl!" do
272
+ it "should DELETE /api/collections/<collection_id>/datasources/<datasource_id>/job" do
273
+ RestClient.should_receive(:delete).with("#{@datasource.uri}/job", {})
274
+ @datasource.stop_crawl!
275
+ end
276
+ end
277
+ end
278
+
243
279
  describe "#empty!" do
244
280
  before do
245
- @collection = @server.collections.first
246
281
  @datasource = LucidWorks::Datasource.create(
247
282
  :collection => @collection,
248
283
  :crawler => LucidWorks::Datasource::CRAWLERS['file'],
@@ -259,18 +294,18 @@ describe LucidWorks::Datasource do
259
294
 
260
295
  @datasource.empty!
261
296
  end
297
+ end
262
298
 
263
- describe "#progress" do
264
- context "when the datasource has no prior history" do
265
- it "should return nil"
299
+ describe "#progress" do
300
+ context "when the datasource has no prior history" do
301
+ it "should return nil"
302
+ end
303
+ context "when the datasource has history" do
304
+ context "and the most last crawl duration was longer then our current crawl duration" do
305
+ it "should return the fraction completed (between 0.0 and 1.0)"
266
306
  end
267
- context "when the datasource has history" do
268
- context "and the most last crawl duration was longer then our current crawl duration" do
269
- it "should return the fraction completed (between 0.0 and 1.0)"
270
- end
271
- context "and the most recent crawl duration was no longer our current duration" do
272
- it "should return nil"
273
- end
307
+ context "and the most recent crawl duration was no longer our current duration" do
308
+ it "should return nil"
274
309
  end
275
310
  end
276
311
  end
@@ -4,7 +4,7 @@ describe LucidWorks::Schema do
4
4
  before do
5
5
  @schema = LucidWorks::Schema.new
6
6
  @schema.instance_eval do
7
- attribute :foo
7
+ attribute :foo, :string, :primary_key => true
8
8
  attribute :abool, :boolean
9
9
  attributes :bar, :baz, :type => :integer
10
10
  end
@@ -18,13 +18,50 @@ describe LucidWorks::Schema do
18
18
  'baz' => {'type' => :integer},
19
19
  'abool' => {'type' => :boolean}
20
20
  }
21
+ @schema.primary_key.should == :foo
22
+ end
23
+ end
24
+
25
+ describe "#primary_key" do
26
+ it "should default to 'id'" do
27
+ LucidWorks::Schema.new.primary_key.should == :id
28
+ end
29
+
30
+ context "when given an argument" do
31
+ it "should set the primary key to the provided value" do
32
+ schema = LucidWorks::Schema.new
33
+ schema.primary_key 'foo'
34
+ schema.primary_key.should == :foo
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#dynamic_attributes" do
40
+ it "should default to true" do
41
+ schema = LucidWorks::Schema.new
42
+ schema.dynamic_attributes.should be_true
43
+ end
44
+
45
+ context "when given an argument" do
46
+ it "should set dynamic_attributes to the provided value" do
47
+ schema = LucidWorks::Schema.new
48
+ schema.dynamic_attributes false
49
+ schema.dynamic_attributes.should be_false
50
+ end
21
51
  end
22
52
  end
23
53
 
24
54
  describe "create_accessors_for_attributes" do
25
55
  before do
26
- class ClassWithAddedAccessors ; end
56
+ class ClassWithAddedAccessors
57
+ include LucidWorks::Utils::BoolConverter
58
+ attr_accessor :attributes
59
+ def initialize
60
+ @attributes = {}
61
+ end
62
+ end
27
63
  @schema.create_accessors_for_attributes(ClassWithAddedAccessors)
64
+ @model = ClassWithAddedAccessors.new
28
65
  end
29
66
 
30
67
  it "should add readers and writers for all attributes" do
@@ -33,8 +70,23 @@ describe LucidWorks::Schema do
33
70
  ClassWithAddedAccessors.new.should respond_to(:abool, :abool=)
34
71
  end
35
72
 
36
- it "should also add a predicate method for boolean attributes" do
37
- ClassWithAddedAccessors.new.should respond_to(:abool?)
73
+ context "for a boolean attribute" do
74
+ it "should add a predicate method" do
75
+ ClassWithAddedAccessors.new.should respond_to(:abool?)
76
+ end
77
+
78
+ [0, '0', false, 'false', 'FALSE', 'no', 'NO'].each do |false_value|
79
+ it "setter should recongnize #{false_value} as false" do
80
+ @model.abool = false_value
81
+ @model.abool.should === false
82
+ end
83
+ end
84
+ [1, '1', true, 'true', 'TRUE', 'yes', 'YES'].each do |true_value|
85
+ it "setter should recongnize #{true_value} as true" do
86
+ @model.abool = true_value
87
+ @model.abool.should === true
88
+ end
89
+ end
38
90
  end
39
91
  end
40
92
 
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe LucidWorks::Utils do
4
+ describe "BoolConverter" do
5
+ before do
6
+ class ::TestClass
7
+ extend LucidWorks::Utils::BoolConverter
8
+ end
9
+ end
10
+
11
+ describe "to_bool" do
12
+ describe "actual booleans" do
13
+ it "should return the boolean itself" do
14
+ ::TestClass.to_bool(true).should be_true
15
+ ::TestClass.to_bool(false).should be_false
16
+ end
17
+ end
18
+
19
+ describe "strings" do
20
+ ['1', 'true', 'TRUE', 'yes', 'YES'].each do |true_value|
21
+ it "should recognize #{true_value} as true" do
22
+ ::TestClass.to_bool(true_value).should be_true
23
+ end
24
+ end
25
+
26
+ ['0', 'false', 'FALSE', 'no', 'NO'].each do |false_value|
27
+ it "should recognize #{false_value} as false" do
28
+ ::TestClass.to_bool(false_value).should be_false
29
+ end
30
+ end
31
+
32
+ it "should raise an error for any non true/false recognized string" do
33
+ lambda {
34
+ ::TestClass.to_bool('foo')
35
+ }.should raise_error
36
+ end
37
+ end
38
+
39
+ describe "integers" do
40
+ it "should recognize 0 and 1 and false and true respectively" do
41
+ ::TestClass.to_bool(1).should be_true
42
+ ::TestClass.to_bool(0).should be_false
43
+ end
44
+
45
+ it "should raise an error for anything but 0/1" do
46
+ lambda {
47
+ ::TestClass.to_bool(2)
48
+ }.should raise_error
49
+ end
50
+ end
51
+
52
+ describe "anything else" do
53
+ it "should raise an error for anything but integers, booleans or strings" do
54
+ lambda {
55
+ ::TestClass.to_bool({})
56
+ }.should raise_error
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,7 @@ def connect_to_live_server
10
10
  end
11
11
 
12
12
  class LucidWorks::Server
13
+ DUMMY_COLLECTION_NAME = 'collection_that_should_never_exist'
13
14
  DEFAULT_COLLECTION_NAME = 'collection1'
14
15
 
15
16
  # Reset set of collections to contain 1 collection with the default name "collection1".
@@ -23,25 +24,27 @@ class LucidWorks::Server
23
24
  def reset_collections!
24
25
  notes = [ "Resetting all collections:" ]
25
26
 
26
- collections = self.collections
27
- if default_collection = collections.detect { |c| c.name == DEFAULT_COLLECTION_NAME }
28
- default_collection.datasources.each do |ds|
29
- ds.destroy
30
- notes << "Deleted collection '#{default_collection.name}' datasource #{ds.name}"
31
- end
32
- default_collection.empty!
33
- notes << "Emptied collection '#{default_collection.name}'"
27
+ collections = self.collections!
28
+
29
+ dummy_collection = collections.find { |c| c.name == DUMMY_COLLECTION_NAME }
30
+ if dummy_collection
31
+ notes << "Using dummy collection #{dummy_collection.name}"
32
+ collections.delete_if { |c| c.name == DUMMY_COLLECTION_NAME }
34
33
  else
35
- default_collection = Collection.create(:name => DEFAULT_COLLECTION_NAME)
36
- notes << "Created collection '#{default_collection.name}'"
34
+ dummy_collection = self.create_collection(:name => DUMMY_COLLECTION_NAME)
35
+ notes << "Created collection #{dummy_collection.name}"
37
36
  end
38
37
 
39
38
  collections.each do |c|
40
- unless c.name == default_collection.name
41
- c.destroy
42
- notes << "Deleted collection '#{c.name}'"
43
- end
39
+ c.destroy
40
+ notes << "Deleted collection '#{c.name}'"
44
41
  end
42
+
43
+ default_collection = self.create_collection(:name => DEFAULT_COLLECTION_NAME)
44
+ notes << "Created collection '#{default_collection.name}'"
45
+
46
+ dummy_collection.destroy
47
+ notes << "Deleted collection #{dummy_collection.name}"
45
48
  notes
46
49
  end
47
50
  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.3.9
5
+ version: 0.4.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Pierson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-24 00:00:00 -07:00
13
+ date: 2011-04-09 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -57,6 +57,28 @@ dependencies:
57
57
  version: "0"
58
58
  type: :runtime
59
59
  version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rsolr
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :runtime
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: nokogiri
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :runtime
81
+ version_requirements: *id006
60
82
  description: Ruby wrapper for the LucidWorks REST API
61
83
  email:
62
84
  - sam.pierson@lucidimagination.com
@@ -81,6 +103,9 @@ files:
81
103
  - lib/lucid_works/associations.rb
82
104
  - lib/lucid_works/base.rb
83
105
  - lib/lucid_works/collection.rb
106
+ - lib/lucid_works/collection/activity.rb
107
+ - lib/lucid_works/collection/activity/history.rb
108
+ - lib/lucid_works/collection/activity/status.rb
84
109
  - lib/lucid_works/collection/index.rb
85
110
  - lib/lucid_works/collection/info.rb
86
111
  - lib/lucid_works/collection/settings.rb
@@ -89,6 +114,7 @@ files:
89
114
  - lib/lucid_works/datasource/crawldata.rb
90
115
  - lib/lucid_works/datasource/history.rb
91
116
  - lib/lucid_works/datasource/index.rb
117
+ - lib/lucid_works/datasource/job.rb
92
118
  - lib/lucid_works/datasource/schedule.rb
93
119
  - lib/lucid_works/datasource/status.rb
94
120
  - lib/lucid_works/exceptions.rb
@@ -99,12 +125,18 @@ files:
99
125
  - lib/lucid_works/logs/query.rb
100
126
  - lib/lucid_works/logs/query/summary.rb
101
127
  - lib/lucid_works/patch_restclient.rb
128
+ - lib/lucid_works/patch_time.rb
102
129
  - lib/lucid_works/schema.rb
103
130
  - lib/lucid_works/server.rb
131
+ - lib/lucid_works/utils.rb
104
132
  - lib/lucid_works/version.rb
105
133
  - lucid_works.gemspec
106
134
  - spec/lib/lucid_works/associations_spec.rb
107
135
  - spec/lib/lucid_works/base_spec.rb
136
+ - spec/lib/lucid_works/collection/activity/history_spec.rb
137
+ - spec/lib/lucid_works/collection/activity/status_spec.rb
138
+ - spec/lib/lucid_works/collection/activity_spec.rb
139
+ - spec/lib/lucid_works/collection/prime_activities_spec.rb
108
140
  - spec/lib/lucid_works/collection_spec.rb
109
141
  - spec/lib/lucid_works/datasource/history_spec.rb
110
142
  - spec/lib/lucid_works/datasource/status_spec.rb
@@ -112,6 +144,7 @@ files:
112
144
  - spec/lib/lucid_works/field_spec.rb
113
145
  - spec/lib/lucid_works/schema_spec.rb
114
146
  - spec/lib/lucid_works/server_spec.rb
147
+ - spec/lib/lucid_works/utils_spec.rb
115
148
  - spec/spec_helper.rb
116
149
  has_rdoc: true
117
150
  homepage: ""
@@ -137,13 +170,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
170
  requirements: []
138
171
 
139
172
  rubyforge_project: lucid_works
140
- rubygems_version: 1.5.2
173
+ rubygems_version: 1.6.2
141
174
  signing_key:
142
175
  specification_version: 3
143
176
  summary: Ruby wrapper for the LucidWorks REST API
144
177
  test_files:
145
178
  - spec/lib/lucid_works/associations_spec.rb
146
179
  - spec/lib/lucid_works/base_spec.rb
180
+ - spec/lib/lucid_works/collection/activity/history_spec.rb
181
+ - spec/lib/lucid_works/collection/activity/status_spec.rb
182
+ - spec/lib/lucid_works/collection/activity_spec.rb
183
+ - spec/lib/lucid_works/collection/prime_activities_spec.rb
147
184
  - spec/lib/lucid_works/collection_spec.rb
148
185
  - spec/lib/lucid_works/datasource/history_spec.rb
149
186
  - spec/lib/lucid_works/datasource/status_spec.rb
@@ -151,4 +188,5 @@ test_files:
151
188
  - spec/lib/lucid_works/field_spec.rb
152
189
  - spec/lib/lucid_works/schema_spec.rb
153
190
  - spec/lib/lucid_works/server_spec.rb
191
+ - spec/lib/lucid_works/utils_spec.rb
154
192
  - spec/spec_helper.rb