schema_validations 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -78,7 +78,7 @@ you probably want -- but if you don't want them, you can disable them using
78
78
  == Compatibility
79
79
 
80
80
  SchemaValidations supports all combinations of:
81
- * rails 3.0 or 3.1
81
+ * rails 2.3, 3.0, or 3.1
82
82
  * MRI ruby 1.8.7 or 1.9.2
83
83
 
84
84
  == How do I know what it did?
@@ -89,7 +89,7 @@ If you're curious (or dubious) about what validations SchemaValidations defines,
89
89
  which shows the exact validation definition call.
90
90
 
91
91
  SchemaValidations defines the validations lazily, only creating them when a
92
- record of the class is first accessed. So you may need to search through
92
+ record of the class is first validated. So you may need to search through
93
93
  the log file for "schema_validations" to find them all (and some may not be
94
94
  defined at all if they were never needed for the logged use case).
95
95
 
@@ -2,6 +2,16 @@ module SchemaValidations
2
2
  module ActiveRecord
3
3
  module Validations
4
4
 
5
+ def self.extended(base) # :nodoc:
6
+ base.delegate :load_schema_validations, :to => 'self.class'
7
+ base.class_attribute :schema_validations_loaded
8
+ end
9
+
10
+ def inherited(klass) # :nodoc:
11
+ super
12
+ before_validation :load_schema_validations unless schema_validations_loaded?
13
+ end
14
+
5
15
  # Per-model override of Config options. Use via, e.g.
6
16
  # class MyModel < ActiveRecord::Base
7
17
  # schema_associations :auto_create => false
@@ -14,13 +24,7 @@ module SchemaValidations
14
24
  @schema_validations_config ||= SchemaValidations.config.dup
15
25
  end
16
26
 
17
- def define_attribute_methods(*) #:nodoc:
18
- super
19
- load_schema_validations
20
- end
21
-
22
27
  private
23
-
24
28
  # Adds schema-based validations to model.
25
29
  # Attributes as well as associations are validated.
26
30
  # For instance if there is column
@@ -46,10 +50,9 @@ module SchemaValidations
46
50
  def load_schema_validations #:nodoc:
47
51
  # Don't bother if: it's already been loaded; the class is abstract; not a base class; or the table doesn't exist
48
52
  return unless create_schema_validations?
49
-
50
53
  load_column_validations
51
54
  load_association_validations
52
- @schema_validations_loaded = true
55
+ self.schema_validations_loaded = true
53
56
  end
54
57
 
55
58
  def load_column_validations #:nodoc:
@@ -102,7 +105,7 @@ module SchemaValidations
102
105
  end
103
106
 
104
107
  def create_schema_validations? #:nodoc:
105
- schema_validations_config.auto_create? && !(@schema_validations_loaded || abstract_class? || name.blank? || !table_exists?)
108
+ schema_validations_config.auto_create? && !(schema_validations_loaded || abstract_class? || name.blank? || !table_exists?)
106
109
  end
107
110
 
108
111
  def validate_logged(method, arg, opts={}) #:nodoc:
@@ -1,3 +1,3 @@
1
1
  module SchemaValidations
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/runspecs CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'optparse'
4
4
 
5
5
  RUBY_VERSIONS = %W[1.8.7 1.9.2]
6
- RAILS_VERSIONS = %W[3.0 3.1]
6
+ RAILS_VERSIONS = %W[2.3 3.0 3.1]
7
7
 
8
8
  options = {}
9
9
  OptionParser.new do |opts|
@@ -22,14 +22,12 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency("schema_plus")
23
23
 
24
24
  case ENV['SCHEMA_VALIDATIONS_RAILS_VERSION']
25
+ when '2.3'
26
+ s.add_development_dependency("rails", "~> 2.3")
25
27
  when '3.0'
26
28
  s.add_development_dependency("rails", "~> 3.0")
27
- s.add_development_dependency("mysql2", "~> 0.2.6")
28
29
  when '3.1'
29
30
  s.add_development_dependency("rails", ">= 3.1.0.rc4")
30
- s.add_development_dependency("mysql2")
31
- else
32
- s.add_development_dependency("mysql2")
33
31
  end
34
32
 
35
33
  s.add_development_dependency("rake", "~> 0.8.7")
@@ -1,7 +1,7 @@
1
1
  # ported from rspec-rails
2
2
  # There is no reason to install whole gem as we
3
3
  # need only that tiny helper
4
- module ::ActiveModel::Validations
4
+ class ::ActiveRecord::Base
5
5
 
6
6
  def error_on(attribute)
7
7
  self.valid?
@@ -28,7 +28,7 @@ describe "Validations" do
28
28
  end
