lucid_works 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/config/locales/en.yml +2 -0
- data/lib/lucid_works.rb +1 -3
- data/lib/lucid_works/base.rb +13 -1
- data/lib/lucid_works/datasource.rb +4 -2
- data/lib/lucid_works/datasource/schedule.rb +69 -0
- data/lib/lucid_works/schema.rb +20 -1
- data/lib/lucid_works/version.rb +1 -1
- data/spec/lib/lucid_works/base_spec.rb +117 -22
- data/spec/lib/lucid_works/datasource/schedule_spec.rb +202 -0
- data/spec/lib/lucid_works/patch_time_spec.rb +1 -1
- data/spec/lib/lucid_works/schema_spec.rb +14 -5
- metadata +4 -2
data/config/locales/en.yml
CHANGED
data/lib/lucid_works.rb
CHANGED
@@ -4,9 +4,7 @@ module LucidWorks
|
|
4
4
|
end
|
5
5
|
|
6
6
|
require 'active_model'
|
7
|
-
require 'active_support/core_ext
|
8
|
-
require 'active_support/core_ext/module/aliasing'
|
9
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
7
|
+
require 'active_support/core_ext'
|
10
8
|
require 'active_support/inflector'
|
11
9
|
begin
|
12
10
|
require 'action_view/helpers/number_helper' # Optional formatter support
|
data/lib/lucid_works/base.rb
CHANGED
@@ -419,7 +419,19 @@ module LucidWorks
|
|
419
419
|
def encode # :nodoc:
|
420
420
|
omit_attrs = [ 'id' ]
|
421
421
|
omit_attrs += self.class.schema.attrs_to_omit_during_update if persisted?
|
422
|
-
@attributes.
|
422
|
+
attrs_as_json = @attributes.inject({}) do |memo, kv|
|
423
|
+
attr, value = kv
|
424
|
+
unless omit_attrs.include?(attr.to_s)
|
425
|
+
case self.class.schema[attr][:type]
|
426
|
+
when :iso8601
|
427
|
+
memo[attr] = value.iso8601
|
428
|
+
else
|
429
|
+
memo[attr] = value
|
430
|
+
end
|
431
|
+
end
|
432
|
+
memo
|
433
|
+
end
|
434
|
+
attrs_as_json.to_json
|
423
435
|
end
|
424
436
|
|
425
437
|
def load_attributes(attributes_and_values) # :nodoc:
|
@@ -10,7 +10,7 @@ module LucidWorks
|
|
10
10
|
schema do
|
11
11
|
# common
|
12
12
|
attributes :name, :type, :crawler
|
13
|
-
attributes :crawl_depth, :max_bytes, :max_docs, :type => :integer
|
13
|
+
attributes :crawl_depth, :max_bytes, :max_docs, :commitWithin, :type => :integer
|
14
14
|
#attribute :commitWithin, :integer
|
15
15
|
attribute :include_paths
|
16
16
|
attribute :exclude_paths
|
@@ -38,10 +38,12 @@ module LucidWorks
|
|
38
38
|
# external
|
39
39
|
attribute :source
|
40
40
|
attribute :source_type
|
41
|
+
# lwelogs
|
42
|
+
attribute :deleteAfter, :integer
|
41
43
|
end
|
42
44
|
|
43
45
|
validates_presence_of :type, :crawler, :name
|
44
|
-
validates_presence_of :crawl_depth, :
|
46
|
+
validates_presence_of :crawl_depth, :if => lambda { |d| %w{web file}.include?(d.type) }
|
45
47
|
validates_numericality_of :max_bytes, :allow_blank => true
|
46
48
|
validates_presence_of :url, :if => lambda { |d| d.type == 'web' }
|
47
49
|
|
@@ -11,6 +11,75 @@ module LucidWorks
|
|
11
11
|
attribute :active
|
12
12
|
attribute :type
|
13
13
|
end
|
14
|
+
|
15
|
+
def frequency
|
16
|
+
case period
|
17
|
+
when 1.weeks.seconds then 'weekly'
|
18
|
+
when 1.days.seconds then 'daily'
|
19
|
+
when 1.hours.seconds then 'hourly'
|
20
|
+
when 0 then nil
|
21
|
+
else 'custom'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def time_of_day
|
26
|
+
Time.now
|
27
|
+
end
|
28
|
+
|
29
|
+
# predict when action will occur next if active at that time
|
30
|
+
def next_start
|
31
|
+
return start_at if reference_time <= start_at
|
32
|
+
# require 'ruby-debug'; debugger
|
33
|
+
time_since_start = reference_time - start_at
|
34
|
+
last_interval_num = (time_since_start / period).to_i
|
35
|
+
next_interval_num = if (time_since_start % period) == 0
|
36
|
+
# this is sort of a stupid condition b/c time precision is millisecond or less
|
37
|
+
# for human purposes we wouldn't care if the result were as though the call
|
38
|
+
# happened a millisecond later. But whatever.
|
39
|
+
last_interval_num # the next interval *is* the last interval if it is exactly now
|
40
|
+
else
|
41
|
+
last_interval_num + 1
|
42
|
+
end
|
43
|
+
start_at + period * next_interval_num
|
44
|
+
end
|
45
|
+
|
46
|
+
# Ruby Time objects for start_time
|
47
|
+
def start_at
|
48
|
+
Time.iso8601(start_time)
|
49
|
+
end
|
50
|
+
|
51
|
+
def start_at=(time)
|
52
|
+
|
53
|
+
self.start_time = time.iso8601
|
54
|
+
end
|
55
|
+
|
56
|
+
# Provide ability to override "now" explicitly for testing purposes
|
57
|
+
def reference_time=(time); @reference_time = time; end
|
58
|
+
def reference_time; @reference_time || Time.now.utc; end
|
59
|
+
|
60
|
+
# phantom attribute for compiling real start time and frequency from appropriate form data
|
61
|
+
def schedule=(all_attributes)
|
62
|
+
# convert to format accepted by Time.advance
|
63
|
+
all_attributes['start'].to_options!
|
64
|
+
all_attributes['start'].each{|k,v| all_attributes['start'][k]=v.to_i}
|
65
|
+
|
66
|
+
self.start_at =
|
67
|
+
case all_attributes['frequency']
|
68
|
+
when 'weekly'
|
69
|
+
# require 'ruby-debug'; debugger
|
70
|
+
start = self.reference_time.beginning_of_week.advance(all_attributes['start'])
|
71
|
+
start < self.reference_time ? start.advance(:weeks => 1) : start
|
72
|
+
when 'daily'
|
73
|
+
start = self.reference_time.beginning_of_day.advance(all_attributes['start'])
|
74
|
+
start < self.reference_time ? start.advance(:days => 1) : start
|
75
|
+
when 'hourly'
|
76
|
+
start = self.reference_time.change(:min => 0).advance(all_attributes['start'])
|
77
|
+
start < self.reference_time ? start.advance(:hours => 1) : start
|
78
|
+
else
|
79
|
+
puts "*** frequency: <#{all_attributes[:frequency]}>"
|
80
|
+
raise "unexpected frequency encountered"
|
81
|
+
end
|
82
|
+
end
|
14
83
|
end
|
15
84
|
end
|
16
85
|
end
|
data/lib/lucid_works/schema.rb
CHANGED
@@ -2,7 +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
|
+
ATTRIBUTES_TYPES = [ :string, :integer, :boolean, :iso8601 ]
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@primary_key = :id
|
@@ -93,6 +93,25 @@ module LucidWorks
|
|
93
93
|
@attributes[:#{attribute}] = new_value # @attributes[:foo] = new_value
|
94
94
|
end # end
|
95
95
|
EOF
|
96
|
+
when :integer
|
97
|
+
klass.class_eval <<-EOF, __FILE__, __LINE__+1
|
98
|
+
def #{attribute}=(new_value)
|
99
|
+
new_value = nil if new_value.blank? && self.class.schema[:#{attribute}][:nil_when_blank]
|
100
|
+
@attributes[:#{attribute}] = new_value.to_i
|
101
|
+
end
|
102
|
+
EOF
|
103
|
+
when :iso8601
|
104
|
+
klass.class_eval <<-EOF, __FILE__, __LINE__+1
|
105
|
+
def #{attribute}=(new_value)
|
106
|
+
if new_value.kind_of?(String)
|
107
|
+
@attributes[:#{attribute}] = Time.iso8601(new_value)
|
108
|
+
elsif new_value.kind_of?(Time)
|
109
|
+
@attributes[:#{attribute}] = new_value
|
110
|
+
else
|
111
|
+
raise "iso8601 attribute= only accepts String or Time"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
EOF
|
96
115
|
else
|
97
116
|
klass.class_eval <<-EOF, __FILE__, __LINE__+1
|
98
117
|
def #{attribute}=(new_value) # def foo=(new_value)
|
data/lib/lucid_works/version.rb
CHANGED
@@ -374,14 +374,14 @@ describe LucidWorks::Base do
|
|
374
374
|
|
375
375
|
describe "instance methods" do
|
376
376
|
|
377
|
-
describe "collection_url" do
|
377
|
+
describe "#collection_url" do
|
378
378
|
it "should generate a url from the server and its name" do
|
379
379
|
widget = Widget.new(:parent => @server, :id => 1234)
|
380
380
|
widget.collection_url.should == "#{@fake_server_uri}/widgets"
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
384
|
-
describe "member_url" do
|
384
|
+
describe "#member_url" do
|
385
385
|
it "should generate a url from the server, its name and its id" do
|
386
386
|
widget = Widget.new(:parent => @server, :id => 1234)
|
387
387
|
widget.member_url.should == "#{@fake_server_uri}/widgets/1234"
|
@@ -597,33 +597,128 @@ describe LucidWorks::Base do
|
|
597
597
|
widget.human_attribute_value(:myattr)
|
598
598
|
end
|
599
599
|
end
|
600
|
-
end
|
601
600
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
601
|
+
context "for a model with primary key other than 'id'" do
|
602
|
+
before :all do
|
603
|
+
class NamedWidget < LucidWorks::Base
|
604
|
+
schema do
|
605
|
+
primary_key :name
|
606
|
+
end
|
607
|
+
end
|
608
|
+
NAMED_WIDGET1_JSON = '{"name":"widget1","size":"small"}'
|
609
|
+
NAMED_WIDGET2_JSON = '{"name":"widget2","size":"medium"}'
|
610
|
+
NAMED_WIDGETS_JSON = "[#{WIDGET1_JSON},#{WIDGET2_JSON}]"
|
611
|
+
end
|
612
|
+
|
613
|
+
describe "#id" do
|
614
|
+
it "should return the primary key's value" do
|
615
|
+
w = NamedWidget.new(:name => 'fake_name', :parent => @server)
|
616
|
+
w.id.should == 'fake_name'
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
describe "#id=" do
|
621
|
+
it "should set the primary key's value" do
|
622
|
+
w = NamedWidget.new(:name => 'fake_name', :parent => @server)
|
623
|
+
w.id = 'new_name'
|
624
|
+
w.id.should == 'new_name'
|
625
|
+
w.name.should == 'new_name'
|
607
626
|
end
|
608
627
|
end
|
609
|
-
NAMED_WIDGET1_JSON = '{"name":"widget1","size":"small"}'
|
610
|
-
NAMED_WIDGET2_JSON = '{"name":"widget2","size":"medium"}'
|
611
|
-
NAMED_WIDGETS_JSON = "[#{WIDGET1_JSON},#{WIDGET2_JSON}]"
|
612
628
|
end
|
629
|
+
end
|
630
|
+
|
631
|
+
describe "private methods" do
|
632
|
+
describe "#load_attributes" do
|
633
|
+
it "should set id using it's accessor and not set it directly in @attributes" do
|
634
|
+
class ModelToTestId < LucidWorks::Base
|
635
|
+
end
|
636
|
+
model = ModelToTestId.new(:parent => @server)
|
637
|
+
model.should_receive(:id=).with(123)
|
638
|
+
model.send(:load_attributes, {:foo => 'bar', :id => 123})
|
639
|
+
end
|
613
640
|
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
641
|
+
context "for a class that belongs_to another object" do
|
642
|
+
before do
|
643
|
+
class ModelThatHas < LucidWorks::Base
|
644
|
+
has_one :model_that_belongs
|
645
|
+
end
|
646
|
+
class ModelThatBelongs < LucidWorks::Base
|
647
|
+
belongs_to :model_that_has
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
it "should ignore attempts to set the belongs_to object" do
|
652
|
+
parent = ModelThatHas.new(:parent => @server)
|
653
|
+
model = ModelThatBelongs.new(:parent => parent)
|
654
|
+
model.class.schema.should_not_receive(:add_attribute)
|
655
|
+
model.send(:load_attributes, :model_that_has => "foo")
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
context "for a class with dynamic_attributes = true" do
|
660
|
+
before do
|
661
|
+
class ModelWithDynamicAttrs < LucidWorks::Base
|
662
|
+
schema do
|
663
|
+
dynamic_attributes true
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
it "should add attributes to the schema as it loads them" do
|
669
|
+
model = ModelWithDynamicAttrs.new(:parent => @server)
|
670
|
+
model.class.schema.should_receive(:add_attribute).with(ModelWithDynamicAttrs, :foo, :string)
|
671
|
+
model.stub(:foo=)
|
672
|
+
model.send(:load_attributes, {:foo => 'bar'})
|
673
|
+
end
|
674
|
+
end
|
675
|
+
|
676
|
+
context "for a class with dynamic_attributes = false" do
|
677
|
+
before do
|
678
|
+
class ModelWithStaticAttrs < LucidWorks::Base
|
679
|
+
schema do
|
680
|
+
dynamic_attributes false
|
681
|
+
end
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
it "should raise an error for unknown attributes" do
|
686
|
+
model = ModelWithStaticAttrs.new(:parent => @server)
|
687
|
+
lambda {
|
688
|
+
model.send(:load_attributes, {:foo => 'bar'})
|
689
|
+
}.should raise_error
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
describe "for a model with an attr described as :iso8601" do
|
694
|
+
before do
|
695
|
+
class ModelWithTimeAttr < LucidWorks::Base
|
696
|
+
schema do
|
697
|
+
attribute :time, :iso8601
|
698
|
+
end
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
it "should convert :iso8601 attributes to a Time object" do
|
703
|
+
model = ModelWithTimeAttr.new(:parent => @server)
|
704
|
+
model.send(:load_attributes, {:time => "2011-05-12T13:33:55-0500"})
|
705
|
+
model.time.should == Time.utc(2011,05,12,18,33,55)
|
706
|
+
end
|
618
707
|
end
|
619
708
|
end
|
620
|
-
|
621
|
-
describe "#
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
709
|
+
|
710
|
+
describe "#encode" do
|
711
|
+
before do
|
712
|
+
# reuse ModelWithTimeAttr
|
713
|
+
# Yes this will fail if we start running tests in random order or bottom up
|
714
|
+
end
|
715
|
+
|
716
|
+
describe "for a model with an attr described as :iso8601" do
|
717
|
+
it "should convert :iso8601 attributes to strings" do
|
718
|
+
time = Time.utc(2011,12,13,14,15,16)
|
719
|
+
model = ModelWithTimeAttr.new(:parent => @server, :time => time)
|
720
|
+
model.send(:encode).should == '{"time":"2011-12-13T14:15:16Z"}'
|
721
|
+
end
|
627
722
|
end
|
628
723
|
end
|
629
724
|
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class String
|
4
|
+
def weekday
|
5
|
+
Time.iso8601(self).strftime('%A')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Time
|
10
|
+
def weekday
|
11
|
+
self.strftime('%A')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe LucidWorks::Datasource::Schedule do
|
16
|
+
before do
|
17
|
+
@server = connect_to_live_server
|
18
|
+
@schedule = LucidWorks::Datasource::Schedule.new(:parent => @server)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#frequency' do
|
22
|
+
it "should return 'daily'" do
|
23
|
+
@schedule.period = 86400
|
24
|
+
@schedule.frequency.should == 'daily'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return 'hourly'" do
|
28
|
+
@schedule.period = 3600
|
29
|
+
@schedule.frequency.should == 'hourly'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return 'custom'" do
|
33
|
+
@schedule.period = 1
|
34
|
+
@schedule.frequency.should == 'custom'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return nil" do
|
38
|
+
@schedule.period = 0
|
39
|
+
@schedule.frequency.should == nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#next_start' do
|
44
|
+
describe 'start_time is in the future' do
|
45
|
+
it 'should return start_time' do
|
46
|
+
@schedule.reference_time = Time.now.utc
|
47
|
+
@schedule.start_time = (@schedule.reference_time + 30.minutes).iso8601
|
48
|
+
@schedule.next_start.should == Time.iso8601(@schedule.start_time)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# some of these are a little sketchy b/c comparing time equality is tricky
|
54
|
+
# Time objects are precise to the millisecond
|
55
|
+
# we cheat by converting to string, which is only accurate to the second
|
56
|
+
# but if these test are run on a second boundary, they might wrongly fail
|
57
|
+
#
|
58
|
+
context 'start_time is in the past' do
|
59
|
+
before do
|
60
|
+
@now = Time.iso8601(Time.now.utc.iso8601)
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'and it is an exact multiple of self.periods until now' do
|
64
|
+
it 'should return now' do
|
65
|
+
# get current time after rounding error
|
66
|
+
@schedule.reference_time = @now
|
67
|
+
@schedule.start_time = (@now - 30.minutes).iso8601
|
68
|
+
@schedule.period = 10.minutes
|
69
|
+
@schedule.next_start.should == @now
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'Time since self.start_time is not even multiple of self.period' do
|
74
|
+
describe 'one interval has passed' do
|
75
|
+
before do
|
76
|
+
@schedule.start_time = (@now - 11.minutes).iso8601
|
77
|
+
@schedule.period = 10.minutes
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return a time less than one interval in the future' do
|
81
|
+
@schedule.next_start.should < @now + @schedule.period
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return a time one interval from the start_time' do
|
85
|
+
@schedule.next_start.to_s.should == (@now + 9.minutes).to_s
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'several (e.g. 4) intervals have passed' do
|
90
|
+
before do
|
91
|
+
@schedule.start_time = (@now - 45.minutes).iso8601
|
92
|
+
@schedule.period = 10.minutes
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return a time between 4 and 6 intervals from start_at' do
|
96
|
+
@schedule.next_start.should > @schedule.start_at + (4 * @schedule.period)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return a start time within 1 period from now' do
|
100
|
+
@schedule.next_start.should < @now + @schedule.period
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#schedule=' do
|
108
|
+
context 'supplied start time has elapsed w/rt current interval' do
|
109
|
+
|
110
|
+
describe 'with hourly frequency' do
|
111
|
+
it "should advance the start time" do
|
112
|
+
half_past_midnight = Time.iso8601("2011-05-09T00:30:00Z")
|
113
|
+
hourly_at_quarter_past = {"frequency"=>"hourly", "start"=>{"minutes"=>"15"}}
|
114
|
+
quarter_past_1_am = '2011-05-09T01:15:00Z'
|
115
|
+
|
116
|
+
@schedule.reference_time = half_past_midnight
|
117
|
+
@schedule.start_time.should_not == quarter_past_1_am
|
118
|
+
@schedule.schedule = hourly_at_quarter_past
|
119
|
+
@schedule.start_time.should == quarter_past_1_am
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'with daily frequency' do
|
124
|
+
it "should advance the start time" do
|
125
|
+
today_at_noon = Time.iso8601("2011-05-09T12:00:00Z")
|
126
|
+
tomorrow_at_eleven_am = '2011-05-10T11:00:00Z'
|
127
|
+
daily_at_11_am = {"frequency"=>"daily", "start"=>{"hours" => "11", "minutes"=>"00"}}
|
128
|
+
|
129
|
+
@schedule.reference_time = today_at_noon
|
130
|
+
@schedule.start_time.should_not == tomorrow_at_eleven_am
|
131
|
+
@schedule.schedule = daily_at_11_am
|
132
|
+
@schedule.start_time.should == tomorrow_at_eleven_am
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'with weekly frequency' do
|
137
|
+
it "should advance the start time" do
|
138
|
+
# note: Rails week starts on Monday
|
139
|
+
friday_of_this_week = Time.iso8601("2011-05-13T00:00:00Z")
|
140
|
+
wednesday_of_next_week = '2011-05-18T00:00:00Z'
|
141
|
+
weekly_on_wednesday = {"frequency"=>"weekly", "start"=>{"days" => "2", "hours" => "0", "minutes"=>"00"}}
|
142
|
+
|
143
|
+
# just make sure I'm not on crack
|
144
|
+
friday_of_this_week.weekday.should == 'Friday'
|
145
|
+
wednesday_of_next_week.weekday.should == 'Wednesday'
|
146
|
+
|
147
|
+
@schedule.reference_time = friday_of_this_week
|
148
|
+
@schedule.start_time.should_not == wednesday_of_next_week
|
149
|
+
@schedule.schedule = weekly_on_wednesday
|
150
|
+
@schedule.start_time.should == wednesday_of_next_week
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'supplied time has not elapsed w/rt current interval' do
|
156
|
+
describe 'with hourly frequency' do
|
157
|
+
it "should not advance the start time" do
|
158
|
+
half_past_midnight = Time.iso8601("2011-05-09T00:30:00Z")
|
159
|
+
three_quarters_past_midnight = '2011-05-09T00:45:00Z'
|
160
|
+
hourly_at_three_quarters_past = {"frequency"=>"hourly", "start"=>{"minutes"=>"45"}}
|
161
|
+
|
162
|
+
@schedule.reference_time = half_past_midnight
|
163
|
+
|
164
|
+
@schedule.start_time.should_not == three_quarters_past_midnight
|
165
|
+
@schedule.schedule = hourly_at_three_quarters_past
|
166
|
+
@schedule.start_time.should == three_quarters_past_midnight
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'with daily frequency' do
|
171
|
+
it "should not advance the start time" do
|
172
|
+
today_at_noon = Time.iso8601("2011-05-09T12:00:00Z")
|
173
|
+
today_at_1pm = '2011-05-09T13:00:00Z'
|
174
|
+
daily_at_1pm = {"frequency"=>"daily", "start"=>{"hours" => "13", "minutes"=>"00"}}
|
175
|
+
|
176
|
+
@schedule.reference_time = today_at_noon
|
177
|
+
@schedule.start_time.should_not == today_at_1pm
|
178
|
+
@schedule.schedule = daily_at_1pm
|
179
|
+
@schedule.start_time.should == today_at_1pm
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'with weekly frequency' do
|
184
|
+
it "should not advance the start time" do
|
185
|
+
# note: Rails week starts on Monday
|
186
|
+
wednesday_of_this_week = Time.iso8601("2011-05-11T00:00:00Z")
|
187
|
+
thursday_of_this_week = '2011-05-12T00:00:00Z'
|
188
|
+
weekly_on_thursday = {"frequency"=>"weekly", "start"=>{"days" => "3", "hours" => "0", "minutes"=>"00"}}
|
189
|
+
|
190
|
+
# just make sure I'm not on crack
|
191
|
+
wednesday_of_this_week.weekday.should == 'Wednesday'
|
192
|
+
thursday_of_this_week.weekday.should == 'Thursday'
|
193
|
+
|
194
|
+
@schedule.reference_time = wednesday_of_this_week
|
195
|
+
@schedule.start_time.should_not == thursday_of_this_week
|
196
|
+
@schedule.schedule = weekly_on_thursday
|
197
|
+
@schedule.start_time.should == thursday_of_this_week
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -9,7 +9,7 @@ describe Time do
|
|
9
9
|
|
10
10
|
describe "#iso8601" do
|
11
11
|
it "should generate a time with a 4 digit timezone" do
|
12
|
-
Time.
|
12
|
+
Time.new(2011, 4, 15, 13, 11, 56, "-07:00").iso8601.should == "2011-04-15T13:11:56-0700"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -6,8 +6,9 @@ describe LucidWorks::Schema do
|
|
6
6
|
@schema.instance_eval do
|
7
7
|
attribute :astring, :string, :primary_key => true
|
8
8
|
attribute :abool, :boolean
|
9
|
-
attributes :
|
9
|
+
attributes :anint, :baz, :type => :integer
|
10
10
|
attribute :nullstring, :string, :nil_when_blank => true
|
11
|
+
attribute :time, :iso8601
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -29,7 +30,7 @@ describe LucidWorks::Schema do
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
[:string, :integer, :boolean].each do |attr_type|
|
33
|
+
[:string, :integer, :boolean, :iso8601].each do |attr_type|
|
33
34
|
it "should allow type #{attr_type}" do
|
34
35
|
@schema.attribute :foo, attr_type
|
35
36
|
@schema[:foo][:type].should == attr_type
|
@@ -41,10 +42,11 @@ describe LucidWorks::Schema do
|
|
41
42
|
it "should process the block in its context and create an attribute list" do
|
42
43
|
@schema.should == {
|
43
44
|
'astring' => {'type' => :string},
|
44
|
-
'
|
45
|
+
'anint' => {'type' => :integer},
|
45
46
|
'baz' => {'type' => :integer},
|
46
47
|
'abool' => {'type' => :boolean},
|
47
|
-
'nullstring' => {'type' => :string, 'nil_when_blank' => true}
|
48
|
+
'nullstring' => {'type' => :string, 'nil_when_blank' => true},
|
49
|
+
'time' => {'type' => :iso8601}
|
48
50
|
}
|
49
51
|
@schema.primary_key.should == :astring
|
50
52
|
end
|
@@ -98,7 +100,7 @@ describe LucidWorks::Schema do
|
|
98
100
|
|
99
101
|
it "should add readers and writers for all attributes" do
|
100
102
|
ClassWithAddedAccessors.new.should respond_to(:astring, :astring=)
|
101
|
-
ClassWithAddedAccessors.new.should respond_to(:
|
103
|
+
ClassWithAddedAccessors.new.should respond_to(:anint, :anint=)
|
102
104
|
ClassWithAddedAccessors.new.should respond_to(:abool, :abool=)
|
103
105
|
end
|
104
106
|
|
@@ -121,6 +123,13 @@ describe LucidWorks::Schema do
|
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
126
|
+
context "for an integer attribute" do
|
127
|
+
it "setter should convert strings to integers" do
|
128
|
+
@model.anint = "1234"
|
129
|
+
@model.anint.should == 1234
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
124
133
|
context "for a string attribute" do
|
125
134
|
context "without :nil_when_blank => true" do
|
126
135
|
it "setter save the empty string" 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.6.
|
5
|
+
version: 0.6.4
|
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-13 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- spec/lib/lucid_works/collection/prime_activities_spec.rb
|
145
145
|
- spec/lib/lucid_works/collection_spec.rb
|
146
146
|
- spec/lib/lucid_works/datasource/history_spec.rb
|
147
|
+
- spec/lib/lucid_works/datasource/schedule_spec.rb
|
147
148
|
- spec/lib/lucid_works/datasource/status_spec.rb
|
148
149
|
- spec/lib/lucid_works/datasource_spec.rb
|
149
150
|
- spec/lib/lucid_works/field_spec.rb
|
@@ -191,6 +192,7 @@ test_files:
|
|
191
192
|
- spec/lib/lucid_works/collection/prime_activities_spec.rb
|
192
193
|
- spec/lib/lucid_works/collection_spec.rb
|
193
194
|
- spec/lib/lucid_works/datasource/history_spec.rb
|
195
|
+
- spec/lib/lucid_works/datasource/schedule_spec.rb
|
194
196
|
- spec/lib/lucid_works/datasource/status_spec.rb
|
195
197
|
- spec/lib/lucid_works/datasource_spec.rb
|
196
198
|
- spec/lib/lucid_works/field_spec.rb
|