mv-sqlite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +141 -0
- data/lib/migration_validators/adapters/sqlite.rb +75 -0
- data/lib/mv-sqlite.rb +4 -0
- data/spec/migration_validators/adapters/sqlite_spec.rb +975 -0
- data/spec/mv-sqlite_spec.rb +4 -0
- data/spec/spec_helper.rb +15 -0
- metadata +122 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Valeriy Prokopchuk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
= Introduction
|
2
|
+
|
3
|
+
mv-sqlite is the SQLite driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core)
|
4
|
+
|
5
|
+
= Validators
|
6
|
+
|
7
|
+
=== uniqueness
|
8
|
+
|
9
|
+
Value uniqueness validation
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
|
13
|
+
validate_column :table_name, :column_name, :uniqueness => true
|
14
|
+
validate_column :table_name, :column_name, :uniqueness => {:message => 'Error message', :as => :trigger}
|
15
|
+
validate_column :table_name, :column_name, :uniqueness => {:as => :index}
|
16
|
+
|
17
|
+
create_table :table_name do |t|
|
18
|
+
t.string :column_name, :validates => {uniqueness => true}
|
19
|
+
end
|
20
|
+
|
21
|
+
Options:
|
22
|
+
|
23
|
+
message: text of the error message that will be shown if constraint violated. Ignored unless :as == :trigger
|
24
|
+
index_name: name of the index that will be created for validator. Ignored unless :as == :index
|
25
|
+
on: validation event. Possible values [:save, :update, :create]. Ignored unless :as == :trigger. Default value :save
|
26
|
+
create_tigger_name: Name of the 'before insert' trigger that will be created if :as == :trigger && :on in [:save, :create]
|
27
|
+
update_tigger_name: Name of the 'before update' trigger that will be created if :as == :trigger && :on in [:save, :update]
|
28
|
+
allow_nil: ignore validation for nil values. Ignored unless :as == :trigger. Default value: false
|
29
|
+
allow_blank: ignore validation for blank values. Ignored unless :as == :trigger. Default value: false
|
30
|
+
as: defines the way how constraint will be implemented. Possible values: [:index, :trigger]. Default value: :index
|
31
|
+
|
32
|
+
=== length
|
33
|
+
|
34
|
+
Value length validation
|
35
|
+
|
36
|
+
Usage:
|
37
|
+
|
38
|
+
validate_column :table_name, :column_name, :length => {:in => 5..8, :message => "Wrong length message"}
|
39
|
+
validate_column :table_name, :column_name, :length => {:is => 3, :allow_nil => true}
|
40
|
+
validate_column :table_name, :column_name, :length => {:maximum => 3, :too_long => "Value is longer than 3 symbols"}
|
41
|
+
|
42
|
+
Options:
|
43
|
+
|
44
|
+
in: range or array that length of the value should be contained in.
|
45
|
+
within: synonym of :in
|
46
|
+
is: exact length of the value
|
47
|
+
maximum: maximum allowed length
|
48
|
+
minimum: minimum allowed length
|
49
|
+
message: message that should be shown if validation failed and specific message is not defined
|
50
|
+
too_long: message that will be shown if value longer than allowed. Ignored unless maximum value is defined
|
51
|
+
too_short: message that will be shown if value shorter than allowed. Ignored unless minimum value is defined
|
52
|
+
on: validation event. Possible values [:save, :update, :create]. Default value: :save
|
53
|
+
create_tigger_name: Name of the 'before insert' trigger
|
54
|
+
update_tigger_name: Name of the 'before update' trigger
|
55
|
+
allow_nil: ignore validation for nil values. Default value: false
|
56
|
+
allow_blank: ignore validation for blank values. Default value: false
|
57
|
+
as: defines the way how constraint will be implemented. Possible values: [:trigger]
|
58
|
+
|
59
|
+
=== inclusion
|
60
|
+
|
61
|
+
Value inclusion validation
|
62
|
+
|
63
|
+
Usage:
|
64
|
+
|
65
|
+
validate_column :table_name, :column_name, :inclusion => {:in => [1, 2, 3]}
|
66
|
+
validate_column :table_name, :column_name, :inclusion => {:in => [1, 2, 3], :message => "Column 'column_name' should be equal to 1 or 2 or 3"}
|
67
|
+
validate_column :table_name, :column_name, :inclusion => {:in => [1, 2, 3], :on => :update, :as => :check}
|
68
|
+
validate_column :table_name, :column_name, :inclusion => {:in => 1..3, :on => :create, :as => :trigger}
|
69
|
+
|
70
|
+
Options:
|
71
|
+
|
72
|
+
in: range or array that column value should be contained in.
|
73
|
+
message: message that should be shown if validation failed
|
74
|
+
on: validation event. Possible values [:save, :update, :create]. Default value: :save
|
75
|
+
create_tigger_name: Name of the 'before insert' trigger
|
76
|
+
update_tigger_name: Name of the 'before update' trigger
|
77
|
+
allow_nil: ignore validation for nil values. Default value: false
|
78
|
+
allow_blank: ignore validation for blank values. Default value: false
|
79
|
+
as: defines the way how constraint will be implemented. Possible values: [:trigger]
|
80
|
+
|
81
|
+
|
82
|
+
=== exclusion
|
83
|
+
|
84
|
+
Value exclusion validation
|
85
|
+
|
86
|
+
Usage:
|
87
|
+
|
88
|
+
validate_column :table_name, :column_name, :exclusion => {:in => [1, 2, 3]}
|
89
|
+
validate_column :table_name, :column_name, :exclusion => {:in => [1, 2, 3], :message => "Column 'column_name' should not be equal to 1 or 2 or 3"}
|
90
|
+
validate_column :table_name, :column_name, :exclusion => {:in => [1, 2, 3], :on => :update, :as => :check}
|
91
|
+
validate_column :table_name, :column_name, :exclusion => {:in => 1..3, :on => :create, :as => :trigger}
|
92
|
+
|
93
|
+
Options:
|
94
|
+
|
95
|
+
in: range or array that column value should NOT be contained in.
|
96
|
+
message: message that should be shown if validation failed
|
97
|
+
on: validation event. Possible values [:save, :update, :create]. Default value: :save
|
98
|
+
create_tigger_name: Name of the 'before insert' trigger
|
99
|
+
update_tigger_name: Name of the 'before update' trigger
|
100
|
+
allow_nil: ignore validation for nil values. Default value: false
|
101
|
+
allow_blank: ignore validation for blank values. Default value: false
|
102
|
+
as: defines the way how constraint will be implemented. Possible values: [:trigger]
|
103
|
+
|
104
|
+
=== presense
|
105
|
+
|
106
|
+
Value presense validation
|
107
|
+
|
108
|
+
Usage:
|
109
|
+
|
110
|
+
validate_column :table_name, :column_name, :presense => true
|
111
|
+
validate_column :table_name, :column_name, :presense => {:message => "value should not be empty"}
|
112
|
+
validate_column :table_name, :column_name, :presense => {:message => "value should not be empty", :as=> :trigger}
|
113
|
+
validate_column :table_name, :column_name, :presense => {:message => "value should not be empty", :as=> :trigger, :on => :create}
|
114
|
+
|
115
|
+
|
116
|
+
Options:
|
117
|
+
|
118
|
+
message: message that should be shown if validation failed
|
119
|
+
on: validation event. Possible values [:save, :update, :create]. Default value: :save
|
120
|
+
create_tigger_name: Name of the 'before insert' trigger
|
121
|
+
update_tigger_name: Name of the 'before update' trigger
|
122
|
+
allow_nil: ignore validation for nil values. Default value: false
|
123
|
+
allow_blank: ignore validation for blank values. Default value: false
|
124
|
+
as: defines the way how constraint will be implemented. Possible values: [:trigger]
|
125
|
+
|
126
|
+
== Contributing to mv-sqlite
|
127
|
+
|
128
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
129
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
130
|
+
* Fork the project
|
131
|
+
* Start a feature/bugfix branch
|
132
|
+
* Commit and push until you are happy with your contribution
|
133
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
134
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
135
|
+
|
136
|
+
== Copyright
|
137
|
+
|
138
|
+
Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
|
139
|
+
further details.
|
140
|
+
|
141
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module MigrationValidators
|
2
|
+
module Adapters
|
3
|
+
class Sqlite < MigrationValidators::Adapters::Base
|
4
|
+
def name
|
5
|
+
"SQLite Migration Validators Adapter"
|
6
|
+
end
|
7
|
+
|
8
|
+
define_base_syntax
|
9
|
+
define_base_validators
|
10
|
+
define_base_containers
|
11
|
+
|
12
|
+
container :insert_trigger do
|
13
|
+
operation :db_value do |value|
|
14
|
+
case value.class.name
|
15
|
+
when "String" then "'#{value}'"
|
16
|
+
when "Date" then "date('#{value.strftime('%Y-%m-%d')}')"
|
17
|
+
when "DateTime" then "datetime('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
18
|
+
when "Time" then "datetime('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
19
|
+
else value.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
operation :bind_to_error do |stmt, error_message|
|
24
|
+
"SELECT RAISE(ABORT, '#{error_message}')
|
25
|
+
WHERE NOT(#{stmt})"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
container :update_trigger do
|
30
|
+
operation :db_value do |value|
|
31
|
+
case value.class.name
|
32
|
+
when "String" then "'#{value}'"
|
33
|
+
when "Date" then "date('#{value.strftime('%Y-%m-%d')}')"
|
34
|
+
when "DateTime" then "datetime('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
35
|
+
when "Time" then "datetime('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
36
|
+
else value.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
operation :bind_to_error do |stmt, error_message|
|
41
|
+
"SELECT RAISE(ABORT, '#{error_message}')
|
42
|
+
WHERE NOT(#{stmt})"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
route :presense, :trigger, :default => true do
|
48
|
+
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
49
|
+
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
50
|
+
end
|
51
|
+
|
52
|
+
route :inclusion, :trigger, :default => true do
|
53
|
+
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
54
|
+
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
55
|
+
end
|
56
|
+
|
57
|
+
route :exclusion, :trigger, :default => true do
|
58
|
+
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
59
|
+
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
60
|
+
end
|
61
|
+
|
62
|
+
route :length, :trigger, :default => true do
|
63
|
+
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
64
|
+
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
65
|
+
end
|
66
|
+
|
67
|
+
route :uniqueness, :trigger do
|
68
|
+
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
69
|
+
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
MigrationValidators.register_adapter! "sqlite3", Sqlite
|
74
|
+
end
|
75
|
+
end
|
data/lib/mv-sqlite.rb
ADDED
@@ -0,0 +1,975 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe MigrationValidators::Adapters::Sqlite, :type => :mv_test do
|
4
|
+
before :all do
|
5
|
+
Driver = Class.new(MigrationValidators::Adapters::Base)
|
6
|
+
use_db :adapter => "sqlite3", :pool => 5, :timeout => 5000, :database => "validation_migration_test_db"
|
7
|
+
db.initialize_schema_migrations_table
|
8
|
+
::ActiveRecord::Migration.verbose = false
|
9
|
+
end
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
MigrationValidators::Core::DbValidator.clear_all
|
13
|
+
end
|
14
|
+
|
15
|
+
for_test_table do
|
16
|
+
|
17
|
+
#integer
|
18
|
+
for_integer_column do
|
19
|
+
with_validator :presense do
|
20
|
+
with_option :as => :trigger do
|
21
|
+
it { should allow(5) }
|
22
|
+
it { should deny(nil).with_initial(5) }
|
23
|
+
end
|
24
|
+
|
25
|
+
with_option :allow_blank => true do
|
26
|
+
it { should allow(nil) }
|
27
|
+
end
|
28
|
+
|
29
|
+
with_option :allow_nil => true do
|
30
|
+
it { should allow(nil) }
|
31
|
+
end
|
32
|
+
|
33
|
+
with_option :on => :update do
|
34
|
+
it { should allow.insert(nil) }
|
35
|
+
end
|
36
|
+
|
37
|
+
with_option :on => :create do
|
38
|
+
it { should allow.update(nil).with_initial(5) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
with_validator :inclusion do
|
43
|
+
with_option :as => :trigger do
|
44
|
+
#closed integer interval
|
45
|
+
with_options :in => 1..9 do
|
46
|
+
it { should allow(1,4,9) }
|
47
|
+
it { should deny(0, 10).with_initial(1) }
|
48
|
+
end
|
49
|
+
|
50
|
+
#open integer interval
|
51
|
+
with_options :in => 1...9 do
|
52
|
+
it { should allow(1,4) }
|
53
|
+
it { should deny(0, 9, 10).with_initial(1) }
|
54
|
+
end
|
55
|
+
|
56
|
+
#single value
|
57
|
+
with_options :in => 9 do
|
58
|
+
it { should allow(9) }
|
59
|
+
it { should deny(8, 10).with_initial(9) }
|
60
|
+
end
|
61
|
+
|
62
|
+
#array
|
63
|
+
with_options :in => [1, 9] do
|
64
|
+
it { should allow(1, 9) }
|
65
|
+
it { should deny(0, 3, 10).with_initial(1) }
|
66
|
+
end
|
67
|
+
|
68
|
+
with_options :in => 9, :message => "Some error message" do
|
69
|
+
it { should deny(8, 10).with_initial(9).and_message(/Some error message/) }
|
70
|
+
|
71
|
+
with_option :on => :update do
|
72
|
+
it { should allow.insert(8, 10) }
|
73
|
+
end
|
74
|
+
|
75
|
+
with_option :on => :create do
|
76
|
+
it { should allow.update(8, 10).with_initial(9) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
with_validator :exclusion do
|
83
|
+
with_option :as => :trigger do
|
84
|
+
#closed integer interval
|
85
|
+
with_options :in => 1..9 do
|
86
|
+
it { should allow(0, 10) }
|
87
|
+
it { should deny(1,4,9).with_initial(0) }
|
88
|
+
end
|
89
|
+
|
90
|
+
#open integer intervalw
|
91
|
+
with_options :in => 1...9 do
|
92
|
+
it { should allow(0, 9, 10) }
|
93
|
+
it { should deny(1,4).with_initial(0) }
|
94
|
+
end
|
95
|
+
|
96
|
+
#single value
|
97
|
+
with_options :in => 9 do
|
98
|
+
it { should allow(8, 10) }
|
99
|
+
it { should deny(9).with_initial(0) }
|
100
|
+
end
|
101
|
+
|
102
|
+
#array
|
103
|
+
with_options :in => [1, 9] do
|
104
|
+
it { should allow(0, 3, 10) }
|
105
|
+
it { should deny(1, 9).with_initial(0) }
|
106
|
+
end
|
107
|
+
|
108
|
+
with_options :in => 9, :message => "Some error message" do
|
109
|
+
it { should deny(9).with_initial(8).and_message(/Some error message/) }
|
110
|
+
|
111
|
+
with_option :on => :update do
|
112
|
+
it { should allow.insert(9) }
|
113
|
+
end
|
114
|
+
|
115
|
+
with_option :on => :create do
|
116
|
+
it { should allow.update(9).with_initial(8) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
with_validator :uniqueness do
|
124
|
+
with_option :as => :trigger do
|
125
|
+
it { should deny.insert.at_least_one(1,1)}
|
126
|
+
it { should deny.update(1).with_initial(1,2)}
|
127
|
+
it { should allow.insert(1,2,3) }
|
128
|
+
|
129
|
+
with_option :message => "Some error message" do
|
130
|
+
it { should deny.at_least_one(1,1).with_initial(1).and_message(/Some error message/) }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
with_option :as => :index do
|
135
|
+
it { should deny.insert.at_least_one(1,1).with_message(/is not unique/) }
|
136
|
+
it { should deny.update(1).with_initial(1,2).and_message(/is not unique/) }
|
137
|
+
it { should allow.insert(1,2,3) }
|
138
|
+
it { should allow.update(1).with_initial(2) }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
for_integer_column :validates => {:uniqueness => {:as => :index, :message => "Some error message"}, :inclusion => {:in => 1..9, :as => :trigger, :message => "Some error message"}} do
|
144
|
+
it { should deny.at_least_one(1,1).with_initial(1, 2).and_message(/is not unique/) }
|
145
|
+
it { should deny(10).with_initial(8).and_message(/Some error message/) }
|
146
|
+
|
147
|
+
with_change :inclusion => false do
|
148
|
+
it { should deny.at_least_one(1,1).with_initial(1, 2).and_message(/is not unique/) }
|
149
|
+
it { should allow(10) }
|
150
|
+
end
|
151
|
+
|
152
|
+
with_change :inclusion => {:in => 1..9} do
|
153
|
+
with_change :inclusion => false do
|
154
|
+
it { should allow(10) }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
for_integer_column :validates => {:uniqueness => {:as => :index, :message => "Some error message"}, :exclusion => {:in => 4..9, :as => :trigger, :message => "Some error message"}} do
|
160
|
+
it { should deny.at_least_one(1,1).with_initial(1, 2).and_message(/is not unique/) }
|
161
|
+
it { should deny(9).with_initial(10).and_message(/Some error message/) }
|
162
|
+
|
163
|
+
with_change :exclusion => false do
|
164
|
+
it { should deny.at_least_one(1,1).with_initial(1, 2).and_message(/is not unique/) }
|
165
|
+
it { should allow(9) }
|
166
|
+
end
|
167
|
+
|
168
|
+
with_change :exclusion => {:in => 4..9} do
|
169
|
+
with_change :exclusion => false do
|
170
|
+
it { should allow(9) }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
for_integer_column :validates => {:uniqueness => {:as => :index, :message => "Some error message"}, :presense => {:as => :trigger, :message => "Some error message"}} do
|
176
|
+
it { should deny.at_least_one(1,1).with_initial(1, 2).and_message(/is not unique/) }
|
177
|
+
it { should deny(nil).with_initial(10).and_message(/Some error message/) }
|
178
|
+
|
179
|
+
with_change :presense => false do
|
180
|
+
it { should deny.at_least_one(1,1).with_initial(1, 2).and_message(/is not unique/) }
|
181
|
+
it { should allow(nil) }
|
182
|
+
end
|
183
|
+
|
184
|
+
with_change :presense => true do
|
185
|
+
with_change :presense => false do
|
186
|
+
it { should allow(nil) }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
#float
|
193
|
+
for_float_column do
|
194
|
+
|
195
|
+
with_validator :presense do
|
196
|
+
with_option :as => :trigger do
|
197
|
+
it { should allow(1.1) }
|
198
|
+
it { should deny(nil).with_initial(1.1) }
|
199
|
+
end
|
200
|
+
|
201
|
+
with_option :allow_blank => true do
|
202
|
+
it { should allow(nil) }
|
203
|
+
end
|
204
|
+
|
205
|
+
with_option :allow_nil => true do
|
206
|
+
it { should allow(nil) }
|
207
|
+
end
|
208
|
+
|
209
|
+
with_option :on => :update do
|
210
|
+
it { should allow.insert(nil) }
|
211
|
+
end
|
212
|
+
|
213
|
+
with_option :on => :create do
|
214
|
+
it { should allow.update(nil).with_initial(1.1) }
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
with_validator :inclusion do
|
219
|
+
with_option :as => :trigger do
|
220
|
+
#closed integer interval
|
221
|
+
with_options :in => 1.1..9.1 do
|
222
|
+
it { should allow(1.1, 9.1) }
|
223
|
+
it { should deny(1.0, 9.2).with_initial(1.1) }
|
224
|
+
end
|
225
|
+
|
226
|
+
#open integer interval
|
227
|
+
with_options :in => 1.1...9.1 do
|
228
|
+
it { should allow(1.1, 9) }
|
229
|
+
it { should deny(1.0, 9.1, 9.2).with_initial(1.1) }
|
230
|
+
end
|
231
|
+
|
232
|
+
#single value
|
233
|
+
with_options :in => 9.1 do
|
234
|
+
it { should allow(9.1) }
|
235
|
+
it { should deny(8.1, 10.1).with_initial(9.1) }
|
236
|
+
end
|
237
|
+
|
238
|
+
#array
|
239
|
+
with_options :in => [1.1, 9.1] do
|
240
|
+
it { should allow(1.1, 9.1) }
|
241
|
+
it { should deny(0.1, 3.1, 10.1).with_initial(1.1) }
|
242
|
+
end
|
243
|
+
|
244
|
+
with_options :in => 9.1, :message => "Some error message" do
|
245
|
+
it { should deny(8.1, 10.1).with_initial(9.1).and_message(/Some error message/) }
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
with_validator :exclusion do
|
251
|
+
with_option :as => :trigger do
|
252
|
+
#closed integer interval
|
253
|
+
with_options :in => 1.1..9.1 do
|
254
|
+
it { should allow(1.0, 9.2) }
|
255
|
+
it { should deny(1.1, 9.1).with_initial(1.0) }
|
256
|
+
end
|
257
|
+
|
258
|
+
#open integer interval
|
259
|
+
with_options :in => 1.1...9.1 do
|
260
|
+
it { should allow(1.0, 9.1, 9.2) }
|
261
|
+
it { should deny(1.1, 9).with_initial(1.0) }
|
262
|
+
end
|
263
|
+
|
264
|
+
#single value
|
265
|
+
with_options :in => 9.1 do
|
266
|
+
it { should deny(9.1).with_initial(9.0) }
|
267
|
+
it { should allow(8.1, 10.1) }
|
268
|
+
end
|
269
|
+
|
270
|
+
#array
|
271
|
+
with_options :in => [1.1, 9.1] do
|
272
|
+
it { should deny(1.1, 9.1).with_initial(1.0) }
|
273
|
+
it { should allow(0.1, 3.1, 10.1) }
|
274
|
+
end
|
275
|
+
|
276
|
+
with_options :in => 9.1, :message => "Some error message" do
|
277
|
+
it { should deny(9.1).with_initial(9.0).and_message(/Some error message/) }
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
#string
|
284
|
+
for_string_column do
|
285
|
+
with_validator :presense do
|
286
|
+
with_option :as => :trigger do
|
287
|
+
it { should allow('b') }
|
288
|
+
it { should deny(nil).with_initial('b') }
|
289
|
+
end
|
290
|
+
|
291
|
+
with_option :allow_blank => true do
|
292
|
+
it { should allow(nil) }
|
293
|
+
end
|
294
|
+
|
295
|
+
with_option :allow_nil => true do
|
296
|
+
it { should allow(nil) }
|
297
|
+
end
|
298
|
+
|
299
|
+
with_option :on => :update do
|
300
|
+
it { should allow.insert(nil) }
|
301
|
+
end
|
302
|
+
|
303
|
+
with_option :on => :create do
|
304
|
+
it { should allow.update(nil).with_initial('b') }
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
with_validator :uniqueness do
|
309
|
+
with_option :as => :trigger do
|
310
|
+
it { should deny.at_least_one(' ', ' ').with_initial(' ', 'a') }
|
311
|
+
|
312
|
+
with_option :allow_blank => true do
|
313
|
+
it { should allow(' ', ' ') }
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
with_validator :inclusion do
|
319
|
+
with_option :as => :trigger do
|
320
|
+
#closed string interval
|
321
|
+
with_options :in => 'b'..'e' do
|
322
|
+
it { should allow('b', 'd', 'e') }
|
323
|
+
it { should deny('a', 'f').with_initial('b') }
|
324
|
+
it { should deny(' ').with_initial('b') }
|
325
|
+
it { should deny(nil).with_initial('b') }
|
326
|
+
|
327
|
+
with_option :allow_blank => true do
|
328
|
+
it { should allow(' ') }
|
329
|
+
end
|
330
|
+
|
331
|
+
with_option :allow_nil => true do
|
332
|
+
it { should allow(nil) }
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
#open string interval
|
337
|
+
with_options :in => 'b'...'e' do
|
338
|
+
it { should allow('b', 'd') }
|
339
|
+
it { should deny('a', 'e', 'f').with_initial('b') }
|
340
|
+
it { should deny(' ').with_initial('b') }
|
341
|
+
it { should deny(nil).with_initial('b') }
|
342
|
+
|
343
|
+
with_option :allow_blank => true do
|
344
|
+
it { should allow(' ') }
|
345
|
+
end
|
346
|
+
|
347
|
+
with_option :allow_nil => true do
|
348
|
+
it { should allow(nil) }
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
#single string value
|
353
|
+
with_options :in => 'b' do
|
354
|
+
it { should allow('b') }
|
355
|
+
it { should deny('a', 'c').with_initial('b') }
|
356
|
+
it { should deny(' ').with_initial('b') }
|
357
|
+
it { should deny(nil).with_initial('b') }
|
358
|
+
|
359
|
+
with_option :allow_blank => true do
|
360
|
+
it { should allow(' ') }
|
361
|
+
end
|
362
|
+
|
363
|
+
with_option :allow_nil => true do
|
364
|
+
it { should allow(nil) }
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
#array
|
369
|
+
with_options :in => ['b', 'e'] do
|
370
|
+
it { should allow('b', 'e') }
|
371
|
+
it { should deny('a', 'c', 'f').with_initial('b') }
|
372
|
+
it { should deny(' ').with_initial('b') }
|
373
|
+
it { should deny(nil).with_initial('b') }
|
374
|
+
|
375
|
+
with_option :allow_blank => true do
|
376
|
+
it { should allow(' ') }
|
377
|
+
end
|
378
|
+
|
379
|
+
with_option :allow_nil => true do
|
380
|
+
it { should allow(nil) }
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
with_options :in => 'b' do
|
385
|
+
it { should allow('b') }
|
386
|
+
|
387
|
+
with_option :message => "Some error message" do
|
388
|
+
it { should deny('c').with_initial('b').with_message(/Some error message/) }
|
389
|
+
end
|
390
|
+
|
391
|
+
it { should deny(' ').with_initial('b') }
|
392
|
+
|
393
|
+
with_option :allow_blank => true do
|
394
|
+
it { should allow(' ') }
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
with_validator :exclusion do
|
401
|
+
with_option :as => :trigger do
|
402
|
+
#closed string interval
|
403
|
+
with_options :in => 'b'..'e' do
|
404
|
+
it { should allow('a', 'f') }
|
405
|
+
it { should deny('b', 'd', 'e').with_initial('a') }
|
406
|
+
it { should allow(nil) }
|
407
|
+
end
|
408
|
+
|
409
|
+
#open string interval
|
410
|
+
with_options :in => 'b'...'e' do
|
411
|
+
it { should deny('b', 'd').with_initial('a') }
|
412
|
+
it { should allow('a', 'e', 'f') }
|
413
|
+
it { should allow(nil) }
|
414
|
+
end
|
415
|
+
|
416
|
+
#single string value
|
417
|
+
with_options :in => 'b' do
|
418
|
+
it { should deny('b').with_initial('a') }
|
419
|
+
it { should allow('a', 'c') }
|
420
|
+
it { should allow(nil) }
|
421
|
+
end
|
422
|
+
|
423
|
+
#array
|
424
|
+
with_options :in => ['b', 'e', ' '] do
|
425
|
+
it { should deny('b', 'e').with_initial('a') }
|
426
|
+
it { should allow('a', 'c', 'f') }
|
427
|
+
it { should deny(' ').with_initial('a') }
|
428
|
+
it { should allow(nil) }
|
429
|
+
|
430
|
+
with_option :allow_blank => true do
|
431
|
+
it { should allow(' ') }
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
with_options :in => 'b', :message => "Some error message" do
|
436
|
+
it { should deny('b').with_initial('a').with_message(/Some error message/) }
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
with_validator :length do
|
442
|
+
with_option :as => :trigger do
|
443
|
+
with_option :is => 5 do
|
444
|
+
it {should allow('12345') }
|
445
|
+
it {should deny('1234', '123456').with_initial('12345') }
|
446
|
+
|
447
|
+
with_option :message => "Some error message" do
|
448
|
+
it {should deny('123456').with_initial('12345').with_message("Some error message") }
|
449
|
+
|
450
|
+
with_option :wrong_length => "Some specific error message" do
|
451
|
+
it {should deny('123456').with_initial('12345').with_message("Some specific error message") }
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
with_option :on => :create do
|
456
|
+
it {should deny.insert('1234', '123456') }
|
457
|
+
it {should allow.update('1234', '123456').with_initial('12345') }
|
458
|
+
end
|
459
|
+
|
460
|
+
with_option :on => :update do
|
461
|
+
it {should allow.insert('1234', '123456') }
|
462
|
+
it {should deny.update('1234', '123456').with_initial('12345') }
|
463
|
+
end
|
464
|
+
|
465
|
+
it {should deny(' ', nil).with_initial('12345') }
|
466
|
+
|
467
|
+
with_option :allow_blank => true do
|
468
|
+
it { should allow.insert(' ') }
|
469
|
+
end
|
470
|
+
|
471
|
+
with_option :allow_nil => true do
|
472
|
+
it { should allow.insert(nil) }
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
with_option :is => 0 do
|
477
|
+
it { should allow(nil) }
|
478
|
+
end
|
479
|
+
|
480
|
+
|
481
|
+
with_option :maximum => 5 do
|
482
|
+
it {should allow('1234', '12345') }
|
483
|
+
it {should deny('123456').with_initial('12345') }
|
484
|
+
|
485
|
+
with_option :message => "Some error message" do
|
486
|
+
it {should deny('123456').with_initial('12345').with_message("Some error message") }
|
487
|
+
|
488
|
+
with_option :too_long => "Some specific error message" do
|
489
|
+
it {should deny('123456').with_initial('12345').with_message("Some specific error message") }
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
it { should allow(' ', nil) }
|
494
|
+
end
|
495
|
+
|
496
|
+
with_option :minimum => 5 do
|
497
|
+
it {should allow('12345', '123456') }
|
498
|
+
it {should deny('1234').with_initial('12345') }
|
499
|
+
|
500
|
+
with_option :message => "Some error message" do
|
501
|
+
it {should deny('1234').with_initial('12345').with_message("Some error message") }
|
502
|
+
|
503
|
+
with_option :too_short => "Some specific error message" do
|
504
|
+
it {should deny('1234').with_initial('12345').with_message("Some specific error message") }
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
it {should deny(' ', nil).with_initial('12345') }
|
509
|
+
|
510
|
+
with_option :allow_blank => true do
|
511
|
+
it { should allow.insert(' ') }
|
512
|
+
end
|
513
|
+
|
514
|
+
with_option :allow_nil => true do
|
515
|
+
it { should allow.insert(nil) }
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
with_option :minimum => 0 do
|
520
|
+
it { should allow(' ', nil) }
|
521
|
+
end
|
522
|
+
|
523
|
+
with_option :in => 2..5 do
|
524
|
+
it {should allow('12', '123', '12345') }
|
525
|
+
it {should deny('1', '123456').with_initial('12') }
|
526
|
+
|
527
|
+
with_option :message => "Some error message" do
|
528
|
+
it {should deny('1').with_initial('12').with_message("Some error message") }
|
529
|
+
end
|
530
|
+
|
531
|
+
it {should deny(' ', nil).with_initial('12') }
|
532
|
+
|
533
|
+
with_option :allow_blank => true do
|
534
|
+
it { should allow.insert(' ') }
|
535
|
+
end
|
536
|
+
|
537
|
+
with_option :allow_nil => true do
|
538
|
+
it { should allow.insert(nil) }
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
with_option :in => 0..1 do
|
543
|
+
it { should allow(' ', nil) }
|
544
|
+
end
|
545
|
+
|
546
|
+
with_option :in => 2...5 do
|
547
|
+
it {should allow('12', '123') }
|
548
|
+
it {should deny('1', '12345', '123456').with_initial('12') }
|
549
|
+
|
550
|
+
with_option :message => "Some error message" do
|
551
|
+
it {should deny('1').with_initial('12').with_message("Some error message") }
|
552
|
+
end
|
553
|
+
|
554
|
+
it {should deny(' ', nil).with_initial('12') }
|
555
|
+
|
556
|
+
with_option :allow_blank => true do
|
557
|
+
it { should allow.insert(' ') }
|
558
|
+
end
|
559
|
+
|
560
|
+
with_option :allow_nil => true do
|
561
|
+
it { should allow.insert(nil) }
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
with_option :in => 0...2 do
|
566
|
+
it { should allow(' ', nil) }
|
567
|
+
end
|
568
|
+
|
569
|
+
with_option :in => [2, 3, 5] do
|
570
|
+
it {should allow('12', '123', '12345') }
|
571
|
+
it {should deny('1', '1234', '123456').with_initial('12') }
|
572
|
+
|
573
|
+
with_option :message => "Some error message" do
|
574
|
+
it {should deny('1').with_initial('12').with_message("Some error message") }
|
575
|
+
end
|
576
|
+
|
577
|
+
it {should deny(' ', nil).with_initial('12') }
|
578
|
+
|
579
|
+
with_option :allow_blank => true do
|
580
|
+
it { should allow.insert(' ') }
|
581
|
+
end
|
582
|
+
|
583
|
+
with_option :allow_nil => true do
|
584
|
+
it { should allow.insert(nil) }
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
with_option :in => [0, 1] do
|
589
|
+
it { should allow(' ', nil) }
|
590
|
+
end
|
591
|
+
|
592
|
+
with_option :in => 5 do
|
593
|
+
it {should allow('12345') }
|
594
|
+
it {should deny('1234', '123456').with_initial('12345') }
|
595
|
+
end
|
596
|
+
|
597
|
+
with_option :within => 2..5 do
|
598
|
+
it {should allow('12', '123', '12345') }
|
599
|
+
it {should deny('1', '123456').with_initial('12') }
|
600
|
+
|
601
|
+
with_option :message => "Some error message" do
|
602
|
+
it {should deny('1').with_initial('12').with_message("Some error message") }
|
603
|
+
end
|
604
|
+
|
605
|
+
it {should deny(' ', nil).with_initial('12') }
|
606
|
+
|
607
|
+
with_option :allow_blank => true do
|
608
|
+
it { should allow.insert(' ') }
|
609
|
+
end
|
610
|
+
|
611
|
+
with_option :allow_nil => true do
|
612
|
+
it { should allow.insert(nil) }
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
with_option :within => 0..1 do
|
617
|
+
it { should allow(' ', nil) }
|
618
|
+
end
|
619
|
+
|
620
|
+
with_option :within => 2...5 do
|
621
|
+
it {should allow('12', '123') }
|
622
|
+
it {should deny('1', '12345', '123456').with_initial('12') }
|
623
|
+
|
624
|
+
with_option :message => "Some error message" do
|
625
|
+
it {should deny('1').with_initial('12').with_message("Some error message") }
|
626
|
+
end
|
627
|
+
|
628
|
+
it {should deny(' ', nil).with_initial('12') }
|
629
|
+
|
630
|
+
with_option :allow_blank => true do
|
631
|
+
it { should allow.insert(' ') }
|
632
|
+
end
|
633
|
+
|
634
|
+
with_option :allow_nil => true do
|
635
|
+
it { should allow.insert(nil) }
|
636
|
+
end
|
637
|
+
end
|
638
|
+
|
639
|
+
with_option :within => 0...2 do
|
640
|
+
it { should allow(' ', nil) }
|
641
|
+
end
|
642
|
+
|
643
|
+
with_option :within => [2, 3, 5] do
|
644
|
+
it {should allow('12', '123', '12345') }
|
645
|
+
it {should deny('1', '1234', '123456').with_initial('12') }
|
646
|
+
|
647
|
+
with_option :message => "Some error message" do
|
648
|
+
it {should deny('1').with_initial('12').with_message("Some error message") }
|
649
|
+
end
|
650
|
+
|
651
|
+
it {should deny(' ', nil).with_initial('12') }
|
652
|
+
|
653
|
+
with_option :allow_blank => true do
|
654
|
+
it { should allow.insert(' ') }
|
655
|
+
end
|
656
|
+
|
657
|
+
with_option :allow_nil => true do
|
658
|
+
it { should allow.insert(nil) }
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
with_option :within => [0, 1] do
|
663
|
+
it { should allow(' ', nil) }
|
664
|
+
end
|
665
|
+
|
666
|
+
with_option :within => 5 do
|
667
|
+
it {should allow('12345') }
|
668
|
+
it {should deny('1234', '123456').with_initial('12345') }
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|
672
|
+
end
|
673
|
+
|
674
|
+
for_string_column :validates => {:uniqueness => {:as => :index}, :length => {:in => 4..9, :as => :trigger, :message => "Some error message"}} do
|
675
|
+
it { should deny.at_least_one('1234','1234').with_initial('1234', '12345').and_message(/is not unique/) }
|
676
|
+
it { should deny('123').with_initial('1234').and_message(/Some error message/) }
|
677
|
+
|
678
|
+
with_change :length => false do
|
679
|
+
it { should deny.at_least_one('1234','1234').with_initial('1234', '12345').and_message(/is not unique/) }
|
680
|
+
it { should allow('123') }
|
681
|
+
end
|
682
|
+
|
683
|
+
with_change :length => {:in => 4..9} do
|
684
|
+
with_change :length => false do
|
685
|
+
it { should allow('123') }
|
686
|
+
end
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
#date
|
691
|
+
for_date_column do
|
692
|
+
startDate = Date.today - 5
|
693
|
+
endDate = Date.today
|
694
|
+
|
695
|
+
with_validator :presense do
|
696
|
+
with_option :as => :trigger do
|
697
|
+
it { should allow(startDate) }
|
698
|
+
it { should deny(nil).with_initial(startDate) }
|
699
|
+
end
|
700
|
+
|
701
|
+
with_option :allow_blank => true do
|
702
|
+
it { should allow(nil) }
|
703
|
+
end
|
704
|
+
|
705
|
+
with_option :allow_nil => true do
|
706
|
+
it { should allow(nil) }
|
707
|
+
end
|
708
|
+
|
709
|
+
with_option :on => :update do
|
710
|
+
it { should allow.insert(nil) }
|
711
|
+
end
|
712
|
+
|
713
|
+
with_option :on => :create do
|
714
|
+
it { should allow.update(nil).with_initial(startDate) }
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
with_validator :inclusion do
|
719
|
+
with_option :as => :trigger do
|
720
|
+
|
721
|
+
#closed date interval
|
722
|
+
with_options :in => startDate..endDate do
|
723
|
+
it { should allow(startDate, endDate - 3, endDate) }
|
724
|
+
it { should deny(startDate - 1, endDate + 1).with_initial(endDate - 1) }
|
725
|
+
end
|
726
|
+
|
727
|
+
#open date interval
|
728
|
+
with_options :in => startDate...endDate do
|
729
|
+
it { should allow(startDate, endDate - 3) }
|
730
|
+
it { should deny(startDate - 1, endDate, endDate + 1).with_initial(endDate - 1) }
|
731
|
+
end
|
732
|
+
|
733
|
+
#single date value
|
734
|
+
with_options :in => endDate do
|
735
|
+
it { should allow(endDate) }
|
736
|
+
it { should deny(endDate - 1, endDate + 1).with_initial(endDate) }
|
737
|
+
end
|
738
|
+
|
739
|
+
#array
|
740
|
+
with_options :in => [startDate, endDate] do
|
741
|
+
it { should allow(startDate, endDate) }
|
742
|
+
it { should deny(startDate - 1, endDate - 1, endDate + 1).with_initial(endDate) }
|
743
|
+
end
|
744
|
+
|
745
|
+
with_options :in => endDate, :message => "Some error message" do
|
746
|
+
it { should deny(endDate + 1).with_initial(endDate).with_message(/Some error message/) }
|
747
|
+
end
|
748
|
+
end
|
749
|
+
end
|
750
|
+
|
751
|
+
with_validator :exclusion do
|
752
|
+
with_option :as => :trigger do
|
753
|
+
|
754
|
+
#closed date interval
|
755
|
+
with_options :in => startDate..endDate do
|
756
|
+
it { should deny(startDate, endDate - 3, endDate).with_initial(startDate - 1) }
|
757
|
+
it { should allow(startDate - 1, endDate + 1) }
|
758
|
+
end
|
759
|
+
|
760
|
+
#open date interval
|
761
|
+
with_options :in => startDate...endDate do
|
762
|
+
it { should deny(startDate, endDate - 3).with_initial(startDate - 1) }
|
763
|
+
it { should allow(startDate - 1, endDate, endDate + 1) }
|
764
|
+
end
|
765
|
+
|
766
|
+
#single date value
|
767
|
+
with_options :in => endDate do
|
768
|
+
it { should deny(endDate).with_initial(endDate - 1) }
|
769
|
+
it { should allow(endDate - 1, endDate + 1) }
|
770
|
+
end
|
771
|
+
|
772
|
+
#array
|
773
|
+
with_options :in => [startDate, endDate] do
|
774
|
+
it { should deny(startDate, endDate).with_initial(startDate - 1) }
|
775
|
+
it { should allow(startDate - 1, endDate - 1, endDate + 1) }
|
776
|
+
end
|
777
|
+
|
778
|
+
with_options :in => endDate, :message => "Some error message" do
|
779
|
+
it { should deny(endDate).with_initial(endDate - 1).with_message(/Some error message/) }
|
780
|
+
end
|
781
|
+
end
|
782
|
+
end
|
783
|
+
end
|
784
|
+
|
785
|
+
#time
|
786
|
+
for_time_column do
|
787
|
+
startTime = Time.now - 10
|
788
|
+
endTime = Time.now
|
789
|
+
|
790
|
+
with_validator :presense do
|
791
|
+
with_option :as => :trigger do
|
792
|
+
it { should allow(startTime) }
|
793
|
+
it { should deny(nil).with_initial(startTime) }
|
794
|
+
end
|
795
|
+
|
796
|
+
with_option :allow_blank => true do
|
797
|
+
it { should allow(nil) }
|
798
|
+
end
|
799
|
+
|
800
|
+
with_option :allow_nil => true do
|
801
|
+
it { should allow(nil) }
|
802
|
+
end
|
803
|
+
|
804
|
+
with_option :on => :update do
|
805
|
+
it { should allow.insert(nil) }
|
806
|
+
end
|
807
|
+
|
808
|
+
with_option :on => :create do
|
809
|
+
it { should allow.update(nil).with_initial(startTime) }
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
with_validator :inclusion do
|
814
|
+
with_option :as => :trigger do
|
815
|
+
|
816
|
+
#closed time interval
|
817
|
+
with_options :in => startTime..endTime do
|
818
|
+
it { should allow(startTime, startTime + 1, endTime) }
|
819
|
+
it { should deny(startTime - 1, endTime + 1).with_initial(startTime) }
|
820
|
+
end
|
821
|
+
|
822
|
+
#open time interval
|
823
|
+
with_options :in => startTime...endTime do
|
824
|
+
it { should allow(startTime, startTime + 1, endTime - 1) }
|
825
|
+
it { should deny(startTime - 1, endTime).with_initial(startTime) }
|
826
|
+
end
|
827
|
+
|
828
|
+
#single time value
|
829
|
+
with_options :in => startTime do
|
830
|
+
it { should allow(startTime) }
|
831
|
+
it { should deny(startTime - 1, endTime).with_initial(startTime) }
|
832
|
+
end
|
833
|
+
|
834
|
+
#array
|
835
|
+
with_options :in => [startTime, endTime] do
|
836
|
+
it { should allow(startTime, endTime) }
|
837
|
+
it { should deny(startTime - 1, startTime + 1, endTime + 1).with_initial(startTime) }
|
838
|
+
end
|
839
|
+
|
840
|
+
with_options :in => startTime, :message => "Some error message" do
|
841
|
+
it { should deny(startTime + 1).with_initial(startTime).with_message(/Some error message/) }
|
842
|
+
end
|
843
|
+
end
|
844
|
+
end
|
845
|
+
|
846
|
+
with_validator :exclusion do
|
847
|
+
with_option :as => :trigger do
|
848
|
+
|
849
|
+
#closed time interval
|
850
|
+
with_options :in => startTime..endTime do
|
851
|
+
it { should deny(startTime, startTime + 1, endTime).with_initial(startTime - 1) }
|
852
|
+
it { should allow(startTime - 1, endTime + 1) }
|
853
|
+
end
|
854
|
+
|
855
|
+
#open time interval
|
856
|
+
with_options :in => startTime...endTime do
|
857
|
+
it { should deny(startTime, startTime + 1, endTime - 1).with_initial(startTime - 1) }
|
858
|
+
it { should allow(startTime - 1, endTime) }
|
859
|
+
end
|
860
|
+
|
861
|
+
#single time value
|
862
|
+
with_options :in => startTime do
|
863
|
+
it { should deny(startTime).with_initial(startTime - 1) }
|
864
|
+
it { should allow(startTime - 1, endTime) }
|
865
|
+
end
|
866
|
+
|
867
|
+
#array
|
868
|
+
with_options :in => [startTime, endTime] do
|
869
|
+
it { should deny(startTime, endTime).with_initial(startTime - 1) }
|
870
|
+
it { should allow(startTime - 1, startTime + 1, endTime + 1)}
|
871
|
+
end
|
872
|
+
|
873
|
+
with_options :in => startTime, :message => "Some error message" do
|
874
|
+
it { should deny(startTime).with_initial(startTime - 1).with_message(/Some error message/) }
|
875
|
+
end
|
876
|
+
end
|
877
|
+
end
|
878
|
+
end
|
879
|
+
|
880
|
+
#datetime
|
881
|
+
for_time_column do
|
882
|
+
startDateTime = DateTime.now - 10
|
883
|
+
endDateTime = DateTime.now
|
884
|
+
|
885
|
+
with_validator :presense do
|
886
|
+
with_option :as => :trigger do
|
887
|
+
it { should allow(startDateTime) }
|
888
|
+
it { should deny(nil).with_initial(startDateTime) }
|
889
|
+
end
|
890
|
+
|
891
|
+
with_option :allow_blank => true do
|
892
|
+
it { should allow(nil) }
|
893
|
+
end
|
894
|
+
|
895
|
+
with_option :allow_nil => true do
|
896
|
+
it { should allow(nil) }
|
897
|
+
end
|
898
|
+
|
899
|
+
with_option :on => :update do
|
900
|
+
it { should allow.insert(nil) }
|
901
|
+
end
|
902
|
+
|
903
|
+
with_option :on => :create do
|
904
|
+
it { should allow.update(nil).with_initial(startDateTime) }
|
905
|
+
end
|
906
|
+
end
|
907
|
+
|
908
|
+
with_validator :inclusion do
|
909
|
+
with_option :as => :trigger do
|
910
|
+
|
911
|
+
#closed time interval
|
912
|
+
with_options :in => startDateTime..endDateTime do
|
913
|
+
it { should allow(startDateTime, startDateTime + 1, endDateTime) }
|
914
|
+
it { should deny(startDateTime - 1, endDateTime + 1).with_initial(startDateTime) }
|
915
|
+
end
|
916
|
+
|
917
|
+
#open time interval
|
918
|
+
with_options :in => startDateTime...endDateTime do
|
919
|
+
it { should allow(startDateTime, startDateTime + 1, endDateTime - 1) }
|
920
|
+
it { should deny(startDateTime - 1, endDateTime).with_initial(startDateTime) }
|
921
|
+
end
|
922
|
+
|
923
|
+
#single time value
|
924
|
+
with_options :in => startDateTime do
|
925
|
+
it { should allow(startDateTime) }
|
926
|
+
it { should deny(startDateTime - 1, endDateTime).with_initial(startDateTime) }
|
927
|
+
end
|
928
|
+
|
929
|
+
#array
|
930
|
+
with_options :in => [startDateTime, endDateTime] do
|
931
|
+
it { should allow(startDateTime, endDateTime) }
|
932
|
+
it { should deny(startDateTime - 1, startDateTime + 1, endDateTime + 1).with_initial(startDateTime) }
|
933
|
+
end
|
934
|
+
|
935
|
+
with_options :in => startDateTime, :message => "Some error message" do
|
936
|
+
it { should deny(startDateTime + 1).with_initial(startDateTime).with_message(/Some error message/) }
|
937
|
+
end
|
938
|
+
end
|
939
|
+
end
|
940
|
+
|
941
|
+
with_validator :exclusion do
|
942
|
+
with_option :as => :trigger do
|
943
|
+
|
944
|
+
#closed time interval
|
945
|
+
with_options :in => startDateTime..endDateTime do
|
946
|
+
it { should deny(startDateTime, startDateTime + 1, endDateTime).with_initial(startDateTime - 1) }
|
947
|
+
it { should allow(startDateTime - 1, endDateTime + 1) }
|
948
|
+
end
|
949
|
+
|
950
|
+
#open time interval
|
951
|
+
with_options :in => startDateTime...endDateTime do
|
952
|
+
it { should deny(startDateTime, startDateTime + 1, endDateTime - 1).with_initial(startDateTime - 1) }
|
953
|
+
it { should allow(startDateTime - 1, endDateTime) }
|
954
|
+
end
|
955
|
+
|
956
|
+
#single time value
|
957
|
+
with_options :in => startDateTime do
|
958
|
+
it { should deny(startDateTime).with_initial(startDateTime - 1) }
|
959
|
+
it { should allow(startDateTime - 1, endDateTime) }
|
960
|
+
end
|
961
|
+
|
962
|
+
#array
|
963
|
+
with_options :in => [startDateTime, endDateTime] do
|
964
|
+
it { should deny(startDateTime, endDateTime).with_initial(startDateTime - 1) }
|
965
|
+
it { should allow(startDateTime - 1, startDateTime + 1, endDateTime + 1) }
|
966
|
+
end
|
967
|
+
|
968
|
+
with_options :in => startDateTime, :message => "Some error message" do
|
969
|
+
it { should deny(startDateTime).with_initial(startDateTime - 1).with_message(/Some error message/) }
|
970
|
+
end
|
971
|
+
end
|
972
|
+
end
|
973
|
+
end
|
974
|
+
end
|
975
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'mv-test'
|
5
|
+
require 'mv-sqlite'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'factory_girl'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mv-sqlite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Valeriy Prokopchuk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-22 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: sqlite3
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mv-core
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.5.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rcov
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
description: Migration Validators project sqlite driver
|
72
|
+
email: vprokopchuk@gmail.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files:
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.rdoc
|
80
|
+
files:
|
81
|
+
- lib/migration_validators/adapters/sqlite.rb
|
82
|
+
- lib/mv-sqlite.rb
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.rdoc
|
85
|
+
- spec/migration_validators/adapters/sqlite_spec.rb
|
86
|
+
- spec/mv-sqlite_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://github.com/vprokochuk256/mv-sqlite
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 4005801410759672602
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.6.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Migration Validators project sqlite driver
|
119
|
+
test_files:
|
120
|
+
- spec/migration_validators/adapters/sqlite_spec.rb
|
121
|
+
- spec/mv-sqlite_spec.rb
|
122
|
+
- spec/spec_helper.rb
|