validates_timeliness 3.0.14 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +21 -0
  3. data/README.rdoc +12 -9
  4. data/Rakefile +1 -1
  5. data/gemfiles/rails_4_0.gemfile +19 -0
  6. data/gemfiles/rails_4_1.gemfile +19 -0
  7. data/gemfiles/rails_4_2.gemfile +19 -0
  8. data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +3 -3
  9. data/lib/validates_timeliness/attribute_methods.rb +36 -36
  10. data/lib/validates_timeliness/extensions/date_time_select.rb +2 -9
  11. data/lib/validates_timeliness/extensions/multiparameter_handler.rb +59 -65
  12. data/lib/validates_timeliness/extensions.rb +3 -4
  13. data/lib/validates_timeliness/helper_methods.rb +8 -2
  14. data/lib/validates_timeliness/orm/active_record.rb +59 -13
  15. data/lib/validates_timeliness/validator.rb +20 -6
  16. data/lib/validates_timeliness/version.rb +1 -1
  17. data/lib/validates_timeliness.rb +9 -13
  18. data/spec/spec_helper.rb +4 -2
  19. data/spec/support/model_helpers.rb +4 -4
  20. data/spec/support/tag_matcher.rb +35 -0
  21. data/spec/support/test_model.rb +0 -1
  22. data/spec/validates_timeliness/attribute_methods_spec.rb +10 -10
  23. data/spec/validates_timeliness/conversion_spec.rb +41 -41
  24. data/spec/validates_timeliness/extensions/date_time_select_spec.rb +5 -4
  25. data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +8 -7
  26. data/spec/validates_timeliness/helper_methods_spec.rb +12 -12
  27. data/spec/validates_timeliness/orm/active_record_spec.rb +70 -80
  28. data/spec/validates_timeliness/validator/after_spec.rb +3 -3
  29. data/spec/validates_timeliness/validator/before_spec.rb +3 -3
  30. data/spec/validates_timeliness/validator/is_at_spec.rb +4 -4
  31. data/spec/validates_timeliness/validator/on_or_after_spec.rb +3 -3
  32. data/spec/validates_timeliness/validator/on_or_before_spec.rb +3 -3
  33. data/spec/validates_timeliness/validator_spec.rb +40 -29
  34. data/spec/validates_timeliness_spec.rb +8 -8
  35. data/validates_timeliness.gemspec +1 -1
  36. metadata +41 -67
  37. data/gemfiles/mongoid_2_1.gemfile +0 -16
  38. data/gemfiles/mongoid_2_2.gemfile +0 -16
  39. data/gemfiles/mongoid_2_3.gemfile +0 -16
  40. data/gemfiles/mongoid_2_4.gemfile +0 -16
  41. data/gemfiles/rails_3_0.gemfile +0 -15
  42. data/gemfiles/rails_3_1.gemfile +0 -15
  43. data/gemfiles/rails_3_2.gemfile +0 -15
  44. data/lib/validates_timeliness/orm/mongoid.rb +0 -63
  45. data/spec/validates_timeliness/orm/mongoid_spec.rb +0 -189
@@ -24,26 +24,24 @@ module ValidatesTimeliness
24
24
 
25
25
  class << self
26
26
  delegate :default_timezone, :default_timezone=, :dummy_date_for_time_type, :dummy_date_for_time_type=, :to => Timeliness
27
+
28
+ attr_accessor :extend_orms, :ignore_restriction_errors, :restriction_shorthand_symbols, :use_plugin_parser
27
29
  end
28
30
 
29
- # Extend ORM/ODMs for full support (:active_record, :mongoid).
30
- mattr_accessor :extend_orms
31
- @@extend_orms = []
31
+ # Extend ORM/ODMs for full support (:active_record).
32
+ self.extend_orms = []
32
33
 
33
34
  # Ignore errors when restriction options are evaluated
34
- mattr_accessor :ignore_restriction_errors
35
- @@ignore_restriction_errors = false
35
+ self.ignore_restriction_errors = false
36
36
 
