validators 2.5.3 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -4
  4. data/Rakefile +9 -4
  5. data/data/disposable.json +1412 -23
  6. data/data/tld.json +391 -5
  7. data/lib/validators/version.rb +1 -1
  8. data/{spec → test}/schema.rb +0 -0
  9. data/{spec → test}/support/dates.rb +0 -0
  10. data/{spec → test}/support/emails.rb +0 -0
  11. data/{spec → test}/support/hostnames.rb +0 -0
  12. data/{spec → test}/support/ips.rb +0 -0
  13. data/{spec → test}/support/models.rb +0 -0
  14. data/{spec → test}/support/translations.yml +0 -0
  15. data/{spec → test}/support/urls.rb +0 -0
  16. data/test/test_helper.rb +41 -0
  17. data/test/validators/disposable_email_test.rb +23 -0
  18. data/test/validators/ip_test.rb +21 -0
  19. data/{spec/validators/validates_cnpj_format_of_spec.rb → test/validators/validates_cnpj_format_of_test.rb} +10 -10
  20. data/{spec/validators/validates_cpf_format_of_spec.rb → test/validators/validates_cpf_format_of_test.rb} +10 -10
  21. data/test/validators/validates_datetime/after_option_test.rb +75 -0
  22. data/test/validators/validates_datetime/before_option_test.rb +20 -0
  23. data/test/validators/validates_datetime/defaults_test.rb +37 -0
  24. data/test/validators/validates_email_format_of_test.rb +76 -0
  25. data/test/validators/validates_hostname_format_of/with_tld_validation_test.rb +25 -0
  26. data/test/validators/validates_hostname_format_of/without_tld_validation_test.rb +27 -0
  27. data/test/validators/validates_ip_address/ipv4_test.rb +20 -0
  28. data/test/validators/validates_ip_address/ipv6_test.rb +20 -0
  29. data/test/validators/validates_ip_address_test.rb +33 -0
  30. data/test/validators/validates_ownership_of_test.rb +65 -0
  31. data/test/validators/validates_ssh_private_key/bits_test.rb +44 -0
  32. data/test/validators/validates_ssh_private_key/common_test.rb +37 -0
  33. data/test/validators/validates_ssh_private_key/dsa_test.rb +36 -0
  34. data/test/validators/validates_ssh_private_key/rsa_test.rb +36 -0
  35. data/test/validators/validates_ssh_public_key_test.rb +37 -0
  36. data/test/validators/validates_url_format_of/with_tld_validation_test.rb +15 -0
  37. data/test/validators/validates_url_format_of/without_tld_validation_test.rb +48 -0
  38. data/validators.gemspec +2 -2
  39. metadata +65 -49
  40. data/.rspec +0 -1
  41. data/spec/spec_helper.rb +0 -38
  42. data/spec/validators/disposable_email_spec.rb +0 -31
  43. data/spec/validators/ip_spec.rb +0 -25
  44. data/spec/validators/validates_datetime_spec.rb +0 -125
  45. data/spec/validators/validates_email_format_of_spec.rb +0 -70
  46. data/spec/validators/validates_hostname_format_of_spec.rb +0 -53
  47. data/spec/validators/validates_ip_address_spec.rb +0 -59
  48. data/spec/validators/validates_ownership_of_spec.rb +0 -69
  49. data/spec/validators/validates_ssh_private_key_spec.rb +0 -152
  50. data/spec/validators/validates_ssh_public_key_spec.rb +0 -39
  51. data/spec/validators/validates_url_format_of_spec.rb +0 -65
