validates_lengths_from_database 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec5757dde636f6b3d800c8a95b29aace5cfa1ce5
4
+ data.tar.gz: 41825787b212ff9cc5a06462e86007c00e9d17b9
5
+ SHA512:
6
+ metadata.gz: b643589ff56a2155c33453422d525256fd012e00ff6b254d6b618c22fc31a776c2ba045c99c1816eb68ea91a2db4a1a9d617f20f0ee3797832e2bc3dbfe6317e
7
+ data.tar.gz: f398c90a2e7f11fe16abbd54b4a3d799f6ded5ccbb67c87464b40349286d729206cda438895799f83898846f5dbf05ceb4b80f1db355c6004fc27d264655d86c
data/Appraisals CHANGED
@@ -1,20 +1,27 @@
1
- appraise "rails-2.3" do
1
+ appraise "2.3" do
2
2
  gem "rails", "~> 2.3.2"
3
- gem "validates_lengths_from_database", :path => "../"
4
3
  end
5
4
 
6
- appraise "rails-3.0" do
5
+ appraise "3.0" do
7
6
  gem "rails", "~> 3.0.12"
8
- gem "validates_lengths_from_database", :path => "../"
9
7
  end
10
8
 
11
- appraise "rails-3.1" do
9
+ appraise "3.1" do
12
10
  gem "rails", "~> 3.1.4"
13
- gem "validates_lengths_from_database", :path => "../"
14
11
  end
15
12
 
16
- appraise "rails-3.2" do
13
+ appraise "3.2" do
17
14
  gem "rails", "~> 3.2.2"
18
- gem "validates_lengths_from_database", :path => "../"
19
15
  end
20
16
 
17
+ appraise "4.0" do
18
+ gem "rails", "~> 4.0.12"
19
+ end
20
+
21
+ appraise "4.1" do
22
+ gem "rails", "~> 4.1.8"
23
+ end
24
+
25
+ appraise "4.2" do
26
+ gem "rails", "~> 4.2.0"
27
+ end
data/CHANGELOG ADDED
@@ -0,0 +1,7 @@
1
+ == v0.3.0 (2015-01-03)
2
+
3
+ * Explicit support for Rails 4.1 and 4.2
4
+ * Up-to-date Appraisals and dependencies
5
+ * Better support for postgres text columns via conditional length validation
6
+ * Bug fix for postgres array column types
7
+
data/Gemfile.lock CHANGED
@@ -1,32 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validates_lengths_from_database (0.1.3)
4
+ validates_lengths_from_database (0.2.0)
5
5
  activerecord (>= 2.3.2)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.2.2)
11
- activesupport (= 3.2.2)
10
+ activemodel (3.2.12)
11
+ activesupport (= 3.2.12)
12
12
  builder (~> 3.0.0)
13
- activerecord (3.2.2)
14
- activemodel (= 3.2.2)
15
- activesupport (= 3.2.2)
13
+ activerecord (3.2.12)
14
+ activemodel (= 3.2.12)
15
+ activesupport (= 3.2.12)
16
16
  arel (~> 3.0.2)
17
17
  tzinfo (~> 0.3.29)
18
- activesupport (3.2.2)
18
+ activesupport (3.2.12)
19
19
  i18n (~> 0.6)
20
20
  multi_json (~> 1.0)
21
- appraisal (0.4.1)
21
+ appraisal (1.0.2)
22
22
  bundler
23
23
  rake
24
- arel (3.0.2)
25
- builder (3.0.0)
24
+ thor (>= 0.14.0)
25
+ arel (3.0.3)
26
+ builder (3.0.4)
26
27
  diff-lcs (1.1.2)
27
28
  i18n (0.6.0)
29
+ iconv (1.0.4)
28
30
  json (1.6.6)
29
- multi_json (1.2.0)
31
+ multi_json (1.10.1)
32
+ pg (0.17.1)
30
33
  rake (0.9.2.2)