37
37
  # Shorthand time and date symbols for restrictions
38
- mattr_accessor :restriction_shorthand_symbols
39
- @@restriction_shorthand_symbols = {
38
+ self.restriction_shorthand_symbols = {
40
39
  :now => lambda { Time.current },
41
40
  :today => lambda { Date.current }
42
41
  }
43
42
 
44
43
  # Use the plugin date/time parser which is stricter and extensible
45
- mattr_accessor :use_plugin_parser
46
- @@use_plugin_parser = false
44
+ self.use_plugin_parser = false
47
45
 
48
46
  # Default timezone
49
47
  self.default_timezone = :utc
@@ -51,10 +49,6 @@ module ValidatesTimeliness
51
49
  # Set the dummy date part for a time type values.
52
50
  self.dummy_date_for_time_type = [ 2000, 1, 1 ]
53
51
 
54
- def self.parser
55
- Timeliness
56
- end
57
-
58
52
  # Setup method for plugin configuration
59
53
  def self.setup
60
54
  yield self
@@ -64,6 +58,8 @@ module ValidatesTimeliness
64
58
  def self.load_orms
65
59
  extend_orms.each {|orm| require "validates_timeliness/orm/#{orm}" }
66
60
  end
61
+
62
+ def self.parser; Timeliness end
67
63
  end
68
64
 
69
65
  require 'validates_timeliness/conversion'
data/spec/spec_helper.rb CHANGED
@@ -5,13 +5,13 @@ require 'active_model/validations'
5
5
  require 'active_record'
6
6
  require 'action_view'
7
7
  require 'timecop'
8
- require 'rspec_tag_matchers'
9
8
 
10
9
  require 'validates_timeliness'
11
10
 
12
11
  require 'support/test_model'
13
12
  require 'support/model_helpers'
14
13
  require 'support/config_helper'
14
+ require 'support/tag_matcher'
15
15
 
16
16
  ValidatesTimeliness.setup do |c|
17
17
  c.extend_orms = [ :active_record ]
@@ -24,6 +24,7 @@ Time.zone = 'Australia/Melbourne'
24
24
 
25
25
  LOCALE_PATH = File.expand_path(File.dirname(__FILE__) + '/../lib/generators/validates_timeliness/templates/en.yml')
26
26
  I18n.load_path.unshift(LOCALE_PATH)
27
+ I18n.available_locales = ['en', 'es']
27
28
 
28
29
  # Extend TestModel as you would another ORM/ODM module
29
30
  module TestModelShim
@@ -57,6 +58,7 @@ class PersonWithShim < Person
57
58
  include TestModelShim
58
59
  end
59
60
 
61
+ ActiveRecord::Base.default_timezone = :utc
60
62
  ActiveRecord::Base.time_zone_aware_attributes = true
61
63
  ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
62
64
  ActiveRecord::Migration.verbose = false
@@ -84,7 +86,7 @@ end
84
86
 
85
87
  RSpec.configure do |c|
86
88
  c.mock_with :rspec
87
- c.include(RspecTagMatchers)
89
+ c.include(TagMatcher)
88
90
  c.include(ModelHelpers)
89
91
  c.include(ConfigHelper)
90
92
  c.before do
@@ -3,15 +3,15 @@ module ModelHelpers
3
3
  # Some test helpers from Rails source
4
4
  def invalid!(attr_name, values, error = nil)
5
5
  with_each_person_value(attr_name, values) do |record, value|
6
- record.should be_invalid
7
- record.errors[attr_name].size.should >= 1
8
- record.errors[attr_name].first.should == error if error
6
+ expect(record).to be_invalid
7
+ expect(record.errors[attr_name].size).to be >= 1
8
+ expect(record.errors[attr_name].first).to eq(error) if error
9
9
  end
10
10
  end
11
11
 
12
12
  def valid!(attr_name, values)
13
13
  with_each_person_value(attr_name, values) do |record, value|
14
- record.should be_valid
14
+ expect(record).to be_valid
15
15
  end
16
16
  end
17
17
 
@@ -0,0 +1,35 @@
1
+ require 'nokogiri'
2
+
3
+ module TagMatcher
4
+ extend RSpec::Matchers::DSL
5
+
6
+ matcher :have_tag do |selector|
7
+ match do |subject|
8
+ matches = doc(subject).search(selector)
9
+
10
+ if @inner_text
11
+ matches = matches.select { |element| element.inner_text == @inner_text }
12
+ end
13
+
14
+ matches.any?
15
+ end
16
+
17
+ chain :with_inner_text do |inner_text|
18
+ @inner_text = inner_text
19
+ end
20
+
21
+ private
22
+
23
+ def body(subject)
24
+ if subject.respond_to?(:body)
25
+ subject.body
26
+ else
27
+ subject.to_s
28
+ end
29
+ end
30
+
31
+ def doc(subject)
32
+ @doc ||= Nokogiri::HTML(body(subject))
33
+ end
34
+ end
35
+ end
@@ -5,7 +5,6 @@ module TestModel
5
5
  include ActiveModel::AttributeMethods
6
6
 
7
7
  included do
8
- attribute_method_suffix ""
9
8
  attribute_method_suffix "="
10
9
  cattr_accessor :model_attributes
11
10
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ValidatesTimeliness::AttributeMethods do
4
- it 'should define _timeliness_raw_value_for instance method' do
5
- PersonWithShim.new.should respond_to(:_timeliness_raw_value_for)
4
+ it 'should define read_timeliness_attribute_before_type_cast instance method' do
5
+ expect(PersonWithShim.new).to respond_to(:read_timeliness_attribute_before_type_cast)
6
6
  end
7
7
 
8
8
  describe ".timeliness_validated_attributes" do
@@ -12,7 +12,7 @@ describe ValidatesTimeliness::AttributeMethods do
12
12
  PersonWithShim.validates_time :birth_time
13
13
  PersonWithShim.validates_datetime :birth_datetime
14
14
 
15
- PersonWithShim.timeliness_validated_attributes.should == [ :birth_date, :birth_time, :birth_datetime ]
15
+ expect(PersonWithShim.timeliness_validated_attributes).to eq([ :birth_date, :birth_time, :birth_datetime ])
16
16
  end
17
17
  end
18
18
 
@@ -31,13 +31,13 @@ describe ValidatesTimeliness::AttributeMethods do
31
31
  it 'should cache attribute raw value' do
32
32
  r = PersonWithCache.new
33
33
  r.birth_datetime = date_string = '2010-01-01'
34
- r._timeliness_raw_value_for('birth_datetime').should == date_string
34
+ expect(r.read_timeliness_attribute_before_type_cast('birth_datetime')).to eq(date_string)
35
35
  end
36
36
 
37
37
  it 'should not overwrite user defined methods' do
38
38
  e = Employee.new
39
39
  e.birth_date = '2010-01-01'
40
- e.redefined_birth_date_called.should be_true
40
+ expect(e.redefined_birth_date_called).to be_truthy
41
41
  end
42
42
 
43
43
  it 'should be undefined if model class has dynamic attribute methods reset' do
@@ -46,13 +46,13 @@ describe ValidatesTimeliness::AttributeMethods do
46
46
  r = PersonWithShim.new
47
47
  r.birth_date = Time.now
48
48
 
49
- write_method = RUBY_VERSION < '1.9' ? 'birth_date=' : :birth_date=
49
+ write_method = :birth_date=
50
50
 
51
- PersonWithShim.send(:generated_timeliness_methods).instance_methods.should include(write_method)
51
+ expect(PersonWithShim.send(:generated_timeliness_methods).instance_methods).to include(write_method)
52
52
 
53
53
  PersonWithShim.undefine_attribute_methods
54
54
 
55
- PersonWithShim.send(:generated_timeliness_methods).instance_methods.should_not include(write_method)
55
+ expect(PersonWithShim.send(:generated_timeliness_methods).instance_methods).not_to include(write_method)
56
56
  end
57
57
 
58
58
  context "with plugin parser" do
@@ -70,7 +70,7 @@ describe ValidatesTimeliness::AttributeMethods do
70
70
  end
71
71
 
72
72
  it 'should parse a string value' do
73
- Timeliness::Parser.should_receive(:parse)
73
+ expect(Timeliness::Parser).to receive(:parse)
74
74
  r = PersonWithParser.new
75
75
  r.birth_date = '2010-01-01'
76
76
  end
@@ -80,7 +80,7 @@ describe ValidatesTimeliness::AttributeMethods do
80
80
 
81
81
  context "before_type_cast method" do
82
82
  it 'should not be defined if ORM does not support it' do
83
- PersonWithShim.new.should_not respond_to(:birth_datetime_before_type_cast)
83
+ expect(PersonWithShim.new).not_to respond_to(:birth_datetime_before_type_cast)
84
84
  end
85
85
  end
86
86
  end
@@ -12,68 +12,68 @@ describe ValidatesTimeliness::Conversion do
12
12
  describe "#type_cast_value" do
13
13
  describe "for date type" do
14
14
  it "should return same value for date value" do
15
- type_cast_value(Date.new(2010, 1, 1), :date).should == Date.new(2010, 1, 1)
15
+ expect(type_cast_value(Date.new(2010, 1, 1), :date)).to eq(Date.new(2010, 1, 1))
16
16
  end
17
17
 
18
18
  it "should return date part of time value" do
19
- type_cast_value(Time.mktime(2010, 1, 1, 0, 0, 0), :date).should == Date.new(2010, 1, 1)
19
+ expect(type_cast_value(Time.mktime(2010, 1, 1, 0, 0, 0), :date)).to eq(Date.new(2010, 1, 1))
20
20
  end
21
21
 
22
22
  it "should return date part of datetime value" do
23
- type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0), :date).should == Date.new(2010, 1, 1)
23
+ expect(type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0), :date)).to eq(Date.new(2010, 1, 1))
24
24
  end
