schema_validations 1.0.1 → 1.1.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: cf56fe0be502dcf9f95a0f67c2a8b03a8c51040e
4
- data.tar.gz: add46e41c04f6a0beb6ab4281ba0c5b6d28560be
3
+ metadata.gz: a393a0d55876bd8f8e7564c4697d49e39192a253
4
+ data.tar.gz: da40a15493d7ee658427ad9b8fa84d55b18cf1c5
5
5
  SHA512:
6
- metadata.gz: 0759bedcb1a79fb0005837fd6554d946ce8125ad2eee50bbb000b74775213bb3fe943ef2cfeb26fce60a29315d29b8c68b92661e7cc94c05ec5a6393e46baaf8
7
- data.tar.gz: 61cd1032954a0b865b916884a44dcdbb88f04129bbde467b311506b802a0ee1feb9aa895ca33122bae07c50f3273b2c1ccce3529d681db3e14c760b4ad16573b
6
+ metadata.gz: 46e9332822a7060a8815c85607a5879299b69626ceffa5cf5702d28272557f62341ae0e6af197841bbf398e985c8726d0eac7d5a7645adeaf75658d7d28e5644
7
+ data.tar.gz: ff590cab2b092c7cc5cdfb75bfe0a5acfc5235a6e8ef787a807550cc1b1fb2072d804447bedbe67df08cd2c2005ba316e18278fa0e8d8adc7a2dbc83fbc9c974
data/.gitignore CHANGED
@@ -21,7 +21,7 @@ pkg
21
21
  ## PROJECT::SPECIFIC
22
22
  .rvmrc
23
23
  *.log
24
- *.sqlite3
24
+ tmp/
25
25
  Gemfile.lock
26
26
  gemfiles/*.lock
27
27
  gemfiles/**/*.lock
data/.travis.yml CHANGED
@@ -3,9 +3,12 @@
3
3
  # Please do not edit this file; any changes will be overwritten next time
4
4
  # schema_dev gets run.
5
5
  ---
6
+ sudo: false
6
7
  rvm:
7
8
  - 1.9.3
8
- - 2.1.3
9
+ - 2.1.5
9
10
  gemfile:
10
11
  - gemfiles/rails-3.2/Gemfile.sqlite3
11
12
  - gemfiles/rails-4.1/Gemfile.sqlite3
13
+ - gemfiles/rails-4.2/Gemfile.sqlite3
14
+ script: bundle exec rake travis
data/README.md CHANGED
@@ -4,9 +4,11 @@ SchemaValidations is an ActiveRecord extension that keeps your model class
4
4
  definitions simpler and more DRY, by automatically defining validations based
