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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5d849122ca6f0e6f08d91e2cb391407fc7fc227
4
- data.tar.gz: f8645f3bc0d1fcb7da740dc1e2f28e86570f0b01
3
+ metadata.gz: f722b7a85eff3f3def8a6355153476f9801da846
4
+ data.tar.gz: 1e6eb1107162cd7eb637473d59ebd1d4de2ec33e
5
5
  SHA512:
6
- metadata.gz: 09ac9381a024e6a9f82ffe2e619217d5eb0c13dce2c83cedb5feb001faccf6ad65c7cd2d51a5291d20e969aad15adcadb4e880ebb6e55054291748b7cb30bdc1
7
- data.tar.gz: d6359451dc9673a2cff5fdd768a0c5e42fe6df3acecf20412c769070f052d70da2f748b583363f1c7a0c5cb656b5884cf1848ab75ed41bf0efd19e025cf98084
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.5
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.5** with activerecord **4.2**, using **mysql2**, **postgresql** or **sqlite3**
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)
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "activerecord", "~> 5.0.0"
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -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.number? then :numeric
103
- when column.text? then :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
- options = { :allow_nil => true, :only_integer => true }
137
-
138
- if range = column.cast_type.try(:range)
139
- options[:greater_than_or_equal_to] = range.begin
140
- if range.exclude_end?
141
- options[:less_than] = range.end
142
- else
143
- options[:less_than_or_equal_to] = range.end
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
@@ -1,3 +1,3 @@
1
1
  module SchemaValidations
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
data/schema_dev.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  ruby:
2
- - 2.1.5
2
+ - 2.3.1
3
3
  activerecord:
4
4
  - 4.2
5
+ - 5.0
5
6
  db:
6
7
  - mysql2
7
8
  - postgresql
@@ -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", "~> 4.2", ">= 4.2.1")
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
@@ -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.1.1
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-04-06 00:00:00.000000000 Z
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.2.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.