schema_validations 1.0.0 → 1.0.1

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: 68ad2ed2f5b40cf34fd23cac6eed63abdb045f01
4
- data.tar.gz: 11a19a7edc455c9ee42d66f735499daaf3c822e0
3
+ metadata.gz: cf56fe0be502dcf9f95a0f67c2a8b03a8c51040e
4
+ data.tar.gz: add46e41c04f6a0beb6ab4281ba0c5b6d28560be
5
5
  SHA512:
6
- metadata.gz: 5d2c1aed062ecb7b7b213c64aecefbf52adc7b9e895f8cd516dd83fadc4888322eebb49f572cac83fa3313069b98a46fa9e3290410cb52e1be12cc3b7a8f18da
7
- data.tar.gz: d82e9c923d391bd05ad32e8cb047ca2c8a122a2e49717b6643ee3b4f4cf92cc17b0431b325049ade8953206c0417e9273a00c8615bd1a2fbac9ca6b291dffb67
6
+ metadata.gz: 0759bedcb1a79fb0005837fd6554d946ce8125ad2eee50bbb000b74775213bb3fe943ef2cfeb26fce60a29315d29b8c68b92661e7cc94c05ec5a6393e46baaf8
7
+ data.tar.gz: 61cd1032954a0b865b916884a44dcdbb88f04129bbde467b311506b802a0ee1feb9aa895ca33122bae07c50f3273b2c1ccce3529d681db3e14c760b4ad16573b
data/.travis.yml CHANGED
@@ -1,10 +1,11 @@
1
+ # This file was auto-generated by the schema_dev tool, based on the data in
2
+ # ./schema_dev.yml
3
+ # Please do not edit this file; any changes will be overwritten next time
4
+ # schema_dev gets run.
5
+ ---
1
6
  rvm:
2
- - 1.9.3
3
- - 2.0.0
7
+ - 1.9.3
8
+ - 2.1.3
4
9
  gemfile:
5
- - gemfiles/Gemfile.rails-3.2
6
- - gemfiles/Gemfile.rails-4.0
7
- notifications:
8
- recipients:
9
- - michal.lomnicki@gmail.com
10
- - ronen@barzel.org
10
+ - gemfiles/rails-3.2/Gemfile.sqlite3
11
+ - gemfiles/rails-4.1/Gemfile.sqlite3
data/README.md CHANGED
@@ -5,8 +5,8 @@ definitions simpler and more DRY, by automatically defining validations based
5
5
  on the database schema.
6
6
 
