lucid_works 0.4.9 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -271,6 +271,7 @@ A class may have a schema defined as follows:
271
271
  attributes :int2, :int3, :type => :integer
272
272
  attribute :string_with_values, :values => ['one', 'two']
273
273
  attribute :dontsendme, :omit_during_update => true
274
+ attribute :sendnull, :string, :nil_when_blank => true
274
275
  end
275
276
  end
276
277
 
@@ -113,3 +113,16 @@ en:
113
113
  numUnchanged: Unchanged docs
114
114
  numFailed: Failed docs
115
115
  numTotal: Total docs
116
+ sharepointUrl: SharePoint URL
117
+ connectorType: Connector Type
118
+ authorization: Authorization
119
+ username: Username
120
+ password: Password
121
+ domain: Domain
122
+ mySiteBaseURL: MySite URL
123
+ includedURls: Included URLs
124
+ excludedURls: Excluded URLs
125
+ kdcserver: Kerberos KDC server
126
+ useSPSearchVisibility: Use SP Search Visibility
127
+ aliases: Site Aliases Mappings
128
+
@@ -39,6 +39,7 @@ module LucidWorks
39
39
  attr_writer :persisted # :nodoc:
40
40
  attr_accessor :raw_response # :nodoc:
41
41
  attr_accessor :response_data # :nodoc:
42
+ attr_reader :attributes # :nodoc:
42
43
 
43
44
  define_model_callbacks :save, :only => [:before, :after]
44
45
 
@@ -268,7 +269,9 @@ module LucidWorks
268
269
  @persisted = true
269
270
  load_attributes_from_json_string(response)
270
271
  true
271
- rescue RestClient::UnprocessableEntity, RestClient::Conflict => e
272
+ rescue RestClient::Conflict, # 409
273
+ RestClient::UnprocessableEntity, # 422
274
+ RestClient::InternalServerError => e # 500
272
275
  payload[:exception] = e
273
276
  attach_errors_to_model(e.response)
274
277
  false
@@ -381,6 +384,7 @@ module LucidWorks
381
384
  if data.is_a?(Hash) && data['errors']
382
385
  data['errors'].each do |error|
383
386
  key = error['key'].blank? ? 'base' : error['key']
387
+ # When core implements FOCUS-2262 start checking for error['code'] and lookup a translation.
384
388
  self.errors.add(key, error['message'])
385
389
  end
386
390
  end
@@ -10,6 +10,7 @@ module LucidWorks
10
10
  # common
11
11
  attributes :name, :type, :crawler
12
12
  attributes :crawl_depth, :max_bytes, :max_docs, :type => :integer
13
+ #attribute :commitWithin, :integer
13
14
  attribute :include_paths
14
15
  attribute :exclude_paths
15
16
  attribute :mapping # Hash
@@ -20,12 +21,26 @@ module LucidWorks
20
21
  # file
21
22
  attribute :path
22
23
  attribute :follow_links, :boolean
23
-
24
- # new un-evaluated
25
- # attributes :commitWithin
24
+ # sharepoint
25
+ attribute :sharepointUrl
26
+ attribute :connectorType
27
+ attribute :authorization
28
+ attribute :username
29
+ attribute :password
30
+ attribute :domain
31
+ attribute :mySiteBaseURL, :string, :nil_when_blank => true
32
+ attribute :includedURls
33
+ attribute :excludedURls
34
+ attribute :kdcserver
35
+ attribute :useSPSearchVisibility, :boolean
36
+ attribute :aliases
37
+ # external
38
+ attribute :source
39
+ attribute :source_type
26
40
  end
27
41
 
28
- validates_presence_of :type, :crawler, :name, :crawl_depth
42
+ validates_presence_of :type, :crawler, :name
43
+ validates_presence_of :crawl_depth, :unless => lambda { |d| %w{external sharepoint}.include?(d.type) }
29
44
  validates_numericality_of :max_bytes, :allow_blank => true
30
45
  validates_presence_of :url, :if => lambda { |d| d.type == 'web' }
31
46
 
@@ -37,6 +52,8 @@ module LucidWorks
37
52
  # Later we may change these to be arrays if we decide to support more than one choice
38
53
  # e.g. :web => ['lucid.aperture', 'nutch']
39
54
  :file => 'lucid.aperture',