25
25
 
26
26
  it 'should return nil for invalid value types' do
27
- type_cast_value(12, :date).should == nil
27
+ expect(type_cast_value(12, :date)).to eq(nil)
28
28
  end
29
29
  end
30
30
 
31
31
  describe "for time type" do
32
32
  it "should return same value for time value matching dummy date part" do
33
- type_cast_value(Time.utc(2000, 1, 1, 0, 0, 0), :time).should == Time.utc(2000, 1, 1, 0, 0, 0)
33
+ expect(type_cast_value(Time.utc(2000, 1, 1, 0, 0, 0), :time)).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
34
34
  end
35
35
 
36
36
  it "should return dummy time value with same time part for time value with different date" do
37
- type_cast_value(Time.utc(2010, 1, 1, 0, 0, 0), :time).should == Time.utc(2000, 1, 1, 0, 0, 0)
37
+ expect(type_cast_value(Time.utc(2010, 1, 1, 0, 0, 0), :time)).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
38
38
  end
39
39
 
40
40
  it "should return dummy time only for date value" do
41
- type_cast_value(Date.new(2010, 1, 1), :time).should == Time.utc(2000, 1, 1, 0, 0, 0)
41
+ expect(type_cast_value(Date.new(2010, 1, 1), :time)).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
42
42
  end
