rails-schema-validations 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,9 +17,11 @@ module ActiveRecord::Validations::ClassMethods
17
17
  if col.limit
18
18
  validates_length_of col.name, :maximum => col.limit, :allow_nil => col.null
19
19
  end
20
+ when :boolean
21
+ validates_inclusion_of col.name, :in => [true, false], :allow_nil => col.null
20
22
  end
21
23
  end.compact + content_columns.map do |col|
22
- validates_presence_of col.name unless col.null
24
+ validates_presence_of col.name unless col.null || col.type == :boolean
23
25
  end
24
26
  end
25
27
  end
@@ -9,7 +9,7 @@ def load_schema
9
9
 
10
10
  ActiveRecord::Schema.define do
11
11
  create_table "models", :force => true do |t|
12
- %w(string integer float datetime date).each do |kind|
12
+ %w(string integer float datetime date boolean).each do |kind|
13
13
  t.send(kind, kind)
14
14
  t.send(kind, "#{kind}_notnull", :null => false)
15
15
  end
@@ -53,7 +53,7 @@ context Model do
53
53
  end
54
54
 
55
55
  # null
56
- %w(string integer float date datetime).each do |name|
56
+ %w(string integer float date datetime boolean).each do |name|
57
57
  asserts_no_error_on name, nil
58
58
  asserts_error_on "#{name}_notnull", nil
59
59
  end
@@ -65,14 +65,20 @@ context Model do
65
65
  # only_integer
66
66
  asserts_error_on :integer_limit, 1.1
67
67
 
68
+ # limits
68
69
  asserts_error_on :string_limit, '12345678910'
69
70
  asserts_error_on :integer_limit, 2 ** (8 * 4)
70
-
71
71
  asserts_no_error_on :string_limit, '12'
72
72
  asserts_no_error_on :integer_limit, 2 ** (8 * 3)
73
73
 
74
+ # not null indexed columns
74
75
  asserts_error_on :indexed_id, nil
75
76
  asserts_error_on :unique_id, nil
76
77
 
78
+ # boolean
79
+ asserts_no_error_on :boolean_notnull, true
80
+ asserts_no_error_on :boolean_notnull, false
81
+ asserts_error_on :boolean_notnull, nil
82
+
77
83
  asserts_no_error_on :id, nil
78
84
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-schema-validations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- version: "0.7"
8
+ - 8
9
+ version: "0.8"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Greg Weber
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-29 00:00:00 -07:00
17
+ date: 2010-10-22 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: Automatically generate validations from the schema
21
+ description: generate validations from the schema - used in production with MySQL
22
22
  email: greg@gregweber.info
23
23
  executables: []
24
24
 
@@ -29,8 +29,8 @@ extra_rdoc_files:
29
29
  files:
30
30
  - README
31
31
  - lib/rails-schema-validations.rb
32
- - test/validations_from_schema_test.rb
33
32
  - test/test_helper.rb
33
+ - test/validations_from_schema_test.rb
34
34
  has_rdoc: true
35
35
  homepage: http://github.com/gregwebs/rails-schema-validations
36
36
  licenses: []
@@ -66,5 +66,5 @@ signing_key:
66
66
  specification_version: 3
67
67
  summary: Automatically generate validations from the schema
68
68
  test_files:
69
- - test/validations_from_schema_test.rb
70
69
  - test/test_helper.rb
70
+ - test/validations_from_schema_test.rb