lucid_works 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/config/locales/en.yml +1 -1
- data/lib/lucid_works/base.rb +5 -5
- data/lib/lucid_works/datasource/schedule.rb +16 -16
- data/lib/lucid_works/datasource.rb +19 -12
- data/lib/lucid_works/patch_time.rb +13 -1
- data/lib/lucid_works/schema.rb +60 -13
- data/lib/lucid_works/version.rb +1 -1
- data/spec/lib/lucid_works/base_spec.rb +16 -5
- data/spec/lib/lucid_works/collection_spec.rb +2 -2
- data/spec/lib/lucid_works/datasource/schedule_spec.rb +22 -13
- data/spec/lib/lucid_works/datasource_spec.rb +2 -3
- data/spec/lib/lucid_works/patch_time_spec.rb +10 -2
- data/spec/lib/lucid_works/schema_spec.rb +17 -0
- data/spec/spec_helper.rb +6 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -261,7 +261,7 @@ A class may have a schema defined as follows:
|
|
261
261
|
end
|
262
262
|
|
263
263
|
Classes with a schema may have validations applied to its attributes.
|
264
|
-
The default attribute type is :string.
|
264
|
+
The default attribute type is :string. See LucidWorks::Schema for more details.
|
265
265
|
|
266
266
|
== Rationale
|
267
267
|
|
data/config/locales/en.yml
CHANGED
data/lib/lucid_works/base.rb
CHANGED
@@ -265,11 +265,10 @@ module LucidWorks
|
|
265
265
|
end
|
266
266
|
|
267
267
|
# For attributes listed in the schema as having :values, this will create an array-of-arrays
|
268
|
-
# suitable for use as options_for_select.
|
268
|
+
# suitable for use as options_for_select.
|
269
269
|
|
270
270
|
def to_select(attribute)
|
271
271
|
raise "Can't to_select for #{attribute} as it has no values" unless schema[attribute][:values]
|
272
|
-
l10n_scope = %w{activemodel models} + self.name.underscore.split('/') + [attribute]
|
273
272
|
schema[attribute][:values].map do |value|
|
274
273
|
[human_attribute_value(attribute, value), value]
|
275
274
|
end
|
@@ -421,10 +420,11 @@ module LucidWorks
|
|
421
420
|
omit_attrs += self.class.schema.attrs_to_omit_during_update if persisted?
|
422
421
|
attrs_as_json = @attributes.inject({}) do |memo, kv|
|
423
422
|
attr, value = kv
|
424
|
-
unless
|
423
|
+
unless (value.blank? && self.class.schema[attr][:omit_when_blank]) ||
|
424
|
+
omit_attrs.include?(attr.to_s)
|
425
425
|
case self.class.schema[attr][:type]
|
426
|
-
|
427
|
-
|
426
|
+
when :iso8601
|
427
|
+
memo[attr] = value.iso8601 rescue value
|
428
428
|
else
|
429
429
|
memo[attr] = value
|
430
430
|
end
|
@@ -7,7 +7,7 @@ module LucidWorks
|
|
7
7
|
|
8
8
|
schema do
|
9
9
|
attribute :period
|
10
|
-
attribute :start_time
|
10
|
+
attribute :start_time, :iso8601
|
11
11
|
attribute :active
|
12
12
|
attribute :type
|
13
13
|
end
|
@@ -22,15 +22,24 @@ module LucidWorks
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def frequency=(frequency)
|
26
|
+
self.period = case frequency
|
27
|
+
when 'hourly' then 1.hours.seconds
|
28
|
+
when 'daily' then 1.days.seconds
|
29
|
+
when 'weekly' then 1.weeks.seconds
|
30
|
+
else raise "unknown frequency"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
def time_of_day
|
26
35
|
Time.now
|
27
36
|
end
|
28
37
|
|
29
38
|
# predict when action will occur next if active at that time
|
30
39
|
def next_start
|
31
|
-
return
|
40
|
+
return start_time if reference_time <= start_time
|
32
41
|
# require 'ruby-debug'; debugger
|
33
|
-
time_since_start = reference_time -
|
42
|
+
time_since_start = reference_time - start_time
|
34
43
|
last_interval_num = (time_since_start / period).to_i
|
35
44
|
next_interval_num = if (time_since_start % period) == 0
|
36
45
|
# this is sort of a stupid condition b/c time precision is millisecond or less
|
@@ -40,19 +49,9 @@ module LucidWorks
|
|
40
49
|
else
|
41
50
|
last_interval_num + 1
|
42
51
|
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
# Ruby Time objects for start_time
|
47
|
-
def start_at
|
48
|
-
Time.iso8601(start_time)
|
52
|
+
start_time + period * next_interval_num
|
49
53
|
end
|
50
|
-
|
51
|
-
def start_at=(time)
|
52
|
-
|
53
|
-
self.start_time = time.iso8601
|
54
|
-
end
|
55
|
-
|
54
|
+
|
56
55
|
# Provide ability to override "now" explicitly for testing purposes
|
57
56
|
def reference_time=(time); @reference_time = time; end
|
58
57
|
def reference_time; @reference_time || Time.now.utc; end
|
@@ -63,7 +62,8 @@ module LucidWorks
|
|
63
62
|
all_attributes['start'].to_options!
|
64
63
|
all_attributes['start'].each{|k,v| all_attributes['start'][k]=v.to_i}
|
65
64
|
|
66
|
-
self.
|
65
|
+
self.frequency = all_attributes['frequency']
|
66
|
+
self.start_time =
|
67
67
|
case all_attributes['frequency']
|
68
68
|
when 'weekly'
|
69
69
|
# require 'ruby-debug'; debugger
|
@@ -10,8 +10,9 @@ module LucidWorks
|
|
10
10
|
schema do
|
11
11
|
# common
|
12
12
|
attributes :name, :type, :crawler
|
13
|
-
attributes :crawl_depth, :
|
14
|
-
|
13
|
+
attributes :crawl_depth, :max_docs, :type => :integer
|
14
|
+
attributes :max_bytes, :commitWithin, :type => :integer, :omit_when_blank => true
|
15
|
+
attribute :commit_within_min, :custom
|
15
16
|
attribute :include_paths
|
16
17
|
attribute :exclude_paths
|
17
18
|
attribute :mapping # Hash
|
@@ -39,7 +40,8 @@ module LucidWorks
|
|
39
40
|
attribute :source
|
40
41
|
attribute :source_type
|
41
42
|
# lwelogs
|
42
|
-
attribute :deleteAfter, :integer
|
43
|
+
attribute :deleteAfter, :integer, :omit_when_blank => true
|
44
|
+
attribute :delete_after_days, :custom
|
43
45
|
end
|
44
46
|
|
45
47
|
validates_presence_of :type, :crawler, :name
|
@@ -47,8 +49,6 @@ module LucidWorks
|
|
47
49
|
validates_numericality_of :max_bytes, :allow_blank => true
|
48
50
|
validates_presence_of :url, :if => lambda { |d| d.type == 'web' }
|
49
51
|
|
50
|
-
before_save :remove_blank_max_bytes
|
51
|
-
|
52
52
|
TYPES = %w{ external file lwelogs web solrxml jdbc sharepoint }
|
53
53
|
BOUNDS = %w{ tree none }
|
54
54
|
CRAWLERS = {
|
@@ -64,6 +64,20 @@ module LucidWorks
|
|
64
64
|
}.with_indifferent_access
|
65
65
|
|
66
66
|
|
67
|
+
# Fake attributes to ease UI implementation
|
68
|
+
def commit_within_min
|
69
|
+
commitWithin.blank? ? nil : commitWithin / 1.second.milliseconds / 1.minute.seconds
|
70
|
+
end
|
71
|
+
def commit_within_min=(mins)
|
72
|
+
self.commitWithin = mins.blank? ? nil : mins.to_i.minutes.milliseconds
|
73
|
+
end
|
74
|
+
def delete_after_days
|
75
|
+
deleteAfter.blank? ? nil : deleteAfter / 1.second.milliseconds / 1.day.seconds
|
76
|
+
end
|
77
|
+
def delete_after_days=(days)
|
78
|
+
self.deleteAfter = days.blank? ? nil : days.to_i.days.milliseconds
|
79
|
+
end
|
80
|
+
|
67
81
|
def empty!
|
68
82
|
build_index.destroy
|
69
83
|
end
|
@@ -94,12 +108,5 @@ module LucidWorks
|
|
94
108
|
def t_type
|
95
109
|
I18n.t(type, :scope => 'activemodel.models.lucid_works.datasource.type')
|
96
110
|
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
def remove_blank_max_bytes # :nodoc:
|
101
|
-
# API can't handle a blank max_bytes. Send nothing to select 'unlimited'
|
102
|
-
@attributes.delete :max_bytes if self.max_bytes.blank?
|
103
|
-
end
|
104
111
|
end
|
105
112
|
end
|
@@ -12,8 +12,20 @@ class Time #:nodoc:
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def iso8601_with_support_for_timezones_without_colons
|
15
|
-
self.iso8601_without_support_for_timezones_without_colons
|
15
|
+
unfixed_string = self.iso8601_without_support_for_timezones_without_colons
|
16
|
+
if unfixed_string =~ /Z$/
|
17
|
+
unfixed_string.gsub /Z$/, '+0000'
|
18
|
+
else
|
19
|
+
unfixed_string.gsub /([+-])(\d\d):(\d\d)$/, '\1\2\3'
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
alias_method_chain :iso8601, :support_for_timezones_without_colons
|
19
24
|
end
|
25
|
+
|
26
|
+
class Fixnum
|
27
|
+
def milliseconds
|
28
|
+
# so we can say 1.second.milliseconds
|
29
|
+
self * 1000
|
30
|
+
end
|
31
|
+
end
|
data/lib/lucid_works/schema.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
1
|
module LucidWorks
|
2
2
|
|
3
|
-
#
|
3
|
+
# Schema is used to delare attributes for a model.
|
4
|
+
|
4
5
|
class Schema < ActiveSupport::HashWithIndifferentAccess
|
5
|
-
ATTRIBUTES_TYPES = [ :string, :integer, :boolean, :iso8601 ]
|
6
|
+
ATTRIBUTES_TYPES = [ :string, :integer, :boolean, :iso8601, :custom ]
|
6
7
|
|
8
|
+
# Initializes the schema, taking a block of schema declarations.
|
9
|
+
# Typically it is called from LucidWorks::Base, e.g.:
|
10
|
+
#
|
11
|
+
# class MyModel < LucidWorks::Base
|
12
|
+
# schema do
|
13
|
+
# attribute :string1, :string
|
14
|
+
# attribute :bool1, :boolean
|
15
|
+
# attribute :integer1, :integer
|
16
|
+
# attributes :string2, :string3, :string4
|
17
|
+
# attributes :bool2, :bool3, :type => :boolean
|
18
|
+
# attributes :int2, :int3, :type => :integer
|
19
|
+
# attribute :string_with_values, :values => ['one', 'two']
|
20
|
+
# attribute :dontsendme, :omit_during_update => true
|
21
|
+
# attribute :sendnull, :string, :nil_when_blank => true
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
7
25
|
def initialize
|
8
26
|
@primary_key = :id
|
9
27
|
@dynamic_attributes = true
|
@@ -14,16 +32,39 @@ module LucidWorks
|
|
14
32
|
@primary_key
|
15
33
|
end
|
16
34
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
35
|
+
# If called with _true_ (the default), attributes will be added to the schema
|
36
|
+
# when the model is first retrieved from the server. If set to _false_
|
37
|
+
# only the attributes defined in the schema will be allowed and anything
|
38
|
+
# else will raise an exception.
|
39
|
+
|
20
40
|
def dynamic_attributes(on=nil)
|
21
41
|
@dynamic_attributes = !!on unless on.nil?
|
22
42
|
@dynamic_attributes
|
23
43
|
end
|
24
44
|
|
25
45
|
alias :dynamic_attributes? :dynamic_attributes
|
26
|
-
|
46
|
+
|
47
|
+
# Declare a single attribute.
|
48
|
+
#
|
49
|
+
# Attributes may be of the following types:
|
50
|
+
#
|
51
|
+
# [:string ] The default type, incurrs no special processing.
|
52
|
+
# [:integer] Setter will attempt cast to_i. Will be sent to server as integer.
|
53
|
+
# [:boolean] Besides true/false, the setter will accept 0, 1 and strings true, false, t, f, 0, 1, yes and no.
|
54
|
+
# [:iso8601] An ISO 8601 formatted datetime. Automatically converts to/from strings when sent / received.
|
55
|
+
# [:custom] Developer will write their own setter/getter.
|
56
|
+
#
|
57
|
+
# Attributes behavior may also be modified using the following options:
|
58
|
+
#
|
59
|
+
# [:type => _type_] Use to set the type of a group of attributes when using \#attributes.
|
60
|
+
# [:values => \[array\]] Provides a set of values that to_select will use to generate options_for_select.
|
61
|
+
# [:omit_during_update => true] Some resources have attributes that may be set during creation,
|
62
|
+
# but will cause an error if sent during an update.
|
63
|
+
# Setting the <em>option</em> to true will skip the attribute when saving
|
64
|
+
# the model during update.
|
65
|
+
# [:nil_when_blank => true] When this attribute is blank?, send nil (actually JSON null) during save.
|
66
|
+
# [:omit_when_blank => true] When this attribute is blank?, don't send it to the server during save.
|
67
|
+
|
27
68
|
def attribute(name, type=:string, options={})
|
28
69
|
raise "Unknown attribute type: #{type.inspect}" unless ATTRIBUTES_TYPES.include?(type)
|
29
70
|
primary_key name if options.delete(:primary_key)
|
@@ -37,10 +78,11 @@ module LucidWorks
|
|
37
78
|
# end
|
38
79
|
#
|
39
80
|
def attributes(*attributes_and_options)
|
40
|
-
options
|
81
|
+
options = attributes_and_options.last.is_a?(Hash) ? attributes_and_options.pop : {}
|
41
82
|
attributes = attributes_and_options
|
83
|
+
type = options.delete(:type) || :string
|
42
84
|
attributes.each do |name|
|
43
|
-
|
85
|
+
attribute name, type, options
|
44
86
|
end
|
45
87
|
end
|
46
88
|
|
@@ -96,8 +138,13 @@ module LucidWorks
|
|
96
138
|
when :integer
|
97
139
|
klass.class_eval <<-EOF, __FILE__, __LINE__+1
|
98
140
|
def #{attribute}=(new_value)
|
99
|
-
|
100
|
-
|
141
|
+
if new_value.blank? && (self.class.schema[:#{attribute}][:nil_when_blank] ||
|
142
|
+
self.class.schema[:#{attribute}][:omit_when_blank])
|
143
|
+
new_value = nil
|
144
|
+
else
|
145
|
+
new_value = new_value.to_i
|
146
|
+
end
|
147
|
+
@attributes[:#{attribute}] = new_value
|
101
148
|
end
|
102
149
|
EOF
|
103
150
|
when :iso8601
|
@@ -105,13 +152,13 @@ module LucidWorks
|
|
105
152
|
def #{attribute}=(new_value)
|
106
153
|
if new_value.kind_of?(String)
|
107
154
|
@attributes[:#{attribute}] = Time.iso8601(new_value)
|
108
|
-
elsif new_value.kind_of?(Time)
|
109
|
-
@attributes[:#{attribute}] = new_value
|
110
155
|
else
|
111
|
-
|
156
|
+
@attributes[:#{attribute}] = new_value
|
112
157
|
end
|
113
158
|
end
|
114
159
|
EOF
|
160
|
+
when :custom
|
161
|
+
# Do nothing. Developer will provide own accessors.
|
115
162
|
else
|
116
163
|
klass.class_eval <<-EOF, __FILE__, __LINE__+1
|
117
164
|
def #{attribute}=(new_value) # def foo=(new_value)
|
data/lib/lucid_works/version.rb
CHANGED
@@ -709,15 +709,26 @@ describe LucidWorks::Base do
|
|
709
709
|
|
710
710
|
describe "#encode" do
|
711
711
|
before do
|
712
|
-
|
713
|
-
|
712
|
+
class ModelToBeEncoded < LucidWorks::Base
|
713
|
+
schema do
|
714
|
+
attribute :time, :iso8601
|
715
|
+
attribute :blanktime, :iso8601, :omit_when_blank => true
|
716
|
+
end
|
717
|
+
end
|
714
718
|
end
|
715
719
|
|
716
720
|
describe "for a model with an attr described as :iso8601" do
|
717
721
|
it "should convert :iso8601 attributes to strings" do
|
718
|
-
time = Time.
|
719
|
-
model =
|
720
|
-
model.send(:encode).should
|
722
|
+
time = Time.local(2011,12,13,14,15,16)
|
723
|
+
model = ModelToBeEncoded.new(:parent => @server, :time => time)
|
724
|
+
model.send(:encode).should =~ /"time":"2011-12-13T14:15:16-\d\d\d\d"/
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
728
|
+
describe "for a model with an attr with option :omit_when_blank" do
|
729
|
+
it "should not encode the attribute" do
|
730
|
+
model = ModelToBeEncoded.new(:parent => @server, :time => 123, :blanktime => nil)
|
731
|
+
model.send(:encode).should == '{"time":123}'
|
721
732
|
end
|
722
733
|
end
|
723
734
|
end
|
@@ -89,7 +89,7 @@ describe LucidWorks::Collection do
|
|
89
89
|
|
90
90
|
describe "#activities" do
|
91
91
|
before do
|
92
|
-
@collection =
|
92
|
+
@collection = @server.collection('collection1')
|
93
93
|
end
|
94
94
|
|
95
95
|
context "for a collection with some activities" do
|
@@ -179,7 +179,7 @@ describe LucidWorks::Collection do
|
|
179
179
|
# Schedule a crawl to create some history
|
180
180
|
@schedule = @ds1.build_schedule
|
181
181
|
@schedule.period = '0'
|
182
|
-
@schedule.start_time =
|
182
|
+
@schedule.start_time = 0
|
183
183
|
@schedule.active = true
|
184
184
|
@schedule.type = 'index'
|
185
185
|
@schedule.save
|
@@ -44,8 +44,8 @@ describe LucidWorks::Datasource::Schedule do
|
|
44
44
|
describe 'start_time is in the future' do
|
45
45
|
it 'should return start_time' do
|
46
46
|
@schedule.reference_time = Time.now.utc
|
47
|
-
@schedule.start_time =
|
48
|
-
@schedule.next_start.should ==
|
47
|
+
@schedule.start_time = @schedule.reference_time + 30.minutes
|
48
|
+
@schedule.next_start.should == @schedule.start_time
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -64,7 +64,7 @@ describe LucidWorks::Datasource::Schedule do
|
|
64
64
|
it 'should return now' do
|
65
65
|
# get current time after rounding error
|
66
66
|
@schedule.reference_time = @now
|
67
|
-
@schedule.start_time =
|
67
|
+
@schedule.start_time = @now - 30.minutes
|
68
68
|
@schedule.period = 10.minutes
|
69
69
|
@schedule.next_start.should == @now
|
70
70
|
end
|
@@ -73,7 +73,7 @@ describe LucidWorks::Datasource::Schedule do
|
|
73
73
|
context 'Time since self.start_time is not even multiple of self.period' do
|
74
74
|
describe 'one interval has passed' do
|
75
75
|
before do
|
76
|
-
@schedule.start_time =
|
76
|
+
@schedule.start_time = @now - 11.minutes
|
77
77
|
@schedule.period = 10.minutes
|
78
78
|
end
|
79
79
|
|
@@ -88,12 +88,12 @@ describe LucidWorks::Datasource::Schedule do
|
|
88
88
|
|
89
89
|
describe 'several (e.g. 4) intervals have passed' do
|
90
90
|
before do
|
91
|
-
@schedule.start_time =
|
91
|
+
@schedule.start_time = @now - 45.minutes
|
92
92
|
@schedule.period = 10.minutes
|
93
93
|
end
|
94
94
|
|
95
|
-
it 'should return a time between 4 and 6 intervals from
|
96
|
-
@schedule.next_start.should > @schedule.
|
95
|
+
it 'should return a time between 4 and 6 intervals from start_time' do
|
96
|
+
@schedule.next_start.should > @schedule.start_time + (4 * @schedule.period)
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should return a start time within 1 period from now' do
|
@@ -111,7 +111,7 @@ describe LucidWorks::Datasource::Schedule do
|
|
111
111
|
it "should advance the start time" do
|
112
112
|
half_past_midnight = Time.iso8601("2011-05-09T00:30:00Z")
|
113
113
|
hourly_at_quarter_past = {"frequency"=>"hourly", "start"=>{"minutes"=>"15"}}
|
114
|
-
quarter_past_1_am = '2011-05-09T01:15:00Z'
|
114
|
+
quarter_past_1_am = Time.iso8601('2011-05-09T01:15:00Z')
|
115
115
|
|
116
116
|
@schedule.reference_time = half_past_midnight
|
117
117
|
@schedule.start_time.should_not == quarter_past_1_am
|
@@ -123,7 +123,7 @@ describe LucidWorks::Datasource::Schedule do
|
|
123
123
|
describe 'with daily frequency' do
|
124
124
|
it "should advance the start time" do
|
125
125
|
today_at_noon = Time.iso8601("2011-05-09T12:00:00Z")
|
126
|
-
tomorrow_at_eleven_am = '2011-05-10T11:00:00Z'
|
126
|
+
tomorrow_at_eleven_am = Time.iso8601('2011-05-10T11:00:00Z')
|
127
127
|
daily_at_11_am = {"frequency"=>"daily", "start"=>{"hours" => "11", "minutes"=>"00"}}
|
128
128
|
|
129
129
|
@schedule.reference_time = today_at_noon
|
@@ -137,7 +137,7 @@ describe LucidWorks::Datasource::Schedule do
|
|
137
137
|
it "should advance the start time" do
|
138
138
|
# note: Rails week starts on Monday
|
139
139
|
friday_of_this_week = Time.iso8601("2011-05-13T00:00:00Z")
|
140
|
-
wednesday_of_next_week = '2011-05-18T00:00:00Z'
|
140
|
+
wednesday_of_next_week = Time.iso8601('2011-05-18T00:00:00Z')
|
141
141
|
weekly_on_wednesday = {"frequency"=>"weekly", "start"=>{"days" => "2", "hours" => "0", "minutes"=>"00"}}
|
142
142
|
|
143
143
|
# just make sure I'm not on crack
|
@@ -156,27 +156,33 @@ describe LucidWorks::Datasource::Schedule do
|
|
156
156
|
describe 'with hourly frequency' do
|
157
157
|
it "should not advance the start time" do
|
158
158
|
half_past_midnight = Time.iso8601("2011-05-09T00:30:00Z")
|
159
|
-
three_quarters_past_midnight = '2011-05-09T00:45:00Z'
|
159
|
+
three_quarters_past_midnight = Time.iso8601('2011-05-09T00:45:00Z')
|
160
160
|
hourly_at_three_quarters_past = {"frequency"=>"hourly", "start"=>{"minutes"=>"45"}}
|
161
161
|
|
162
162
|
@schedule.reference_time = half_past_midnight
|
163
163
|
|
164
164
|
@schedule.start_time.should_not == three_quarters_past_midnight
|
165
|
+
@schedule.frequency.should_not == 'hourly'
|
166
|
+
|
165
167
|
@schedule.schedule = hourly_at_three_quarters_past
|
166
168
|
@schedule.start_time.should == three_quarters_past_midnight
|
169
|
+
@schedule.frequency.should == 'hourly'
|
167
170
|
end
|
168
171
|
end
|
169
172
|
|
170
173
|
describe 'with daily frequency' do
|
171
174
|
it "should not advance the start time" do
|
172
175
|
today_at_noon = Time.iso8601("2011-05-09T12:00:00Z")
|
173
|
-
today_at_1pm = '2011-05-09T13:00:00Z'
|
176
|
+
today_at_1pm = Time.iso8601('2011-05-09T13:00:00Z')
|
174
177
|
daily_at_1pm = {"frequency"=>"daily", "start"=>{"hours" => "13", "minutes"=>"00"}}
|
175
178
|
|
176
179
|
@schedule.reference_time = today_at_noon
|
177
180
|
@schedule.start_time.should_not == today_at_1pm
|
181
|
+
@schedule.frequency.should_not == 'daily'
|
182
|
+
|
178
183
|
@schedule.schedule = daily_at_1pm
|
179
184
|
@schedule.start_time.should == today_at_1pm
|
185
|
+
@schedule.frequency.should == 'daily'
|
180
186
|
end
|
181
187
|
end
|
182
188
|
|
@@ -184,7 +190,7 @@ describe LucidWorks::Datasource::Schedule do
|
|
184
190
|
it "should not advance the start time" do
|
185
191
|
# note: Rails week starts on Monday
|
186
192
|
wednesday_of_this_week = Time.iso8601("2011-05-11T00:00:00Z")
|
187
|
-
thursday_of_this_week = '2011-05-12T00:00:00Z'
|
193
|
+
thursday_of_this_week = Time.iso8601('2011-05-12T00:00:00Z')
|
188
194
|
weekly_on_thursday = {"frequency"=>"weekly", "start"=>{"days" => "3", "hours" => "0", "minutes"=>"00"}}
|
189
195
|
|
190
196
|
# just make sure I'm not on crack
|
@@ -193,8 +199,11 @@ describe LucidWorks::Datasource::Schedule do
|
|
193
199
|
|
194
200
|
@schedule.reference_time = wednesday_of_this_week
|
195
201
|
@schedule.start_time.should_not == thursday_of_this_week
|
202
|
+
@schedule.frequency.should_not == 'weekly'
|
203
|
+
|
196
204
|
@schedule.schedule = weekly_on_thursday
|
197
205
|
@schedule.start_time.should == thursday_of_this_week
|
206
|
+
@schedule.frequency.should == 'weekly'
|
198
207
|
end
|
199
208
|
end
|
200
209
|
end
|
@@ -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.
|
7
|
+
@collection = @server.collection('collection1')
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "CRUD" do
|
@@ -60,7 +60,7 @@ describe LucidWorks::Datasource do
|
|
60
60
|
:crawler => LucidWorks::Datasource::CRAWLERS['web'],
|
61
61
|
:type => 'web',
|
62
62
|
:url => "invalid url",
|
63
|
-
:crawl_depth =>
|
63
|
+
:crawl_depth => 1
|
64
64
|
}
|
65
65
|
end
|
66
66
|
|
@@ -70,7 +70,6 @@ describe LucidWorks::Datasource do
|
|
70
70
|
d = LucidWorks::Datasource.create(@parameters)
|
71
71
|
}.should_not change(self, :datasource_count)
|
72
72
|
d.errors[:url].should_not be_empty
|
73
|
-
d.errors[:crawl_depth].should_not be_empty
|
74
73
|
d.errors[:base].should be_blank
|
75
74
|
end
|
76
75
|
end
|
@@ -8,8 +8,16 @@ describe Time do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#iso8601" do
|
11
|
-
|
12
|
-
|
11
|
+
context "when time is a UTC time" do
|
12
|
+
it "should end in +0000" do
|
13
|
+
Time.utc(2011, 4, 15, 13, 11, 56).iso8601.should == "2011-04-15T13:11:56+0000"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when time is non-UTC" do
|
18
|
+
it "should generate a time with a 4 digit timezone" do
|
19
|
+
Time.new(2011, 4, 15, 13, 11, 56, "-07:00").iso8601.should == "2011-04-15T13:11:56-0700"
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
@@ -144,6 +144,23 @@ describe LucidWorks::Schema do
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
context "for an iso8601 attribute" do
|
149
|
+
it "setter should just store a Time" do
|
150
|
+
@model.time = Time.utc(2011)
|
151
|
+
@model.time.should be_a(Time)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "setter should assume string is ISO8601 and convert to Time" do
|
155
|
+
@model.time = "2011-05-12T13:33:55-0500"
|
156
|
+
@model.time.should == Time.utc(2011,05,12,18,33,55)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "setter should just store an integer" do
|
160
|
+
@model.time = 12345678
|
161
|
+
@model.time.should == 12345678
|
162
|
+
end
|
163
|
+
end
|
147
164
|
end
|
148
165
|
|
149
166
|
describe "#has_attribute?" do
|
data/spec/spec_helper.rb
CHANGED
@@ -36,8 +36,12 @@ class LucidWorks::Server
|
|
36
36
|
end
|
37
37
|
|
38
38
|
collections.each do |c|
|
39
|
-
|
40
|
-
|
39
|
+
# TODO: figure out how to delete and recreate lwelogs
|
40
|
+
# For now just don't delete it
|
41
|
+
unless c.name == 'lwelogs'
|
42
|
+
c.destroy
|
43
|
+
notes << "Deleted collection '#{c.name}'"
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
default_collection = self.create_collection(:name => DEFAULT_COLLECTION_NAME)
|
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.
|
5
|
+
version: 0.6.5
|
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-05-
|
13
|
+
date: 2011-05-16 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|