43
43
 
44
44
  it "should return dummy date with time part for datetime value" do
45
- type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :time).should == Time.utc(2000, 1, 1, 12, 34, 56)
45
+ expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :time)).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
46
46
  end
47
47
 
48
48
  it 'should return nil for invalid value types' do
49
- type_cast_value(12, :time).should == nil
49
+ expect(type_cast_value(12, :time)).to eq(nil)
50
50
  end
51
51
  end
52
52
 
53
53
  describe "for datetime type" do
54
54
  it "should return Date as Time value" do
55
- type_cast_value(Date.new(2010, 1, 1), :datetime).should == Time.local_time(2010, 1, 1, 0, 0, 0)
55
+ expect(type_cast_value(Date.new(2010, 1, 1), :datetime)).to eq(Time.local(2010, 1, 1, 0, 0, 0))
56
56
  end
57
57
 
58
58
  it "should return same Time value" do
59
59
  value = Time.utc(2010, 1, 1, 12, 34, 56)
60
- type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56), :datetime).should == value
60
+ expect(type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56), :datetime)).to eq(value)
61
61
  end
62
62
 
63
63
  it "should return as Time with same component values" do
64
- type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :datetime).should == Time.utc(2010, 1, 1, 12, 34, 56)
64
+ expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :datetime)).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
65
65
  end
