active_validators 1.0.1 → 1.1.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 +4 -4
- data/CHANGELOG.rdoc +5 -1
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.rdoc +14 -1
- data/app/validators/not_equals_validator.rb +21 -0
- data/lib/active_validators/version.rb +1 -1
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/test.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20140408144900_create_tests.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +5039 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/validators/date_validator_spec.rb +194 -0
- data/spec/validators/not_equals_validator_spec.rb +68 -0
- data/spec/validators/time_validator_spec.rb +196 -0
- metadata +102 -16
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] ||= 'test'
|
5
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
6
|
+
|
7
|
+
require "database_cleaner"
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
|
11
|
+
config.mock_with :rspec
|
12
|
+
|
13
|
+
config.order = "random"
|
14
|
+
|
15
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
16
|
+
config.filter_run focus: true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
|
19
|
+
config.before(:all) do
|
20
|
+
DatabaseCleaner.strategy = :transaction
|
21
|
+
DatabaseCleaner.clean_with(:deletion)
|
22
|
+
end
|
23
|
+
|
24
|
+
config.around(:each) do |example|
|
25
|
+
DatabaseCleaner.start
|
26
|
+
example.run
|
27
|
+
DatabaseCleaner.clean
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DateValidator do
|
4
|
+
|
5
|
+
# Undo validations after each test
|
6
|
+
before { Test.reset_callbacks(:validate) }
|
7
|
+
|
8
|
+
context "with a :before key given" do
|
9
|
+
|
10
|
+
before { Test.validates :date, date: { before: 2.days.from_now }}
|
11
|
+
let!(:test) { Test.new }
|
12
|
+
|
13
|
+
context "if an attribute's value is before given date" do
|
14
|
+
|
15
|
+
before { test.date = 1.days.from_now.to_date }
|
16
|
+
|
17
|
+
it "validation passes" do
|
18
|
+
test.should be_valid
|
19
|
+
test.errors.should be_blank
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "if an attribute's value equals given date" do
|
24
|
+
|
25
|
+
before { test.date = 2.days.from_now.to_date }
|
26
|
+
|
27
|
+
it "validation fails" do
|
28
|
+
test.should_not be_valid
|
29
|
+
test.errors.should_not be_blank
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "if an attribute's value is after given date" do
|
34
|
+
|
35
|
+
before { test.date = 3.days.from_now.to_date }
|
36
|
+
|
37
|
+
it "validation fails" do
|
38
|
+
test.should_not be_valid
|
39
|
+
test.errors.should_not be_blank
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "if an attribute's value isn't set" do
|
44
|
+
|
45
|
+
it "validation fails" do
|
46
|
+
test.should_not be_valid
|
47
|
+
test.errors.should_not be_blank
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with an :after key given" do
|
53
|
+
|
54
|
+
before { Test.validates :date, date: { after: 2.days.from_now }}
|
55
|
+
let!(:test) { Test.new }
|
56
|
+
|
57
|
+
context "if an attribute's value is before given date" do
|
58
|
+
|
59
|
+
before { test.date = 1.days.from_now.to_date }
|
60
|
+
|
61
|
+
it "validation fails" do
|
62
|
+
test.should_not be_valid
|
63
|
+
test.errors.should_not be_blank
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "if an attribute's value equals given date" do
|
68
|
+
|
69
|
+
before { test.date = 2.days.from_now.to_date }
|
70
|
+
|
71
|
+
it "validation fails" do
|
72
|
+
test.should_not be_valid
|
73
|
+
test.errors.should_not be_blank
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "if an attribute's value is after given date" do
|
78
|
+
|
79
|
+
before { test.date = 3.days.from_now.to_date }
|
80
|
+
|
81
|
+
it "validation passes" do
|
82
|
+
test.should be_valid
|
83
|
+
test.errors.should be_blank
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "if an attribute's value isn't set" do
|
88
|
+
|
89
|
+
it "validation fails" do
|
90
|
+
test.should_not be_valid
|
91
|
+
test.errors.should_not be_blank
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with a :not_before key given" do
|
97
|
+
|
98
|
+
before { Test.validates :date, date: { not_before: 2.days.from_now }}
|
99
|
+
let!(:test) { Test.new }
|
100
|
+
|
101
|
+
context "if an attribute's value is before given date" do
|
102
|
+
|
103
|
+
before { test.date = 1.days.from_now.to_date }
|
104
|
+
|
105
|
+
it "validation fails" do
|
106
|
+
test.should_not be_valid
|
107
|
+
test.errors.should_not be_blank
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "if an attribute's value equals given date" do
|
112
|
+
|
113
|
+
before { test.date = 2.days.from_now.to_date }
|
114
|
+
|
115
|
+
it "validation passes" do
|
116
|
+
test.should be_valid
|
117
|
+
test.errors.should be_blank
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "if an attribute's value is after given date" do
|
122
|
+
|
123
|
+
before { test.date = 3.days.from_now.to_date }
|
124
|
+
|
125
|
+
it "validation passes" do
|
126
|
+
test.should be_valid
|
127
|
+
test.errors.should be_blank
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "if an attribute's value isn't set" do
|
132
|
+
|
133
|
+
it "validation fails" do
|
134
|
+
test.should_not be_valid
|
135
|
+
test.errors.should_not be_blank
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "with a :not_after key given" do
|
141
|
+
|
142
|
+
before { Test.validates :date, date: { not_after: 2.days.from_now }}
|
143
|
+
let!(:test) { Test.new }
|
144
|
+
|
145
|
+
context "if an attribute's value is before given date" do
|
146
|
+
|
147
|
+
before { test.date = 1.days.from_now.to_date }
|
148
|
+
|
149
|
+
it "validation passes" do
|
150
|
+
test.should be_valid
|
151
|
+
test.errors.should be_blank
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "if an attribute's value equals given date" do
|
156
|
+
|
157
|
+
before { test.date = 2.days.from_now.to_date }
|
158
|
+
|
159
|
+
it "validation passes" do
|
160
|
+
test.should be_valid
|
161
|
+
test.errors.should be_blank
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "if an attribute's value is after given date" do
|
166
|
+
|
167
|
+
before { test.date = 3.days.from_now.to_date }
|
168
|
+
|
169
|
+
it "validation fails" do
|
170
|
+
test.should_not be_valid
|
171
|
+
test.errors.should_not be_blank
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "if an attribute's value isn't set" do
|
176
|
+
|
177
|
+
it "validation fails" do
|
178
|
+
test.should_not be_valid
|
179
|
+
test.errors.should_not be_blank
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "with an :allow_nil option set to true" do
|
185
|
+
|
186
|
+
before { Test.validates :date, date: { not_after: 2.days.from_now, allow_nil: true }}
|
187
|
+
let!(:test) { Test.new }
|
188
|
+
|
189
|
+
it "validation passes even if an attribute's value isn't set" do
|
190
|
+
test.should be_valid
|
191
|
+
test.errors.should be_blank
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NotEqualsValidator do
|
4
|
+
|
5
|
+
# Undo validations after each test
|
6
|
+
before { Test.reset_callbacks(:validate) }
|
7
|
+
|
8
|
+
context "without an :allow_nil key given:" do
|
9
|
+
|
10
|
+
before { Test.validates :finish, not_equals: { to: :start }}
|
11
|
+
let!(:test) { Test.new }
|
12
|
+
|
13
|
+
context "if the attributes' values differ" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
test.start = 2.days.ago.to_date
|
17
|
+
test.finish = 1.day.ago.to_date
|
18
|
+
end
|
19
|
+
|
20
|
+
it "validation passes" do
|
21
|
+
test.should be_valid
|
22
|
+
test.errors.should be_blank
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "if the attributes' values are equal" do
|
27
|
+
|
28
|
+
before { test.start = test.finish = 1.day.ago.to_date }
|
29
|
+
|
30
|
+
it "validation fails" do
|
31
|
+
test.should_not be_valid
|
32
|
+
test.errors.should_not be_blank
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "if both the attributes' values aren't set" do
|
37
|
+
|
38
|
+
before do
|
39
|
+
test.start = nil
|
40
|
+
test.finish = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it "validation fails" do
|
44
|
+
test.should_not be_valid
|
45
|
+
test.errors.should_not be_blank
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with an :allow_nil option set to true:" do
|
51
|
+
|
52
|
+
before { Test.validates :finish, not_equals: { to: :start, allow_nil: true }}
|
53
|
+
let!(:test) { Test.new }
|
54
|
+
|
55
|
+
context "if both the attributes' values aren't set" do
|
56
|
+
|
57
|
+
before do
|
58
|
+
test.start = nil
|
59
|
+
test.finish = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
it "validation passes" do
|
63
|
+
test.should be_valid
|
64
|
+
test.errors.should be_blank
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TimeValidator do
|
4
|
+
|
5
|
+
# Undo validations after each test
|
6
|
+
before { Test.reset_callbacks(:validate) }
|
7
|
+
|
8
|
+
let!(:time) { Time.now }
|
9
|
+
|
10
|
+
context "with a :before key given" do
|
11
|
+
|
12
|
+
before { Test.validates :time, time: { before: time.since(2) }}
|
13
|
+
let!(:test) { Test.new }
|
14
|
+
|
15
|
+
context "if an attribute's value is before given time" do
|
16
|
+
|
17
|
+
before { test.time = time.since(1) }
|
18
|
+
|
19
|
+
it "validation passes" do
|
20
|
+
test.should be_valid
|
21
|
+
test.errors.should be_blank
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "if an attribute's value equals given time" do
|
26
|
+
|
27
|
+
before { test.time = time.since(2) }
|
28
|
+
|
29
|
+
it "validation fails" do
|
30
|
+
test.should_not be_valid
|
31
|
+
test.errors.should_not be_blank
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "if an attribute's value is after given time" do
|
36
|
+
|
37
|
+
before { test.time = time.since(3) }
|
38
|
+
|
39
|
+
it "validation fails" do
|
40
|
+
test.should_not be_valid
|
41
|
+
test.errors.should_not be_blank
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "if an attribute's value isn't set" do
|
46
|
+
|
47
|
+
it "validation fails" do
|
48
|
+
test.should_not be_valid
|
49
|
+
test.errors.should_not be_blank
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with an :after key given" do
|
55
|
+
|
56
|
+
before { Test.validates :time, time: { after: time.since(2) }}
|
57
|
+
let!(:test) { Test.new }
|
58
|
+
|
59
|
+
context "if an attribute's value is before given time" do
|
60
|
+
|
61
|
+
before { test.time = time.since(1) }
|
62
|
+
|
63
|
+
it "validation fails" do
|
64
|
+
test.should_not be_valid
|
65
|
+
test.errors.should_not be_blank
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "if an attribute's value equals given time" do
|
70
|
+
|
71
|
+
before { test.time = time.since(2) }
|
72
|
+
|
73
|
+
it "validation fails" do
|
74
|
+
test.should_not be_valid
|
75
|
+
test.errors.should_not be_blank
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "if an attribute's value is after given time" do
|
80
|
+
|
81
|
+
before { test.time = time.since(3) }
|
82
|
+
|
83
|
+
it "validation passes" do
|
84
|
+
test.should be_valid
|
85
|
+
test.errors.should be_blank
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "if an attribute's value isn't set" do
|
90
|
+
|
91
|
+
it "validation fails" do
|
92
|
+
test.should_not be_valid
|
93
|
+
test.errors.should_not be_blank
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with a :not_before key given" do
|
99
|
+
|
100
|
+
before { Test.validates :time, time: { not_before: time.since(2) }}
|
101
|
+
let!(:test) { Test.new }
|
102
|
+
|
103
|
+
context "if an attribute's value is before given time" do
|
104
|
+
|
105
|
+
before { test.time = time.since(1) }
|
106
|
+
|
107
|
+
it "validation fails" do
|
108
|
+
test.should_not be_valid
|
109
|
+
test.errors.should_not be_blank
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "if an attribute's value equals given time" do
|
114
|
+
|
115
|
+
before { test.time = time.since(2) }
|
116
|
+
|
117
|
+
it "validation passes" do
|
118
|
+
test.should be_valid
|
119
|
+
test.errors.should be_blank
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "if an attribute's value is after given time" do
|
124
|
+
|
125
|
+
before { test.time = time.since(3) }
|
126
|
+
|
127
|
+
it "validation passes" do
|
128
|
+
test.should be_valid
|
129
|
+
test.errors.should be_blank
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "if an attribute's value isn't set" do
|
134
|
+
|
135
|
+
it "validation fails" do
|
136
|
+
test.should_not be_valid
|
137
|
+
test.errors.should_not be_blank
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "with a :not_after key given" do
|
143
|
+
|
144
|
+
before { Test.validates :time, time: { not_after: time.since(2) }}
|
145
|
+
let!(:test) { Test.new }
|
146
|
+
|
147
|
+
context "if an attribute's value is before given time" do
|
148
|
+
|
149
|
+
before { test.time = time.since(1) }
|
150
|
+
|
151
|
+
it "validation passes" do
|
152
|
+
test.should be_valid
|
153
|
+
test.errors.should be_blank
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "if an attribute's value equals given time" do
|
158
|
+
|
159
|
+
before { test.time = time.since(2) }
|
160
|
+
|
161
|
+
it "validation passes" do
|
162
|
+
test.should be_valid
|
163
|
+
test.errors.should be_blank
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "if an attribute's value is after given time" do
|
168
|
+
|
169
|
+
before { test.time = time.since(3) }
|
170
|
+
|
171
|
+
it "validation fails" do
|
172
|
+
test.should_not be_valid
|
173
|
+
test.errors.should_not be_blank
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "if an attribute's value isn't set" do
|
178
|
+
|
179
|
+
it "validation fails" do
|
180
|
+
test.should_not be_valid
|
181
|
+
test.errors.should_not be_blank
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "with an :allow_nil option set to true" do
|
187
|
+
|
188
|
+
before { Test.validates :time, time: { not_after: time.since(2), allow_nil: true }}
|
189
|
+
let!(:test) { Test.new }
|
190
|
+
|
191
|
+
it "validation passes even if an attribute's value isn't set" do
|
192
|
+
test.should be_valid
|
193
|
+
test.errors.should be_blank
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|