lucid_works 0.6.22 → 0.6.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -314,30 +314,29 @@ module LucidWorks
314
314
 
315
315
  def save
316
316
  _run_save_callbacks do
317
- if valid?
318
- ActiveSupport::Notifications.instrument("lucid_works.request") do |payload|
319
- method, uri = persisted? ? [:put, member_url] : [:post, collection_url]
320
- data = encode
321
- payload[:method] = method
322
- payload[:uri] = uri
323
- payload[:data] = data
324
- begin
325
- response = RestClient.send(method, uri, data, :content_type => :json)
326
- payload[:response] = response
327
- @persisted = true
328
- load_attributes_from_json_string(response)
329
- true
330
- rescue RestClient::Conflict, # 409
331
- RestClient::UnprocessableEntity, # 422
332
- RestClient::InternalServerError => e # 500
333
- payload[:exceptionion] = e
334
- attach_errors_to_model(e.response)
335
- false
336
- rescue RestClient::Exception => exception
337
- # Tack on what we were doing when we got the exception, then send it on up
338
- exception.message = "#{exception.message} while performing #{payload[:method]} #{payload[:uri]}"
339
- raise exception
340
- end
317
+ return false unless valid?
318
+ ActiveSupport::Notifications.instrument("lucid_works.request") do |payload|
319
+ method, uri = persisted? ? [:put, member_url] : [:post, collection_url]
320
+ data = encode
321
+ payload[:method] = method
322
+ payload[:uri] = uri
323
+ payload[:data] = data
324
+ begin
325
+ response = RestClient.send(method, uri, data, :content_type => :json)
326
+ payload[:response] = response
327
+ @persisted = true
328
+ load_attributes_from_json_string(response)
329
+ true
330
+ rescue RestClient::Conflict, # 409
331
+ RestClient::UnprocessableEntity, # 422
332
+ RestClient::InternalServerError => e # 500
333
+ payload[:exceptionion] = e
334
+ attach_errors_to_model(e.response)
335
+ false
336
+ rescue RestClient::Exception => exception
337
+ # Tack on what we were doing when we got the exception, then send it on up
338
+ exception.message = "#{exception.message} while performing #{payload[:method]} #{payload[:uri]}"
339
+ raise exception
341
340
  end
342
341
  end
343
342
  end
@@ -64,7 +64,7 @@ module LucidWorks
64
64
  ]
65
65
 
66
66
  validates_presence_of :name
67
- validates_each :name, :allow_blank => true do |model, attr, value|
67
+ validates_each :name, :unless => :persisted?, :allow_blank => true do |model, attr, value|
68
68
  model.errors.add(attr, 'must be unique') if model.collection.fields.any? {|f| f.name == value }
69
69
  end
70
70
  validates_each :short_field_boost do |model, attr, value|
@@ -90,5 +90,9 @@ module LucidWorks
90
90
  def self.t_field_type(type)
91
91
  I18n.translate(type, :scope => 'activemodel.models.lucid_works.collection.field.field_type')
92
92
  end
93
+
94
+ def initialize(options)
95
+ super(options.reverse_merge(:omit_tf => false, :short_field_boost => 'high'))
96
+ end
93
97
  end
94
98
  end
@@ -1,3 +1,3 @@
1
1
  module LucidWorks
2
- VERSION = "0.6.22"
2
+ VERSION = "0.6.23"
3
3
  end
@@ -426,6 +426,10 @@ describe LucidWorks::Base do
426
426
 
427
427
  describe "#save" do
428
428
  context "for a new model" do
429
+ before(:each) do
430
+ RestClient.stub(:post)
431
+ end
432
+
429
433
  context "with valid attributes" do
430
434
  before do
431
435
  @widget_attrs = { :name => 'widget4', :size => 'extra medium' }
@@ -440,53 +444,68 @@ describe LucidWorks::Base do
440
444
  end
441
445
 
442
446
  it "should set persisted" do
443
- RestClient.should_receive(:post)
444
447
  @widget.save
445
448
  @widget.should be_persisted
446
449
  end
450
+
451
+ it "returns true" do
452
+ @widget.save
453
+ @widget.should be_true
454
+ end
447
455
  end