31
34
  rdoc (3.12)
32
35
  json (~> 1.4)
@@ -39,14 +42,18 @@ GEM
39
42
  diff-lcs (~> 1.1.2)
40
43
  rspec-mocks (2.5.0)
41
44
  sqlite3 (1.3.5)
42
- tzinfo (0.3.32)
45
+ thor (0.19.1)
46
+ tzinfo (0.3.42)
43
47
 
44
48
  PLATFORMS
45
49
  ruby
46
50
 
47
51
  DEPENDENCIES
48
- appraisal (~> 0.4.0)
52
+ activesupport (>= 2.3.2)
53
+ appraisal (~> 1.0.2)
49
54
  i18n
55
+ iconv (~> 1.0.3)
56
+ pg (~> 0.17.1)
50
57
  rake
51
58
  rdoc (~> 3.12)
52
59
  rspec (~> 2.0)
data/README.rdoc CHANGED
@@ -1,4 +1,6 @@
1
1
  {<img src="https://secure.travis-ci.org/rubiety/validates_lengths_from_database.png?branch=master" alt="Build Status" />}[http://travis-ci.org/rubiety/validates_lengths_from_database]
2
+ {<img src="https://gemnasium.com/rubiety/validates_lengths_from_database.png" alt="Dependency Status" />}[https://gemnasium.com/rubiety/validates_lengths_from_database]
3
+ {<img src="https://codeclimate.com/github/rubiety/validates_lengths_from_database.png" />}[https://codeclimate.com/github/rubiety/validates_lengths_from_database]
2
4
 
3
5
  == Validates Lengths from Database
4
6
 
@@ -43,3 +45,13 @@ Or to set the limit differently for string (VARCHAR) and (TEXT) columns:
43
45
 
44
46
  Note that unfortunately this cannot be done at a global level directly against ActiveRecord::Base, since the +validates_length_from_database+ method requires the class to have a table name (with the ability to load the schema).
45
47
 
48
+ == Running Tests
49
+
50
+ This gem uses appraisal to test with different versions of the dependencies. See Appraisal first for which versions are tested.
51
+
52
+ # Just the gems locked in Gemfile.lock
53
+ $ rake test
54
+
55
+ # All of the Appraisals:
56
+ $ rake appraisal test
57
+
data/Rakefile CHANGED
@@ -3,18 +3,11 @@ require 'bundler/setup'
3
3
 
4
4
  require 'rake'
5
5
  require 'rspec/core/rake_task'
6
- require 'appraisal'
7
6
 
8
7
  Bundler::GemHelper.install_tasks
9
8
 
10
9
  desc 'Default: run unit tests.'
11
- task :default => [:clean, :all]
12
-
13
- desc "Run Specs against all Appraisals"
14
- task :all => :spec do
15
- Rake::Task["appraisal:install"].execute
16
- system("bundle exec rake -s appraisal spec")
17
- end
10
+ task :default => [:clean, :test]
18
11
 
19
12
  desc "Run Specs"
20
13
  RSpec::Core::RakeTask.new(:spec) do |t|
@@ -31,7 +31,8 @@ module ValidatesLengthsFromDatabase
31
31
  column_schema = columns.find {|c| c.name == column }
32
32
  next if column_schema.nil?
33
33
  next if ![:string, :text].include?(column_schema.type)
34
-
34
+ next if column_schema.respond_to?(:array) && column_schema.array
35
+
35
36
  column_limit = options[:limit][column_schema.type] || column_schema.limit
36
37
  next unless column_limit
37
38
 
@@ -1,3 +1,3 @@
1
1
  module ValidatesLengthsFromDatabase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/spec/db/schema.rb CHANGED
@@ -1,19 +1,33 @@
1
1
  ActiveRecord::Schema.define(:version => 0) do
2
-
3
2
  create_table :articles, :force => true do |t|
4
3
  t.string :string_1, :limit => 5
5
4
  t.string :string_2, :limit => 5
6
- t.text :text_1, :limit => 5
5
+
6
+ if postgresql?
7
+ # PostgreSQL doesn't support limits on text columns
8
+ t.text :text_1
9
+ else
10
+ t.text :text_1, :limit => 5
11
+ end
12
+
7
13
  t.date :date_1
8
14
  t.integer :integer_1
15
+
16
+ if database_supports_arrays?
17
+ t.string :array_1, :array => true, :limit => 5
18
+ end
9
19
  end
10
-
20
+
11
21
  create_table :articles_high_limit, :force => true do |t|
12
22
  t.string :string_1
13
23
  t.string :string_2
14
24
  t.text :text_1
15
25
  t.date :date_1
16
26
  t.integer :integer_1
27
+
28
+ if database_supports_arrays?
29
+ t.string :array_1, :array => true
30
+ end
17
31
  end
18
-
19
32
  end
33
+
data/spec/db/test.sqlite3 CHANGED
Binary file
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,26 @@
1
1
  require "rubygems"
2
2
  require "rspec"
3
3
  require "active_record"
4
+ require "active_support"
5
+ require "yaml"
4
6
 
5
7
  # Establish DB Connection
6
8
  config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'db', 'database.yml')))
