validates_timeliness 3.0.13 → 3.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ = 3.0.14 [2012-08-23]
2
+ * Fix for using validates :timeliness => {} form to correctly add attributes to timeliness validated attributes.
3
+
1
4
  = 3.0.13 [2012-08-21]
2
5
  * Fix ActiveRecord issues with using plugin parser by using old way of caching values.
3
6
  * Allow any ActiveRecord non-column attribute to be validated
@@ -0,0 +1,16 @@
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=>"../"
@@ -0,0 +1,16 @@
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=>"../"
@@ -0,0 +1,16 @@
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=>"../"
@@ -0,0 +1,16 @@
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=>"../"
@@ -15,12 +15,7 @@ module ActiveModel
15
15
  end
16
16
 
17
17
  def timeliness_validation_for(attr_names, type)
18
- options = _merge_attributes(attr_names).merge(:type => type)
19
- if respond_to?(:timeliness_validated_attributes)
20
- self.timeliness_validated_attributes ||= []
21
- self.timeliness_validated_attributes += (attr_names - self.timeliness_validated_attributes)
22
- end
23
- validates_with TimelinessValidator, options
18
+ validates_with TimelinessValidator, _merge_attributes(attr_names).merge(:type => type)
24
19
  end
25
20
  end
26
21
 
@@ -21,7 +21,7 @@ module ValidatesTimeliness
21
21
  def timeliness_attribute_type(attr_name)
22
22
  {
23
23
  Date => :date,
24
- Time => :datetime,
24
+ Time => :time,
25
25
  DateTime => :datetime
26
26
  }[fields[attr_name.to_s].type] || :datetime
27
27
  end
@@ -39,6 +39,13 @@ module ValidatesTimeliness
39
39
  super
40
40
  end
41
41
 
42
+ def setup(model)
43
+ if model.respond_to?(:timeliness_validated_attributes)
44
+ model.timeliness_validated_attributes ||= []
45
+ model.timeliness_validated_attributes |= @attributes
46
+ end
47
+ end
48
+
42
49
  def validate_each(record, attr_name, value)
43
50
  raw_value = attribute_raw_value(record, attr_name) || value
44
51
  return if (@allow_nil && raw_value.nil?) || (@allow_blank && raw_value.blank?)
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '3.0.13'
2
+ VERSION = '3.0.14'
3
3
  end
@@ -5,6 +5,7 @@ begin
5
5
 
6
6
  require 'mongoid'
7
7
  require 'validates_timeliness/orm/mongoid'
8
+
8
9
  Mongoid.configure do |config|
9
10
  name = "validates_timeliness_test"
10
11
  host = "localhost"
@@ -16,17 +17,17 @@ describe ValidatesTimeliness, 'Mongoid' do
16
17
 
17
18
  class Article
18
19
  include Mongoid::Document
19
- ValidatesTimeliness.use_plugin_parser = true
20
20
  field :publish_date, :type => Date
21
21
  field :publish_time, :type => Time
22
22
  field :publish_datetime, :type => DateTime
23
23
  validates_date :publish_date, :allow_nil => true
24
24
  validates_time :publish_time, :allow_nil => true
25
25
  validates_datetime :publish_datetime, :allow_nil => true
26
- ValidatesTimeliness.use_plugin_parser = false
27
26
  end
28
27
 
29
28
  context "validation methods" do
29
+ let(:record) { Article.new }
30
+
30
31
  it 'should be defined on the class' do
31
32
  Article.should respond_to(:validates_date)
32
33
  Article.should respond_to(:validates_time)
@@ -34,33 +35,33 @@ describe ValidatesTimeliness, 'Mongoid' do
34
35
  end
35
36
 
36
37
  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)
38
+ record.should respond_to(:validates_date)
39
+ record.should respond_to(:validates_time)
40
+ record.should respond_to(:validates_datetime)
40
41
  end
41
42
 
42
43
  it "should validate a valid value string" do
43
- r = Article.new
44
- r.publish_date = '2012-01-01'
44
+ record.publish_date = '2012-01-01'
45
45
 
46
- r.valid?
47
- r.errors[:publish_date].should be_empty
46
+ record.valid?
47
+ record.errors[:publish_date].should be_empty
48
48
  end
49
49
 
50
50
  it "should validate a invalid value string" do
51
- r = Article.new
52
- r.publish_date = 'not a date'
51
+ begin
52
+ record.publish_date = 'not a date'
53
+ rescue
54
+ end
53
55
 
54
- r.valid?
55
- r.errors[:publish_date].should_not be_empty
56
+ record.valid?
57
+ record.errors[:publish_date].should_not be_empty
56
58
  end
57
59
 
58
60
  it "should validate a nil value" do
59
- r = Article.new
60
- r.publish_date = nil
61
+ record.publish_date = nil
61
62
 
62
- r.valid?
63
- r.errors[:publish_date].should be_empty
63
+ record.valid?
64
+ record.errors[:publish_date].should be_empty
64
65
  end