448
456
 
449
- context "with invalid attributes" do
450
- before :all do
451
- @widget_attrs = { :name => '', :size => ''}
452
- ERROR_422_RESPONSE = '{"errors":[{"message":"name is a required key","key":"name"},{"message":"name must consist of only A-Z a-z 0-9 - _","key":"name"}],"http_status_name":"Unprocessable Entity","http_status_code":422}'
457
+ context "with an API error" do
458
+ before do
453
459
  RestClient.stub(:post) {
454
460
  e = RestClient::UnprocessableEntity.new
455
- e.response = ERROR_422_RESPONSE
461
+ e.response = '{"errors":[{"message":"name is a required key","key":"name"},{"message":"name must consist of only A-Z a-z 0-9 - _","key":"name"}],"http_status_name":"Unprocessable Entity","http_status_code":422}'
456
462
  raise e
457
463
  }
458
-
459
- @widget = Widget.new @widget_attrs.merge(:parent => @server)
460
- @returncode = @widget.save
464
+ @widget = Widget.new(:name => '', :size => '', :parent => @server)
461
465
  end
462
-
466
+
463
467
  it "should set errors on the model" do
468
+ @widget.save
464
469
  @widget.errors.should_not be_empty
465
470
  @widget.errors['name'].should_not be_empty
466
471
  end
467
472
 
468
473
  it "should not set persisted" do
474
+ @widget.save
469
475
  @widget.should_not be_persisted
470
476
  end
471
477
 
472
- it "should return false" do
473
- @returncode.should be_false
478
+ it "returns false" do
479
+ @widget.save.should be_false
474
480
  end
475
481
  end
476
482
 
477
- describe "local validation" do
483
+ describe "with invalid attributes" do
484
+ class WidgetRequiringName < LucidWorks::Base
485
+ validates_presence_of :name
486
+ end
487
+
478
488
  before do
479
- class WidgetRequiringName < LucidWorks::Base
480
- validates_presence_of :name
481
- end
489
+ @widget = WidgetRequiringName.new(:parent => @server)
490
+ end
491
+
492
+ it "is invalid" do
493
+ @widget.save
494
+ @widget.should_not be_valid
495
+ end
496
+
497
+ it "returns the validation errors" do
498
+ @widget.save
499
+ @widget.errors[:name].should == ["can't be blank"]
482
500
  end
483
501
 
484
- it "should validate presence of" do
485
- widget = WidgetRequiringName.new(:parent => @server)
502
+ it "doesn't post to the REST API" do
486
503
  RestClient.should_not_receive(:post)
487
- widget.should_not be_valid
488
- widget.errors[:name].should == ["can't be blank"]
489
- widget.save
504
+ @widget.save
505
+ end
506
+
507
+ it "returns false" do
508
+ @widget.save.should be_false
490
509
  end
491
510
  end
492
511
  end
@@ -615,6 +634,10 @@ describe LucidWorks::Base do
615
634
  widget.name.should == 'new_name'
616
635
  widget.size.should == 'new_size'
617
636
  end
637
+
638
+ it "returns false" do
639
+
640
+ end
618
641
  end
619
642
 
620
643
  describe "#destroy" do
@@ -11,68 +11,84 @@ describe LucidWorks::Field do
11
11
  LucidWorks::Field.new(:parent => @collection).should be_a(LucidWorks::Base)
12
12
  end
13
13
 
14
+ describe "default attribute values" do
15
+ subject { LucidWorks::Field.new(:parent => @collection) }
16
+
17
+ it { subject.omit_tf.should be_false }
18
+ it { subject.short_field_boost.should == 'high' }
19
+ end
20
+
14
21
  describe "validations" do
15
- context :name do
16
- it "is required" do
17
- field = LucidWorks::Field.new(:parent => @collection)
18
- field.should_not be_valid
19
- field.errors[:name].should == ["can't be blank"]
22
+ context "for a new field" do
23
+ context :name do
24
+ it "is required" do
25
+ field = LucidWorks::Field.new(:parent => @collection)
26
+ field.should_not be_valid
27
+ field.errors[:name].should == ["can't be blank"]
28
+ end
29
+
30
+ it "needs to be unique" do
31
+ field = LucidWorks::Field.new(:parent => @collection, :name => 'data_source')
32
+ field.should_not be_valid
33
+ field.errors[:name].should == ["must be unique"]
34
+ end
20
35
  end