29
29
 
30
30
  it "should validate content presence" do
31
- post = Article.new.should have(1).error_on(:content)
31
+ Article.new.should have(1).error_on(:content)
32
32
  end
33
33
 
34
34
  it "should check title length" do
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_validations
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
4
+ prerelease:
5
+ version: 0.1.1
10
6
  platform: ruby
11
7
  authors:
12
8
  - Ronen Barzel
@@ -15,44 +11,39 @@ autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-07-26 00:00:00 +02:00
14
+ date: 2011-07-28 00:00:00 -07:00
19
15
  default_executable:
20
16
  dependencies:
21
17
  - !ruby/object:Gem::Dependency
22
18
  name: schema_plus
23
19
  prerelease: false
24
20
  requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
25
22
  requirements:
26
23
  - - ">="
27
24
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
25
  version: "0"
31
26
  type: :runtime
32
27
  version_requirements: *id001
33
28
  - !ruby/object:Gem::Dependency
34
- name: mysql2
29
+ name: rails
35
30
  prerelease: false
36
31
  requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
37
33
  requirements:
38
- - - ">="
34
+ - - ~>
39
35
  - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
36
+ version: "2.3"
43
37
  type: :development
44
38
  version_requirements: *id002
45
39
  - !ruby/object:Gem::Dependency
46
40
  name: rake
47
41
  prerelease: false
48
42
  requirement: &id003 !ruby/object:Gem::Requirement
43
+ none: false
49
44
  requirements:
50
45
  - - ~>
51
46
  - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- - 8
55
- - 7
56
47
  version: 0.8.7
57
48
  type: :development
58
49
  version_requirements: *id003
@@ -60,11 +51,10 @@ dependencies:
60
51
  name: rspec
61
52
  prerelease: false
62
53
  requirement: &id004 !ruby/object:Gem::Requirement
54
+ none: false
63
55
  requirements:
64
56
  - - ">="
65
57
  - !ruby/object:Gem::Version
66
- segments:
67
- - 0
68
58
  version: "0"
69
59
  type: :development
70
60
  version_requirements: *id004
@@ -72,11 +62,10 @@ dependencies:
72
62
  name: sqlite3
73
63
  prerelease: false
74
64
  requirement: &id005 !ruby/object:Gem::Requirement
65
+ none: false
75
66
  requirements:
76
67
  - - ">="
77
68
  - !ruby/object:Gem::Version
78
- segments:
79
- - 0
80
69
  version: "0"
81
70
  type: :development
82
71
  version_requirements: *id005
@@ -84,11 +73,10 @@ dependencies:
84
73
  name: simplecov
85
74
  prerelease: false
86
75
  requirement: &id006 !ruby/object:Gem::Requirement
76
+ none: false
87
77
  requirements:
88
78
  - - ">="
89
79
  - !ruby/object:Gem::Version
90
- segments:
91
- - 0
92
80
  version: "0"
93
81
  type: :development
94
82
  version_requirements: *id006
@@ -96,14 +84,24 @@ dependencies:
96
84
  name: simplecov-gem-adapter
97
85
  prerelease: false
98
86
  requirement: &id007 !ruby/object:Gem::Requirement
87
+ none: false
99
88
  requirements:
100
89
  - - ">="
101
90
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
91
  version: "0"
105
92
  type: :development
106
93
  version_requirements: *id007
94
+ - !ruby/object:Gem::Dependency
95
+ name: ruby-debug19
96
+ prerelease: false
97
+ requirement: &id008 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ type: :development
104
+ version_requirements: *id008
107
105
  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.
108
106
  email:
109
107
  - ronen@barzel.org
@@ -141,25 +139,26 @@ rdoc_options: []
141
139
  require_paths:
142
140
  - lib
143
141
  required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
144
143
  requirements:
145
144
  - - ">="
146
145
  - !ruby/object:Gem::Version
147
- segments:
148
- - 0
149
146
  version: "0"
150
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
151
149
  requirements:
152
150
  - - ">="
153
151
  - !ruby/object:Gem::Version
154
- segments:
155
- - 0
156
152
  version: "0"
157
153
  requirements: []
158
154
 
159
155
  rubyforge_project: schema_validations
160
- rubygems_version: 1.3.6
156
+ rubygems_version: 1.6.2
161
157
  signing_key:
162
158
  specification_version: 3
163
159
  summary: Automatically creates validations basing on the database schema.
164
- test_files: []
165
-
160
+ test_files:
161
+ - spec/connection.rb
162
+ - spec/spec_helper.rb
163
+ - spec/support/active_model.rb
164
+ - spec/validations_spec.rb