7
9
  ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
8
10
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
9
11
 
12
+ def database_supports_arrays?
13
+ postgresql? && active_record_4?
14
+ end
15
+
16
+ def postgresql?
17
+ ActiveRecord::Base.connection.instance_values["config"][:adapter] == 'postgresql'
18
+ end
19
+
20
+ def active_record_4?
21
+ ActiveRecord::VERSION::MAJOR >= 4
22
+ end
23
+
10
24
  # Load Test Schema into the Database
11
25
  load(File.dirname(__FILE__) + "/db/schema.rb")
12
26
 
@@ -26,7 +26,7 @@ describe ValidatesLengthsFromDatabase do
26
26
  specify "defining validates_lengths_from_database should not raise an error" do
27
27
  lambda {
28
28
  class InvalidTableArticle < ActiveRecord::Base
29
- set_table_name "articles_invalid"
29
+ self.table_name = "articles_invalid"
30
30
  validates_lengths_from_database
31
31
  end
32
32
  }.should_not raise_error
@@ -36,7 +36,7 @@ describe ValidatesLengthsFromDatabase do
36
36
  context "Model with validates_lengths_from_database" do
37
37
  before do
38
38
  class ArticleValidateAll < ActiveRecord::Base
39
- set_table_name "articles"
39
+ self.table_name = "articles"
40
40
  validates_lengths_from_database
41
41
  end
42
42
  end
@@ -51,7 +51,7 @@ describe ValidatesLengthsFromDatabase do
51
51
  it "should have errors on all string/text attributes" do
52
52
  @article.errors["string_1"].join.should =~ /too long/
53
53
  @article.errors["string_2"].join.should =~ /too long/
54
- @article.errors["text_1"].join.should =~ /too long/
54
+ @article.errors["text_1"].join.should =~ /too long/ unless postgresql? # PostgreSQL doesn't support limits on text columns
55
55
  end
56
56
  end
57
57
 
@@ -62,12 +62,22 @@ describe ValidatesLengthsFromDatabase do
62
62
  @article.should be_valid
63
63
  end
64
64
  end
65
+
66
+ if database_supports_arrays?
67
+ context "an article with with string array attribute" do
68
+ before { @article = ArticleValidateAll.new(:array_1 => %w(1 2 3 4 5 6 7 8 9 10)); @article.valid? }
69
+
70
+ it "should be valid" do
71
+ @article.should be_valid
72
+ end
73
+ end
74
+ end
65
75
  end
66
-
67
- context "Model with validates_lengths_from_database :limit => 10" do
76
+
77
+ context "Model with validates_lengths_from_database :limit => 5" do
68
78
  before do