7
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/lomba/schema_validations.png)](http://travis-ci.org/lomba/schema_validations)
9
- [![Dependency Status](https://gemnasium.com/lomba/schema_validations.png)](https://gemnasium.com/lomba/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)
10
10
 
11
11
  ## Overview
12
12
 
@@ -25,7 +25,7 @@ In that case :null => false, :limit => 30 and :boolean must be covered on the
25
25
  model level.
26
26
 
27
27
  class User < ActiveRecord::Base
28
- validates :email, :presence => true, :length => 30
28
+ validates :email, :presence => true, :length => { :maximum => 30 }
29
29
  validates :confirmed, :presence => true, :inclusion => { :in => [true, false] }
30
30
  end
31
31
 
@@ -81,19 +81,19 @@ You can also pass options as per above.
81
81
 
82
82
  Constraints:
83
83
 
84
- | Constraint | Validation |
85
- |---------------------|----------------------------------------------------------|
86
- | :null => false | validates ... :presence => true |
87
- | :limit => 100 | validates ... :length => { :maximum => 100 } |
88
- | :unique => true | validates ... :uniqueness => true |
84
+ | Constraint | Validation |
85
+ |---------------------|----------------------------------------------------------|
86
+ | :null => false | validates ... :presence => true |
87
+ | :limit => 100 | validates ... :length => { :maximum => 100 } |
88
+ | :unique => true | validates ... :uniqueness => true |
89
89
 
90
90
  Data types:
91
91
 
92
- | Type | Validation |
93
- |--------------------|-----------------------------------------------------------|
94
- | :boolean | :validates ... :inclusion => { :in => [true, false] } |
95
- | :float | :validates ... :numericality => true |
96
- | :integer | :validates ... :numericality => { :only_integer => true } |
92
+ | Type | Validation |
93
+ |--------------------|-----------------------------------------------------------|
94
+ | :boolean | :validates ... :inclusion => { :in => [true, false] } |
95
+ | :float | :validates ... :numericality => true |
96
+ | :integer | :validates ... :numericality => { :only_integer => true } |
97
97
 
98
98
  ## Dependency
99
99
 
@@ -105,11 +105,10 @@ config.
105
105
 
106
106
  ## Compatibility
107
107
 
108
- SchemaValidations supports all combinations of:
109
-
110
- * rails 3.2 or 4.0
111
- * MRI ruby 1.9.3 or 2.0.0
108
+ SchemaValidations is tested on all combinations of:
112
109
 
110
+ * rails 3.2 or 4.1
111
+ * MRI ruby 1.9.3 and 2.1.3
113
112
 
114
113
  ## How do I know what it did?
115
114
  If you're curious (or dubious) about what validations SchemaValidations
@@ -130,9 +129,13 @@ use case.
130
129
 
131
130
  ## Release Notes
132
131
 
132
+ ### 1.0.1
133
+
134
+ * Fix enums in Rails 4.1. [@lowjoel](https://github.com/lowjoel)
135
+
133
136
  ### 1.0.0
134
137
 
135
- * Works with Rails 4.0. Thanks to (@davll)[https://github.com/davll]
138
+ * Works with Rails 4.0. Thanks to [@davll](https://github.com/davll)
136
139
  * No longer support Rails < 3.2 or Ruby < 1.9.3
137
140
 
138
141
  ### 0.2.2
@@ -154,22 +157,16 @@ use case.
154
157
 
155
158
  ## Testing
156
159
 
157
- SchemaValidations is tested using rspec, sqlite3, and rvm, with some hackery
158
- to test against multiple versions of rails and ruby. To run the full combo of
159
- tests, after you've forked & cloned:
160
+ SchemaValidations is tested against the matrix of combinations. To run the full combo of
161
+ tests, after you've forked & cloned:
160
162
 
161
163
  $ cd schema_validations
162
- $ ./runspecs --install # do this once to install gem dependencies for all versions (slow)
163
- $ ./runspecs # as many times as you like
164
+ $ schema_dev bundle install
165
+ $ schema_dev rspec
164
166
 
165
- See `./runspecs --help` for other options. You can also pick a specific
166
- version of rails and ruby to use, such as:
167
- $ rvm use 1.9.2
168
- $ export BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.1
169
- $ rake spec
167
+ For more info, see [schema_dev](https://github.com/SchemaPlus/schema_dev)
170
168
 
171
- If you're running ruby 1.9, code coverage results will be in
172
- coverage/index.html -- it should be at 100% coverage.
169
+ Code coverage results will be in coverage/index.html -- it should be at 100% coverage.
173
170
 
174
171
  ## License
175
172
 
data/Rakefile CHANGED
@@ -2,9 +2,9 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec) do |spec|
6
- spec.rspec_opts = '-Ispec'
7
- end
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ require 'schema_dev/tasks'
8
8
 
9
9
  task :default => :spec
10
10
 
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => File.expand_path('..', __FILE__)
3
+
4
+ gem "byebug" if RUBY_VERSION > "2"
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "rails", "~> 3.2.0"
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "rails", "~> 4.1.0"
@@ -97,11 +97,11 @@ module SchemaValidations
97
97
 
98
98
  # Data-type validation
99
99
  if column.type == :integer
100
- validate_logged :validates_numericality_of, name, :allow_nil => true, :only_integer => true
100
+ load_integer_column_validations(name, column)
101
101
  elsif column.number?
102
- validate_logged :validates_numericality_of, name, :allow_nil => true
102
+ load_numeric_column_validations(name, column)
103
103
  elsif column.text? && column.limit
104
- validate_logged :validates_length_of, name, :allow_nil => true, :maximum => column.limit
104
+ load_string_column_validations(name, column)
105
105
  end
106
106
 
107
107
  # NOT NULL constraints
@@ -118,6 +118,21 @@ module SchemaValidations
118
118
  end
119
119
  end
120
120
 
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
+
121
136
  def load_association_validations #:nodoc:
122
137
  reflect_on_all_associations(:belongs_to).each do |association|
123
138
  # :primary_key_name was deprecated (noisily) in rails 3.1
@@ -1,3 +1,3 @@
1
1
  module SchemaValidations
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/schema_dev.yml ADDED
@@ -0,0 +1,7 @@
1
+ ruby:
2
+ - 1.9.3
3
+ - 2.1.3
4
+ rails:
5
+ - 3.2
6
+ - 4.1
7
+ db: sqlite3
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Ronen Barzel", "Michał Łomnicki"]
10
10
  s.email = ["ronen@barzel.org", "michal.lomnicki@gmail.com"]
11
- s.homepage = "https://github.com/lomba/schema_validations"
11
+ s.homepage = "https://github.com/SchemaPlus/schema_validations"
12
12
  s.summary = "Automatically creates validations basing on the database schema."
13
13
  s.description = "SchemaValidations extends ActiveRecord to automatically create validations by inspecting the database schema. This makes your models more DRY as you no longer need to duplicate NOT NULL, unique, numeric and varchar constraints on the model level."
14
14
  s.license = 'MIT'
@@ -22,11 +22,12 @@ 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
26
  s.add_development_dependency("rake")
26
27
  s.add_development_dependency("rdoc")
27
28
  s.add_development_dependency("rspec")
28
- s.add_development_dependency("sqlite3")
29
29
  s.add_development_dependency("simplecov")
30
- s.add_development_dependency("simplecov-gem-adapter")
30
+ s.add_development_dependency("simplecov-gem-profile")
31
+ s.add_development_dependency("database_cleaner")
31
32
  end
32
33
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'simplecov'
2
- require 'simplecov-gem-adapter'
2
+ require 'simplecov-gem-profile'
3
3
  SimpleCov.start "gem"
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -8,8 +8,20 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
8
  require 'rspec'
9
9
  require 'active_record'
10
10
  require 'schema_validations'
11
- require 'logger'
12
- require 'connection'
11
+ require 'schema_dev/rspec'
12
+ require 'database_cleaner'
13
+ DatabaseCleaner.strategy = :truncation
14
+
15
+ SchemaDev::Rspec.setup_db
16
+
17
+ RSpec.configure do |config|
18
+ config.before(:each) do
19
+ DatabaseCleaner.clean
20
+ end
21
+ end
22
+
23
+ # avoid deprecation warnings
24
+ I18n.enforce_available_locales = true
13
25
 
14
26
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
15
27
 
@@ -24,91 +24,81 @@ describe "Validations" do
24
24
  end
25
25
 
26
26
  it "should create validations for introspection with validators" do
27
- Article.validators.map{|v| v.class.name.demodulize}.uniq.should =~ %W[
27
+ expect(Article.validators.map{|v| v.class.name.demodulize}.uniq).to match_array(%W[
28
28
  InclusionValidator
29
29
  LengthValidator
30
30
  NumericalityValidator
31
31
  PresenceValidator
32
32
  UniquenessValidator
33
- ]
33
+ ])
34
34
  end
35
35
 
36
36
  it "should create validations for introspection with validators_on" do
37
- Article.validators_on(:content).map{|v| v.class.name.demodulize}.uniq.should =~ %W[
37
+ expect(Article.validators_on(:content).map{|v| v.class.name.demodulize}.uniq).to match_array(%W[
38
38
  PresenceValidator
39
- ]
39
+ ])
40
40
  end
41
41
 
42
42
  it "should be valid with valid attributes" do
43
- Article.new(valid_attributes).should be_valid
43
+ expect(Article.new(valid_article_attributes)).to be_valid
44
44
  end
45
45
 
46
46
  it "should validate content presence" do
47
- Article.new.should have(1).error_on(:content)
47
+ expect(Article.new.error_on(:content).size).to eq(1)
48
48
  end
49
49
 
50
50
  it "should check title length" do
51
- Article.new(:title => 'a' * 100).should have(1).error_on(:title)
51
+ expect(Article.new(:title => 'a' * 100).error_on(:title).size).to eq(1)
52
52
  end
53
53
 
54
54
  it "should validate state numericality" do
55
- Article.new(:state => 'unknown').should have(1).error_on(:state)
55
+ expect(Article.new(:state => 'unknown').error_on(:state).size).to eq(1)
56
56
  end
57
57
 
58
58
  it "should validate if state is integer" do
59
- Article.new(:state => 1.23).should have(1).error_on(:state)
59
+ expect(Article.new(:state => 1.23).error_on(:state).size).to eq(1)
60
60
  end
61
61
 
62
62
  it "should validate average_mark numericality" do
63
- Article.new(:average_mark => "high").should have(1).error_on(:average_mark)
63
+ expect(Article.new(:average_mark => "high").error_on(:average_mark).size).to eq(1)
64
64
  end
65
65
 
66
66
  it "should validate boolean fields" do
67
- Article.new(:active => nil).should have(1).error_on(:active)
67
+ expect(Article.new(:active => nil).error_on(:active).size).to eq(1)
68
68
  end
69
69
 
70
70
  it "should validate title uniqueness" do
71
- article1 = Article.create(valid_attributes)
72
- article2 = Article.new(:title => valid_attributes[:title])
73
- article2.should have(1).error_on(:title)
71
+ article1 = Article.create(valid_article_attributes)
72
+ article2 = Article.new(:title => valid_article_attributes[:title])
73
+ expect(article2.error_on(:title).size).to eq(1)
74
74
  article1.destroy
75
75
  end
76
76
 
77
77
  it "should validate state uniqueness in scope of 'active' value" do
78
- article1 = Article.create(valid_attributes)
79
- article2 = Article.new(valid_attributes.merge(:title => 'SchemaPlus 2.0 released'))
80
- article2.should_not be_valid
78
+ article1 = Article.create(valid_article_attributes)
79
+ article2 = Article.new(valid_article_attributes.merge(:title => 'SchemaPlus 2.0 released'))
80
+ expect(article2).not_to be_valid
81
81
  article2.toggle(:active)
82
- article2.should be_valid
82
+ expect(article2).to be_valid
83
83
  article1.destroy
84
84
  end
85
85
 
86
86
  it "should validate presence of belongs_to association" do
87
87
  review = Review.new
88
- review.should have(1).error_on(:article)
88
+ expect(review.error_on(:article).size).to eq(1)
89
89
  end
90
90
 
91
91
  it "should validate uniqueness of belongs_to association" do
92
- article = Article.create(valid_attributes)
93
- article.should be_valid
92
+ article = Article.create(valid_article_attributes)
93
+ expect(article).to be_valid
94
94
  review1 = Review.create(:article => article, :author => 'michal')
95
- review1.should be_valid
95
+ expect(review1).to be_valid
96
96
  review2 = Review.new(:article => article, :author => 'michal')
97
- review2.should have_at_least(1).error_on(:article_id)
97
+ expect(review2.error_on(:article_id).size).to be >= 1
98
98
  end
99
99
 
100
100
  it "should validate associations with unmatched column and name" do
101
- Review.new.should have(1).error_on(:news_article)
102
- end
103
-
104
- def valid_attributes
105
- {
106
- :title => 'SchemaPlus released!',
107
- :content => "Database matters. Get full use of it but don't write unecessary code. Get SchemaPlus!",
108
- :state => 3,
109
- :average_mark => 9.78,
110
- :active => true
111
- }
101
+ expect(Review.new.error_on(:news_article).size).to eq(1)
112
102
  end
113
103
 
114
104
  end
@@ -127,44 +117,44 @@ describe "Validations" do
127
117
 
128
118
  it "would normally have an error" do
129
119
  @review = Review.new(:content => @too_big_content)
130
- @review.should have(1).error_on(:content)
131
- @review.should have(1).error_on(:author)
120
+ expect(@review.error_on(:content).size).to eq(1)
121
+ expect(@review.error_on(:author).size).to eq(1)
132
122
  end
133
123
 
134
124
  it "shouldn't validate fields passed to :except option" do
135
125
  Review.schema_validations :except => :content
136
126
  @review = Review.new(:content => @too_big_content)
137
- @review.should have(:no).errors_on(:content)
138
- @review.should have(1).error_on(:author)
127
+ expect(@review.errors_on(:content).size).to eq(0)
128
+ expect(@review.error_on(:author).size).to eq(1)
139
129
  end
140
130
 
141
131
  it "shouldn't validate types passed to :except_type option using full validation" do
142
132
  Review.schema_validations :except_type => :validates_length_of
143
133
  @review = Review.new(:content => @too_big_content)
144
- @review.should have(:no).errors_on(:content)
145
- @review.should have(1).error_on(:author)
134
+ expect(@review.errors_on(:content).size).to eq(0)
135
+ expect(@review.error_on(:author).size).to eq(1)
146
136
  end
147
137
 
148
138
  it "shouldn't validate types passed to :except_type option using shorthand" do
149
139
  Review.schema_validations :except_type => :length
150
140
  @review = Review.new(:content => @too_big_content)
151
- @review.should have(:no).errors_on(:content)
152
- @review.should have(1).error_on(:author)
141
+ expect(@review.errors_on(:content).size).to eq(0)
142
+ expect(@review.error_on(:author).size).to eq(1)
153
143
  end
154
144
 
155
145
  it "should only validate type passed to :only_type option" do
156
146
  Review.schema_validations :only_type => :length
157
147
  @review = Review.new(:content => @too_big_content)
158
- @review.should have(1).error_on(:content)
159
- @review.should have(:no).errors_on(:author)
148
+ expect(@review.error_on(:content).size).to eq(1)
149
+ expect(@review.errors_on(:author).size).to eq(0)
160
150
  end
161
151
 
162
152
 
163
153
  it "shouldn't create validations if locally disabled" do
164
154
  Review.schema_validations :auto_create => false
165
155
  @review = Review.new(:content => @too_big_content)
166
- @review.should have(:no).errors_on(:content)
167
- @review.should have(:no).error_on(:author)
156
+ expect(@review.errors_on(:content).size).to eq(0)
157
+ expect(@review.error_on(:author).size).to eq(0)
168
158
  end
169
159
  end
170
160
 
@@ -182,17 +172,17 @@ describe "Validations" do
182
172
  end
183
173
 
184
174
  it "should not create validation" do
185
- Review.new(:content => @too_big_title).should have(:no).errors_on(:content)
175
+ expect(Review.new(:content => @too_big_title).errors_on(:content).size).to eq(0)
186
176
  end
187
177
 
188
178
  it "should create validation if locally enabled explicitly" do
189
179
  Review.schema_validations :auto_create => true
190
- Review.new(:content => @too_big_content).should have(1).error_on(:content)
180
+ expect(Review.new(:content => @too_big_content).error_on(:content).size).to eq(1)
191
181
  end
192
182
 
193
183
  it "should create validation if locally enabled implicitly" do
194
184
  Review.schema_validations
195
- Review.new(:content => @too_big_content).should have(1).error_on(:content)
185
+ expect(Review.new(:content => @too_big_content).error_on(:content).size).to eq(1)
196
186
  end
197
187
 
198
188
  end
@@ -212,26 +202,26 @@ describe "Validations" do
212
202
  too_big_title = 'a' * 100
213
203
  wrong_state = 'unknown'
214
204
  article = Article.new(:title => too_big_title, :state => wrong_state)
215
- article.should have(1).error_on(:title)
216
- article.should have(1).error_on(:state)
205
+ expect(article.error_on(:title).size).to eq(1)
206
+ expect(article.error_on(:state).size).to eq(1)
217
207
  end
218
208
 
219
209
  it "shouldn't validate skipped fields" do
220
210
  article = Article.new
221
- article.should have(:no).errors_on(:content)
222
- article.should have(:no).errors_on(:average_mark)
211
+ expect(article.errors_on(:content).size).to eq(0)
212
+ expect(article.errors_on(:average_mark).size).to eq(0)
223
213
  end
224
214
 
225
215
  it "shouldn't validate association on unexisting column" do
226
- Review.new.should have(:no).errors_on(:dummy_association)
216
+ expect(Review.new.errors_on(:dummy_association).size).to eq(0)
227
217
  end
228
218
 
229
219
  it "shouldn't validate fields passed to :except option" do
230
- Review.new.should have(:no).errors_on(:content)
220
+ expect(Review.new.errors_on(:content).size).to eq(0)
231
221
  end
232
222
 
233
223
  it "should validate all fields but passed to :except option" do
234
- Review.new.should have(1).error_on(:author)
224
+ expect(Review.new.error_on(:author).size).to eq(1)
235
225
  end
236
226
 
237
227
  end
@@ -246,11 +236,11 @@ describe "Validations" do
246
236
  end
247
237
 
248
238
  it "shouldn't validate associations not included in :only option" do
249
- Review.new.should have(:no).errors_on(:article)
239
+ expect(Review.new.errors_on(:article).size).to eq(0)
250
240
  end
251
241
 
252
242
  it "shouldn't change content columns of the model" do
253
- @columns.should == Review.content_columns
243
+ expect(@columns).to eq(Review.content_columns)
254
244
  end
255
245
 
256
246
  end
@@ -262,18 +252,27 @@ describe "Validations" do
262
252
  class Review < ActiveRecord::Base ; end
263
253
  class PremiumReview < Review ; end
264
254
  PremiumReview.new
265
- Review.new.should have(1).error_on(:author)
255
+ expect(Review.new.error_on(:author).size).to eq(1)
266
256
  end
267
257
 
268
258
  it "shouldn't create doubled validations" do
269
259
  class Review < ActiveRecord::Base ; end
270
260
  Review.new
271
261
  class PremiumReview < Review ; end
272
- PremiumReview.new.should have(1).error_on(:author)
262
+ expect(PremiumReview.new.error_on(:author).size).to eq(1)
273
263
  end
274
264
 
275
265
  end
276
266
 
267
+ context "when used with enum" do
268
+ it "does not validate numericality" do
269
+ class Article < ActiveRecord::Base
270
+ enum :state => [:happy, :sad]
271
+ end
272
+ expect(Article.new(valid_article_attributes.merge(:state => :happy))).to be_valid
273
+ end
274
+ end if ActiveRecord::Base.respond_to? :enum
275
+
277
276
  protected
278
277
  def with_auto_validations(value = true)
279
278
  old_value = SchemaValidations.config.auto_create
@@ -314,4 +313,15 @@ describe "Validations" do
314
313
  end
315
314
  end
316
315
 
316
+ def valid_article_attributes
317
+ {
318
+ :title => 'SchemaPlus released!',
319
+ :content => "Database matters. Get full use of it but don't write unecessary code. Get SchemaPlus!",
320
+ :state => 3,
321
+ :average_mark => 9.78,
322
+ :active => true
323
+ }
324
+ end
325
+
326
+
317
327
  end
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.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,104 +9,118 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-19 00:00:00.000000000 Z
12
+ date: 2014-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: schema_plus
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: schema_dev
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rake
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
- - - '>='
46
+ - - ">="
33
47
  - !ruby/object:Gem::Version
34
48
  version: '0'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
- - - '>='
53
+ - - ">="
40
54
  - !ruby/object:Gem::Version
41
55
  version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rdoc
44
58
  requirement: !ruby/object:Gem::Requirement
45
59
  requirements:
46
- - - '>='
60
+ - - ">="
47
61
  - !ruby/object:Gem::Version
48
62
  version: '0'
49
63
  type: :development
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
- - - '>='
67
+ - - ">="
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: rspec
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
- - - '>='
74
+ - - ">="
61
75
  - !ruby/object:Gem::Version
62
76
  version: '0'
63
77
  type: :development
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
- - - '>='
81
+ - - ">="
68
82
  - !ruby/object:Gem::Version
69
83
  version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
- name: sqlite3
85
+ name: simplecov
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - '>='
88
+ - - ">="
75
89
  - !ruby/object:Gem::Version
76
90
  version: '0'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - '>='
95
+ - - ">="
82
96
  - !ruby/object:Gem::Version
83
97
  version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
- name: simplecov
99
+ name: simplecov-gem-profile
86
100
  requirement: !ruby/object:Gem::Requirement
87
101
  requirements:
88
- - - '>='
102
+ - - ">="
89
103
  - !ruby/object:Gem::Version
90
104
  version: '0'
91
105
  type: :development
92
106
  prerelease: false
93
107
  version_requirements: !ruby/object:Gem::Requirement
94
108
  requirements:
95
- - - '>='
109
+ - - ">="
96
110
  - !ruby/object:Gem::Version
97
111
  version: '0'
98
112
  - !ruby/object:Gem::Dependency
99
- name: simplecov-gem-adapter
113
+ name: database_cleaner
100
114
  requirement: !ruby/object:Gem::Requirement
101
115
  requirements:
102
- - - '>='
116
+ - - ">="
103
117
  - !ruby/object:Gem::Version
104
118
  version: '0'
105
119
  type: :development
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
108
122
  requirements:
109
- - - '>='
123
+ - - ">="
110
124
  - !ruby/object:Gem::Version
111
125
  version: '0'
112
126
  description: SchemaValidations extends ActiveRecord to automatically create validations
@@ -120,26 +134,26 @@ executables: []
120
134
  extensions: []
121
135
  extra_rdoc_files: []
122
136
  files:
123
- - .gitignore
124
- - .travis.yml
137
+ - ".gitignore"
138
+ - ".travis.yml"
125
139
  - Gemfile
126
140
  - MIT-LICENSE
127
141
  - README.md
128
142
  - Rakefile
129
- - gemfiles/Gemfile.rails-3.2
130
- - gemfiles/Gemfile.rails-4.0
143
+ - gemfiles/Gemfile.base
144
+ - gemfiles/rails-3.2/Gemfile.base
145
+ - gemfiles/rails-4.1/Gemfile.base
131
146
  - init.rb
132
147
  - lib/schema_validations.rb
133
148
  - lib/schema_validations/active_record/validations.rb
134
149
  - lib/schema_validations/railtie.rb
135
150
  - lib/schema_validations/version.rb
136
- - runspecs
151
+ - schema_dev.yml
137
152
  - schema_validations.gemspec
138
- - spec/connection.rb
139
153
  - spec/spec_helper.rb
140
154
  - spec/support/active_model.rb
141
155
  - spec/validations_spec.rb
142
- homepage: https://github.com/lomba/schema_validations
156
+ homepage: https://github.com/SchemaPlus/schema_validations
143
157
  licenses:
144
158
  - MIT
145
159
  metadata: {}
@@ -149,22 +163,21 @@ require_paths:
149
163
  - lib
150
164
  required_ruby_version: !ruby/object:Gem::Requirement
151
165
  requirements:
152
- - - '>='
166
+ - - ">="
153
167
  - !ruby/object:Gem::Version
154
168
  version: '0'
155
169
  required_rubygems_version: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - '>='
171
+ - - ">="
158
172
  - !ruby/object:Gem::Version
159
173
  version: '0'
160
174
  requirements: []
161
175
  rubyforge_project: schema_validations
162
- rubygems_version: 2.0.3
176
+ rubygems_version: 2.2.2
163
177
  signing_key:
164
178
  specification_version: 4
165
179
  summary: Automatically creates validations basing on the database schema.
166
180
  test_files:
167
- - spec/connection.rb
168
181
  - spec/spec_helper.rb
169
182
  - spec/support/active_model.rb
170
183
  - spec/validations_spec.rb
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec :path => File.expand_path('../..', __FILE__)
4
- gem "rails", "~> 3.2.0"
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec :path => File.expand_path('../..', __FILE__)
4
- gem "rails", "~> 4.0.0"
data/runspecs DELETED
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'ostruct'
5
- require 'shellwords'
6
- require 'tempfile'
7
-
8
- RUBY_VERSIONS = %W[1.9.3 2.0.0]
9
- RAILS_VERSIONS = %W[3.2 4.0]
10
-
11
- o = OpenStruct.new
12
- o.ruby_versions = RUBY_VERSIONS
13
- o.rails_versions = RAILS_VERSIONS
14
-
15
- OptionParser.new do |opts|
16
- opts.banner = "Usage: #{$0} [options]"
17
-
18
- opts.on("-n", "--dry-run", "Do a dry run without executing actions") do |v|
19
- o.dry_run = true
20
- end
21
-
22
- opts.on("--update", "Update gem dependencies") do |v|
23
- o.update = v
24
- end
25
-
26
- opts.on("--install", "Install gem dependencies") do |v|
27
- o.install = v
28
- end
29
-
30
- opts.on("--ruby version", String, "Choose which version(s) of ruby to run. Default is: #{o.ruby_versions.join(' ')}") do |ruby|
31
- o.ruby_versions = ruby.split(' ')
32
- end
33
-
34
- opts.on("--rails version", String, "Choose which version(s) of rails to run. Default is: #{o.rails_versions.join(' ')}") do |rails|
35
- o.rails_versions = rails.split(' ')
36
- end
37
-
38
- opts.on("--quick", "quick run ruby #{RUBY_VERSIONS.last} and rails #{RAILS_VERSIONS.last}") do
39
- o.ruby_versions = [RUBY_VERSIONS.last]
40
- o.rails_versions = [RAILS_VERSIONS.last]
41
- end
42
-
43
- opts.on("--rspec", "run rspec rather than rake") do |v|
44
- o.rspec = v
45
- end
46
-
47
- end.parse!
48
-
49
-
50
- Combo = Struct.new(:ruby, :rails)
51
-
52
- combos = o.ruby_versions.product(o.rails_versions).map{|product| Combo.new(*product)}.select {|combo|
53
- case
54
- when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false # no longer happens, just keeping it as an example
55
- else true
56
- end
57
- }
58
-
59
- if system("which -s rvm")
60
- # using rvm
61
- def ruby_version_selector(ruby)
62
- "rvm #{ruby} do"
63
- end
64
- else
65
- # using rbenv. remove current version from path and current gem path
66
- # so that forked shell will respect RBENV_VERSION variable
67
- ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/rbenv/versions/}}.join(':')
68
- ENV['GEM_PATH'] = nil
69
-
70
- def ruby_version_selector(ruby)
71
- @versions ||= `rbenv versions --bare`.split
72
- version = @versions.select{|v| v.start_with? ruby}.last || abort("no ruby version '#{ruby}' installed in rbenv")
73
- "RBENV_VERSION=#{version}"
74
- end
75
- end
76
-
77
- GEMFILES_DIR = File.expand_path('../gemfiles', __FILE__)
78
- errs = []
79
- combos.each_with_index do |combo, n|
80
- ruby = combo.ruby
81
- rails = combo.rails
82
-
83
- cmd = case
84
- when o.update
85
- "bundle update"
86
- when o.install
87
- "bundle install"
88
- when o.rspec
89
- "bundle exec rspec"
90
- else
91
- "bundle exec rake spec"
92
- end
93
-
94
- command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}" #{ruby_version_selector(ruby)} #{cmd} #{Shellwords.join(ARGV)}}
95
-
96
- puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n+1} of #{combos.size}]\n\n#{command}"
97
-
98
- next if o.dry_run
99
-
100
- Tempfile.open('runspecs') do |file|
101
- system("(#{command}) 2>&1 | tee #{file.path}")
102
- file.rewind
103
- errs << "ruby #{ruby}, rails #{rails}" if file.readlines.grep(/^Failed examples/).any?
104
- end
105
- end
106
- puts errs.any? ? "\n*** #{errs.size} failures:\n\t#{errs.join("\n\t")}" : "\n*** #{combos.size > 1 ? 'all versions' : 'spec'} succeeded ***" unless o.dry_run
107
- exit !errs.any?
data/spec/connection.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'logger'
2
-
3
- ActiveRecord::Base.logger = Logger.new(File.open("sqlite3.log", "w"))
4
-
5
- ActiveRecord::Base.configurations = {
6
- 'schema_validations' => {
7
- :adapter => 'sqlite3',
8
- :database => File.expand_path('schema_validations.sqlite3', File.dirname(__FILE__)),
9
- }
10
-
11
- }
12
-
13
- ActiveRecord::Base.establish_connection 'schema_validations'
14
- ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"