acts_as_span 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -3
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +0 -3
- data/README.rdoc +4 -16
- data/Rakefile +5 -1
- data/acts_as_span.gemspec +21 -5
- data/lib/acts_as_span.rb +55 -98
- data/lib/acts_as_span/no_overlap_validator.rb +51 -0
- data/lib/acts_as_span/span_instance.rb +17 -33
- data/lib/acts_as_span/span_instance/status.rb +12 -27
- data/lib/acts_as_span/span_instance/validations.rb +5 -53
- data/lib/acts_as_span/span_klass.rb +11 -19
- data/lib/acts_as_span/span_klass/status.rb +33 -12
- data/lib/acts_as_span/version.rb +2 -2
- data/lib/acts_as_span/within_parent_date_span_validator.rb +42 -0
- data/spec/lib/acts_as_span_spec.rb +18 -36
- data/spec/lib/delegation_spec.rb +45 -78
- data/spec/lib/no_overlap_validator_spec.rb +96 -0
- data/spec/lib/span_instance/named_scopes_on_spec.rb +193 -193
- data/spec/lib/span_instance/named_scopes_spec.rb +193 -191
- data/spec/lib/span_instance/overlap_spec.rb +193 -253
- data/spec/lib/span_instance/status_spec.rb +22 -35
- data/spec/lib/span_instance/validations_spec.rb +8 -44
- data/spec/lib/span_instance_spec.rb +5 -30
- data/spec/lib/within_parent_date_span_validator_spec.rb +115 -0
- data/spec/spec_helper.rb +19 -6
- data/spec/spec_models.rb +69 -0
- metadata +158 -58
- data/Gemfile.lock +0 -47
- data/lib/acts_as_span/span_instance/overlap.rb +0 -17
- data/lib/acts_as_span/span_klass/overlap.rb +0 -21
- data/spec/lib/negative_spec.rb +0 -30
- data/spec/spec.opts +0 -1
data/Gemfile.lock
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
acts_as_span (0.0.5)
|
5
|
-
activerecord (>= 3)
|
6
|
-
activesupport
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (3.0.10)
|
12
|
-
activesupport (= 3.0.10)
|
13
|
-
builder (~> 2.1.2)
|
14
|
-
i18n (~> 0.5.0)
|
15
|
-
activerecord (3.0.10)
|
16
|
-
activemodel (= 3.0.10)
|
17
|
-
activesupport (= 3.0.10)
|
18
|
-
arel (~> 2.0.10)
|
19
|
-
tzinfo (~> 0.3.23)
|
20
|
-
activesupport (3.0.10)
|
21
|
-
acts_as_fu (0.0.7.2)
|
22
|
-
activerecord
|
23
|
-
sqlite3-ruby
|
24
|
-
arel (2.0.10)
|
25
|
-
builder (2.1.2)
|
26
|
-
diff-lcs (1.1.2)
|
27
|
-
i18n (0.5.0)
|
28
|
-
rspec (2.6.0)
|
29
|
-
rspec-core (~> 2.6.0)
|
30
|
-
rspec-expectations (~> 2.6.0)
|
31
|
-
rspec-mocks (~> 2.6.0)
|
32
|
-
rspec-core (2.6.4)
|
33
|
-
rspec-expectations (2.6.0)
|
34
|
-
diff-lcs (~> 1.1.2)
|
35
|
-
rspec-mocks (2.6.0)
|
36
|
-
sqlite3 (1.3.4)
|
37
|
-
sqlite3-ruby (1.3.3)
|
38
|
-
sqlite3 (>= 1.3.3)
|
39
|
-
tzinfo (0.3.29)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
ruby
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
acts_as_fu
|
46
|
-
acts_as_span!
|
47
|
-
rspec
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module ActsAsSpan
|
4
|
-
class SpanInstance
|
5
|
-
module Overlap
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
module InstanceMethods
|
9
|
-
#http://stackoverflow.com/questions/699448/ruby-how-do-you-check-whether-a-range-contains-a-subset-of-another-range
|
10
|
-
#start_date <= record_end_date && record_start_date <= end_date
|
11
|
-
def overlap?(other_span)
|
12
|
-
(start_date.nil? || other_span.end_date.nil? || start_date <= other_span.end_date) && (end_date.nil? || other_span.start_date.nil? || other_span.start_date <= end_date)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module ActsAsSpan
|
4
|
-
class SpanKlass
|
5
|
-
module Overlap
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
module InstanceMethods
|
9
|
-
def overlap(test_span)
|
10
|
-
overlap_scope = klass.where( ["(#{table_name}.#{start_date_field} IS NULL OR :end_date IS NULL OR #{table_name}.#{start_date_field} <= :end_date) AND (#{table_name}.#{end_date_field} IS NULL OR :start_date IS NULL OR :start_date <= #{table_name}.#{end_date_field})", { :start_date => test_span.start_date, :end_date => test_span.end_date } ] )
|
11
|
-
|
12
|
-
if !test_span.new_record? && test_span.span_klass == klass
|
13
|
-
overlap_scope.where( ["#{table_name}.id != :id", { :id => test_span.id } ] )
|
14
|
-
end
|
15
|
-
|
16
|
-
overlap_scope
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/spec/lib/negative_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "acts_as_span" do
|
4
|
-
before(:each) do
|
5
|
-
build_model :negative_model do
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
context "NegativeModel (Class)" do
|
10
|
-
it "should respond_to acts_as_span" do
|
11
|
-
NegativeModel.should respond_to(:acts_as_span)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return false for acts_as_span?" do
|
15
|
-
NegativeModel.acts_as_span?.should be_false
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should have no acts_as_span_definitions" do
|
19
|
-
NegativeModel.acts_as_span_definitions.should be_empty
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "NegativeModel (Instance)" do
|
24
|
-
let(:negative_model) { NegativeModel.new }
|
25
|
-
|
26
|
-
it "should return false for acts_as_span?" do
|
27
|
-
negative_model.acts_as_span?.should be_false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|