66
66
 
67
67
  it "should return same Time in correct zone if timezone aware" do
68
68
  @timezone_aware = true
69
69
  value = Time.utc(2010, 1, 1, 12, 34, 56)
70
70
  result = type_cast_value(value, :datetime)
71
- result.should == Time.zone.local(2010, 1, 1, 23, 34, 56)
72
- result.zone.should == 'EST'
71
+ expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
72
+ expect(result.zone).to eq('AEDT')
73
73
  end
74
74
 
75
75
  it 'should return nil for invalid value types' do
76
- type_cast_value(12, :datetime).should == nil
76
+ expect(type_cast_value(12, :datetime)).to eq(nil)
77
77
  end
78
78
  end
79
79
 
@@ -82,41 +82,41 @@ describe ValidatesTimeliness::Conversion do
82
82
 
83
83
  it "should ignore usec on time values when evaluated" do
84
84
  value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
85
- type_cast_value(value, :datetime).should == Time.utc(2010, 1, 1, 12, 34, 56)
85
+ expect(type_cast_value(value, :datetime)).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
86
86
  end
87
87
 
88
88
  it "should ignore usec and return time in correct zone if timezone aware" do
89
89
  @timezone_aware = true
90
90
  value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
91
91
  result = type_cast_value(value, :datetime)
92
- result.should == Time.zone.local(2010, 1, 1, 23, 34, 56)
93
- result.zone.should == 'EST'
92
+ expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
93
+ expect(result.zone).to eq('AEDT')
94
94
  end
95
95
  end
96
96
  end
97
97
 
98
98
  describe "#dummy_time" do
99
99
  it 'should return Time with dummy date values but same time components' do
100
- dummy_time(Time.utc(2010, 11, 22, 12, 34, 56)).should == Time.utc(2000, 1, 1, 12, 34, 56)
100
+ expect(dummy_time(Time.utc(2010, 11, 22, 12, 34, 56))).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
101
101
  end
102
102
 
103
103
  it 'should return same value for Time which already has dummy date values' do
104
- dummy_time(Time.utc(2000, 1, 1, 12, 34, 56)).should == Time.utc(2000, 1, 1, 12, 34, 56)
104
+ expect(dummy_time(Time.utc(2000, 1, 1, 12, 34, 56))).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
105
105
  end
106
106
 
107
107
  it 'should return time component values shifted to current zone if timezone aware' do
108
108
  @timezone_aware = true
109
- dummy_time(Time.utc(2000, 1, 1, 12, 34, 56)).should == Time.zone.local(2000, 1, 1, 23, 34, 56)
109
+ expect(dummy_time(Time.utc(2000, 1, 1, 12, 34, 56))).to eq(Time.zone.local(2000, 1, 1, 23, 34, 56))
110
110
  end
111
111
 
112
112
  it 'should return base dummy time value for Date value' do
113
- dummy_time(Date.new(2010, 11, 22)).should == Time.utc(2000, 1, 1, 0, 0, 0)
113
+ expect(dummy_time(Date.new(2010, 11, 22))).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
114
114
  end
115
115
 
116
116
  describe "with custom dummy date" do
117
117
  it 'should return dummy time with custom dummy date' do
118
118
  with_config(:dummy_date_for_time_type, [2010, 1, 1] ) do