5
5
  on the database schema.
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/schema_validations.png)](http://badge.fury.io/rb/schema_validations)
8
- [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_validations.png)](http://travis-ci.org/SchemaPlus/schema_validations)
9
- [![Dependency Status](https://gemnasium.com/SchemaPlus/schema_validations.png)](https://gemnasium.com/SchemaPlus/schema_validations)
7
+ [![Gem Version](https://badge.fury.io/rb/schema_validations.svg)](http://badge.fury.io/rb/schema_validations)
8
+ [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_validations.svg)](http://travis-ci.org/SchemaPlus/schema_validations)
9
+ [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_validations.svg)](https://coveralls.io/r/SchemaPlus/schema_validations)
10
+ [![Dependency Status](https://gemnasium.com/lomba/schema_validations.svg)](https://gemnasium.com/lomba/schema_validations)
11
+
10
12
 
11
13
  ## Overview
12
14
 
@@ -41,11 +43,19 @@ installing it your model is as simple as it can be.
41
43
  Validations are there but they are created by schema_validations under the
42
44
  hood.
43
45
 
46
+ ## Compatibility
47
+
48
+ SchemaValidations is tested on all combinations of:
49
+
50
+ * rails 3.2, 4.1, and 4.2
51
+ * MRI ruby 1.9.3 and 2.1.5)'s
52
+ config.
53
+
44
54
  ## Installation
45
55
 
46
56
  Simply add schema_validations to your Gemfile.
47
57
 
48
- gem "schema_validations"
58
+ gem "schema_validations"
49
59
 
50
60
  ### What if I want something special?
51
61
 
@@ -100,15 +110,9 @@ Data types:
100
110
  SchemaValidations uses the [schema_plus](http://rubygems.org/gems/schema_plus)
101
111
  gem for its schema queries. That gem will by default auto-create foreign key
102
112
  constraints that you probably want -- but if you don't want them, you can
103
- disable them using [schema_plus](http://rubygems.org/gems/schema_plus)'s
104
- config.
105
-
106
- ## Compatibility
113
+ disable them using [schema_plus](http://rubygems.org/gems/schema_plus
107
114
 
108
- SchemaValidations is tested on all combinations of:
109
115
 
110
- * rails 3.2 or 4.1
111
- * MRI ruby 1.9.3 and 2.1.3
112
116
 
113
117
  ## How do I know what it did?
114
118
  If you're curious (or dubious) about what validations SchemaValidations
@@ -129,9 +133,13 @@ use case.
129
133
 
130
134
  ## Release Notes
131
135
 
136
+ ### 1.1.0
137
+
138
+ * Works with Rails 4.2.
139
+
132
140
  ### 1.0.1
133
141
 
134
- * Fix enums in Rails 4.1. [@lowjoel](https://github.com/lowjoel)
142
+ * Fix enums in Rails 4.1. Thanks to [@lowjoel](https://github.com/lowjoel)
135
143
 
136
144
  ### 1.0.0
137
145
 
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec :path => File.expand_path('..', __FILE__)
3
3
 
4
- gem "byebug" if RUBY_VERSION > "2"
4
+ platform :ruby do
5
+ gem "byebug" if RUBY_VERSION > "2"
6
+ 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
@@ -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
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "rails", "~> 4.2.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 "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -96,17 +96,27 @@ module SchemaValidations
96
96
  name = column.name.to_sym
97
97
 
98
98
  # Data-type validation
99
- if column.type == :integer
100
- load_integer_column_validations(name, column)
101
- elsif column.number?
102
- load_numeric_column_validations(name, column)
103
- elsif column.text? && column.limit
104
- load_string_column_validations(name, column)
99
+ datatype = case
100
+ when respond_to?(:defined_enums) && defined_enums.has_key?(column.name) then :enum
101
+ when column.type == :integer then :integer
102
+ when column.number? then :numeric
103
+ when column.respond_to?(:text?) && column.text? then :text
104
+ when [:string, :text].include?(column.type) then :text
105
+ when column.type == :boolean then :boolean
106
+ end
107
+
108
+ case datatype
109
+ when :integer
110
+ validate_logged :validates_numericality_of, name, :allow_nil => true, :only_integer => true
111
+ when :numeric
112
+ validate_logged :validates_numericality_of, name, :allow_nil => true
113
+ when :text
114
+ validate_logged :validates_length_of, name, :allow_nil => true, :maximum => column.limit if column.limit
105
115
  end
106
116
 
107
117
  # NOT NULL constraints
108
118
  if column.required_on
109
- if column.type == :boolean
119
+ if datatype == :boolean
110
120
  validate_logged :validates_inclusion_of, name, :in => [true, false], :message => :blank
111
121
  else
112
122
  validate_logged :validates_presence_of, name
@@ -118,21 +128,6 @@ module SchemaValidations
118
128
  end
119
129
  end
120
130
 
121
- def load_integer_column_validations(name, column)
122
- is_enum_column = respond_to?(:defined_enums) && defined_enums.has_key?(column.name)
123
- unless is_enum_column
124
- validate_logged :validates_numericality_of, name, :allow_nil => true, :only_integer => true
125
- end
126
- end
127
-
128
- def load_numeric_column_validations(name, _)
129
- validate_logged :validates_numericality_of, name, :allow_nil => true
130
- end
131
-
132
- def load_string_column_validations(name, column)
133
- validate_logged :validates_length_of, name, :allow_nil => true, :maximum => column.limit
134
- end
135
-
136
131
  def load_association_validations #:nodoc:
137
132
  reflect_on_all_associations(:belongs_to).each do |association|
138
133
  # :primary_key_name was deprecated (noisily) in rails 3.1
@@ -1,3 +1,3 @@
1
1
  module SchemaValidations
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/schema_dev.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  ruby:
2
2
  - 1.9.3
3
- - 2.1.3
3
+ - 2.1.5
4
4
  rails:
5
5
  - 3.2
6
6
  - 4.1
7
+ - 4.2
7
8
  db: sqlite3
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency("schema_plus")
24
24
 
25
- s.add_development_dependency("schema_dev", "~> 1.0")
25
+ s.add_development_dependency("schema_dev", "~> 1.2")
26
26
  s.add_development_dependency("rake")
27
27
  s.add_development_dependency("rdoc")
28
28
  s.add_development_dependency("rspec")
Binary file
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: 1.0.1
4
+ version: 1.1.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: 2014-12-10 00:00:00.000000000 Z
12
+ date: 2015-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: schema_plus
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.0'
34
+ version: '1.2'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.0'
41
+ version: '1.2'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +142,11 @@ files:
142
142
  - Rakefile
143
143
  - gemfiles/Gemfile.base
144
144
  - gemfiles/rails-3.2/Gemfile.base
145
+ - gemfiles/rails-3.2/Gemfile.sqlite3
145
146
  - gemfiles/rails-4.1/Gemfile.base
147
+ - gemfiles/rails-4.1/Gemfile.sqlite3
148
+ - gemfiles/rails-4.2/Gemfile.base
149
+ - gemfiles/rails-4.2/Gemfile.sqlite3
146
150
  - init.rb
147
151
  - lib/schema_validations.rb
148
152
  - lib/schema_validations/active_record/validations.rb
@@ -150,6 +154,7 @@ files:
150
154
  - lib/schema_validations/version.rb
151
155
  - schema_dev.yml
152
156
  - schema_validations.gemspec
157
+ - spec/schema_validations.sqlite3
153
158
  - spec/spec_helper.rb
154
159
  - spec/support/active_model.rb
155
160
  - spec/validations_spec.rb
@@ -178,6 +183,7 @@ signing_key:
178
183
  specification_version: 4
179
184
  summary: Automatically creates validations basing on the database schema.
180
185
  test_files:
186
+ - spec/schema_validations.sqlite3
181
187
  - spec/spec_helper.rb
182
188
  - spec/support/active_model.rb
183
189
  - spec/validations_spec.rb