21
-
22
- it "needs to be unique" do
23
- field = LucidWorks::Field.new(:parent => @collection, :name => 'data_source')
24
- field.should_not be_valid
25
- field.errors[:name].should == ["must be unique"]
36
+
37
+ context :short_field_boost do
38
+ it "cannot be set to 'none' for a non-indexed field" do
39
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :short_field_boost => 'none').tap do |field|
40
+ field.should_not be_valid
41
+ field.errors[:short_field_boost].should == ['cannot be set to "none" for a non-indexed field']
42
+ end
43
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :short_field_boost => true).should be_valid
44
+ end
26
45
  end
27
- end
28
-
29
- context :short_field_boost do
30
- it "cannot be set to 'none' for a non-indexed field" do
31
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :short_field_boost => 'none').tap do |field|
32
- field.should_not be_valid
33
- field.errors[:short_field_boost].should == ['cannot be set to "none" for a non-indexed field']
46
+
47
+ context :include_in_results do
48
+ it "requires the field to be stored" do
49
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => false, :include_in_results => true).tap do |field|
50
+ field.should_not be_valid
51
+ field.errors[:include_in_results].should == ["a field must be stored to be included in results"]
52
+ end
53
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => true, :include_in_results => true).should be_valid
34
54
  end
35
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :short_field_boost => true).should be_valid
36
55
  end
37
- end
38
56
 
39
- context :include_in_results do
40
- it "requires the field to be stored" do
41
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => false, :include_in_results => true).tap do |field|
42
- field.should_not be_valid
43
- field.errors[:include_in_results].should == ["a field must be stored to be included in results"]
57
+ context :highlight do
58
+ it "requires the field to be stored" do
59
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => false, :highlight => true).tap do |field|
60
+ field.should_not be_valid
61
+ field.errors[:highlight].should == ["a field must be stored to be highlighted"]
62
+ end
63
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => true, :highlighted => true).should be_valid
44
64
  end
45
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => true, :include_in_results => true).should be_valid
46
65
  end
47
- end
48
66
 
49
- context :highlight do
50
- it "requires the field to be stored" do
51
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => false, :highlight => true).tap do |field|
52
- field.should_not be_valid
53
- field.errors[:highlight].should == ["a field must be stored to be highlighted"]
67
+ context :facet do
68
+ it "requires the field to be indexed" do
69
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :facet => true).tap do |field|
70
+ field.should_not be_valid
71
+ field.errors[:facet].should == ["a field must be indexed to be facetable"]
72
+ end
73
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :facet => true).should be_valid
54
74
  end
55
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => true, :highlighted => true).should be_valid
56
75
  end
57
- end
58
76
 
59
- context :facet do
60
- it "requires the field to be indexed" do
61
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :facet => true).tap do |field|
62
- field.should_not be_valid
63
- field.errors[:facet].should == ["a field must be indexed to be facetable"]
77
+ context :use_in_find_similar do
78
+ it "requires the field to be indexed" do
79
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :use_in_find_similar => true).tap do |field|
80
+ field.should_not be_valid
81
+ field.errors[:use_in_find_similar].should == ["a field must be indexed for it to be used for find-similar"]
82
+ end
83
+ LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :use_in_find_similar => true).should be_valid
64
84
  end
65
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :facet => true).should be_valid
66
85
  end
67
86
  end
68
87
 
69
- context :use_in_find_similar do
70
- it "requires the field to be indexed" do
71
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :use_in_find_similar => true).tap do |field|
72
- field.should_not be_valid
73
- field.errors[:use_in_find_similar].should == ["a field must be indexed for it to be used for find-similar"]
74
- end
75
- LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :use_in_find_similar => true).should be_valid
88
+ context "for an existing field" do
89
+ it "doesn't validate the name's uniqueness" do
90
+ field = LucidWorks::Field.find('body', :parent => @collection)
91
+ field.should be_valid
76
92
  end