119
- dummy_time(Time.utc(1999, 11, 22, 12, 34, 56)).should == Time.utc(2010, 1, 1, 12, 34, 56)
119
+ expect(dummy_time(Time.utc(1999, 11, 22, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
120
120
  end
121
121
  end
122
122
  end
@@ -127,56 +127,56 @@ describe ValidatesTimeliness::Conversion do
127
127
 
128
128
  it 'should return Date object as is' do
129
129
  value = Date.new(2010,1,1)
130
- evaluate_option_value(value, person).should == value
130
+ expect(evaluate_option_value(value, person)).to eq(value)
131
131
  end
132
132
 
133
133
  it 'should return Time object as is' do
134
134
  value = Time.mktime(2010,1,1)
135
- evaluate_option_value(value, person).should == value
135
+ expect(evaluate_option_value(value, person)).to eq(value)
136
136
  end
137
137
 
138
138
  it 'should return DateTime object as is' do
139
139
  value = DateTime.new(2010,1,1,0,0,0)
140
- evaluate_option_value(value, person).should == value
140
+ expect(evaluate_option_value(value, person)).to eq(value)
141
141
  end
142
142
 
143
143
  it 'should return Time value returned from proc with 0 arity' do
144
144
  value = Time.mktime(2010,1,1)
145
- evaluate_option_value(lambda { value }, person).should == value
145
+ expect(evaluate_option_value(lambda { value }, person)).to eq(value)
146
146
  end
147
147
 
148
148
  it 'should return Time value returned by record attribute call in proc arity of 1' do
149
149
  value = Time.mktime(2010,1,1)
150
150
  person.birth_time = value
151
- evaluate_option_value(lambda {|r| r.birth_time }, person).should == value
151
+ expect(evaluate_option_value(lambda {|r| r.birth_time }, person)).to eq(value)
152
152
  end
153
153
 
154
154
  it 'should return Time value for attribute method symbol which returns Time' do
155
155
  value = Time.mktime(2010,1,1)
156
156
  person.birth_time = value
157
- evaluate_option_value(:birth_time, person).should == value
157
+ expect(evaluate_option_value(:birth_time, person)).to eq(value)
158
158
  end
159
159
 
160
160
  it 'should return Time value is default zone from string time value' do
161
161
  value = '2010-01-01 12:00:00'
162
- evaluate_option_value(value, person).should == Time.utc(2010,1,1,12,0,0)
162
+ expect(evaluate_option_value(value, person)).to eq(Time.utc(2010,1,1,12,0,0))
163
163
  end
164
164
 
165
165
  it 'should return Time value is current zone from string time value if timezone aware' do
166
166
  @timezone_aware = true
167
167
  value = '2010-01-01 12:00:00'
168
- evaluate_option_value(value, person).should == Time.zone.local(2010,1,1,12,0,0)
168
+ expect(evaluate_option_value(value, person)).to eq(Time.zone.local(2010,1,1,12,0,0))
169
169
  end
170
170
 
171
171
  it 'should return Time value in default zone from proc which returns string time' do
172
172
  value = '2010-01-01 12:00:00'
173
- evaluate_option_value(lambda { value }, person).should == Time.utc(2010,1,1,12,0,0)
173
+ expect(evaluate_option_value(lambda { value }, person)).to eq(Time.utc(2010,1,1,12,0,0))
174
174
  end
175
175
 
176
176
  it 'should return Time value for attribute method symbol which returns string time value' do
177
177
  value = '2010-01-01 12:00:00'
178
178
  person.birth_time = value
179
- evaluate_option_value(:birth_time, person).should == Time.utc(2010,1,1,12,0,0)
179
+ expect(evaluate_option_value(:birth_time, person)).to eq(Time.zone.local(2010,1,1,12,0,0))
180
180
  end
181
181
 
182
182
  context "restriction shorthand" do
@@ -185,17 +185,17 @@ describe ValidatesTimeliness::Conversion do
185
185
  end
186
186
 
187
187
  it 'should evaluate :now as current time' do
188
- evaluate_option_value(:now, person).should == Time.now
188
+ expect(evaluate_option_value(:now, person)).to eq(Time.now)
189
189
  end
190
190
 
191
191
  it 'should evaluate :today as current time' do
192
- evaluate_option_value(:today, person).should == Date.today
192
+ expect(evaluate_option_value(:today, person)).to eq(Date.today)
193
193
  end
194
194
 
195
195
  it 'should not use shorthand if symbol if is record method' do
196
196
  time = 1.day.from_now
197
- person.stub!(:now).and_return(time)
198
- evaluate_option_value(:now, person).should == time
197
+ allow(person).to receive(:now).and_return(time)
198
+ expect(evaluate_option_value(:now, person)).to eq(time)
199
199
  end
200
200
  end
201
201
  end
@@ -205,7 +205,7 @@ describe ValidatesTimeliness::Conversion do
205
205
  with_config(:use_plugin_parser, true)
206
206
 
207
207
  it 'should use timeliness' do
208
- Timeliness::Parser.should_receive(:parse)
208
+ expect(Timeliness::Parser).to receive(:parse)
209
209
  parse('2000-01-01')
210
210
  end
211
211
  end
@@ -215,20 +215,20 @@ describe ValidatesTimeliness::Conversion do
215
215
 
216
216
  it 'should use Time.zone.parse attribute is timezone aware' do
217
217
  @timezone_aware = true
218
- Time.zone.should_receive(:parse)
218
+ expect(Time.zone).to receive(:parse)
219
219
  parse('2000-01-01')
220
220
  end
221
221
 
222
222
  it 'should use value#to_time if use_plugin_parser setting is false and attribute is not timezone aware' do
223
223
  @timezone_aware = false
224
224
  value = '2000-01-01'
225
- value.should_receive(:to_time)
225
+ expect(value).to receive(:to_time)
226
226
  parse(value)
227
227
  end
228
228
  end
229
229
 
230
230
  it 'should return nil if value is nil' do
231
- parse(nil).should be_nil
231
+ expect(parse(nil)).to be_nil
232
232
  end
233
233
  end
234
234
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ValidatesTimeliness::Extensions::DateTimeSelect do
3
+ describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
4
4
  include ActionView::Helpers::DateHelper
5
5
  attr_reader :person, :params
6
6
 
@@ -111,7 +111,7 @@ describe ValidatesTimeliness::Extensions::DateTimeSelect do
111
111
  @output = date_select(:person, :birth_date, :include_blank => true, :discard_day => true)
112
112
  should_have_datetime_selected(:birth_date, :year => 2009, :month => 'February')
113
113
  should_not_have_datetime_selected(:birth_time, :day)
114
- @output.should have_tag("input[id=person_birth_date_3i][type=hidden][value='1']")
114
+ expect(@output).to have_tag("input[id=person_birth_date_3i][type=hidden][value='1']")
115
115
  end
116
116
  end
117
117
 
@@ -150,14 +150,15 @@ describe ValidatesTimeliness::Extensions::DateTimeSelect do
150
150
  def should_have_datetime_selected(field, datetime_hash)
151
151
  datetime_hash.each do |key, value|
152
152
  index = {:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6}[key]
153
- @output.should have_tag("select[id=person_#{field}_#{index}i] option[selected=selected]", value.to_s)
153
+ expect(@output).to have_tag("select[id=person_#{field}_#{index}i] option[selected=selected]", value.to_s)
154
154
  end
155
155
  end
156
156
 
157
157
  def should_not_have_datetime_selected(field, *attributes)
158
158
  attributes.each do |attribute|
159
159
  index = {:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6}[attribute]
160
- @output.should_not have_tag("select[id=person_#{attribute}_#{index}i] option[selected=selected]")
160
+ expect(@output).not_to have_tag("select[id=person_#{attribute}_#{index}i] option[selected=selected]")
161
161
  end
162
162
  end
163
+
163
164
  end
@@ -1,38 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ValidatesTimeliness::Extensions::MultiparameterHandler do
3
+ describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
4
4
 
5
5
  context "time column" do
6
6
  it 'should assign a string value for invalid date portion' do
7
7
  employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
8
- employee.birth_datetime_before_type_cast.should eq '2000-02-31 12:00:00'
8
+ expect(employee.birth_datetime_before_type_cast).to eq '2000-02-31 12:00:00'
9
9
  end
10
10
 
11
11
  it 'should assign a Time value for valid datetimes' do
12
12
  employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
13
- employee.birth_datetime_before_type_cast.should eq Time.local(2000, 2, 28, 12, 0, 0)
13
+ expect(employee.birth_datetime_before_type_cast).to eq Time.zone.local(2000, 2, 28, 12, 0, 0)
14
14
  end
15
15
 
16
16
  it 'should assign a string value for incomplete time' do
17
17
  employee = record_with_multiparameter_attribute(:birth_datetime, [2000, nil, nil])
18
- employee.birth_datetime_before_type_cast.should eq '2000-00-00'
18
+ expect(employee.birth_datetime_before_type_cast).to eq '2000-00-00'
19
19
  end
20
20
  end
21
21
 
22
22
  context "date column" do
23
23
  it 'should assign a string value for invalid date' do
24
24
  employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 31])
25
- employee.birth_date_before_type_cast.should eq '2000-02-31'
25
+ expect(employee.birth_date_before_type_cast).to eq '2000-02-31'
26
26
  end
27
27
 
28
28
  it 'should assign a Date value for valid date' do
29
29
  employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 28])