@@ -0,0 +1,37 @@
1
+ require "test_helper"
2
+
3
+ class ValidatesSshPrivateKeyCommonTest < Minitest::Test
4
+ let(:model) { Class.new {
5
+ def self.name
6
+ "User"
7
+ end
8
+
9
+ include ActiveModel::Model
10
+ validates_ssh_private_key :key
11
+ attr_accessor :key
12
+ } }
13
+
14
+ test "requires valid key" do
15
+ record = model.new(key: "invalid")
16
+ record.valid?
17
+
18
+ refute record.errors[:key].empty?
19
+ end
20
+
21
+ test "accepts valid key" do
22
+ record = model.new(key: SSHKey.generate.private_key)
23
+ record.valid?
24
+
25
+ assert record.errors[:key].empty?
26
+ end
27
+
28
+ test "sets translated error message" do
29
+ I18n.locale = "pt-BR"
30
+ message = "não é uma chave privada de SSH válida"
31
+
32
+ record = model.new(key: "invalid")
33
+ record.valid?
34
+
35
+ assert_includes record.errors[:key], message
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class DsaTest < Minitest::Test
4
+ let(:model) { Class.new {
5
+ def self.name
6
+ "User"
7
+ end
8
+
9
+ include ActiveModel::Model
10
+ validates_ssh_private_key :key, type: "dsa"
11
+ attr_accessor :key
12
+ } }
13
+
14
+ test "accepts dsa key" do
15
+ record = model.new(key: SSHKey.generate(type: "dsa").private_key)
16
+ record.valid?
17
+
18
+ assert record.errors[:key].empty?
19
+ end
20
+
21
+ test "rejects rsa key" do
22
+ record = model.new(key: SSHKey.generate(type: 'rsa').private_key)
23
+ record.valid?
24
+
25
+ refute record.errors[:key].empty?
26
+ end
27
+
28
+ test "sets translated error message" do
29
+ I18n.locale = "pt-BR"
30
+
31
+ record = model.new(key: SSHKey.generate(type: 'rsa').private_key)
32
+ record.valid?
33
+
34
+ assert_includes record.errors[:key], "precisa ser uma chave DSA"
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class RsaTest < Minitest::Test
4
+ let(:model) { Class.new {
5
+ def self.name
6
+ "User"
7
+ end
8
+
9
+ include ActiveModel::Model
10
+ validates_ssh_private_key :key, type: 'rsa'
11
+ attr_accessor :key
12
+ } }
13
+
14
+ test "accepts rsa key" do
15
+ record = model.new(key: SSHKey.generate(type: "rsa").private_key)
16
+ record.valid?
17
+
18
+ assert record.errors[:key].empty?
19
+ end
20
+
21
+ test "rejects dsa key" do
22
+ record = model.new(key: SSHKey.generate(type: "dsa").private_key)
23
+ record.valid?
24
+
25
+ refute record.errors[:key].empty?
26
+ end
27
+
28
+ test "sets translated error message" do
29
+ I18n.locale = "pt-BR"
30
+
31
+ record = model.new(key: SSHKey.generate(type: "dsa").private_key)
32
+ record.valid?
33
+
34
+ assert_includes record.errors[:key], "precisa ser uma chave RSA"
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require "test_helper"
2
+
3
+ class ValidatesSsshPublicKeyCommonTest < Minitest::Test
4
+ let(:model) { Class.new {
5
+ def self.name
6
+ "User"
7
+ end
8
+
9
+ include ActiveModel::Model
10
+ validates_ssh_public_key :key
11
+ attr_accessor :key
12
+ } }
13
+
14
+ test "requires valid key" do
15
+ record = model.new(key: nil)
16
+ record.valid?
17
+
18
+ refute record.errors[:key].empty?
19
+ end
20
+
21
+ test "accepts valid key" do
22
+ record = model.new(key: SSHKey.generate.ssh_public_key)
23
+ record.valid?
24
+
25
+ assert record.errors[:key].empty?
26
+ end
27
+
28
+ test "sets translated error message" do
29
+ I18n.locale = "pt-BR"
30
+ message = "não é uma chave pública de SSH válida"
31
+
32
+ record = model.new(key: "invalid")
33
+ record.valid?
34
+
35
+ assert_includes record.errors[:key], message
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ class ValidatesurlFormatUrlWithTldValidationTest < Minitest::Test
4
+ test "rejects invalid TLD" do
5
+ user = UserWithTLD.new('http://example.xy')
6
+ refute user.valid?
7
+ end
8
+
9
+ TLDs.each do |tld|
10
+ test "accepts #{tld} as TLD" do
11
+ user = UserWithTLD.new("http://example.#{tld}")
12
+ assert user.valid?
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ require "test_helper"
2
+
3
+ class ValidatesurlFormatUrlWithoutTldValidationTest < Minitest::Test
4
+ setup do
5
+ User.validates_url_format_of :url, :allow_blank => false
6
+ end
7
+
8
+ VALID_URLS.each do |url|
9
+ test "accepts #{url.inspect} as a valid url" do
10
+ user = User.new(:url => url)
11
+ assert user.valid?
12
+ end
13
+ end
14
+
15
+ INVALID_URLS.each do |url|
16
+ test "rejects #{url.inspect} as a valid url" do
17
+ user = User.new(:url => url)
18
+ refute user.valid?
19
+ end
20
+ end
21
+
22
+ test "defines alias method" do
23
+ assert User.respond_to?(:validates_url)
24
+ end
25
+
26
+ test "uses default error message" do
27
+ user = User.new(:url => "invalid")
28
+ refute user.valid?
29
+ assert_includes user.errors[:url], "is not a valid address"
30
+ end
31
+
32
+ test "uses I18n string as error message [pt-BR]" do
33
+ I18n.locale = :'pt-BR'
34
+ user = User.new(:url => "invalid")
35
+ refute user.valid?
36
+ assert_includes user.errors[:url], "não parece ser uma URL válida"
37
+ end
38
+
39
+ test "rejects nil urls" do
40
+ user = User.new(url: nil)
41
+ refute user.valid?
42
+ end
43
+
44
+ test "rejects blank urls" do
45
+ user = User.new(url: '')
46
+ refute user.valid?
47
+ end
48
+ end
data/validators.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  require "./lib/validators/version"
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.required_ruby_version = ">= 1.9"
4
+ s.required_ruby_version = ">= 2.0"
5
5
  s.name = "validators"
