validates_timeliness 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1b8043b997be8d2c2c20462ad6ff2569c36f361e831648e62afcdccfb34a9a9
4
- data.tar.gz: 4fd9cdea497d79b06469b973669f961aca84fb876c0fdbc00b66d5eb0006f62d
3
+ metadata.gz: a72c9c656e7bb6b4987658858001d6654a591b12a2aa6322f2b38a932ef4c7b5
4
+ data.tar.gz: b8449806435f41af895a80c61a7e641f42d4581aaee40183781a222ea027876a
5
5
  SHA512:
6
- metadata.gz: 103153fbfef87bbf3dabb2ec3bf1fe8c9178ad45dfda1d90948ca21802c40a7a70c41089e85bb717ed5f9861c163ce67058d9016c6e68e0aaa1bac4684e96971
7
- data.tar.gz: de9ba7e8bb62fe6ccffb5e9e2507ec11fcbf8b30403ebf1c1d0e91ac25d1aa5377f2147d5b508ef0a2ce23ad71ce3ce440ce3282c011abeb7f1a47b3f63b9b17
6
+ metadata.gz: 68e98f1017b315190106b17608ce8d5df1977f101154c91a89fea550b2546b10ec569b6ba79ff51ae4efd760bc61e91756e7561624b8e8da7ae281d407c012a4
7
+ data.tar.gz: bda2a3e5f833ed1e3467e5e3ee2c2030d964187e9c23611c2afa1265c76096590332ae1739d8196c429eca57a2f8720a1c2e67cb87e75ba8a777f1c7f8939e56
@@ -19,12 +19,13 @@ module ValidatesTimeliness
19
19
  when :date
20
20
  value.to_date
21
21
  when :datetime
22
- value.is_a?(Time) ? value : value.to_time
22
+ value.is_a?(Time) ? value : (time_zone_aware? ? value.in_time_zone : value.to_time)
23
23
  else
24
24
  value
25
25
  end
26
+
26
27
  if ignore_usec && value.is_a?(Time)
27
- Timeliness::Parser.make_time(Array(value).reverse[4..9], (:current if time_zone_aware?))
28
+ value.change(usec: 0)
28
29
  else
29
30
  value
30
31
  end
@@ -20,7 +20,7 @@ module ActiveModel
20
20
 
21
21
  def timeliness_validation_for(attr_names, type=nil)
22
22
  options = _merge_attributes(attr_names)
23
- options.update(:type => type) if type
23
+ options.update(type: type) if type
24
24
  validates_with TimelinessValidator, options
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '6.0.0'
2
+ VERSION = '6.0.1'
3
3
  end
@@ -63,30 +63,61 @@ RSpec.describe ValidatesTimeliness::Converter do
63
63
 
64
64
  describe "for datetime type" do
65
65
  let(:type) { :datetime }
66
- let(:time_zone_aware) { true }
67
66
 
68
- it "should return Date as Time value" do
69
- expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Time.local(2010, 1, 1, 0, 0, 0))
67
+ it 'should return nil for invalid value types' do
68
+ expect(type_cast_value(12)).to eq(nil)
70
69
  end
71
70
 
72
- it "should return same Time value" do
73
- value = Time.utc(2010, 1, 1, 12, 34, 56)
74
- expect(type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56))).to eq(value)
75
- end
71
+ context "time zone aware" do
72
+ let(:time_zone_aware) { true }
76
73
 
77
- it "should return as Time with same component values" do
78
- expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
79
- end
74
+ around { |example|
75
+ Time.use_zone("Perth", &example)
76
+ }
77
+
78
+ it "should return Date as Time value" do
79
+ Time.use_zone('London') do
80
+ result = type_cast_value(Date.new(2010, 1, 1))
81
+ expected = Time.zone.local(2010, 1, 1, 0, 0, 0)
82
+
83
+ expect(result).to eq(expected)
84
+ expect(result.zone).to eq(expected.zone)
85
+ end
86
+ end
87
+
88
+ it "should return same Time value" do
89
+ value = Time.utc(2010, 1, 1, 12, 34, 56)
90
+ expect(type_cast_value(value)).to eq(value)
91
+ end
92
+
93
+ it "should return as Time with same component values" do
94
+ expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
95
+ end
80
96
 
81
- it "should return same Time in correct zone if timezone aware" do
82
- value = Time.utc(2010, 1, 1, 12, 34, 56)
83
- result = type_cast_value(value)
84
- expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
85
- expect(result.zone).to eq('AEDT')
97
+ it "should return same Time in correct zone if timezone aware" do
98
+ value = Time.utc(2010, 1, 1, 12, 34, 56)
99
+ result = type_cast_value(value)
100
+
101
+ expect(result).to eq(Time.zone.local(2010, 1, 1, 20, 34, 56))
102
+ expect(result.zone).to eq('AWST')
103
+ end
86
104
  end
87
105
 
88
- it 'should return nil for invalid value types' do
89
- expect(type_cast_value(12)).to eq(nil)
106
+ context "not time zone aware" do
107
+ let(:time_zone_aware) { false }
108
+
109
+ it "should return Date as Time value" do
110
+ expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Time.local(2010, 1, 1, 0, 0, 0))
111
+ end
112
+
113
+ it "should return same Time value" do
114
+ value = Time.utc(2010, 1, 1, 12, 34, 56)
115
+ expect(type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56))).to eq(value)
116
+ end
117
+
118
+ it "should return as Time with same component values" do
119
+ expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
120
+ end
90
121
  end
91
122
  end
92
123
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_timeliness
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Meehan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-20 00:00:00.000000000 Z
11
+ date: 2023-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -68,7 +68,6 @@ files:
68
68
  - Rakefile
69
69
  - gemfiles/rails_6_0.gemfile
70
70
  - gemfiles/rails_6_1.gemfile
71
- - gemfiles/rails_edge.gemfile
72
71
  - init.rb
73
72
  - lib/generators/validates_timeliness/install_generator.rb
74
73
  - lib/generators/validates_timeliness/templates/en.yml
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
6
- gem "rspec"
7
- gem "rspec-rails", "~> 3.7"
8
- gem "sqlite3"
9
- gem "byebug"
10
- gem "appraisal"
11
- gem "nokogiri", "~> 1.8"
12
-
13
- gemspec path: "../"