30
- employee.birth_date_before_type_cast.should eq Date.new(2000, 2, 28)
30
+ expect(employee.birth_date_before_type_cast).to eq Date.new(2000, 2, 28)
31
31
  end
32
32
 
33
33
  it 'should assign a string value for incomplete date' do
34
34
  employee = record_with_multiparameter_attribute(:birth_date, [2000, nil, nil])
35
- employee.birth_date_before_type_cast.should eq '2000-00-00'
35
+ expect(employee.birth_date_before_type_cast).to eq '2000-00-00'
36
36
  end
37
37
  end
38
38
 
@@ -41,4 +41,5 @@ describe ValidatesTimeliness::Extensions::MultiparameterHandler do
41
41
  values.each_with_index {|value, index| hash["#{name}(#{index+1}i)"] = value.to_s }
42
42
  Employee.new(hash)
43
43
  end
44
+
44
45
  end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ValidatesTimeliness, 'HelperMethods' do
4
+ let(:record) { Person.new }
5
+
4
6
  it 'should define class validation methods' do
5
- Person.should respond_to(:validates_date)
6
- Person.should respond_to(:validates_time)
7
- Person.should respond_to(:validates_datetime)
7
+ expect(Person).to respond_to(:validates_date)
8
+ expect(Person).to respond_to(:validates_time)
9
+ expect(Person).to respond_to(:validates_datetime)
8
10
  end
9
11
 
10
12
  it 'should define instance validation methods' do
11
- Person.new.should respond_to(:validates_date)
12
- Person.new.should respond_to(:validates_time)
13
- Person.new.should respond_to(:validates_datetime)
13
+ expect(record).to respond_to(:validates_date)
14
+ expect(record).to respond_to(:validates_time)
15
+ expect(record).to respond_to(:validates_datetime)
14
16
  end
15
17
 
16
18
  it 'should validate instance using class validation defined' do
17
19
  Person.validates_date :birth_date
18
- r = Person.new
19
- r.valid?
20
+ record.valid?
20
21
 
21
- r.errors[:birth_date].should_not be_empty
22
+ expect(record.errors[:birth_date]).not_to be_empty
22
23
  end
23
24
 
24
25
  it 'should validate instance using instance valiation method' do
25
- r = Person.new
26
- r.validates_date :birth_date
26
+ record.validates_date :birth_date
27
27
 
28
- r.errors[:birth_date].should_not be_empty
28
+ expect(record.errors[:birth_date]).not_to be_empty
29
29
  end
30
30
  end