6
6
  s.version = Validators::Version::STRING
7
7
  s.platform = Gem::Platform::RUBY
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency "activerecord", ">= 3.0"
21
- s.add_development_dependency "rspec"
21
+ s.add_development_dependency "minitest-utils"
22
22
  s.add_development_dependency "sqlite3-ruby"
23
23
  s.add_development_dependency "rake"
24
24
  s.add_development_dependency "pry-meta"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: minitest-utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -132,7 +132,6 @@ extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
134
  - ".gitignore"
135
- - ".rspec"
136
135
  - ".travis.yml"
137
136
  - Gemfile
138
137
  - README.md
@@ -157,27 +156,36 @@ files:
157
156
  - lib/validators/validates_ssh_public_key.rb
158
157
  - lib/validators/validates_url_format_of.rb
159
158
  - lib/validators/version.rb
160
- - spec/schema.rb
161
- - spec/spec_helper.rb
162
- - spec/support/dates.rb
163
- - spec/support/emails.rb
164
- - spec/support/hostnames.rb
165
- - spec/support/ips.rb
166
- - spec/support/models.rb
167
- - spec/support/translations.yml
168
- - spec/support/urls.rb
169
- - spec/validators/disposable_email_spec.rb
170
- - spec/validators/ip_spec.rb
171
- - spec/validators/validates_cnpj_format_of_spec.rb
172
- - spec/validators/validates_cpf_format_of_spec.rb
173
- - spec/validators/validates_datetime_spec.rb
174
- - spec/validators/validates_email_format_of_spec.rb
175
- - spec/validators/validates_hostname_format_of_spec.rb
176
- - spec/validators/validates_ip_address_spec.rb
177
- - spec/validators/validates_ownership_of_spec.rb
178
- - spec/validators/validates_ssh_private_key_spec.rb
179
- - spec/validators/validates_ssh_public_key_spec.rb
180
- - spec/validators/validates_url_format_of_spec.rb
159
+ - test/schema.rb
160
+ - test/support/dates.rb
161
+ - test/support/emails.rb
162
+ - test/support/hostnames.rb
163
+ - test/support/ips.rb
164
+ - test/support/models.rb
165
+ - test/support/translations.yml
166
+ - test/support/urls.rb
167
+ - test/test_helper.rb
168
+ - test/validators/disposable_email_test.rb
169
+ - test/validators/ip_test.rb
170
+ - test/validators/validates_cnpj_format_of_test.rb
171
+ - test/validators/validates_cpf_format_of_test.rb
172
+ - test/validators/validates_datetime/after_option_test.rb
173
+ - test/validators/validates_datetime/before_option_test.rb
174
+ - test/validators/validates_datetime/defaults_test.rb
175
+ - test/validators/validates_email_format_of_test.rb
176
+ - test/validators/validates_hostname_format_of/with_tld_validation_test.rb
177
+ - test/validators/validates_hostname_format_of/without_tld_validation_test.rb
178
+ - test/validators/validates_ip_address/ipv4_test.rb
179
+ - test/validators/validates_ip_address/ipv6_test.rb
180
+ - test/validators/validates_ip_address_test.rb
181
+ - test/validators/validates_ownership_of_test.rb
182
+ - test/validators/validates_ssh_private_key/bits_test.rb
183
+ - test/validators/validates_ssh_private_key/common_test.rb
184
+ - test/validators/validates_ssh_private_key/dsa_test.rb
185
+ - test/validators/validates_ssh_private_key/rsa_test.rb
186
+ - test/validators/validates_ssh_public_key_test.rb
187
+ - test/validators/validates_url_format_of/with_tld_validation_test.rb
188
+ - test/validators/validates_url_format_of/without_tld_validation_test.rb
181
189
  - validators.gemspec
