acts_as_historical 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_historical}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hasclass"]
@@ -16,7 +16,6 @@ module ActsAsHistorical
16
16
  def acts_as_historical(opts = {})
17
17
  configuration = {
18
18
  :date_column => "snapshot_date",
19
- :
20
19
  :scope => nil
21
20
  }
22
21
  configuration.update(opts) if opts.is_a?(Hash)
@@ -90,24 +89,24 @@ module ActsAsHistorical
90
89
  # Does not include date
91
90
  #
92
91
  named_scope :upto, lambda {|date|
93
- raise "passed parameter does not respond_to? to_date" if date.respond_to?(:to_date)
92
+ raise "passed parameter does not respond_to? to_date" unless date.respond_to?(:to_date)
94
93
  { :conditions => ["#{self.historical_date_col_sql} < ?", date.to_date] }
95
94
  }
96
95
 
97
96
  # Includes date
98
97
  #
99
98
  named_scope :upto_including, lambda {|date|
100
- raise "passed parameter does not respond_to? to_date" if date.respond_to?(:to_date)
99
+ raise "passed parameter does not respond_to? to_date" unless date.respond_to?(:to_date)
101
100
  { :conditions => ["#{self.historical_date_col_sql} <= ?", date.to_date] }
102
101
  }
103
102
 
104
103
  named_scope :from, lambda {|date|
105
- raise "passed parameter does not respond_to? to_date" if date.respond_to?(:to_date)
104
+ raise "passed parameter does not respond_to? to_date" unless date.respond_to?(:to_date)
106
105
  { :conditions => ["#{self.historical_date_col_sql} > ?", date.to_date] }
107
106
  }
108
107
 
109
108
  named_scope :from_including, lambda {|date|
110
- raise "passed parameter does not respond_to? to_date" if date.respond_to?(:to_date)
109
+ raise "passed parameter does not respond_to? to_date" unless date.respond_to?(:to_date)
111
110
  { :conditions => ["#{self.historical_date_col_sql} >= ?", date.to_date] }
112
111
  }
113
112
 
@@ -147,9 +146,9 @@ module ActsAsHistorical
147
146
  end
148
147
  true
149
148
  end
150
-
151
- def previous; find_record_at(prev_day); end
152
- def next; find_record_at(next_day); end
149
+
150
+ def previous; find_record_at(to_date - 1); end
151
+ def next; find_record_at(to_date + 1); end
153
152
 
154
153
  def to_date
155
154
  self.send(self.class.historical_date_col)
@@ -159,17 +158,6 @@ module ActsAsHistorical
159
158
  def find_record_at(date)
160
159
  self.class.at_date(date).same_scope(self).find(:first)
161
160
  end
162
-
163
- def next_day; self.class.step_date(to_date, 1); end
164
- def prev_day; self.class.step_date(to_date, -1); end
165
- end
166
-
167
- module AllDays
168
- module ClassMethods
169
- def step_date(date, step_size)
170
- date + step_size
171
- end
172
- end
173
161
  end
174
162
  end
175
163
 
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class ActsAsHistoricalTest < ActiveSupport::TestCase
4
4
  load_schema
5
+
5
6
 
6
7
  class Record < ActiveRecord::Base
7
8
  acts_as_historical
@@ -35,7 +36,42 @@ class ActsAsHistoricalTest < ActiveSupport::TestCase
35
36
  should "create 5 records" do
36
37
  assert_equal 5, Record.count
37
38
  end
38
-
39
+
40
+ context "upto" do
41
+ should "return records upto date excluding date" do
42
+ assert Record.upto(@tue).include?(@r_mon)
43
+ assert !Record.upto(@tue).include?(@r_tue)
44
+ assert !Record.upto(@tue).include?(@r_wed)
45
+ end
46
+ end
47
+
48
+ context "upto_including" do
49
+ should "return records upto and including given date" do
50
+ records = Record.upto_including(@tue)
51
+ assert records.include?(@r_mon)
52
+ assert records.include?(@r_tue)
53
+ assert !records.include?(@r_wed)
54
+ end
55
+ end
56
+
57
+ context "from_including" do
58
+ should "return records from including given date" do
59
+ records = Record.from_including(@tue)
60
+ assert !records.include?(@r_mon)
61
+ assert records.include?(@r_tue)
62
+ assert records.include?(@r_wed)
63
+ end
64
+ end
65
+
66
+ context "from" do
67
+ should "return records from excluding given date" do
68
+ records = Record.from(@tue)
69
+ assert !records.include?(@r_mon)
70
+ assert !records.include?(@r_tue)
71
+ assert records.include?(@r_wed)
72
+ end
73
+ end
74
+
39
75
  context "nearest" do
40
76
  should "always return monday no matter what tolerance range" do
41
77
  assert_equal @r_mon, Record.nearest(@mon-1, 1).first
@@ -51,7 +87,7 @@ class ActsAsHistoricalTest < ActiveSupport::TestCase
51
87
  end
52
88
  end
53
89
 
54
- context "within" do
90
+ context "between" do
55
91
  setup { @records = Record.between(@tue, @wed)}
56
92
 
57
93
  should "include only days within range" do
@@ -63,7 +99,7 @@ class ActsAsHistoricalTest < ActiveSupport::TestCase
63
99
  end
64
100
 
65
101
  should "return record when range start and end are the same" do
66
- assert Record.between(@mon, @mon).include?(@r_mon)
102
+ assert Record.between(@mon, @mon).include?(@r_mon)
67
103
  end
68
104
  end
69
105
  end
data/test/test_helper.rb CHANGED
@@ -31,4 +31,8 @@ def load_schema
31
31
 
32
32
  load(File.dirname(__FILE__) + "/schema.rb")
33
33
  require File.dirname(__FILE__) + '/../rails/init.rb'
34
- end
34
+ end
35
+
36
+ class Date
37
+ def to_date(); self; end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_historical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hasclass