schema_validations 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,7 +37,7 @@ Simply add schema_validations to your Gemfile.
37
37
 
38
38
  gem "schema_validations"
39
39
 
40
- == What if I want something special?
40
+ === What if I want something special?
41
41
 
42
42
  SchemaValidations is highly customizable. You can configure behavior
43
43
  globally via SchemaValidations.setup or per-model via
@@ -50,6 +50,24 @@ SchemaValidations::ActiveRecord::schema_validations, such as:
50
50
 
51
51
  See SchemaValidations::Config for the available options.
52
52
 
53
+ === This seems cool, but I'm worried about too much automagic
54
+
55
+ You can globally turn off automatic creation in
56
+ <tt>config/initializers/schema_validations.rb</tt>:
57
+
58
+ SchemaValidations.setup do |config|
59
+ config.auto_create = false
60
+ end
61
+
62
+ Then in any model where you want automatic validations, just do
63
+
64
+ class Post < ActiveRecord::Base
65
+ schema_validations
66
+ end
67
+
68
+ You can also pass options as per above.
69
+
70
+
53
71
  == Which validations are covered?
54
72
 
55
73
  Constraints:
@@ -112,7 +130,7 @@ full combo of tests, after you've forked & cloned:
112
130
  $ ./runspecs --install # do this once to install gem dependencies for all versions (slow)
113
131
  $ ./runspecs # as many times as you like
114
132
 
115
- You can also pick a specific version of rails and ruby to use, such as:
133
+ See <tt>./runspecs --help</tt> for other options. You can also pick a specific version of rails and ruby to use, such as:
116
134
  $ rvm use 1.9.2
117
135
  $ export SCHEMA_VALIDATIONS_RAILS_VERSION=3.1
118
136
  $ bundle update --local rails
@@ -14,10 +14,28 @@ module SchemaValidations
14
14
 
15
15
  # Per-model override of Config options. Use via, e.g.
16
16
  # class MyModel < ActiveRecord::Base
17
- # schema_associations :auto_create => false
17
+ # schema_validations :auto_create => false
18
18
  # end
19
- def schema_validations(opts)
20
- @schema_validations_config = SchemaValidations.config.merge(opts)
19
+ #
20
+ # If <tt>:auto_create</tt> is not specified, it is implicitly
21
+ # specified as true. This allows the "non-invasive" style of using
22
+ # SchemaValidations in which you set the global Config to
23
+ # <tt>auto_create = false</tt>, then in any model that you want auto
24
+ # validations you simply do:
25
+ #
26
+ # class MyModel < ActiveRecord::Base
27
+ # schema_validations
28
+ # end
29
+ #
30
+ # Of course other options can be passed, such as
31
+ #
32
+ # class MyModel < ActiveRecord::Base
33
+ # schema_validations :except_type => :validates_presence_of
34
+ # end
35
+ #
36
+ #
37
+ def schema_validations(opts={})
38
+ @schema_validations_config = SchemaValidations.config.merge({:auto_create => true}.merge(opts))
21
39
  end
22
40
 
23
41
  def schema_validations_config # :nodoc:
@@ -1,3 +1,3 @@
1
1
  module SchemaValidations
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/runspecs CHANGED
@@ -1,36 +1,58 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
+ require 'ostruct'
5
+
6
+ PROJECT = File.basename(File.expand_path('..', __FILE__))
4
7
 
5
8
  RUBY_VERSIONS = %W[1.8.7 1.9.2]
6
9
  RAILS_VERSIONS = %W[2.3 3.0 3.1]
7
10
 
8
- options = {}
11
+ o = OpenStruct.new
12
+ o.ruby_versions = RUBY_VERSIONS
13
+ o.rails_versions = RAILS_VERSIONS
14
+ o.run_cmd = "rake spec"
15
+
9
16
  OptionParser.new do |opts|
10
17
  opts.banner = "Usage: #{$0} [options]"
11
18
 
12
19
  opts.on("--install", "Install gem dependencies") do |v|
13
- options[:install] = v
20
+ o.install = v
21
+ end
22
+
23
+ opts.on("--ruby version", String, "Choose which version(s) of ruby to run. Default is: #{o.ruby_versions.join(' ')}") do |ruby|
24
+ o.ruby_versions = ruby.split(' ')
25
+ end
26
+
27
+ opts.on("--rails version", String, "Choose which version(s) of rails to run. Default is: #{o.rails_versions.join(' ')}") do |rails|
28
+ o.rails_versions = rails.split(' ')
29
+ end
30
+
31
+ opts.on("--quick", "quick run ruby #{RUBY_VERSIONS.last} and rails #{RAILS_VERSIONS.last}") do
32
+ o.ruby_versions = [RUBY_VERSIONS.last]
33
+ o.rails_versions = [RAILS_VERSIONS.last]
14
34
  end
35
+
15
36
  end.parse!
16
37
 
17
- cmds = if options [:install]
38
+ cmds = if o.install
18
39
  ['bundle update']
19
40
  else