69
79
  class ArticleValidateLimit < ActiveRecord::Base
70
- set_table_name "articles_high_limit"
80
+ self.table_name = "articles_high_limit"
71
81
  validates_lengths_from_database :limit => 5
72
82
  end
73
83
  end
@@ -94,11 +104,11 @@ describe ValidatesLengthsFromDatabase do
94
104
  end
95
105
  end
96
106
  end
97
-
107
+
98
108
  context "Model with validates_lengths_from_database :limit => {:string => 5, :text => 100}" do
99
109
  before do
100
110
  class ArticleValidateSpecificLimit < ActiveRecord::Base
101
- set_table_name "articles_high_limit"
111
+ self.table_name = "articles_high_limit"
102
112
  validates_lengths_from_database :limit => {:string => 5, :text => 100}
103
113
  end
104
114
  end
@@ -117,11 +127,11 @@ describe ValidatesLengthsFromDatabase do
117
127
  end
118
128
  end
119
129
  end
120
-
130
+
121
131
  context "Model with validates_lengths_from_database :only => [:string_1, :text_1]" do
122
132
  before do
123
133
  class ArticleValidateOnly < ActiveRecord::Base
124
- set_table_name "articles"
134
+ self.table_name = "articles"
125
135
  validates_lengths_from_database :only => [:string_1, :text_1]
126
136
  end
127
137
  end
@@ -136,7 +146,7 @@ describe ValidatesLengthsFromDatabase do
136
146
  it "should have errors on only string_1 and text_1" do
137
147
  @article.errors["string_1"].join.should =~ /too long/
138
148
  (@article.errors["string_2"] || []).should be_empty
139
- @article.errors["text_1"].join.should =~ /too long/
149
+ @article.errors["text_1"].join.should =~ /too long/ unless postgresql? # PostgreSQL doesn't support limits on text columns
140
150
  end
141
151
  end
142
152
 
@@ -152,7 +162,7 @@ describe ValidatesLengthsFromDatabase do
152
162
  context "Model with validates_lengths_from_database :except => [:string_1, :text_1]" do
153
163
  before do
154
164
  class ArticleValidateExcept < ActiveRecord::Base
155
- set_table_name "articles"
165
+ self.table_name = "articles"
156
166
  validates_lengths_from_database :except => [:string_1, :text_1]
157
167
  end
158
168
  end
@@ -179,5 +189,5 @@ describe ValidatesLengthsFromDatabase do
179
189
  end
180
190
  end
181
191
  end
182
-
192
+
183
193
  end
metadata CHANGED
@@ -1,93 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_lengths_from_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ben Hughes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-01 00:00:00.000000000Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
- requirement: &70330927789240 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.3.2
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70330927789240
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.2
25
41
  - !ruby/object:Gem::Dependency
26
42
  name: rspec
27
- requirement: &70330927787800 !ruby/object:Gem::Requirement
28
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
29
44
  requirements:
30
- - - ~>
45
+ - - "~>"
31
46
  - !ruby/object:Gem::Version
32
47
  version: '2.0'
33
48
  type: :development
34
49
  prerelease: false
35
- version_requirements: *70330927787800
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
36
55
  - !ruby/object:Gem::Dependency
37
56
  name: sqlite3
38
- requirement: &70330927781040 !ruby/object:Gem::Requirement
39
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
40
58
  requirements:
41
- - - ~>
59
+ - - "~>"
42
60
  - !ruby/object:Gem::Version
43
61
  version: 1.3.4
44
62
  type: :development
45
63
  prerelease: false
46
- version_requirements: *70330927781040
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.4
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: appraisal
49
- requirement: &70330927779540 !ruby/object:Gem::Requirement
50
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
51
72
  requirements:
52
- - - ~>
73
+ - - "~>"
53
74
  - !ruby/object:Gem::Version
54
- version: 0.4.0
75
+ version: 1.0.2
55
76
  type: :development