77
93
  end
78
94
  end
metadata CHANGED
@@ -1,101 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lucid_works
3
- version: !ruby/object:Gem::Version
4
- version: 0.6.22
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.6.23
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Sam Pierson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-24 00:00:00.000000000 -07:00
12
+
13
+ date: 2011-06-28 00:00:00 -07:00
13
14
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
16
17
  name: activesupport
17
- requirement: &2161726780 !ruby/object:Gem::Requirement
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
18
20
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '3'
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "3"
23
25
  type: :runtime
24
- prerelease: false
25
- version_requirements: *2161726780
26
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
27
28
  name: activemodel
28
- requirement: &2161726280 !ruby/object:Gem::Requirement
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
29
31
  none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '3'
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "3"
34
36
  type: :runtime
35
- prerelease: false
36
- version_requirements: *2161726280
37
- - !ruby/object:Gem::Dependency
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
38
39
  name: rest-client
39
- requirement: &2161725820 !ruby/object:Gem::Requirement
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
40
42
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
44
46
  version: 1.6.1
45
47
  type: :runtime
46
- prerelease: false
47
- version_requirements: *2161725820
48
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
49
50
  name: json
50
- requirement: &2161725440 !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
51
53
  none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
56
58
  type: :runtime
57
- prerelease: false
58
- version_requirements: *2161725440
59
- - !ruby/object:Gem::Dependency
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
60
61
  name: rsolr
61
- requirement: &2161724980 !ruby/object:Gem::Requirement
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
62
64
  none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
67
69
  type: :runtime
68
- prerelease: false
69
- version_requirements: *2161724980
70
- - !ruby/object:Gem::Dependency
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
71
72
  name: rsolr-ext
72
- requirement: &2161724560 !ruby/object:Gem::Requirement
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
73
75
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
78
80
  type: :runtime
79
- prerelease: false
80
- version_requirements: *2161724560
81
- - !ruby/object:Gem::Dependency
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
82
83
  name: nokogiri
83
- requirement: &2161724140 !ruby/object:Gem::Requirement
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
84
86
  none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
89
91
  type: :runtime
90
- prerelease: false
91
- version_requirements: *2161724140
92
+ version_requirements: *id007
92
93
  description: Ruby wrapper for the LucidWorks REST API
93
- email:
94
+ email:
94
95
  - sam.pierson@lucidimagination.com
95
96
  executables: []
97
+
96
98
  extensions: []
99
+
97
100
  extra_rdoc_files: []
98
- files:
101
+
102
+ files:
99
103
  - .autotest
100
104
  - .gitignore
101
105
  - .rspec
@@ -165,31 +169,34 @@ files:
165
169
  - spec/lib/lucid_works/utils_spec.rb
166
170
  - spec/spec_helper.rb
167
171
  has_rdoc: true
168
- homepage: ''
172
+ homepage: ""
169
173
  licenses: []
174
+
170
175
  post_install_message:
171
176
  rdoc_options: []
172
- require_paths:
177
+
178
+ require_paths:
173
179
  - lib
174
- required_ruby_version: !ruby/object:Gem::Requirement
180
+ required_ruby_version: !ruby/object:Gem::Requirement
175
181
  none: false
176
- requirements:
177
- - - ! '>='
178
- - !ruby/object:Gem::Version
179
- version: '0'
180
- required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: "0"
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
187
  none: false
182
- requirements:
183
- - - ! '>='
184
- - !ruby/object:Gem::Version
185
- version: '0'
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: "0"
186
192
  requirements: []
193
+
187
194
  rubyforge_project: lucid_works
188
195
  rubygems_version: 1.6.2
189
196
  signing_key:
190
197
  specification_version: 3
191
198
  summary: Ruby wrapper for the LucidWorks REST API
192
- test_files:
199
+ test_files:
193
200
  - spec/lib/lucid_works/associations/has_many_spec.rb
194
201
  - spec/lib/lucid_works/associations/has_one_spec.rb
195
202
  - spec/lib/lucid_works/associations_spec.rb