acts_as_span 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +22 -0
- data/README.rdoc +33 -0
- data/Rakefile +4 -0
- data/acts_as_span.gemspec +23 -0
- data/lib/acts_as_span.rb +161 -0
- data/lib/acts_as_span/span_instance.rb +53 -0
- data/lib/acts_as_span/span_instance/overlap.rb +17 -0
- data/lib/acts_as_span/span_instance/status.rb +58 -0
- data/lib/acts_as_span/span_instance/validations.rb +67 -0
- data/lib/acts_as_span/span_klass.rb +31 -0
- data/lib/acts_as_span/span_klass/overlap.rb +21 -0
- data/lib/acts_as_span/span_klass/status.rb +29 -0
- data/lib/acts_as_span/version.rb +12 -0
- data/spec/lib/acts_as_span_spec.rb +64 -0
- data/spec/lib/delegation_spec.rb +128 -0
- data/spec/lib/negative_spec.rb +30 -0
- data/spec/lib/span_instance/named_scopes_on_spec.rb +304 -0
- data/spec/lib/span_instance/named_scopes_spec.rb +302 -0
- data/spec/lib/span_instance/overlap_spec.rb +597 -0
- data/spec/lib/span_instance/status_spec.rb +49 -0
- data/spec/lib/span_instance/validations_spec.rb +54 -0
- data/spec/lib/span_instance_spec.rb +41 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- metadata +112 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Span" do
|
4
|
+
before(:each) do
|
5
|
+
build_model :span_model do
|
6
|
+
date :start_date
|
7
|
+
date :end_date
|
8
|
+
|
9
|
+
acts_as_span
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:span_model) { SpanModel.new(:start_date => Date.today, :end_date => nil) }
|
14
|
+
let(:span) { span_model.span }
|
15
|
+
|
16
|
+
context "#span_status & #span_status_to_s" do
|
17
|
+
before(:each) do
|
18
|
+
span.stub!(:current?).and_return(false)
|
19
|
+
span.stub!(:future?).and_return(false)
|
20
|
+
span.stub!(:expired?).and_return(false)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return :unknown when all_conditions == false" do
|
24
|
+
span.span_status.should == :unknown
|
25
|
+
span.span_status_to_s.should == 'Unknown'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return :current when current? == true" do
|
29
|
+
span.should_receive(:current?).twice.and_return(true)
|
30
|
+
|
31
|
+
span.span_status.should == :current
|
32
|
+
span.span_status_to_s.should == 'Current'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return :current when future? == true" do
|
36
|
+
span.should_receive(:future?).twice.and_return(true)
|
37
|
+
|
38
|
+
span.span_status.should == :future
|
39
|
+
span.span_status_to_s.should == 'Future'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return :current when expired? == true" do
|
43
|
+
span.should_receive(:expired?).twice.and_return(true)
|
44
|
+
|
45
|
+
span.span_status.should == :expired
|
46
|
+
span.span_status_to_s.should == 'Expired'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Span" do
|
4
|
+
before(:each) do
|
5
|
+
build_model :span_model do
|
6
|
+
date :start_date
|
7
|
+
date :end_date
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
#let(:span_model) { SpanModel.new(:start_date => Date.today, :end_date => Date.today + 1) }
|
12
|
+
#let(:span) { span_model.span }
|
13
|
+
|
14
|
+
it "should be valid" do
|
15
|
+
SpanModel.acts_as_span
|
16
|
+
span_model = SpanModel.new(:start_date => nil, :end_date => nil)
|
17
|
+
|
18
|
+
span_model.should be_valid
|
19
|
+
end
|
20
|
+
|
21
|
+
context ":start_date_field_required => true" do
|
22
|
+
before do
|
23
|
+
SpanModel.acts_as_span :start_date_field_required => true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should require a start_date" do
|
27
|
+
span_model = SpanModel.new(:start_date => nil, :end_date => Date.today + 1)
|
28
|
+
|
29
|
+
span_model.should_not be_valid
|
30
|
+
span_model.errors[:start_date].should have(1).error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context ":end_date_field_required => true" do
|
35
|
+
before do
|
36
|
+
SpanModel.acts_as_span :end_date_field_required => true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should require an end_date" do
|
40
|
+
span_model = SpanModel.new(:start_date => Date.today, :end_date => nil)
|
41
|
+
|
42
|
+
span_model.should_not be_valid
|
43
|
+
span_model.errors[:end_date].should have(1).error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should require a start_date before the end_date" do
|
48
|
+
SpanModel.acts_as_span
|
49
|
+
span_model = SpanModel.new(:start_date => Date.today, :end_date => Date.today - 1)
|
50
|
+
|
51
|
+
span_model.should_not be_valid
|
52
|
+
span_model.errors[:end_date].should have(1).error
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#NOTE: we're also testing :start_date_field & :end_date_field options work
|
4
|
+
|
5
|
+
describe "Span" do
|
6
|
+
before(:each) do
|
7
|
+
build_model :span_model do
|
8
|
+
date :start_date_x
|
9
|
+
date :end_date_x
|
10
|
+
|
11
|
+
acts_as_span :start_date_field => :start_date_x,
|
12
|
+
:end_date_field => :end_date_x
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "#close!" do
|
17
|
+
let(:span_model) { SpanModel.new(:start_date_x => Date.today, :end_date_x => nil) }
|
18
|
+
let(:span) { span_model.span }
|
19
|
+
|
20
|
+
it "should set end_date? to today" do
|
21
|
+
lambda { span.close! }.should change(span_model, :end_date_x).from(nil).to(Date.today)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set end_date? to the parameter" do
|
25
|
+
lambda { span.close_on!(Date.today + 1.day) }.should change(span_model, :end_date_x).from(nil).to(Date.today + 1.day)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "start_date & end_date" do
|
30
|
+
let(:span_model) { SpanModel.new(:start_date_x => Date.today, :end_date_x => Date.today + 1) }
|
31
|
+
let(:span) { span_model.span }
|
32
|
+
|
33
|
+
it "should return the start_date" do
|
34
|
+
span.start_date.should == span_model.start_date_x
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return the end_date" do
|
38
|
+
span.end_date.should == span_model.end_date_x
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_span
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.5
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Sullivan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-28 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "3"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
description: start_date and end_date as a span w/ ActiveRecord
|
38
|
+
email:
|
39
|
+
- eric.sullivan@annkissam.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- LICENSE
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- acts_as_span.gemspec
|
54
|
+
- lib/acts_as_span.rb
|
55
|
+
- lib/acts_as_span/span_instance.rb
|
56
|
+
- lib/acts_as_span/span_instance/overlap.rb
|
57
|
+
- lib/acts_as_span/span_instance/status.rb
|
58
|
+
- lib/acts_as_span/span_instance/validations.rb
|
59
|
+
- lib/acts_as_span/span_klass.rb
|
60
|
+
- lib/acts_as_span/span_klass/overlap.rb
|
61
|
+
- lib/acts_as_span/span_klass/status.rb
|
62
|
+
- lib/acts_as_span/version.rb
|
63
|
+
- spec/lib/acts_as_span_spec.rb
|
64
|
+
- spec/lib/delegation_spec.rb
|
65
|
+
- spec/lib/negative_spec.rb
|
66
|
+
- spec/lib/span_instance/named_scopes_on_spec.rb
|
67
|
+
- spec/lib/span_instance/named_scopes_spec.rb
|
68
|
+
- spec/lib/span_instance/overlap_spec.rb
|
69
|
+
- spec/lib/span_instance/status_spec.rb
|
70
|
+
- spec/lib/span_instance/validations_spec.rb
|
71
|
+
- spec/lib/span_instance_spec.rb
|
72
|
+
- spec/spec.opts
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/annkissam/acts_as_span
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: acts_as_span
|
97
|
+
rubygems_version: 1.8.8
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: acts_as_span 0.0.5
|
101
|
+
test_files:
|
102
|
+
- spec/lib/acts_as_span_spec.rb
|
103
|
+
- spec/lib/delegation_spec.rb
|
104
|
+
- spec/lib/negative_spec.rb
|
105
|
+
- spec/lib/span_instance/named_scopes_on_spec.rb
|
106
|
+
- spec/lib/span_instance/named_scopes_spec.rb
|
107
|
+
- spec/lib/span_instance/overlap_spec.rb
|
108
|
+
- spec/lib/span_instance/status_spec.rb
|
109
|
+
- spec/lib/span_instance/validations_spec.rb
|
110
|
+
- spec/lib/span_instance_spec.rb
|
111
|
+
- spec/spec.opts
|
112
|
+
- spec/spec_helper.rb
|