schema_validations 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/README.md +8 -1
- data/gemfiles/activerecord-5.0/Gemfile.base +3 -0
- data/gemfiles/activerecord-5.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-5.0/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-5.0/Gemfile.sqlite3 +10 -0
- data/lib/schema_validations/active_record/validations.rb +13 -13
- data/lib/schema_validations/version.rb +1 -1
- data/schema_dev.yml +2 -1
- data/schema_validations.gemspec +2 -2
- data/spec/spec_helper.rb +9 -0
- data/spec/validations_spec.rb +8 -2
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f722b7a85eff3f3def8a6355153476f9801da846
|
4
|
+
data.tar.gz: 1e6eb1107162cd7eb637473d59ebd1d4de2ec33e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5dfa087e36e5a81ac6f3e38fa6912db50e43785bb0d6c46959d1c48dc1a208cf6108d5eabab8c255a159ca65ed5de5994f6519f039dcca155e3548ad7963534
|
7
|
+
data.tar.gz: 102c7dda2cc81cb0c0dbbc0e5518ee6c14368b365ce34c0181c69405b7521964b764a978b2e3ca598446894d3ee54a01bd8cbfaff3e420a6974c2351db12733a
|
data/.travis.yml
CHANGED
@@ -5,11 +5,14 @@
|
|
5
5
|
---
|
6
6
|
sudo: false
|
7
7
|
rvm:
|
8
|
-
- 2.1
|
8
|
+
- 2.3.1
|
9
9
|
gemfile:
|
10
10
|
- gemfiles/activerecord-4.2/Gemfile.mysql2
|
11
11
|
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
12
12
|
- gemfiles/activerecord-4.2/Gemfile.sqlite3
|
13
|
+
- gemfiles/activerecord-5.0/Gemfile.mysql2
|
14
|
+
- gemfiles/activerecord-5.0/Gemfile.postgresql
|
15
|
+
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
13
16
|
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
|
14
17
|
addons:
|
15
18
|
postgresql: '9.4'
|
data/README.md
CHANGED
@@ -174,7 +174,8 @@ As of version 1.2.0, SchemaValidations supports and is tested on:
|
|
174
174
|
|
175
175
|
<!-- SCHEMA_DEV: MATRIX - begin -->
|
176
176
|
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
177
|
-
* ruby **2.1
|
177
|
+
* ruby **2.3.1** with activerecord **4.2**, using **mysql2**, **postgresql** or **sqlite3**
|
178
|
+
* ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **postgresql** or **sqlite3**
|
178
179
|
|
179
180
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
180
181
|
|
@@ -186,6 +187,12 @@ Earlier versions of SchemaValidations supported:
|
|
186
187
|
|
187
188
|
## Release Notes
|
188
189
|
|
190
|
+
### 2.2.0
|
191
|
+
|
192
|
+
* Works with AR 5.0. Thanks to [@plicjo](https://github.coms/plicjo).
|
193
|
+
* Works with `:money` type
|
194
|
+
* Bug fix when logger is nil. Thanks to [@gamecreature](https://github.com/gamecreature).
|
195
|
+
|
189
196
|
### 2.1.1
|
190
197
|
|
191
198
|
* Bug fix for `:decimal` when `precision` is nil (#37)
|
@@ -98,9 +98,9 @@ module SchemaValidations
|
|
98
98
|
datatype = case
|
99
99
|
when respond_to?(:defined_enums) && defined_enums.has_key?(column.name) then :enum
|
100
100
|
when column.type == :integer then :integer
|
101
|
-
when column.type == :decimal then :decimal
|
102
|
-
when column.
|
103
|
-
when column.text
|
101
|
+
when column.type == :decimal || column.type == :money then :decimal
|
102
|
+
when column.type == :float then :numeric
|
103
|
+
when column.type == :text || column.type == :string then :text
|
104
104
|
when column.type == :boolean then :boolean
|
105
105
|
end
|
106
106
|
|
@@ -133,15 +133,15 @@ module SchemaValidations
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def load_integer_column_validations(name, column) # :nodoc:
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
136
|
+
integer_range = ::ActiveRecord::Type::Integer.new.range
|
137
|
+
# The Ruby Range object does not support excluding the beginning of a Range,
|
138
|
+
# so we always include :greater_than_or_equal_to
|
139
|
+
options = { :allow_nil => true, :only_integer => true, greater_than_or_equal_to: integer_range.begin }
|
140
|
+
|
141
|
+
if integer_range.exclude_end?
|
142
|
+
options[:less_than] = integer_range.end
|
143
|
+
else
|
144
|
+
options[:less_than_or_equal_to] = integer_range.end
|
145
145
|
end
|
146
146
|
|
147
147
|
validate_logged :validates_numericality_of, name, options
|
@@ -196,7 +196,7 @@ module SchemaValidations
|
|
196
196
|
if _filter_validation(method, arg)
|
197
197
|
msg = "[schema_validations] #{self.name}.#{method} #{arg.inspect}"
|
198
198
|
msg += ", #{opts.inspect[1...-1]}" if opts.any?
|
199
|
-
logger.debug msg
|
199
|
+
logger.debug msg if logger
|
200
200
|
send method, arg, opts
|
201
201
|
end
|
202
202
|
end
|
data/schema_dev.yml
CHANGED
data/schema_validations.gemspec
CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
23
|
s.add_dependency("schema_plus_columns")
|
24
|
-
s.add_dependency("activerecord", "
|
24
|
+
s.add_dependency("activerecord", ">= 4.2.1", "< 5.1")
|
25
25
|
s.add_dependency("valuable")
|
26
|
-
|
26
|
+
|
27
27
|
s.add_development_dependency("schema_dev", "~> 3.6")
|
28
28
|
s.add_development_dependency("rake")
|
29
29
|
s.add_development_dependency("rdoc")
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,15 @@ RSpec.configure do |config|
|
|
18
18
|
config.around(:each) do |example|
|
19
19
|
DatabaseCleaner.clean
|
20
20
|
remove_all_models
|
21
|
+
|
22
|
+
class ActiveRecord::InternalMetadata
|
23
|
+
def self.create_table
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.[]=(first, second)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
21
30
|
ActiveRecord::Migration.suppress_messages do
|
22
31
|
example.run
|
23
32
|
end
|
data/spec/validations_spec.rb
CHANGED
@@ -97,19 +97,25 @@ describe "Validations" do
|
|
97
97
|
expect(Article.new(votes: -2147483649).error_on(:votes).size).to eq(1)
|
98
98
|
end
|
99
99
|
|
100
|
+
it "can include the end range" do
|
101
|
+
allow_any_instance_of(::ActiveRecord::Type::Integer).to receive(:range).and_return(-2147483648..2147483648)
|
102
|
+
|
103
|
+
expect(Article.new(votes: 2147483648).error_on(:votes).size).to eq(0)
|
104
|
+
end
|
105
|
+
|
100
106
|
it "should validate the range of decimal precision with scale" do
|
101
107
|
expect(Article.new(max10: 10).error_on(:max10).size).to eq(1)
|
102
108
|
expect(Article.new(max10: 5).error_on(:max10).size).to eq(0)
|
103
109
|
expect(Article.new(max10: -10).error_on(:max10).size).to eq(1)
|
104
110
|
end
|
105
|
-
|
111
|
+
|
106
112
|
it "should validate the range of decimal precision without scale" do
|
107
113
|
expect(Article.new(max100: 100).error_on(:max100).size).to eq(1)
|
108
114
|
expect(Article.new(max100: 50).error_on(:max100).size).to eq(0)
|
109
115
|
expect(Article.new(max100: -100).error_on(:max100).size).to eq(1)
|
110
116
|
end
|
111
117
|
|
112
|
-
it "should not validate the range of arbitrary decimal" do
|
118
|
+
it "should not validate the range of arbitrary decimal", :mysql => :skip do # mysql provides a default precision
|
113
119
|
expect(Article.new(arbitrary: Float::MAX).error_on(:arbitrary).size).to eq(0)
|
114
120
|
end
|
115
121
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus_columns
|
@@ -29,22 +29,22 @@ dependencies:
|
|
29
29
|
name: activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '4.2'
|
35
32
|
- - ">="
|
36
33
|
- !ruby/object:Gem::Version
|
37
34
|
version: 4.2.1
|
35
|
+
- - "<"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '5.1'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- - "~>"
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '4.2'
|
45
42
|
- - ">="
|
46
43
|
- !ruby/object:Gem::Version
|
47
44
|
version: 4.2.1
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.1'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: valuable
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +179,10 @@ files:
|
|
179
179
|
- gemfiles/activerecord-4.2/Gemfile.mysql2
|
180
180
|
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
181
181
|
- gemfiles/activerecord-4.2/Gemfile.sqlite3
|
182
|
+
- gemfiles/activerecord-5.0/Gemfile.base
|
183
|
+
- gemfiles/activerecord-5.0/Gemfile.mysql2
|
184
|
+
- gemfiles/activerecord-5.0/Gemfile.postgresql
|
185
|
+
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
182
186
|
- init.rb
|
183
187
|
- lib/schema_validations.rb
|
184
188
|
- lib/schema_validations/active_record/type.rb
|
@@ -211,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
215
|
version: '0'
|
212
216
|
requirements: []
|
213
217
|
rubyforge_project: schema_validations
|
214
|
-
rubygems_version: 2.
|
218
|
+
rubygems_version: 2.5.1
|
215
219
|
signing_key:
|
216
220
|
specification_version: 4
|
217
221
|
summary: Automatically creates validations basing on the database schema.
|