validates_timeliness 3.0.8 → 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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +21 -0
  3. data/CHANGELOG.rdoc +21 -1
  4. data/README.rdoc +20 -22
  5. data/Rakefile +5 -1
  6. data/gemfiles/rails_4_0.gemfile +19 -0
  7. data/gemfiles/rails_4_1.gemfile +19 -0
  8. data/gemfiles/rails_4_2.gemfile +19 -0
  9. data/lib/generators/validates_timeliness/install_generator.rb +0 -1
  10. data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +3 -3
  11. data/lib/validates_timeliness/attribute_methods.rb +42 -26
  12. data/lib/validates_timeliness/extensions/date_time_select.rb +2 -9
  13. data/lib/validates_timeliness/extensions/multiparameter_handler.rb +59 -54
  14. data/lib/validates_timeliness/extensions.rb +3 -4
  15. data/lib/validates_timeliness/helper_methods.rb +7 -6
  16. data/lib/validates_timeliness/orm/active_record.rb +70 -15
  17. data/lib/validates_timeliness/railtie.rb +2 -1
  18. data/lib/validates_timeliness/validator.rb +29 -4
  19. data/lib/validates_timeliness/version.rb +1 -1
  20. data/lib/validates_timeliness.rb +13 -13
  21. data/spec/spec_helper.rb +10 -5
  22. data/spec/support/config_helper.rb +10 -0
  23. data/spec/support/model_helpers.rb +4 -4
  24. data/spec/support/tag_matcher.rb +35 -0
  25. data/spec/support/test_model.rb +0 -1
  26. data/spec/validates_timeliness/attribute_methods_spec.rb +22 -7
  27. data/spec/validates_timeliness/conversion_spec.rb +41 -41
  28. data/spec/validates_timeliness/extensions/date_time_select_spec.rb +5 -4
  29. data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +28 -16
  30. data/spec/validates_timeliness/helper_methods_spec.rb +12 -12
  31. data/spec/validates_timeliness/orm/active_record_spec.rb +178 -44
  32. data/spec/validates_timeliness/validator/after_spec.rb +3 -3
  33. data/spec/validates_timeliness/validator/before_spec.rb +3 -3
  34. data/spec/validates_timeliness/validator/is_at_spec.rb +4 -4
  35. data/spec/validates_timeliness/validator/on_or_after_spec.rb +3 -3
  36. data/spec/validates_timeliness/validator/on_or_before_spec.rb +3 -3
  37. data/spec/validates_timeliness/validator_spec.rb +66 -25
  38. data/spec/validates_timeliness_spec.rb +8 -8
  39. data/validates_timeliness.gemspec +2 -2
  40. metadata +41 -60
  41. data/lib/validates_timeliness/orm/mongoid.rb +0 -54
  42. data/spec/validates_timeliness/orm/mongoid_spec.rb +0 -113
metadata CHANGED
@@ -1,54 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: validates_timeliness
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 3
8
- - 0
9
- - 8
10
- version: 3.0.8
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
- date: 2011-12-24 00:00:00 +11:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: timeliness
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 27
30
- segments:
31
- - 0
32
- - 3
33
- - 4
34
- version: 0.3.4
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.7
35
20
  type: :runtime
36
- version_requirements: *id001
37
- description: Adds validation methods to ActiveModel for validating dates and times. Works with multiple ORMS.
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
42
+ - gemfiles/rails_4_0.gemfile
43
+ - gemfiles/rails_4_1.gemfile
44
+ - gemfiles/rails_4_2.gemfile
52
45
  - init.rb
53
46
  - lib/generators/validates_timeliness/install_generator.rb
54
47
  - lib/generators/validates_timeliness/templates/en.yml
@@ -61,13 +54,13 @@ files:
61
54
  - lib/validates_timeliness/extensions/multiparameter_handler.rb
62
55
  - lib/validates_timeliness/helper_methods.rb