20
- ['bundle update --local rails | grep rails', 'rake spec']
41
+ ['bundle update --local rails | grep rails', o.run_cmd]
21
42
  end
22
43
 
23
44
  n = 1
24
- total = RUBY_VERSIONS.size * RAILS_VERSIONS.size
25
- RUBY_VERSIONS.each do |ruby|
26
- RAILS_VERSIONS.each do |rails|
45
+ total = o.ruby_versions.size * o.rails_versions.size
46
+ o.ruby_versions.each do |ruby|
47
+ o.rails_versions.each do |rails|
27
48
  puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n} of #{total}]\n\n"
28
49
  n += 1
29
50
  allcmds = []
30
51
  allcmds << "rvm use #{ruby}"
31
- allcmds << "export SCHEMA_VALIDATIONS_RAILS_VERSION=#{rails}"
52
+ allcmds << "export #{PROJECT.upcase}_RAILS_VERSION=#{rails}"
32
53
  allcmds += cmds
33
54
  allcmds << 'exit'
34
55
  system %Q{echo '#{allcmds.join(' \n ')}' | bash -i} or abort "aborting #{$0}"
35
56
  end
36
57
  end
58
+
data/spec/connection.rb CHANGED
@@ -3,11 +3,12 @@ require 'logger'
3
3
  ActiveRecord::Base.logger = Logger.new(File.open("sqlite3.log", "w"))
4
4
 
5
5
  ActiveRecord::Base.configurations = {
6
- 'schema_plus' => {
6
+ 'schema_validations' => {
7
7
  :adapter => 'sqlite3',
8
- :database => File.expand_path('schema_plus.sqlite3', File.dirname(__FILE__)),
8
+ :database => File.expand_path('schema_validations.sqlite3', File.dirname(__FILE__)),
9
9
  }
10
10
 
11
11
  }
12
12
 
13
- ActiveRecord::Base.establish_connection 'schema_plus'
13
+ ActiveRecord::Base.establish_connection 'schema_validations'
14
+ ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"
@@ -169,11 +169,16 @@ describe "Validations" do
169
169
  Review.new(:content => @too_big_title).should have(:no).errors_on(:content)
170
170
  end
171
171
 
172
- it "should create validation if locally enabled" do
172
+ it "should create validation if locally enabled explicitly" do
173
173
  Review.schema_validations :auto_create => true
174
174
  Review.new(:content => @too_big_content).should have(1).error_on(:content)
175
175
  end
176
176
 
177
+ it "should create validation if locally enabled implicitly" do
178
+ Review.schema_validations
179
+ Review.new(:content => @too_big_content).should have(1).error_on(:content)
180
+ end
181
+
177
182
  end
178
183
 
179
184
  context "manually invoked" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: schema_validations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ronen Barzel
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-28 00:00:00 -07:00
14
+ date: 2011-08-02 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -26,29 +26,29 @@ dependencies:
26
26
  type: :runtime
27
27
  version_requirements: *id001
28
28
  - !ruby/object:Gem::Dependency
29
- name: rails
29
+ name: rake
30
30
  prerelease: false
31
31
  requirement: &id002 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ~>
35
35
  - !ruby/object:Gem::Version
36
- version: "2.3"
36
+ version: 0.8.7
37
37
  type: :development
38
38
  version_requirements: *id002
39
39
  - !ruby/object:Gem::Dependency
40
- name: rake
40
+ name: rspec
41
41
  prerelease: false
42
42
  requirement: &id003 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
- - - ~>
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.7
47
+ version: "0"
48
48
  type: :development
49
49
  version_requirements: *id003
50
50
  - !ruby/object:Gem::Dependency
51
- name: rspec
51
+ name: sqlite3
52
52
  prerelease: false
53
53
  requirement: &id004 !ruby/object:Gem::Requirement
54
54
  none: false
@@ -59,7 +59,7 @@ dependencies:
59
59
  type: :development
60
60
  version_requirements: *id004
61
61
  - !ruby/object:Gem::Dependency
62
- name: sqlite3
62
+ name: simplecov
63
63
  prerelease: false
64
64
  requirement: &id005 !ruby/object:Gem::Requirement
65
65
  none: false
@@ -70,7 +70,7 @@ dependencies:
70
70
  type: :development
71
71
  version_requirements: *id005
72
72
  - !ruby/object:Gem::Dependency
73
- name: simplecov
73
+ name: simplecov-gem-adapter
74
74
  prerelease: false
75
75
  requirement: &id006 !ruby/object:Gem::Requirement
76
76
  none: false
@@ -81,7 +81,7 @@ dependencies:
81
81
  type: :development
82
82
  version_requirements: *id006
83
83
  - !ruby/object:Gem::Dependency
84
- name: simplecov-gem-adapter
84
+ name: ruby-debug19
85
85
  prerelease: false
86
86
  requirement: &id007 !ruby/object:Gem::Requirement
87
87
  none: false
@@ -91,17 +91,6 @@ dependencies:
91
91
  version: "0"
92
92
  type: :development
93
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
105
94
  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.
106
95
  email:
107
96
  - ronen@barzel.org