lucid_works 0.2.0 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ module LucidWorks
2
+
3
+ class Schema < ActiveSupport::HashWithIndifferentAccess
4
+
5
+ # Specify an attribute for this model.
6
+
7
+ def attribute(name, type=:string, options={})
8
+ self[name] = options.merge(:type => type)
9
+ end
10
+
11
+ # Specify multiple attributes. Options apply to all attributes, e.g.
12
+ #
13
+ # schema do
14
+ # attributes :first_name, :last_name, :type => :string
15
+ # end
16
+
17
+ def attributes(*attributes_and_options)
18
+ options = attributes_and_options.last.is_a?(Hash) ? attributes_and_options.pop : {}
19
+ attributes = attributes_and_options
20
+ attributes.each do |name|
21
+ self[name] = { :type => options[:type] || :string }
22
+ end
23
+ end
24
+
25
+ def has_attribute?(name)
26
+ has_key? sanitize_identifier(name)
27
+ end
28
+
29
+ # Used for classes that have no predefined schema.
30
+ # When the class is retrieved.
31
+ def add_attribute(klass, name, type=:string) # :nodoc:
32
+ attr = sanitize_identifier(name)
33
+ raise "Class #{klass.name} already has attribute #{attr}" if has_attribute?(attr)
34
+ self[attr] = { :type => type }
35
+ create_attribute(klass, attr)
36
+ end
37
+
38
+ # Create accessors for all attributes defined in the schema.
39
+ def create_accessors_for_attributes(klass) # :nodoc:
40
+ self.keys.each do |attr|
41
+ create_attribute(klass, attr)
42
+ end
43
+ end
44
+
45
+ def create_attribute(klass, attribute) # :nodoc:
46
+ klass.class_eval <<-EOF, __FILE__, __LINE__+1
47
+ def #{attribute} # def foo
48
+ @attributes[:#{attribute}] # @attributes[:foo]
49
+ end # end
50
+
51
+ def #{attribute}=(new_value) # def foo=(new_value)
52
+ @attributes[:#{attribute}] = new_value # @attributes[:foo] = new_value
53
+ end # end
54
+ EOF
55
+
56
+ if self[attribute][:type] == :boolean
57
+ klass.class_eval <<-EOF, __FILE__, __LINE__+1
58
+ def #{attribute}? # def foo?
59
+ @attributes[:#{attribute}] # @attributes[:foo]
60
+ end # end
61
+ EOF
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ # Change any characters illegal for an identifier to _
68
+ def sanitize_identifier(identifier) # :nodoc:
69
+ identifier.to_s.gsub(/[^\w]/, '_').to_sym
70
+ end
71
+ end
72
+ end
@@ -5,8 +5,8 @@ module LucidWorks
5
5
  class Server
6
6
  include Associations
7
7
 
8
- has_many :collections
9
- has_one :logs
8
+ has_many :collections, :crawlers
9
+ has_one :logs, :has_content => false
10
10
 
11
11
  DEFAULT_REST_API_PATH = "/api"
12
12
 
@@ -1,3 +1,3 @@
1
1
  module LucidWorks
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.9"
3
3
  end
data/lib/lucid_works.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # This is the namespace module in which all our classes and modules live.
2
+
1
3
  module LucidWorks
2
4
  end
3
5
 
@@ -5,6 +7,10 @@ require 'active_model'
5
7
  require 'active_support/core_ext/module/attr_accessor_with_default'
6
8
  require 'active_support/core_ext/hash/indifferent_access'
7
9
  require 'active_support/inflector'
10
+ begin
11
+ require 'action_view/helpers/number_helper' # Optional formatter support
12
+ rescue LoadError
13
+ end
8
14
  require 'restclient'
9
15
  require 'json'
10
16
 
@@ -14,18 +20,24 @@ require 'lucid_works/exceptions'
14
20
  require 'lucid_works/associations'
15
21
  require 'lucid_works/server'
16
22
  require 'lucid_works/base'
23
+ require 'lucid_works/schema'
17
24
 
18
25
  require 'lucid_works/collection'
19
26
  require 'lucid_works/collection/info'
20
27
  require 'lucid_works/collection/index'
21
28
  require 'lucid_works/collection/settings'
29
+ require 'lucid_works/crawler'
22
30
  require 'lucid_works/datasource'
23
31
  require 'lucid_works/datasource/index'
24
32
  require 'lucid_works/datasource/status'
25
33
  require 'lucid_works/datasource/history'
26
34
  require 'lucid_works/datasource/schedule'
35
+ require 'lucid_works/datasource/crawldata'
36
+ require 'lucid_works/field'
27
37
  require 'lucid_works/logs'
28
38
  require 'lucid_works/logs/query'
29
39
  require 'lucid_works/logs/query/summary'
30
40
  require 'lucid_works/logs/index'
31
41
  require 'lucid_works/logs/index/summary'
42
+
43
+ I18n.load_path += Dir.glob(File.join(File.dirname(__FILE__), '..', 'config', 'locales', '*.yml'))
@@ -8,6 +8,7 @@ describe LucidWorks::Associations do
8
8
  class ::Blog < LucidWorks::Base
9
9
  has_many :posts
10
10
  has_one :homepage
11
+ has_one :launch_party, :has_content => false
11
12
  end
12
13
  @blog = ::Blog.new(:parent => @server)
13
14
 
@@ -19,30 +20,56 @@ describe LucidWorks::Associations do
19
20
  self.singleton = true
20
21
  belongs_to :blog
21
22
  end
23
+
24
+ class ::LaunchParty < LucidWorks::Base
25
+ self.singleton = true
26
+ belongs_to :blog
27
+ end
22
28
  end
23
29
 
24
30
  describe ".has_one" do
25
- describe "#<child>!" do
26
- it "should call Child.find" do
27
- Homepage.should_receive(:find).with(:parent => @blog)
28
- @blog.homepage!
31
+ context "without content" do
32
+ describe "#<child>" do
33
+ it "should build a new model, and not call REST API to retrieve" do
34
+ LaunchParty.should_not_receive(:find)
35
+ launch_party = @blog.launch_party
36
+
37
+ launch_party.should be_a(LaunchParty)
38
+ launch_party.should be_persisted # All singletons are always persisted
39
+ end
29
40
  end
30
41
  end
31
42
 
32
- describe "#<child>" do
33
- it "should call child! the first time then return the cached value thereafter" do
34
- mock_homepage = double('homepage')
35
- Homepage.should_receive(:find).once.and_return(mock_homepage)
36
- @blog.homepage.should == mock_homepage
37
- @blog.homepage.should == mock_homepage
43
+ context "with content" do
44
+ describe "#<child>!" do
45
+ it "should call Child.find" do
46
+ Homepage.should_receive(:find).with(:parent => @blog)
47
+ @blog.homepage!
48
+ end
49
+ end
50
+
51
+ describe "#<child>" do
52
+ it "should call child! the first time then return the cached value thereafter" do
53
+ mock_homepage = double('homepage')
54
+ Homepage.should_receive(:find).once.and_return(mock_homepage)
55
+ @blog.homepage.should == mock_homepage
56
+ @blog.homepage.should == mock_homepage
57
+ end
58
+ end
59
+
60
+ describe "#build_<child>" do
61
+ it "should create a new child with persisted = true" do
62
+ homepage = @blog.build_homepage
63
+ homepage.should be_a(Homepage)
64
+ homepage.should be_persisted
65
+ end
38
66
  end
39
67
  end
68
+ end
40
69
 
41
- describe "#build_<child>" do
70
+ describe ".has_singleton" do
71
+ describe "#<child>" do
42
72
  it "should create a new child with persisted = true" do
43
- homepage = @blog.build_homepage
44
- homepage.should be_a(Homepage)
45
- homepage.should be_persisted
46
73
  end
47
74
  end
48
75
  end
@@ -6,19 +6,100 @@ describe LucidWorks::Base do
6
6
  @server = LucidWorks::Server.new(fake_server)
7
7
  @fake_server_uri = "#{fake_server}/api"
8
8
 
9
+ @widget1 = { :id => 1, :name => 'wrench', :size => 'small' }
10
+ @widget2 = { :id => 2, :name => 'hammer', :size => 'medium' }
11
+ @widget3 = { :id => 3, :name => 'spanner', :size => 'large' }
12
+ @widgets = [@widget1, @widget2, @widget3]
13
+ WIDGET1_JSON = @widget1.to_json
14
+ WIDGET2_JSON = @widget2.to_json
15
+ WIDGETS_JSON = @widgets.to_json
16
+
9
17
  class Widget < LucidWorks::Base
10
18
  has_one :singleton_widget
11
19
  end
12
- WIDGET1_JSON = '{"id":1,"name":"widget1","size":"small"}'
13
- WIDGET2_JSON = '{"id":2,"name":"widget2","size":"medium"}'
14
- WIDGETS_JSON = "[#{WIDGET1_JSON},#{WIDGET2_JSON}]"
15
20
 
16
21
  class SingletonWidget < LucidWorks::Base
17
22
  self.singleton = true
18
23
  end
24
+
25
+ class WidgetWithoutSchema < LucidWorks::Base
26
+ end
27
+
28
+ class WidgetWithSchema < LucidWorks::Base
29
+ schema do
30
+ attribute :name
31
+ attribute :frooble
32
+ attribute :iambool, :boolean
33
+ end
34
+ end
19
35
  end
20
36
 
21
37
  describe "class methods" do
38
+
39
+ describe ".schema" do
40
+ context "for a class with a schema" do
41
+ it "should set has_schema" do
42
+ WidgetWithSchema.has_schema.should be_true
43
+ end
44
+
45
+ it "should have accessors for the attributes defined in the schema" do
46
+ [:name, :name=, :frooble, :frooble=].each do |method|
47
+ WidgetWithSchema.new(:parent => @server).should respond_to(method)
48
+ end
49
+ end
50
+
51
+ it "should create predicate reader for boolean attributes" do
52
+ WidgetWithSchema.new(:parent => @server).should respond_to(:iambool?)
53
+ end
54
+
55
+ it "should remember the attribute values" do
56
+ widget = WidgetWithSchema.new(:parent => @server)
57
+ widget.frooble = "foo"
58
+ widget.frooble.should == "foo"
59
+ end
60
+
61
+ it "should raise an error for an unknown attribute" do
62
+ widget = WidgetWithSchema.new(:parent => @server)
63
+ lambda {
64
+ widget.unknown_attribute
65
+ }.should raise_error NoMethodError
66
+ end
67
+ end
68
+
69
+ context "for a class without a schema" do
70
+ it "should return false for has_schema" do
71
+ WidgetWithoutSchema.has_schema.should be_false
72
+ end
73
+
74
+ it "should create accessors upon retrieval" do
75
+ widget = WidgetWithoutSchema.new(:parent => @server)
76
+ widget.should_not respond_to(:name)
77
+ widget.should_not respond_to(:size=)
78
+ RestClient.should_receive(:get).with("#{@fake_server_uri}/widget_without_schemas/1").and_return(WIDGET1_JSON)
79
+ widget = WidgetWithoutSchema.find(1, :parent => @server)
80
+ widget.should respond_to(:name)
81
+ widget.should respond_to(:size=)
82
+ end
83
+
84
+ it "should remember the attribute values" do
85
+ class Widget2WithoutSchema < LucidWorks::Base ; end # Define another to stop bleedover from the above test
86
+ RestClient.should_receive(:get).with("#{@fake_server_uri}/widget2_without_schemas/1").and_return(WIDGET1_JSON)
87
+ widget = Widget2WithoutSchema.find(1, :parent => @server)
88
+ widget.size = 71077345
89
+ widget.size.should == 71077345
90
+ end
91
+
92
+ it "should raise an error for an unknown attribute" do
93
+ class Widget3WithoutSchema < LucidWorks::Base ; end # Define another to stop bleedover from the above test
94
+ RestClient.should_receive(:get).with("#{@fake_server_uri}/widget3_without_schemas/1").and_return(WIDGET1_JSON)
95
+ widget = Widget3WithoutSchema.find(1, :parent => @server)
96
+ lambda {
97
+ widget.unknown_attribute
98
+ }.should raise_error NoMethodError
99
+ end
100
+ end
101
+ end
102
+
22
103
  describe ".new" do
23
104
  it "should require a hash argument" do
24
105
  lambda {
@@ -97,17 +178,24 @@ describe LucidWorks::Base do
97
178
  RestClient.should_receive(:get).with(correct_url).and_return(WIDGETS_JSON)
98
179
 
99
180
  widgets = Widget.find(:all, :parent => @server)
100
- widgets.size.should == 2
181
+ widgets.size.should == @widgets.size
101
182
 
102
- widget1 = widgets.find { |c| c.id == 1 }
183
+ widget1 = widgets.find { |c| c.id == @widget1[:id] }
103
184
  widget1.should be_a(Widget)
104
- widget1.name.should == 'widget1'
105
- widget1.size.should == 'small'
185
+ widget1.name.should == @widget1[:name]
186
+ widget1.size.should == @widget1[:size]
106
187
 
107
- widget2 = widgets.find { |c| c.id == 2 }
188
+ widget2 = widgets.find { |c| c.id == @widget3[:id] }
108
189
  widget2.should be_a(Widget)
109
- widget2.name.should == 'widget2'
110
- widget2.size.should == 'medium'
190
+ widget2.name.should == @widget3[:name]
191
+ widget2.size.should == @widget3[:size]
192
+ end
193
+
194
+ it "should sort items if given option :order" do
195
+ RestClient.stub(:get) { WIDGETS_JSON }
196
+ Widget.find(:all, :parent => @server, :order => :id).map(&:id).should == [1,2,3]
197
+ Widget.find(:all, :parent => @server, :order => :name).map(&:name).should == %w{ hammer spanner wrench }
198
+ Widget.find(:all, :parent => @server, :order => :size).map(&:size).should == %w{ large medium small }
111
199
  end
112
200
  end
113
201
 
@@ -116,10 +204,18 @@ describe LucidWorks::Base do
116
204
  correct_url = "#{@fake_server_uri}/widgets/1"
117
205
  RestClient.should_receive(:get).with(correct_url).and_return(WIDGET1_JSON)
118
206
 
119
- widget = Widget.find(:one, 1, :parent => @server)
207
+ widget = Widget.find(:one, @widget1[:id], :parent => @server)
120
208
  widget.should be_a(Widget)
121
- widget.name.should == 'widget1'
122
- widget.size.should == 'small'
209
+ widget.name.should == @widget1[:name]
210
+ widget.size.should == @widget1[:size]
211
+ end
212
+
213
+ it "should sanitize any keys that cannot be represented as a Ruby identifier" do
214
+ RestClient.should_receive(:get).
215
+ with("#{@fake_server_uri}/widgets/1").
216
+ and_return('{"id":1,"bad.key":"period should map to underscore"}')
217
+ widget = Widget.find(:one, 1, :parent => @server)
218
+ widget.bad_key == "period should map to underscore"
123
219
  end
124
220
  end
125
221
 
@@ -130,8 +226,8 @@ describe LucidWorks::Base do
130
226
 
131
227
  widget = SingletonWidget.find(:singleton, :parent => @server)
132
228
  widget.should be_a(SingletonWidget)
133
- widget.name.should == 'widget1'
134
- widget.size.should == 'small'
229
+ widget.name.should == @widget1[:name]
230
+ widget.size.should == @widget1[:size]
135
231
  end
136
232
  end
137
233
 
@@ -141,12 +237,14 @@ describe LucidWorks::Base do
141
237
  RestClient.should_receive(:get).with("#{@fake_server_uri}/widgets").and_return(WIDGETS_JSON)
142
238
  mock_singleton1 = double('singleton widget1')
143
239
  mock_singleton2 = double('singleton widget2')
144
- SingletonWidget.should_receive(:find).and_return(mock_singleton1, mock_singleton2)
240
+ mock_singleton3 = double('singleton widget3')
241
+ SingletonWidget.should_receive(:find).and_return(mock_singleton1, mock_singleton2, mock_singleton3)
145
242
 
146
243
  widgets = Widget.find(:all, :include => :singleton_widget, :parent => @server)
147
244
 
148
- widgets.first.singleton_widget.should == mock_singleton1
149
- widgets.last.singleton_widget.should == mock_singleton2
245
+ widgets[0].singleton_widget.should == mock_singleton1
246
+ widgets[1].singleton_widget.should == mock_singleton2
247
+ widgets[2].singleton_widget.should == mock_singleton3
150
248
  end
151
249
  end
152
250
 
@@ -161,17 +259,21 @@ describe LucidWorks::Base do
161
259
  RestClient.should_receive(:get).with("#{@fake_server_uri}/widgets").and_return(WIDGETS_JSON)
162
260
  mock_singleton1 = double('singleton widget1')
163
261
  mock_singleton2 = double('singleton widget2')
262
+ mock_singleton3 = double('singleton widget3')
164
263
  mock_other_widgets_1 = double('other widgets 1')
165
264
  mock_other_widgets_2 = double('other widgets 2')
166
- SingletonWidget.should_receive(:find).and_return(mock_singleton1, mock_singleton2)
167
- OtherWidget.should_receive(:find).and_return(mock_other_widgets_1, mock_other_widgets_2)
265
+ mock_other_widgets_3 = double('other widgets 3')
266
+ SingletonWidget.should_receive(:find).and_return(mock_singleton1, mock_singleton2, mock_singleton3)
267
+ OtherWidget.should_receive(:find).and_return(mock_other_widgets_1, mock_other_widgets_2, mock_other_widgets_3)
168
268
 
169
269
  widgets = Widget.find(:all, :include => [:singleton_widget, :other_widgets], :parent => @server)
170
270
 
171
- widgets.first.singleton_widget.should == mock_singleton1
172
- widgets.first.other_widgets.should == mock_other_widgets_1
173
- widgets.last.singleton_widget.should == mock_singleton2
174
- widgets.last.other_widgets.should == mock_other_widgets_2
271
+ widgets[0].singleton_widget.should == mock_singleton1
272
+ widgets[0].other_widgets.should == mock_other_widgets_1
273
+ widgets[1].singleton_widget.should == mock_singleton2
274
+ widgets[1].other_widgets.should == mock_other_widgets_2
275
+ widgets[2].singleton_widget.should == mock_singleton3
276
+ widgets[2].other_widgets.should == mock_other_widgets_3
175
277
  end
176
278
  end
177
279
  end
@@ -194,71 +296,83 @@ describe LucidWorks::Base do
194
296
  Widget.first(:parent => @server).should == mock_coll1
195
297
  end
196
298
  end
197
- end
198
-
199
- describe "instance methods" do
200
-
201
- describe "collection_url" do
202
- it "should generate a url from the server and its name" do
203
- widget = Widget.new(:parent => @server, :id => 1234)
204
- widget.collection_url.should == "#{@fake_server_uri}/widgets"
205
- end
206
- end
207
299
 
208
- describe "member_url" do
209
- it "should generate a url from the server, its name and its id" do
210
- widget = Widget.new(:parent => @server, :id => 1234)
211
- widget.member_url.should == "#{@fake_server_uri}/widgets/1234"
212
- end
213
- end
214
-
215
- describe "attributes" do
216
- before { @widget = Widget.new(:known_attr => 'known_value', :nil_attr => nil, :parent => @server) }
217
-
218
- describe '#attr=' do
219
- context "for an unknown attr" do
220
- it "should set an attribute" do
221
- @widget.new_attr = "fake_value"
222
- @widget.new_attr.should == 'fake_value'
300
+ context "for a model with a schema" do
301
+ before :all do
302
+ class WidgetWithBigSchema < LucidWorks::Base
303
+ schema do
304
+ attribute :astring, :string
305
+ attribute :large_number, :integer
306
+ attribute :iambool, :boolean
307
+ #attribute :when, :iso8601
223
308
  end
224
309
  end
225
- context "for a known attr" do
226
- it "should set an attribute" do
227
- @widget.known_attr = "new_value"
228
- @widget.known_attr.should == 'new_value'
310
+ class TrueClass
311
+ def to_yesno
312
+ self ? "yes" : "no"
229
313
  end
230
314
  end
231
315
  end
232
316
 
233
- describe "#attr" do
234
- context "for an unknown attr" do
235
- it "should raise an error" do
236
- lambda {
237
- @widget.bogus_attr
238
- }.should raise_error("Unknown attribute: 'bogus_attr'")
317
+ describe ".human_attribute_value(attribute, value)" do
318
+
319
+ context "for an attribute described as :boolean in the schema" do
320
+ it "should to_yesno the attribute" do
321
+ WidgetWithBigSchema.human_attribute_value(:iambool, true).should == "yes"
239
322
  end
240
323
  end
241
- context "for a known attr" do
242
- it "should return the attr" do
243
- @widget.known_attr.should == 'known_value'
324
+
325
+ context "for an attribute described as :integer in the schema" do
326
+ before do
327
+ # So we can test without actually needing ActionPack
328
+ class LucidWorks::Base
329
+ def self.number_with_delimiter(x)
330
+ x.to_s.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
331
+ end
332
+ end
244
333
  end
245
- end
246
- end
247
334
 
248
- describe "#attr?" do
249
- context "for an unknown attr" do
250
- it "should raise an error" do
251
- lambda {
252
- @widget.bogus_attr?
253
- }.should raise_error("Unknown attribute: 'bogus_attr'")
335
+ it "should number_with_delimeter the attribute" do
336
+ WidgetWithBigSchema.human_attribute_value(:large_number, 12345678).should == "12,345,678"
254
337
  end
255
338
  end
256
- context "for a known attr" do
257
- it "should return true or false" do
258
- @widget.known_attr?.should be_true
259
- @widget.nil_attr?.should be_false
339
+
340
+ context "for an attributed described as :string in the schema" do
341
+ it "should just to_s the attribute" do
342
+ WidgetWithBigSchema.human_attribute_value(:astring, true).should == "true"
260
343
  end
261
344
  end
345
+
346
+ #context "for an attribute described as :iso8601 in the schema" do
347
+ # it "should convert it to localtime to_s(:short)" do
348
+ # @widget.human_attribute_value(:when).should == "19 Mar 10:40"
349
+ # end
350
+ #end
351
+ end
352
+
353
+ describe ".to_select(attribute)" do
354
+ it "should create an array of arrays suitable for a form select" do
355
+ # Use Collection::Settings because we know de_duplication as translations
356
+ LucidWorks::Collection::Settings.to_select(:de_duplication).should ==
357
+ [['off', 'Off'], ['overwrite', 'Overwrite'], ['tag', 'Tag']]
358
+ end
359
+ end
360
+ end
361
+ end
362
+
363
+ describe "instance methods" do
364
+
365
+ describe "collection_url" do
366
+ it "should generate a url from the server and its name" do
367
+ widget = Widget.new(:parent => @server, :id => 1234)
368
+ widget.collection_url.should == "#{@fake_server_uri}/widgets"
369
+ end
370
+ end
371
+
372
+ describe "member_url" do
373
+ it "should generate a url from the server, its name and its id" do
374
+ widget = Widget.new(:parent => @server, :id => 1234)
375
+ widget.member_url.should == "#{@fake_server_uri}/widgets/1234"
262
376
  end
263
377
  end
264
378
 
@@ -266,7 +380,7 @@ describe LucidWorks::Base do
266
380
  context "for a new model" do
267
381
  context "with valid attributes" do
268
382
  before do
269
- @widget_attrs = { :name => 'widget3', :size => 'large' }
383
+ @widget_attrs = { :name => 'widget4', :size => 'extra medium' }
270
384
  @widget = Widget.new @widget_attrs.merge(:parent => @server)
271
385
  end
272
386
 
@@ -360,6 +474,20 @@ describe LucidWorks::Base do
360
474
  end
361
475
  end
362
476
 
477
+ describe "#update_attributes" do
478
+ it "should update the model with the supplied attributes then call #save" do
479
+ widget_attrs = { :id => 123, :name => 'widget3', :size => 'large' }
480
+ widget = Widget.new widget_attrs.merge(:parent => @server)
481
+ widget.persisted = true
482
+ widget.should_receive(:save)
483
+
484
+ widget.update_attributes(:name => 'new_name', :size => 'new_size')
485
+
486
+ widget.name.should == 'new_name'
487
+ widget.size.should == 'new_size'
488
+ end
489
+ end
490
+
363
491
  describe "#destroy" do
364
492
  it "should call RestClient.delete with the appropriate URL" do
365
493
  widget = Widget.new(:parent => @server)
@@ -368,6 +496,12 @@ describe LucidWorks::Base do
368
496
  widget.destroy
369
497
  end
370
498
  end
499
+
500
+ describe "#human_attribute_value" do
501
+ it "should call class.human_attribute_value with attribute name and value" do
502
+ #TODO
503
+ end
504
+ end
371
505
  end
372
506
 
373
507
  describe "for a model with primary key other than 'id'" do
@@ -126,8 +126,8 @@ describe LucidWorks::Collection do
126
126
  @collection.should be_valid
127
127
  @ds1 = LucidWorks::Datasource.create(
128
128
  :collection => @collection,
129
- :crawler => "lucid.aperture",
130
- :type => LucidWorks::Datasource::TYPES[:FileSystemDataSource][:type],
129
+ :crawler => LucidWorks::Datasource::CRAWLERS['file'],
130
+ :type => "file",
131
131
  :name => "US zoneinfo",
132
132
  :path => "/usr/share/zoneinfo/US",
133
133
  :crawl_depth => 1
@@ -135,8 +135,8 @@ describe LucidWorks::Collection do
135
135
  @ds1.should be_valid
136
136
  @ds2 = LucidWorks::Datasource.create(
137
137
  :collection => @collection,
138
- :crawler => "lucid.aperture",
139
- :type => LucidWorks::Datasource::TYPES[:WebDataSource][:type],
138
+ :crawler => LucidWorks::Datasource::CRAWLERS['web'],
139
+ :type => 'web',
140
140
  :name => "nothing_com",
141
141
  :url => "http://nothing.com/",
142
142
  :crawl_depth => 1
@@ -228,4 +228,16 @@ describe LucidWorks::Collection do
228
228
  @collection.empty!
229
229
  end
230
230
  end
231
+
232
+ describe "#fields" do
233
+ before do
234
+ @collection = @server.collections.first
235
+ end
236
+ it "should return a valid LucidWorks::Collection::Field" do
237
+ @collection.should respond_to(:field)
238
+ field = @collection.field('body')
239
+ field.should be_a(LucidWorks::Field)
240
+ field.should respond_to(:field_type)
241
+ end
242
+ end
231
243
  end