63
56
  - lib/validates_timeliness/orm/active_record.rb
64
- - lib/validates_timeliness/orm/mongoid.rb
65
57
  - lib/validates_timeliness/railtie.rb
66
58
  - lib/validates_timeliness/validator.rb
67
59
  - lib/validates_timeliness/version.rb
68
60
  - spec/spec_helper.rb
69
61
  - spec/support/config_helper.rb
70
62
  - spec/support/model_helpers.rb
63
+ - spec/support/tag_matcher.rb
71
64
  - spec/support/test_model.rb
72
65
  - spec/validates_timeliness/attribute_methods_spec.rb
73
66
  - spec/validates_timeliness/conversion_spec.rb
@@ -75,7 +68,6 @@ files:
75
68
  - spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
76
69
  - spec/validates_timeliness/helper_methods_spec.rb
77
70
  - spec/validates_timeliness/orm/active_record_spec.rb
78
- - spec/validates_timeliness/orm/mongoid_spec.rb
79
71
  - spec/validates_timeliness/validator/after_spec.rb
80
72
  - spec/validates_timeliness/validator/before_spec.rb
81
73
  - spec/validates_timeliness/validator/is_at_spec.rb
@@ -84,44 +76,34 @@ files:
84
76
  - spec/validates_timeliness/validator_spec.rb
85
77
  - spec/validates_timeliness_spec.rb
86
78
  - validates_timeliness.gemspec
87
- has_rdoc: true
88
79
  homepage: http://github.com/adzap/validates_timeliness
89
80
  licenses: []
90
-
81
+ metadata: {}
91
82
  post_install_message:
92
83
  rdoc_options: []
93
-
94
- require_paths:
84
+ require_paths:
95
85
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
99
88
  - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
105
- required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
108
93
  - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
114
96
  requirements: []
115
-
116
97
  rubyforge_project:
117
- rubygems_version: 1.5.2
98
+ rubygems_version: 2.4.5
118
99
  signing_key:
119
- specification_version: 3
100
+ specification_version: 4
120
101
  summary: Date and time validation plugin for Rails which allows custom formats
121
- test_files:
102
+ test_files:
122
103
  - spec/spec_helper.rb
123
104
  - spec/support/config_helper.rb
124
105
  - spec/support/model_helpers.rb
106
+ - spec/support/tag_matcher.rb
125
107
  - spec/support/test_model.rb
126
108
  - spec/validates_timeliness/attribute_methods_spec.rb
127
109
  - spec/validates_timeliness/conversion_spec.rb
@@ -129,7 +111,6 @@ test_files:
129
111
  - spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
130
112
  - spec/validates_timeliness/helper_methods_spec.rb
131
113
  - spec/validates_timeliness/orm/active_record_spec.rb
132
- - spec/validates_timeliness/orm/mongoid_spec.rb
133
114
  - spec/validates_timeliness/validator/after_spec.rb
134
115
  - spec/validates_timeliness/validator/before_spec.rb
135
116
  - spec/validates_timeliness/validator/is_at_spec.rb