65
66
  end
66
67
 
@@ -69,46 +70,97 @@ describe ValidatesTimeliness, 'Mongoid' do
69
70
  end
70
71
 
71
72
  context "attribute write method" do
73
+ let(:record) { Article.new }
74
+
72
75
  it 'should cache attribute raw value' do
73
- r = Article.new
74
- r.publish_datetime = date_string = '2010-01-01'
75
- r._timeliness_raw_value_for('publish_datetime').should == date_string
76
+ record.publish_datetime = date_string = '2010-01-01'
77
+
78
+ record._timeliness_raw_value_for('publish_datetime').should == date_string
76
79
  end
77
80
 
78
81
  context "with plugin parser" do
79
- with_config(:use_plugin_parser, true)
80
-
81
- it 'should parse a string value' do
82
- Timeliness::Parser.should_receive(:parse)
83
- r = Article.new
84
- r.publish_date = '2010-01-01'
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
85
95
  end
86
96
 
87
- it 'should parse an invalid value as nil' do
88
- Timeliness::Parser.should_receive(:parse)
89
- r = Article.new
90
- r.publish_date = 'bad value'
97
+ context "for a date column" do
98
+ it 'should parse a string value' do
99
+ Timeliness::Parser.should_receive(:parse)
91
100
 
92
- r.publish_date.should be_nil
93
- end
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
94
109
 
95
- context "for a date column" do
96
110
  it 'should store a Date value after parsing string' do
97
- r = Article.new
98
- r.publish_date = '2010-01-01'
111
+ record.publish_date = '2010-01-01'
99
112
 
100
- r.publish_date.should be_kind_of(Date)
101
- r.publish_date.should == Date.new(2010, 1, 1)
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)
102
136
  end
103
137
  end
104
138
 
105
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
+
106
154
  it 'should parse string into DateTime value' do
107
- r = Article.new
108
- r.publish_datetime = '2010-01-01 12:00'
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'
109
162
 
110
- r.publish_datetime.should be_kind_of(DateTime)
111
- r.publish_datetime.should == DateTime.new(2010,1,1,12,0)
163
+ record.publish_datetime.utc_offset.should eq Time.zone.utc_offset
112
164
  end
113
165
  end
114
166
  end
@@ -116,10 +168,10 @@ describe ValidatesTimeliness, 'Mongoid' do
116
168
 
117
169
  context "cached value" do
118
170
  it 'should be cleared on reload' do
119
- r = Article.create!
120
- r.publish_date = '2010-01-01'
121
- r.reload
122
- r._timeliness_raw_value_for('publish_date').should be_nil
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
123
175
  end
124
176
  end
125
177
 
@@ -19,6 +19,14 @@ describe ValidatesTimeliness::Validator do
19
19
  Person.validates :birth_datetime, :timeliness => {:is_at => Time.mktime(2010,1,1)}
20
20
  Person.validators.first.type.should == :datetime
21
21
  end
22
+
23
+ it 'should add attribute to timeliness attributes set' do
24
+ PersonWithShim.timeliness_validated_attributes.should_not include(:birth_time)
25
+
26
+ PersonWithShim.validates :birth_time, :timeliness => {:is_at => "12:30"}
27
+
28
+ PersonWithShim.timeliness_validated_attributes.should include(:birth_time)
29
+ end
22
30
  end
23
31
 
24
32
  it 'should not be valid for value which not valid date or time value' do
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.homepage = %q{http://github.com/adzap/validates_timeliness}
13
13
 
14
14
  s.require_paths = ["lib"]
15
- s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb }
15
+ s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb Appraisals Travis.yml } - Dir['gemsfiles/*']
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
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_timeliness
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 13
10
- version: 3.0.13
9
+ - 14
10
+ version: 3.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-21 00:00:00 +10:00
18
+ date: 2012-08-23 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,11 +45,14 @@ extra_rdoc_files:
45
45
  - CHANGELOG.rdoc
46
46
  - LICENSE
47
47
  files:
48
- - Appraisals
49
48
  - CHANGELOG.rdoc
50
49
  - LICENSE
51
50
  - README.rdoc
52
51
  - Rakefile
52
+ - gemfiles/mongoid_2_1.gemfile
53
+ - gemfiles/mongoid_2_2.gemfile
54
+ - gemfiles/mongoid_2_3.gemfile
55
+ - gemfiles/mongoid_2_4.gemfile
53
56
  - gemfiles/rails_3_0.gemfile
54
57
  - gemfiles/rails_3_1.gemfile
55
58
  - gemfiles/rails_3_2.gemfile
data/Appraisals DELETED
@@ -1,11 +0,0 @@
1
- appraise "rails_3_0" do
2
- gem "rails", "~> 3.0.0"
3
- end
4
-
5
- appraise "rails_3_1" do
6
- gem "rails", "~> 3.1.0"
7
- end
8
-
9
- appraise "rails_3_2" do
10
- gem "rails", "~> 3.2.0"
11
- end