182
190
  homepage: http://rubygems.org/gems/validators
183
191
  licenses:
@@ -191,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
199
  requirements:
192
200
  - - ">="
193
201
  - !ruby/object:Gem::Version
194
- version: '1.9'
202
+ version: '2.0'
195
203
  required_rubygems_version: !ruby/object:Gem::Requirement
196
204
  requirements:
197
205
  - - ">="
@@ -199,30 +207,38 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
207
  version: '0'
200
208
  requirements: []
201
209
  rubyforge_project:
202
- rubygems_version: 2.4.5.1
210
+ rubygems_version: 2.6.11
203
211
  signing_key:
204
212
  specification_version: 4
205
213
  summary: Add some nice ActiveModel/ActiveRecord validators.
206
214
  test_files:
207
- - spec/schema.rb
208
- - spec/spec_helper.rb
209
- - spec/support/dates.rb
210
- - spec/support/emails.rb
211
- - spec/support/hostnames.rb
212
- - spec/support/ips.rb
213
- - spec/support/models.rb
214
- - spec/support/translations.yml
215
- - spec/support/urls.rb
216
- - spec/validators/disposable_email_spec.rb
217
- - spec/validators/ip_spec.rb
218
- - spec/validators/validates_cnpj_format_of_spec.rb
219
- - spec/validators/validates_cpf_format_of_spec.rb
220
- - spec/validators/validates_datetime_spec.rb
221
- - spec/validators/validates_email_format_of_spec.rb
222
- - spec/validators/validates_hostname_format_of_spec.rb
223
- - spec/validators/validates_ip_address_spec.rb
224
- - spec/validators/validates_ownership_of_spec.rb
225
- - spec/validators/validates_ssh_private_key_spec.rb
226
- - spec/validators/validates_ssh_public_key_spec.rb
227
- - spec/validators/validates_url_format_of_spec.rb
228
- has_rdoc:
215
+ - test/schema.rb
216
+ - test/support/dates.rb
217
+ - test/support/emails.rb
218
+ - test/support/hostnames.rb
219
+ - test/support/ips.rb
220
+ - test/support/models.rb
221
+ - test/support/translations.yml
222
+ - test/support/urls.rb
223
+ - test/test_helper.rb
224
+ - test/validators/disposable_email_test.rb
225
+ - test/validators/ip_test.rb
226
+ - test/validators/validates_cnpj_format_of_test.rb
227
+ - test/validators/validates_cpf_format_of_test.rb
228
+ - test/validators/validates_datetime/after_option_test.rb
229
+ - test/validators/validates_datetime/before_option_test.rb
230
+ - test/validators/validates_datetime/defaults_test.rb
231
+ - test/validators/validates_email_format_of_test.rb
232
+ - test/validators/validates_hostname_format_of/with_tld_validation_test.rb
233
+ - test/validators/validates_hostname_format_of/without_tld_validation_test.rb
234
+ - test/validators/validates_ip_address/ipv4_test.rb
235
+ - test/validators/validates_ip_address/ipv6_test.rb
236
+ - test/validators/validates_ip_address_test.rb
237
+ - test/validators/validates_ownership_of_test.rb
238
+ - test/validators/validates_ssh_private_key/bits_test.rb
239
+ - test/validators/validates_ssh_private_key/common_test.rb
240
+ - test/validators/validates_ssh_private_key/dsa_test.rb
241
+ - test/validators/validates_ssh_private_key/rsa_test.rb
242
+ - test/validators/validates_ssh_public_key_test.rb
243
+ - test/validators/validates_url_format_of/with_tld_validation_test.rb
244
+ - test/validators/validates_url_format_of/without_tld_validation_test.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/spec/spec_helper.rb DELETED
@@ -1,38 +0,0 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
- require "bundler/setup"
5
- require "active_record"
6
- require "validators"
7
- require "active_support/all"
8
-
9
- Time.zone = "America/Sao_Paulo"
10
- TLDs = Validators::TLD.all.sample(50)
11
- DISPOSABLE_EMAILS = Validators::DisposableHostnames.all.sample(50)
12
-
13
- Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
14
-
15
- ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
16
- load "schema.rb"
17
-
18
- I18n.enforce_available_locales = false
19
- I18n.load_path << File.dirname(__FILE__) + "/support/translations.yml"
20
-
21
- RSpec.configure do |config|
22
- config.before do
23
- I18n.locale = :en
24
- Time.zone = "America/Sao_Paulo"
25
-
26
- ActiveRecord::Base.descendants.each do |model|
27
- next if model.name == "ActiveRecord::SchemaMigration"
28
-
29
- model.delete_all
30
-
31
- Object.class_eval {
32
- remove_const model.name if const_defined?(model.name)
33
- }
34
- end
35
-
36
- load File.dirname(__FILE__) + "/support/models.rb"
37
- end
38
- end
@@ -1,31 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ".validates_email_format_of" do
4
- context "when using disposable e-mail" do
5
- before do
6
- User.validates_email_format_of :email
7
- end
8
-
9
- DISPOSABLE_EMAILS.each do |domain|
10
- it "rejects disposable e-mail (#{domain})" do
11
- user = User.new(email: "user@#{domain}")
12
- user.valid?
13
-
14
- expect(user.errors[:email]).to include(I18n.t('activerecord.errors.messages.disposable_email'))
15
- end
16
- end
17
- end
18
-
19
- context "disable disposable e-mail" do
20
- before do
21
- User.validates_email_format_of :email, disposable: true
22
- end
23
-
24
- it "accepts e-mail" do
25
- user = User.new(email: "user@mailinator.com")
26
- user.valid?
27
-
28
- expect(user.errors[:email]).to be_empty
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Validators::Ip do
4
- context "IPv4" do
5
- VALID_IPV4.each do |ip|
6
- it "should accept #{ip.inspect} as ip address" do
7
- expect(Validators::Ip).to be_v4(ip)
8
- end
9
- end
10
- end
11
-
12
- context "IPv6" do
13
- VALID_IPV6.each do |ip|
14
- it "should accept #{ip.inspect} as ip address" do
15
- expect(Validators::Ip).to be_v6(ip)
16
- end
17
- end
18
- end
19
-
20
- (VALID_IPV4 + VALID_IPV6).each do |ip|
21
- it "should accept #{ip.inspect} as ip address" do
22
- expect(Validators::Ip).to be_valid(ip)
23
- end
24
- end
25
- end
@@ -1,125 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ".validates_datetime" do
4
- subject { User.new }
5
-
6
- context "default options" do
7
- before do
8
- User.validates_datetime :registered_at
9
- User.validates :birthday, :datetime => true
10
- end
11
-
12
- VALID_DATES.each do |date|
13
- it "accepts #{date.inspect} as valid date" do
14
- subject.registered_at = date
15
- subject.birthday = date
16
-
17
- expect(subject).to be_valid
18
- end
19
- end
20
-
21
- INVALID_DATES.each do |date|
22
- it "rejects #{date.inspect} as valid date" do
23
- subject.registered_at = date
24
- subject.birthday = date
25
- expect(subject).not_to be_valid
26
-
27
- expect(subject.errors[:registered_at]).not_to be_empty
28
- expect(subject.errors[:birthday]).not_to be_empty
29
- end
30
- end
31
-
32
- it "includes default error message" do
33
- subject.registered_at = nil
34
- expect(subject).not_to be_valid
35
-
36
- expect(subject.errors[:registered_at]).to eq(["is not a valid date"])
37
- end
38
- end
39
-
40
- context "after option" do
41
- it "rejects when date is set to before :after option" do
42
- future_date = 1.week.from_now
43
- User.validates_datetime :registered_at, :after => future_date
44
- subject.registered_at = Time.now
45
-
46
- expect(subject).not_to be_valid
47
- expect(subject.errors[:registered_at]).to eq(["needs to be after #{I18n.l(future_date)}"])
48
- end
49
-
50
- it "accepts when date is set accordingly to the :after option" do
51
- User.validates_datetime :registered_at, :after => 1.week.from_now
52
- subject.registered_at = 2.weeks.from_now
53
-
54
- expect(subject).to be_valid
55
- end
56
-
57
- it "validates using today as date" do
58
- User.validates_datetime :registered_at, :after => :today
59
-
60
- subject.registered_at = Time.now
61
- expect(subject).not_to be_valid
62
-
63
- subject.registered_at = Date.today
64
- expect(subject).not_to be_valid
65
-
66
- subject.registered_at = Date.tomorrow
67
- expect(subject).to be_valid
68
-
69
- subject.registered_at = 1.day.from_now
70
- expect(subject).to be_valid
71
- end
72
-
73
- it "validates using now as date" do
74
- User.validates_datetime :registered_at, :after => :now
75
-
76
- subject.registered_at = Time.now
77
- expect(subject).not_to be_valid
78
-
79
- subject.registered_at = Date.today
80
- expect(subject).not_to be_valid
81
-
82
- subject.registered_at = Date.tomorrow
83
- expect(subject).to be_valid
84
-
85
- subject.registered_at = 1.day.from_now
86
- expect(subject).to be_valid
87
- end
88
-
89
- it "validates using method as date" do
90
- User.validates_datetime :starts_at
91
- User.validates_datetime :ends_at, :after => :starts_at, :if => :starts_at?
92
-
93
- subject.starts_at = nil
94
- subject.ends_at = Time.now
95
- expect(subject).not_to be_valid
96
- expect(subject.errors[:ends_at]).to be_empty
97
-
98
- subject.starts_at = Time.parse("Apr 26 2010")
99
- subject.ends_at = Time.parse("Apr 25 2010")
100
- expect(subject).not_to be_valid
101
- expect(subject.errors[:ends_at]).to eq(["needs to be after #{I18n.l(Time.parse("Apr 26 2010"))}"])
102
-
103
- subject.starts_at = Time.now
104
- subject.ends_at = 1.hour.from_now
105
- expect(subject).to be_valid
106
- end
107
- end
108
-
109
- context "before option" do
110
- it "rejects when date is set to after :before option" do
111
- User.validates_datetime :registered_at, :before => 1.week.ago
112
- subject.registered_at = Time.now
113
-
114
- expect(subject).not_to be_valid
115
- expect(subject.errors[:registered_at]).to eq(["needs to be before #{I18n.l(1.week.ago)}"])
116
- end
117
-
118
- it "accepts when date is set accordingly to the :before option" do
119
- User.validates_datetime :registered_at, :before => 1.week.ago
120
- subject.registered_at = 2.weeks.ago
121
-
122
- expect(subject).to be_valid
123
- end
124
- end
125
- end