55
+ :lwelogs => 'licid.lwelogs',
56
+ :external => 'lucid.external',
40
57
  :web => 'lucid.aperture',
41
58
  :solrxml => 'lucid.solrxml',
42
59
  :jdbc => 'lucid.jdbc',
@@ -10,4 +10,10 @@ class Time
10
10
 
11
11
  alias_method_chain :iso8601, :support_for_timezones_without_colons
12
12
  end
13
+
14
+ def iso8601_with_support_for_timezones_without_colons
15
+ self.iso8601_without_support_for_timezones_without_colons.gsub /([+-])(\d\d):(\d\d)$/, '\1\2\3'
16
+ end
17
+
18
+ alias_method_chain :iso8601, :support_for_timezones_without_colons
13
19
  end
@@ -2,6 +2,7 @@ module LucidWorks
2
2
 
3
3
  # Specify an attributes for a model.
4
4
  class Schema < ActiveSupport::HashWithIndifferentAccess
5
+ ATTRIBUTES_TYPES = [ :string, :integer, :boolean ]
5
6
 
6
7
  def initialize
7
8
  @primary_key = :id
@@ -24,6 +25,7 @@ module LucidWorks
24
25
  alias :dynamic_attributes? :dynamic_attributes
25
26
 
26
27
  def attribute(name, type=:string, options={})
28
+ raise "Unknown attribute type: #{type.inspect}" unless ATTRIBUTES_TYPES.include?(type)
27
29
  primary_key name if options.delete(:primary_key)
28
30
  self[name] = options.merge(:type => type)
29
31
  end
@@ -73,7 +75,8 @@ module LucidWorks
73
75
  end # end
74
76
  EOF
75
77
 
76
- if self[attribute][:type] == :boolean
78
+ case self[attribute][:type]
79
+ when :boolean
77
80
  klass.class_eval <<-EOF, __FILE__, __LINE__+1
78
81
  def #{attribute}? # def foo?
