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.
- checksums.yaml +7 -0
- data/.travis.yml +21 -0
- data/README.rdoc +12 -9
- data/Rakefile +1 -1
- data/gemfiles/rails_4_0.gemfile +19 -0
- data/gemfiles/rails_4_1.gemfile +19 -0
- data/gemfiles/rails_4_2.gemfile +19 -0
- data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +3 -3
- data/lib/validates_timeliness/attribute_methods.rb +36 -36
- data/lib/validates_timeliness/extensions/date_time_select.rb +2 -9
- data/lib/validates_timeliness/extensions/multiparameter_handler.rb +59 -65
- data/lib/validates_timeliness/extensions.rb +3 -4
- data/lib/validates_timeliness/helper_methods.rb +8 -2
- data/lib/validates_timeliness/orm/active_record.rb +59 -13
- data/lib/validates_timeliness/validator.rb +20 -6
- data/lib/validates_timeliness/version.rb +1 -1
- data/lib/validates_timeliness.rb +9 -13
- data/spec/spec_helper.rb +4 -2
- data/spec/support/model_helpers.rb +4 -4
- data/spec/support/tag_matcher.rb +35 -0
- data/spec/support/test_model.rb +0 -1
- data/spec/validates_timeliness/attribute_methods_spec.rb +10 -10
- data/spec/validates_timeliness/conversion_spec.rb +41 -41
- data/spec/validates_timeliness/extensions/date_time_select_spec.rb +5 -4
- data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +8 -7
- data/spec/validates_timeliness/helper_methods_spec.rb +12 -12
- data/spec/validates_timeliness/orm/active_record_spec.rb +70 -80
- data/spec/validates_timeliness/validator/after_spec.rb +3 -3
- data/spec/validates_timeliness/validator/before_spec.rb +3 -3
- data/spec/validates_timeliness/validator/is_at_spec.rb +4 -4
- data/spec/validates_timeliness/validator/on_or_after_spec.rb +3 -3
- data/spec/validates_timeliness/validator/on_or_before_spec.rb +3 -3
- data/spec/validates_timeliness/validator_spec.rb +40 -29
- data/spec/validates_timeliness_spec.rb +8 -8
- data/validates_timeliness.gemspec +1 -1
- metadata +41 -67
- data/gemfiles/mongoid_2_1.gemfile +0 -16
- data/gemfiles/mongoid_2_2.gemfile +0 -16
- data/gemfiles/mongoid_2_3.gemfile +0 -16
- data/gemfiles/mongoid_2_4.gemfile +0 -16
- data/gemfiles/rails_3_0.gemfile +0 -15
- data/gemfiles/rails_3_1.gemfile +0 -15
- data/gemfiles/rails_3_2.gemfile +0 -15
- data/lib/validates_timeliness/orm/mongoid.rb +0 -63
- data/spec/validates_timeliness/orm/mongoid_spec.rb +0 -189
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
17
17
|
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
|
18
18
|
|
|
19
|
-
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.
|
|
19
|
+
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.7"])
|
|
20
20
|
end
|
metadata
CHANGED
|
@@ -1,61 +1,47 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: validates_timeliness
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 3
|
|
8
|
-
- 0
|
|
9
|
-
- 14
|
|
10
|
-
version: 3.0.14
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 4.0.0
|
|
11
5
|
platform: ruby
|
|
12
|
-
authors:
|
|
6
|
+
authors:
|
|
13
7
|
- Adam Meehan
|
|
14
8
|
autorequire:
|
|
15
9
|
bindir: bin
|
|
16
10
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
dependencies:
|
|
21
|
-
- !ruby/object:Gem::Dependency
|
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
23
|
-
none: false
|
|
24
|
-
requirements:
|
|
25
|
-
- - ~>
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
hash: 31
|
|
28
|
-
segments:
|
|
29
|
-
- 0
|
|
30
|
-
- 3
|
|
31
|
-
- 6
|
|
32
|
-
version: 0.3.6
|
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
33
14
|
name: timeliness
|
|
34
|
-
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.3.7
|
|
35
20
|
type: :runtime
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.3.7
|
|
27
|
+
description: Adds validation methods to ActiveModel for validating dates and times.
|
|
28
|
+
Works with multiple ORMS.
|
|
38
29
|
email: adam.meehan@gmail.com
|
|
39
30
|
executables: []
|
|
40
|
-
|
|
41
31
|
extensions: []
|
|
42
|
-
|
|
43
|
-
extra_rdoc_files:
|
|
32
|
+
extra_rdoc_files:
|
|
44
33
|
- README.rdoc
|
|
45
34
|
- CHANGELOG.rdoc
|
|
46
35
|
- LICENSE
|
|
47
|
-
files:
|
|
36
|
+
files:
|
|
37
|
+
- ".travis.yml"
|
|
48
38
|
- CHANGELOG.rdoc
|
|
49
39
|
- LICENSE
|
|
50
40
|
- README.rdoc
|
|
51
41
|
- Rakefile
|
|
52
|
-
- gemfiles/
|
|
53
|
-
- gemfiles/
|
|
54
|
-
- gemfiles/
|
|
55
|
-
- gemfiles/mongoid_2_4.gemfile
|
|
56
|
-
- gemfiles/rails_3_0.gemfile
|
|
57
|
-
- gemfiles/rails_3_1.gemfile
|
|
58
|
-
- gemfiles/rails_3_2.gemfile
|
|
42
|
+
- gemfiles/rails_4_0.gemfile
|
|
43
|
+
- gemfiles/rails_4_1.gemfile
|
|
44
|
+
- gemfiles/rails_4_2.gemfile
|
|
59
45
|
- init.rb
|
|
60
46
|
- lib/generators/validates_timeliness/install_generator.rb
|
|
61
47
|
- lib/generators/validates_timeliness/templates/en.yml
|
|
@@ -68,13 +54,13 @@ files:
|
|
|
68
54
|
- lib/validates_timeliness/extensions/multiparameter_handler.rb
|
|
69
55
|
- lib/validates_timeliness/helper_methods.rb
|
|
70
56
|
- lib/validates_timeliness/orm/active_record.rb
|
|
71
|
-
- lib/validates_timeliness/orm/mongoid.rb
|
|
72
57
|
- lib/validates_timeliness/railtie.rb
|
|
73
58
|
- lib/validates_timeliness/validator.rb
|
|
74
59
|
- lib/validates_timeliness/version.rb
|
|
75
60
|
- spec/spec_helper.rb
|
|
76
61
|
- spec/support/config_helper.rb
|
|
77
62
|
- spec/support/model_helpers.rb
|
|
63
|
+
- spec/support/tag_matcher.rb
|
|
78
64
|
- spec/support/test_model.rb
|
|
79
65
|
- spec/validates_timeliness/attribute_methods_spec.rb
|
|
80
66
|
- spec/validates_timeliness/conversion_spec.rb
|
|
@@ -82,7 +68,6 @@ files:
|
|
|
82
68
|
- spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
|
|
83
69
|
- spec/validates_timeliness/helper_methods_spec.rb
|
|
84
70
|
- spec/validates_timeliness/orm/active_record_spec.rb
|
|
85
|
-
- spec/validates_timeliness/orm/mongoid_spec.rb
|
|
86
71
|
- spec/validates_timeliness/validator/after_spec.rb
|
|
87
72
|
- spec/validates_timeliness/validator/before_spec.rb
|
|
88
73
|
- spec/validates_timeliness/validator/is_at_spec.rb
|
|
@@ -91,44 +76,34 @@ files:
|
|
|
91
76
|
- spec/validates_timeliness/validator_spec.rb
|
|
92
77
|
- spec/validates_timeliness_spec.rb
|
|
93
78
|
- validates_timeliness.gemspec
|
|
94
|
-
has_rdoc: true
|
|
95
79
|
homepage: http://github.com/adzap/validates_timeliness
|
|
96
80
|
licenses: []
|
|
97
|
-
|
|
81
|
+
metadata: {}
|
|
98
82
|
post_install_message:
|
|
99
83
|
rdoc_options: []
|
|
100
|
-
|
|
101
|
-
require_paths:
|
|
84
|
+
require_paths:
|
|
102
85
|
- lib
|
|
103
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
-
|
|
105
|
-
requirements:
|
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
106
88
|
- - ">="
|
|
107
|
-
- !ruby/object:Gem::Version
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
version: "0"
|
|
112
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
|
-
none: false
|
|
114
|
-
requirements:
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
115
93
|
- - ">="
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
|
|
118
|
-
segments:
|
|
119
|
-
- 0
|
|
120
|
-
version: "0"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
121
96
|
requirements: []
|
|
122
|
-
|
|
123
97
|
rubyforge_project:
|
|
124
|
-
rubygems_version:
|
|
98
|
+
rubygems_version: 2.4.5
|
|
125
99
|
signing_key:
|
|
126
|
-
specification_version:
|
|
100
|
+
specification_version: 4
|
|
127
101
|
summary: Date and time validation plugin for Rails which allows custom formats
|
|
128
|
-
test_files:
|
|
102
|
+
test_files:
|
|
129
103
|
- spec/spec_helper.rb
|
|
130
104
|
- spec/support/config_helper.rb
|
|
131
105
|
- spec/support/model_helpers.rb
|
|
106
|
+
- spec/support/tag_matcher.rb
|
|
132
107
|
- spec/support/test_model.rb
|
|
133
108
|
- spec/validates_timeliness/attribute_methods_spec.rb
|
|
134
109
|
- spec/validates_timeliness/conversion_spec.rb
|
|
@@ -136,7 +111,6 @@ test_files:
|
|
|
136
111
|
- spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
|
|
137
112
|
- spec/validates_timeliness/helper_methods_spec.rb
|
|
138
113
|
- spec/validates_timeliness/orm/active_record_spec.rb
|
|
139
|
-
- spec/validates_timeliness/orm/mongoid_spec.rb
|
|
140
114
|
- spec/validates_timeliness/validator/after_spec.rb
|
|
141
115
|
- spec/validates_timeliness/validator/before_spec.rb
|
|
142
116
|
- spec/validates_timeliness/validator/is_at_spec.rb
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rails", "~> 3.2.6"
|
|
6
|
-
gem "rspec", "~> 2.8"
|
|
7
|
-
gem "rspec-rails", "~> 2.8"
|
|
8
|
-
gem "timecop"
|
|
9
|
-
gem "rspec_tag_matchers"
|
|
10
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
11
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
12
|
-
gem "appraisal"
|
|
13
|
-
gem "sqlite3"
|
|
14
|
-
gem "mongoid", "~> 2.1.0"
|
|
15
|
-
|
|
16
|
-
gemspec :path=>"../"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rails", "~> 3.2.6"
|
|
6
|
-
gem "rspec", "~> 2.8"
|
|
7
|
-
gem "rspec-rails", "~> 2.8"
|
|
8
|
-
gem "timecop"
|
|
9
|
-
gem "rspec_tag_matchers"
|
|
10
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
11
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
12
|
-
gem "appraisal"
|
|
13
|
-
gem "sqlite3"
|
|
14
|
-
gem "mongoid", "~> 2.2.0"
|
|
15
|
-
|
|
16
|
-
gemspec :path=>"../"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rails", "~> 3.2.6"
|
|
6
|
-
gem "rspec", "~> 2.8"
|
|
7
|
-
gem "rspec-rails", "~> 2.8"
|
|
8
|
-
gem "timecop"
|
|
9
|
-
gem "rspec_tag_matchers"
|
|
10
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
11
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
12
|
-
gem "appraisal"
|
|
13
|
-
gem "sqlite3"
|
|
14
|
-
gem "mongoid", "~> 2.3.0"
|
|
15
|
-
|
|
16
|
-
gemspec :path=>"../"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rails", "~> 3.2.6"
|
|
6
|
-
gem "rspec", "~> 2.8"
|
|
7
|
-
gem "rspec-rails", "~> 2.8"
|
|
8
|
-
gem "timecop"
|
|
9
|
-
gem "rspec_tag_matchers"
|
|
10
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
11
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
12
|
-
gem "appraisal"
|
|
13
|
-
gem "sqlite3"
|
|
14
|
-
gem "mongoid", "~> 2.4.0"
|
|
15
|
-
|
|
16
|
-
gemspec :path=>"../"
|
data/gemfiles/rails_3_0.gemfile
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rspec", "~> 2.8"
|
|
6
|
-
gem "rspec-rails", "~> 2.8"
|
|
7
|
-
gem "timecop"
|
|
8
|
-
gem "rspec_tag_matchers"
|
|
9
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
10
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
11
|
-
gem "appraisal"
|
|
12
|
-
gem "sqlite3"
|
|
13
|
-
gem "rails", "~> 3.0.0"
|
|
14
|
-
|
|
15
|
-
gemspec :path=>"../"
|
data/gemfiles/rails_3_1.gemfile
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rspec", "~> 2.8"
|
|
6
|
-
gem "rspec-rails", "~> 2.8"
|
|
7
|
-
gem "timecop"
|
|
8
|
-
gem "rspec_tag_matchers"
|
|
9
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
10
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
11
|
-
gem "appraisal"
|
|
12
|
-
gem "sqlite3"
|
|
13
|
-
gem "rails", "~> 3.1.0"
|
|
14
|
-
|
|
15
|
-
gemspec :path=>"../"
|
data/gemfiles/rails_3_2.gemfile
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "http://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rspec", "~> 2.8"
|
|
6
|
-
gem "rspec-rails", "~> 2.8"
|
|
7
|
-
gem "timecop"
|
|
8
|
-
gem "rspec_tag_matchers"
|
|
9
|
-
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
|
10
|
-
gem "debugger", :platforms=>[:ruby_19]
|
|
11
|
-
gem "appraisal"
|
|
12
|
-
gem "sqlite3"
|
|
13
|
-
gem "rails", "~> 3.2.0"
|
|
14
|
-
|
|
15
|
-
gemspec :path=>"../"
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
module ValidatesTimeliness
|
|
2
|
-
module ORM
|
|
3
|
-
module Mongoid
|
|
4
|
-
extend ActiveSupport::Concern
|
|
5
|
-
# You need define the fields before you define the validations.
|
|
6
|
-
# It is best to use the plugin parser to avoid errors on a bad
|
|
7
|
-
# field value in Mongoid. Parser will return nil rather than error.
|
|
8
|
-
|
|
9
|
-
module ClassMethods
|
|
10
|
-
public
|
|
11
|
-
|
|
12
|
-
# Mongoid has no bulk attribute method definition hook. It defines
|
|
13
|
-
# them with each field definition. So we likewise define them after
|
|
14
|
-
# each validation is defined.
|
|
15
|
-
#
|
|
16
|
-
def timeliness_validation_for(attr_names, type)
|
|
17
|
-
super
|
|
18
|
-
attr_names.each { |attr_name| define_timeliness_write_method(attr_name) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def timeliness_attribute_type(attr_name)
|
|
22
|
-
{
|
|
23
|
-
Date => :date,
|
|
24
|
-
Time => :time,
|
|
25
|
-
DateTime => :datetime
|
|
26
|
-
}[fields[attr_name.to_s].type] || :datetime
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
protected
|
|
30
|
-
|
|
31
|
-
def timeliness_type_cast_code(attr_name, var_name)
|
|
32
|
-
type = timeliness_attribute_type(attr_name)
|
|
33
|
-
|
|
34
|
-
"#{var_name} = Timeliness::Parser.parse(value, :#{type})"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
module Reload
|
|
40
|
-
def reload(*args)
|
|
41
|
-
_clear_timeliness_cache
|
|
42
|
-
super
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
module Mongoid::Document
|
|
50
|
-
include ValidatesTimeliness::AttributeMethods
|
|
51
|
-
include ValidatesTimeliness::ORM::Mongoid
|
|
52
|
-
|
|
53
|
-
# Pre-2.3 reload
|
|
54
|
-
if (instance_methods & ['reload', :reload]).present?
|
|
55
|
-
def reload_with_timeliness
|
|
56
|
-
_clear_timeliness_cache
|
|
57
|
-
reload_without_timeliness
|
|
58
|
-
end
|
|
59
|
-
alias_method_chain :reload, :timeliness
|
|
60
|
-
else
|
|
61
|
-
include ValidatesTimeliness::ORM::Mongoid::Reload
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
# Try loading mongoid and connecting. Otherwise, abort and skip spec.
|
|
4
|
-
begin
|
|
5
|
-
|
|
6
|
-
require 'mongoid'
|
|
7
|
-
require 'validates_timeliness/orm/mongoid'
|
|
8
|
-
|
|
9
|
-
Mongoid.configure do |config|
|
|
10
|
-
name = "validates_timeliness_test"
|
|
11
|
-
host = "localhost"
|
|
12
|
-
config.master = Mongo::Connection.new.db(name)
|
|
13
|
-
config.persist_in_safe_mode = false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe ValidatesTimeliness, 'Mongoid' do
|
|
17
|
-
|
|
18
|
-
class Article
|
|
19
|
-
include Mongoid::Document
|
|
20
|
-
field :publish_date, :type => Date
|
|
21
|
-
field :publish_time, :type => Time
|
|
22
|
-
field :publish_datetime, :type => DateTime
|
|
23
|
-
validates_date :publish_date, :allow_nil => true
|
|
24
|
-
validates_time :publish_time, :allow_nil => true
|
|
25
|
-
validates_datetime :publish_datetime, :allow_nil => true
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "validation methods" do
|
|
29
|
-
let(:record) { Article.new }
|
|
30
|
-
|
|
31
|
-
it 'should be defined on the class' do
|
|
32
|
-
Article.should respond_to(:validates_date)
|
|
33
|
-
Article.should respond_to(:validates_time)
|
|
34
|
-
Article.should respond_to(:validates_datetime)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it 'should be defined on the instance' do
|
|
38
|
-
record.should respond_to(:validates_date)
|
|
39
|
-
record.should respond_to(:validates_time)
|
|
40
|
-
record.should respond_to(:validates_datetime)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should validate a valid value string" do
|
|
44
|
-
record.publish_date = '2012-01-01'
|
|
45
|
-
|
|
46
|
-
record.valid?
|
|
47
|
-
record.errors[:publish_date].should be_empty
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should validate a invalid value string" do
|
|
51
|
-
begin
|
|
52
|
-
record.publish_date = 'not a date'
|
|
53
|
-
rescue
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
record.valid?
|
|
57
|
-
record.errors[:publish_date].should_not be_empty
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should validate a nil value" do
|
|
61
|
-
record.publish_date = nil
|
|
62
|
-
|
|
63
|
-
record.valid?
|
|
64
|
-
record.errors[:publish_date].should be_empty
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'should determine type for attribute' do
|
|
69
|
-
Article.timeliness_attribute_type(:publish_date).should == :date
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context "attribute write method" do
|
|
73
|
-
let(:record) { Article.new }
|
|
74
|
-
|
|
75
|
-
it 'should cache attribute raw value' do
|
|
76
|
-
record.publish_datetime = date_string = '2010-01-01'
|
|
77
|
-
|
|
78
|
-
record._timeliness_raw_value_for('publish_datetime').should == date_string
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
context "with plugin parser" do
|
|
82
|
-
let(:record) { ArticleWithParser.new }
|
|
83
|
-
|
|
84
|
-
class ArticleWithParser
|
|
85
|
-
include Mongoid::Document
|
|
86
|
-
field :publish_date, :type => Date
|
|
87
|
-
field :publish_time, :type => Time
|
|
88
|
-
field :publish_datetime, :type => DateTime
|
|
89
|
-
|
|
90
|
-
ValidatesTimeliness.use_plugin_parser = true
|
|
91
|
-
validates_date :publish_date, :allow_nil => true
|
|
92
|
-
validates_time :publish_time, :allow_nil => true
|
|
93
|
-
validates_datetime :publish_datetime, :allow_nil => true
|
|
94
|
-
ValidatesTimeliness.use_plugin_parser = false
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context "for a date column" do
|
|
98
|
-
it 'should parse a string value' do
|
|
99
|
-
Timeliness::Parser.should_receive(:parse)
|
|
100
|
-
|
|
101
|
-
record.publish_date = '2010-01-01'
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it 'should parse a invalid string value as nil' do
|
|
105
|
-
Timeliness::Parser.should_receive(:parse)
|
|
106
|
-
|
|
107
|
-
record.publish_date = 'not valid'
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it 'should store a Date value after parsing string' do
|
|
111
|
-
record.publish_date = '2010-01-01'
|
|
112
|
-
|
|
113
|
-
record.publish_date.should be_kind_of(Date)
|
|
114
|
-
record.publish_date.should eq Date.new(2010, 1, 1)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
context "for a time column" do
|
|
119
|
-
it 'should parse a string value' do
|
|
120
|
-
Timeliness::Parser.should_receive(:parse)
|
|
121
|
-
|
|
122
|
-
record.publish_time = '12:30'
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it 'should parse a invalid string value as nil' do
|
|
126
|
-
Timeliness::Parser.should_receive(:parse)
|
|
127
|
-
|
|
128
|
-
record.publish_time = 'not valid'
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it 'should store a Time value after parsing string' do
|
|
132
|
-
record.publish_time = '12:30'
|
|
133
|
-
|
|
134
|
-
record.publish_time.should be_kind_of(Time)
|
|
135
|
-
record.publish_time.should eq Time.utc(2000, 1, 1, 12, 30)
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
context "for a datetime column" do
|
|
140
|
-
with_config(:default_timezone, 'Australia/Melbourne')
|
|
141
|
-
|
|
142
|
-
it 'should parse a string value' do
|
|
143
|
-
Timeliness::Parser.should_receive(:parse)
|
|
144
|
-
|
|
145
|
-
record.publish_datetime = '2010-01-01 12:00'
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it 'should parse a invalid string value as nil' do
|
|
149
|
-
Timeliness::Parser.should_receive(:parse)
|
|
150
|
-
|
|
151
|
-
record.publish_datetime = 'not valid'
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
it 'should parse string into DateTime value' do
|
|
155
|
-
record.publish_datetime = '2010-01-01 12:00'
|
|
156
|
-
|
|
157
|
-
record.publish_datetime.should be_kind_of(DateTime)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
pending 'should parse string as current timezone' do
|
|
161
|
-
record.publish_datetime = '2010-06-01 12:00'
|
|
162
|
-
|
|
163
|
-
record.publish_datetime.utc_offset.should eq Time.zone.utc_offset
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context "cached value" do
|
|
170
|
-
it 'should be cleared on reload' do
|
|
171
|
-
record = Article.create!
|
|
172
|
-
record.publish_date = '2010-01-01'
|
|
173
|
-
record.reload
|
|
174
|
-
record._timeliness_raw_value_for('publish_date').should be_nil
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
context "before_type_cast method" do
|
|
179
|
-
it 'should not be defined if ORM does not support it' do
|
|
180
|
-
Article.new.should_not respond_to(:publish_datetime_before_type_cast)
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
rescue LoadError
|
|
186
|
-
puts "Mongoid specs skipped. Mongoid not installed"
|
|
187
|
-
rescue StandardError => e
|
|
188
|
-
puts "Mongoid specs skipped. MongoDB connection failed with error: #{e.message}"
|
|
189
|
-
end
|