auto_validations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ vendor/*
5
+ tmp/*
6
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lenghtbot.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "auto_validations/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "auto_validations"
7
+ s.version = AutoValidations::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Rodrigo Navarro', 'Guilherme Ceolin']
10
+ s.email = ['rnavarro1@gmail.com', 'guiceolin@gmail.com']
11
+ s.homepage = ""
12
+ s.summary = %q{Auto generate validations for your models}
13
+ s.description = %q{Extract validations from your database information}
14
+
15
+ s.rubyforge_project = "auto_validations"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'activerecord', '~> 3'
23
+
24
+ s.add_development_dependency 'sqlite3-ruby', '~> 1.3'
25
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'active_record'
4
+
5
+ module AutoValidations
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def auto_length_validation
10
+ columns.each do |column|
11
+ validates_length_of column.name, :maximum => column.limit if column.limit
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class ActiveRecord::Base
18
+ include AutoValidations
19
+ end
@@ -0,0 +1,3 @@
1
+ module AutoValidations
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class AboveLengthValidationsTest < Test::Unit::TestCase
4
+ def setup
5
+ Android.auto_length_validation
6
+
7
+ @android = Android.new :name => 'A Very big name indeed',
8
+ :description => 'Fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu',
9
+ :number => 115
10
+ end
11
+
12
+ def test_should_add_errors_to_the_name_field
13
+ assert @android.invalid?
14
+ assert_not_nil @android.errors[:name]
15
+ end
16
+
17
+ def test_should_add_errors_to_the_descriptiom_field
18
+ assert @android.invalid?
19
+ assert_not_nil @android.errors[:description]
20
+ end
21
+
22
+ def test_should_add_errors_to_the_number_field
23
+ assert @android.invalid?
24
+ assert_not_nil @android.errors[:number]
25
+ end
26
+ end
27
+
28
+ class BelowLengthValidationsTest < Test::Unit::TestCase
29
+ def setup
30
+ Android.auto_length_validation
31
+
32
+ @android = Android.new :name => 'Android',
33
+ :description => 'DBZ character',
34
+ :number => 16
35
+ end
36
+
37
+ def test_should_be_valid
38
+ assert @android.valid?
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: ":memory:"
@@ -0,0 +1,2 @@
1
+ class Android < ActiveRecord::Base
2
+ end
@@ -0,0 +1,7 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :androids, :force => true do |t|
3
+ t.string :name, :limit => 10
4
+ t.text :description, :limit => 40
5
+ t.integer :number, :limit => 2
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'test/unit'
4
+ require 'active_record'
5
+
6
+ require File.dirname(__FILE__) + '/../lib/auto_validations'
7
+
8
+ config = YAML.load_file File.join(File.dirname(__FILE__), 'support', 'database.yml')
9
+ ActiveRecord::Base.establish_connection config[ENV['DB'] || 'sqlite3']
10
+
11
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_validations
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Rodrigo Navarro
14
+ - Guilherme Ceolin
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-05-12 00:00:00 -03:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: activerecord
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 5
31
+ segments:
32
+ - 3
33
+ version: "3"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3-ruby
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 9
45
+ segments:
46
+ - 1
47
+ - 3
48
+ version: "1.3"
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Extract validations from your database information
52
+ email:
53
+ - rnavarro1@gmail.com
54
+ - guiceolin@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Rakefile
65
+ - auto_validations.gemspec
66
+ - lib/auto_validations.rb
67
+ - lib/auto_validations/version.rb
68
+ - test/auto_length_test.rb
69
+ - test/support/database.yml
70
+ - test/support/models.rb
71
+ - test/support/schema.rb
72
+ - test/test_helper.rb
73
+ has_rdoc: true
74
+ homepage: ""
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: auto_validations
103
+ rubygems_version: 1.5.0
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Auto generate validations for your models
107
+ test_files:
108
+ - test/auto_length_test.rb
109
+ - test/support/database.yml
110
+ - test/support/models.rb
111
+ - test/support/schema.rb
112
+ - test/test_helper.rb