date_validator 0.5.4 → 0.5.5
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.
- data/VERSION +1 -1
- data/date_validator.gemspec +1 -1
- data/lib/date_validator.rb +1 -1
- data/locales/en.yml +4 -4
- data/spec/date_validator_spec.rb +32 -13
- data/spec/spec_helper.rb +2 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.5
|
data/date_validator.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{date_validator}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oriol Gual", "Josep M\302\252 Bach", "Josep Jaume Rey"]
|
data/lib/date_validator.rb
CHANGED
@@ -47,7 +47,7 @@ module ActiveModel
|
|
47
47
|
|
48
48
|
|
49
49
|
unless is_time?(option_value) && value.to_i.send(CHECKS[option], option_value.to_i)
|
50
|
-
record.errors.add(attr_name, option, :default => options[:message], :value => original_value, :date => original_option_value)
|
50
|
+
record.errors.add(attr_name, I18n.t("errors.messages.#{option}", :value => original_option_value), :default => options[:message], :value => original_value, :date => original_option_value)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/locales/en.yml
CHANGED
@@ -5,7 +5,7 @@ en:
|
|
5
5
|
errors:
|
6
6
|
messages:
|
7
7
|
not_a_date: "is not a date"
|
8
|
-
after: "must be after {
|
9
|
-
after_or_equal_to: "must be after or equal to {
|
10
|
-
before: "must be before {
|
11
|
-
before_or_equal_to: "must be before or equal to {
|
8
|
+
after: "must be after %{value}"
|
9
|
+
after_or_equal_to: "must be after or equal to %{value}"
|
10
|
+
before: "must be before %{value}"
|
11
|
+
before_or_equal_to: "must be before or equal to %{value}"
|
data/spec/date_validator_spec.rb
CHANGED
@@ -16,25 +16,44 @@ describe "DateValidator" do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
[:
|
20
|
-
[:valid,:invalid].each do |should_be|
|
19
|
+
[:valid,:invalid].each do |should_be|
|
21
20
|
|
22
|
-
|
21
|
+
_context = should_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
context _context do
|
24
|
+
|
25
|
+
[:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
|
26
|
+
|
27
|
+
now = Time.now.to_datetime
|
28
|
+
|
29
|
+
model_date = case check
|
30
|
+
when :after then should_be == :valid ? now + 21000 : now - 1
|
31
|
+
when :before then should_be == :valid ? now - 21000 : now + 1
|
32
|
+
when :after_or_equal_to then should_be == :valid ? now : now - 21000
|
33
|
+
when :before_or_equal_to then should_be == :valid ? now : now + 21000
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should ensure that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
|
37
|
+
TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
|
38
|
+
model = TestRecord.new(model_date)
|
39
|
+
should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check") : model.should_not(be_valid, "an attribute should be invalidwhen offending the #{check} check")
|
40
|
+
end
|
41
|
+
|
42
|
+
if _context == 'when value does not match validation requirements'
|
43
|
+
|
44
|
+
it "should yield an error message indicating that value must be #{check} validation requirements" do
|
45
|
+
TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
|
46
|
+
model = TestRecord.new(model_date)
|
47
|
+
model.should_not be_valid
|
48
|
+
model.errors[:expiration_date].should == ["must be " + check.to_s.gsub('_',' ') + " #{Time.now}"]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
30
52
|
|
31
|
-
it "should ensure that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
|
32
|
-
TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
|
33
|
-
model = TestRecord.new(model_date)
|
34
|
-
should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check") : model.should(be_invalid, "an attribute should be invalid when offending the #{check} check")
|
35
53
|
end
|
36
54
|
|
37
55
|
end
|
56
|
+
|
38
57
|
end
|
39
58
|
|
40
59
|
extra_types = [:proc, :symbol]
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 5
|
10
|
+
version: 0.5.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Oriol Gual
|