79
82
  @attributes[:#{attribute}] # @attributes[:foo]
@@ -83,6 +86,13 @@ module LucidWorks
83
86
  @attributes[:#{attribute}] = to_bool(new_value) # @attributes[:foo] = to_bool(new_value)
84
87
  end # end
85
88
  EOF
89
+ when :string
90
+ klass.class_eval <<-EOF, __FILE__, __LINE__+1
91
+ def #{attribute}=(new_value) # def foo=(new_value)
92
+ new_value = nil if new_value.blank? && self.class.schema[:#{attribute}][:nil_when_blank]
93
+ @attributes[:#{attribute}] = new_value # @attributes[:foo] = new_value
94
+ end # end
95
+ EOF
86
96
  else
87
97
  klass.class_eval <<-EOF, __FILE__, __LINE__+1
88
98
  def #{attribute}=(new_value) # def foo=(new_value)
@@ -1,3 +1,3 @@
1
1
  module LucidWorks
2
- VERSION = "0.4.9"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -395,7 +395,6 @@ describe LucidWorks::Base do
395
395
  before :all do
396
396
  @widget_attrs = { :name => '', :size => ''}
397
397
  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}'
398
- # ERROR_500_RESPONSE = '{"errors":[{"message":"The server encountered an unexpected condition which prevented it from fulfilling the request","key":""}],"http_status_name":"Internal Server Error","http_status_code":500}'
399
398
  RestClient.stub(:post) {
400
399
  e = RestClient::UnprocessableEntity.new
401
400
  e.response = ERROR_422_RESPONSE
@@ -486,6 +485,67 @@ describe LucidWorks::Base do
486
485
  @widget_with_omit.save
487
486
  end
488
487
  end
488
+
489
+ describe "error processing" do
490
+ before do
491
+ @widget_attrs = { :foo => "bar", :bar => "baz" }
492
+ @widget = Widget.new @widget_attrs.merge(:parent => @server)
493
+ end
494
+
495
+ context "for an attempt that returns attr errors and global errors" do
496
+ before do
497
+ response = '{"errors":[{"message":"foo err 1","key":"foo"},' +
498
+ '{"message":"foo err 2","key":"foo"},' +
499
+ '{"message":"bar err 1","key":"bar"},' +
500
+ '{"message":"global err 1","key":""},' +
501
+ '{"message":"global err 2","key":""}],' +
502
+ '"http_status_name":"Unprocessable Entity","http_status_code":422}'
503
+ RestClient.stub(:post) {
504
+ e = RestClient::UnprocessableEntity.new
505
+ e.response = response
506
+ raise e
507
+ }
508
+ @widget.save.should be_false
509
+ end
510
+
511
+ it "should attach the attr errors to their respective attributes" do
512
+ @widget.errors[:foo].should == ["foo err 1", "foo err 2"]
513
+ @widget.errors[:bar].should == ["bar err 1"]
514
+ end
515
+
516
+ it "should attach global errors to :base" do
517
+ @widget.errors[:base].should == ["global err 1", "global err 2"]
518
+ end
519
+ end
520
+ end
521
+
522
+ describe "exception handling" do
523
+ before do
524
+ @widget_attrs = { :foo => "bar", :bar => "baz" }
525
+ @widget = Widget.new @widget_attrs.merge(:parent => @server)
526
+ end
527
+
528
+ it "should catch 409 errors" do
529
+ RestClient.stub(:post) { raise RestClient::Conflict.new }
530
+ lambda {
531
+ @widget.save.should be_false
532
+ }.should_not raise_error
533
+ end
534
+
535
+ it "should catch 422 errors" do
536
+ RestClient.stub(:post) { raise RestClient::UnprocessableEntity.new }
537
+ lambda {
538
+ @widget.save.should be_false
539
+ }.should_not raise_error
540
+ end
541
+
542
+ it "should catch 500 errors" do
543
+ RestClient.stub(:post) { raise RestClient::InternalServerError.new }
544
+ lambda {
545
+ @widget.save.should be_false
546
+ }.should_not raise_error
547
+ end
548
+ end
489
549
  end
490
550
 
491
551
  describe "#update_attributes" do
@@ -513,7 +573,9 @@ describe LucidWorks::Base do
513
573
 
514
574
  describe "#human_attribute_value" do
515
575
  it "should call class.human_attribute_value with attribute name and value" do
516
- #TODO
576
+ widget = Widget.new(:myattr => 'foo', :parent => @server)
577
+ Widget.should_receive(:human_attribute_value).with(:myattr, 'foo')
578
+ widget.human_attribute_value(:myattr)
517
579
  end
518
580
  end
519
581
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Time do
4
+ describe ".iso8601" do
5
+ it "should be able to parse a time with a 4 digit timezone" do
6
+ Time.iso8601("2011-04-15T13:11:56-0700").should == Time.utc(2011, 4, 15, 20, 11, 56)
7
+ end
8
+ end
9
+
10
+ describe "#iso8601" do
11
+ it "should generate a time with a 4 digit timezone" do
12
+ Time.utc(2011, 4, 15, 20, 11, 56).localtime.iso8601.should == "2011-04-15T13:11:56-0700"
13
+ end
14
+ end
15
+ end
@@ -4,21 +4,49 @@ describe LucidWorks::Schema do
4
4
  before do
5
5
  @schema = LucidWorks::Schema.new
6
6
  @schema.instance_eval do
7
- attribute :foo, :string, :primary_key => true
7
+ attribute :astring, :string, :primary_key => true
8
8
  attribute :abool, :boolean
9
9
  attributes :bar, :baz, :type => :integer
10
+ attribute :nullstring, :string, :nil_when_blank => true
11
+ end
12
+ end
13
+
14
+ describe "#attribute" do
15
+ before { @schema = LucidWorks::Schema.new }
16
+
17
+ describe "using default type" do
18
+ it "should create a string attribute" do
19
+ @schema.attribute :foo
20
+ @schema[:foo][:type].should == :string
21
+ end
22
+ end
23
+
24
+ describe "with a bad type" do
25
+ it "should raise an error" do
26
+ lambda {
27
+ @schema.attribute :foo, :badtype
28
+ }.should raise_error
29
+ end
30
+ end
31
+
32
+ [:string, :integer, :boolean].each do |attr_type|
33
+ it "should allow type #{attr_type}" do
34
+ @schema.attribute :foo, attr_type
35
+ @schema[:foo][:type].should == attr_type
36
+ end
10
37
  end
11
38
  end
12
39
 
13
40
  describe "instance_eval" do
14
41
  it "should process the block in its context and create an attribute list" do
15
42
  @schema.should == {
16
- 'foo' => {'type' => :string},
17
- 'bar' => {'type' => :integer},
18
- 'baz' => {'type' => :integer},
19
- 'abool' => {'type' => :boolean}
43
+ 'astring' => {'type' => :string},
44
+ 'bar' => {'type' => :integer},
45
+ 'baz' => {'type' => :integer},
46
+ 'abool' => {'type' => :boolean},
47
+ 'nullstring' => {'type' => :string, 'nil_when_blank' => true}
20
48
  }
21
- @schema.primary_key.should == :foo
49
+ @schema.primary_key.should == :astring
22
50
  end
23
51
  end
24
52
 
@@ -30,8 +58,8 @@ describe LucidWorks::Schema do
30
58
  context "when given an argument" do
31
59
  it "should set the primary key to the provided value" do
32
60
  schema = LucidWorks::Schema.new
33
- schema.primary_key 'foo'
34
- schema.primary_key.should == :foo
61
+ schema.primary_key 'astring'
62
+ schema.primary_key.should == :astring
35
63
  end
36
64
  end
37
65
  end
@@ -55,17 +83,21 @@ describe LucidWorks::Schema do
55
83
  before do
56
84
  class ClassWithAddedAccessors
57
85
  include LucidWorks::Utils::BoolConverter
86
+ class << self
87
+ attr_accessor :schema
88
+ end
58
89
  attr_accessor :attributes
59
90
  def initialize
60
91
  @attributes = {}
61
92
  end
62
93
  end
94
+ ClassWithAddedAccessors.schema = @schema
63
95
  @schema.create_accessors_for_attributes(ClassWithAddedAccessors)
64
96
  @model = ClassWithAddedAccessors.new
65
97
  end
66
98
 
67
99
  it "should add readers and writers for all attributes" do
68
- ClassWithAddedAccessors.new.should respond_to(:foo, :foo=)
100
+ ClassWithAddedAccessors.new.should respond_to(:astring, :astring=)
69
101
  ClassWithAddedAccessors.new.should respond_to(:bar, :bar=)
70
102
  ClassWithAddedAccessors.new.should respond_to(:abool, :abool=)
71
103
  end
@@ -88,11 +120,26 @@ describe LucidWorks::Schema do
88
120
  end
89
121
  end
90
122
  end
123
+
124
+ context "for a string attribute" do
125
+ context "without :nil_when_blank => true" do
126
+ it "setter save the empty string" do
127
+ @model.astring = ""
128
+ @model.astring.should == ""
129
+ end
130
+ end
131
+ context "with :nil_when_blank => true" do
132
+ it "setter should convert blank to nil" do
133
+ @model.nullstring = ""
134
+ @model.nullstring.should be_nil
135
+ end
136
+ end
137
+ end
91
138
  end
92
139
 
93
140
  describe "#has_attribute?" do
94
141
  it "should return true if the schema has that attribute" do
95
- @schema.has_attribute?(:foo).should be_true
142
+ @schema.has_attribute?(:astring).should be_true
96
143
  end
97
144
 
98
145
  it "should return false if the schema does not have that attribute" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lucid_works
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.9
5
+ version: 0.5.3
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-04-09 00:00:00 -07:00
13
+ date: 2011-04-15 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -142,6 +142,7 @@ files:
142
142
  - spec/lib/lucid_works/datasource/status_spec.rb
143
143
  - spec/lib/lucid_works/datasource_spec.rb
144
144
  - spec/lib/lucid_works/field_spec.rb
145
+ - spec/lib/lucid_works/patch_time_spec.rb
145
146
  - spec/lib/lucid_works/schema_spec.rb
146
147
  - spec/lib/lucid_works/server_spec.rb
147
148
  - spec/lib/lucid_works/utils_spec.rb
@@ -186,6 +187,7 @@ test_files:
186
187
  - spec/lib/lucid_works/datasource/status_spec.rb
187
188
  - spec/lib/lucid_works/datasource_spec.rb
188
189
  - spec/lib/lucid_works/field_spec.rb
190
+ - spec/lib/lucid_works/patch_time_spec.rb
189
191
  - spec/lib/lucid_works/schema_spec.rb
190
192
  - spec/lib/lucid_works/server_spec.rb
191
193
  - spec/lib/lucid_works/utils_spec.rb