@@ -1,54 +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
- # Mongoid has no bulk attribute method definition hook. It defines
11
- # them with each field definition. So we likewise define them after
12
- # each validation is defined.
13
- #
14
- def timeliness_validation_for(attr_names, type)
15
- super
16
- attr_names.each { |attr_name| define_timeliness_write_method(attr_name) }
17
- end
18
-
19
- def timeliness_type_cast_code(attr_name, var_name)
20
- type = timeliness_attribute_type(attr_name)
21
-
22
- "#{var_name} = Timeliness::Parser.parse(value, :#{type})"
23
- end
24
-
25
- def timeliness_attribute_type(attr_name)
26
- {
27
- Date => :date,
28
- Time => :datetime,
29
- DateTime => :datetime
30
- }[fields[attr_name.to_s].type] || :datetime
31
- end
32
- end
33
-
34
- def reload
35
- _clear_timeliness_cache
36
- super
37
- end
38
- end
39
- end
40
- end
41
-
42
- module Mongoid::Document
43
- include ValidatesTimeliness::AttributeMethods
44
- include ValidatesTimeliness::ORM::Mongoid
45
-
46
- # Pre-2.3 reload
47
- if instance_methods.include?('reload')
48
- def reload_with_timeliness
49
- _clear_timeliness_cache
50
- reload_without_timeliness
51
- end
52
- alias_method_chain :reload, :timeliness
53
- end
54
- end
@@ -1,113 +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
- Mongoid.configure do |config|
9
- name = "validates_timeliness_test"
10
- host = "localhost"
11
- config.master = Mongo::Connection.new.db(name)
12
- config.persist_in_safe_mode = false
13
- end
14
-
15
- describe ValidatesTimeliness, 'Mongoid' do
16
-
17
- class Article
18
- include Mongoid::Document
19
- ValidatesTimeliness.use_plugin_parser = true
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
- ValidatesTimeliness.use_plugin_parser = false
27
- end
28
-
29
- context "validation methods" do
30
- it 'should be defined on the class' do
31
- Article.should respond_to(:validates_date)
32
- Article.should respond_to(:validates_time)
33
- Article.should respond_to(:validates_datetime)
34
- end
35
-
36
- it 'should be defined on the instance' do
37
- Article.new.should respond_to(:validates_date)
38
- Article.new.should respond_to(:validates_time)
39
- Article.new.should respond_to(:validates_datetime)
40
- end
41
- end
42
-
43
- it 'should determine type for attribute' do
44
- Article.timeliness_attribute_type(:publish_date).should == :date
45
- end
46
-
47
- context "attribute write method" do
48
- it 'should cache attribute raw value' do
49
- r = Article.new
50
- r.publish_datetime = date_string = '2010-01-01'
51
- r._timeliness_raw_value_for(:publish_datetime).should == date_string
52
- end
53
-
54
- context "with plugin parser" do
55
- with_config(:use_plugin_parser, true)
56
-
57
- it 'should parse a string value' do
58
- Timeliness::Parser.should_receive(:parse)
59
- r = Article.new
60
- r.publish_date = '2010-01-01'
61
- end
62
-
63
- it 'should parse an invalid value as nil' do
64
- Timeliness::Parser.should_receive(:parse)
65
- r = Article.new
66
- r.publish_date = 'bad value'
67
-
68
- r.publish_date.should be_nil
69
- end
70
-
71
- context "for a date column" do
72
- it 'should store a Date value after parsing string' do
73
- r = Article.new
74
- r.publish_date = '2010-01-01'
75
-
76
- r.publish_date.should be_kind_of(Date)
77
- r.publish_date.should == Date.new(2010, 1, 1)
78
- end
79
- end
80
-
81
- context "for a datetime column" do
82
- it 'should parse string into DateTime value' do
83
- r = Article.new
84
- r.publish_datetime = '2010-01-01 12:00'
85
-
86
- r.publish_datetime.should be_kind_of(DateTime)
87
- r.publish_datetime.should == DateTime.new(2010,1,1,12,0)
88
- end
89
- end
90
- end
91
- end
92
-
93
- context "cached value" do
94
- it 'should be cleared on reload' do
95
- r = Article.create!
96
- r.publish_date = '2010-01-01'
97
- r.reload
98
- r._timeliness_raw_value_for(:publish_date).should be_nil
99
- end
100
- end
101
-
102
- context "before_type_cast method" do
103
- it 'should not be defined if ORM does not support it' do
104
- Article.new.should_not respond_to(:publish_datetime_before_type_cast)
105
- end
106
- end
107
- end
108
-
109
- rescue LoadError
110
- puts "Mongoid specs skipped. Mongoid not installed"
111
- rescue StandardError => e
112
- puts "Mongoid specs skipped. MongoDB connection failed with error: #{e.message}"
113
- end