56
77
  prerelease: false
57
- version_requirements: *70330927779540
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.17.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.17.1
58
97
  - !ruby/object:Gem::Dependency
59
98
  name: rdoc
60
- requirement: &70330927777720 !ruby/object:Gem::Requirement
61
- none: false
99
+ requirement: !ruby/object:Gem::Requirement
62
100
  requirements:
63
- - - ~>
101
+ - - "~>"
64
102
  - !ruby/object:Gem::Version
65
103
  version: '3.12'
66
104
  type: :development
67
105
  prerelease: false
68
- version_requirements: *70330927777720
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.12'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: rake
71
- requirement: &70330927776440 !ruby/object:Gem::Requirement
72
- none: false
113
+ requirement: !ruby/object:Gem::Requirement
73
114
  requirements:
74
- - - ! '>='
115
+ - - ">="
75
116
  - !ruby/object:Gem::Version
76
117
  version: '0'
77
118
  type: :development
78
119
  prerelease: false
79
- version_requirements: *70330927776440
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
80
125
  - !ruby/object:Gem::Dependency
81
126
  name: i18n
82
- requirement: &70330927774820 !ruby/object:Gem::Requirement
83
- none: false
127
+ requirement: !ruby/object:Gem::Requirement
84
128
  requirements:
85
- - - ! '>='
129
+ - - ">="
86
130
  - !ruby/object:Gem::Version
87
131
  version: '0'
88
132
  type: :development
89
133
  prerelease: false
90
- version_requirements: *70330927774820
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: iconv
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.0.3
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.0.3
91
153
  description: Introspects your database string field maximum lengths and automatically
92
154
  defines length validations.
93
155
  email: ben@railsgarden.com
@@ -95,44 +157,45 @@ executables: []
95
157
  extensions: []
96
158
  extra_rdoc_files: []
97
159
  files:
160
+ - Appraisals
161
+ - CHANGELOG
162
+ - Gemfile
163
+ - Gemfile.lock
164
+ - LICENSE
165
+ - README.rdoc
166
+ - Rakefile
167
+ - init.rb
168
+ - lib/validates_lengths_from_database.rb
98
169
  - lib/validates_lengths_from_database/railtie.rb
99
170
  - lib/validates_lengths_from_database/version.rb
100
- - lib/validates_lengths_from_database.rb
171
+ - rails/init.rb
101
172
  - spec/db/database.yml
102
173
  - spec/db/schema.rb
103
174
  - spec/db/test.sqlite3
104
175
  - spec/spec_helper.rb
105
176
  - spec/validates_lengths_from_database_spec.rb
106
- - rails/init.rb
107
- - Appraisals
108
- - Gemfile
109
- - Gemfile.lock
110
- - LICENSE
111
- - Rakefile
112
- - README.rdoc
113
- - init.rb
114
177
  homepage: http://github.com/rubiety/validates_lengths_from_database
115
178
  licenses: []
179
+ metadata: {}
116
180
  post_install_message:
117
181
  rdoc_options: []
118
182
  require_paths:
119
183
  - lib
120
184
  required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
185
  requirements:
123
- - - ! '>='
186
+ - - ">="
124
187
  - !ruby/object:Gem::Version
125
188
  version: '0'
126
189
  required_rubygems_version: !ruby/object:Gem::Requirement
127
- none: false
128
190
  requirements:
129
- - - ! '>='
191
+ - - ">="
130
192
  - !ruby/object:Gem::Version
131
193
  version: 1.3.4
132
194
  requirements: []
133
195
  rubyforge_project: validates_lengths_from_database
134
- rubygems_version: 1.8.10
196
+ rubygems_version: 2.2.2
135
197
  signing_key:
136
- specification_version: 3
198
+ specification_version: 4
137
199
  summary: Automatic maximum-length validations.
138
200
  test_files: []
201
+ has_rdoc: