table_warnings 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/table_warnings/version.rb +1 -1
- data/lib/table_warnings/warning/arbitrary.rb +13 -0
- data/lib/table_warnings/warning.rb +1 -0
- data/lib/table_warnings.rb +6 -0
- data/table_warnings.gemspec +6 -2
- data/test/helper.rb +7 -2
- data/test/test_table_warnings.rb +29 -8
- metadata +35 -12
data/lib/table_warnings.rb
CHANGED
@@ -37,6 +37,12 @@ module TableWarnings
|
|
37
37
|
warning = ::TableWarnings::Warning::Size.new :table => self, :approximate_size => approximate_size
|
38
38
|
::TableWarnings.config.warnings[self].add warning
|
39
39
|
end
|
40
|
+
|
41
|
+
# An arbitrary warning.
|
42
|
+
def warn(&blk)
|
43
|
+
warning = ::TableWarnings::Warning::Arbitrary.new :table => self, :blk => blk
|
44
|
+
::TableWarnings.config.warnings[self].add warning
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
unless ::ActiveRecord::Base.method_defined? :table_warnings
|
data/table_warnings.gemspec
CHANGED
@@ -18,7 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'activerecord'
|
23
|
+
|
21
24
|
s.add_development_dependency 'fastercsv'
|
22
|
-
s.add_development_dependency '
|
23
|
-
s.
|
25
|
+
s.add_development_dependency 'rake'
|
26
|
+
s.add_development_dependency 'mini_record'
|
27
|
+
s.add_development_dependency 'sqlite3'
|
24
28
|
end
|
data/test/helper.rb
CHANGED
@@ -4,6 +4,7 @@ Bundler.setup
|
|
4
4
|
require 'test/unit'
|
5
5
|
require 'active_support/all'
|
6
6
|
require 'active_record'
|
7
|
+
require 'mini_record'
|
7
8
|
# thanks authlogic!
|
8
9
|
ActiveRecord::Schema.verbose = false
|
9
10
|
begin
|
@@ -11,8 +12,12 @@ begin
|
|
11
12
|
rescue ArgumentError
|
12
13
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
13
14
|
end
|
14
|
-
|
15
|
-
|
15
|
+
|
16
|
+
# require 'logger'
|
17
|
+
# logger = Logger.new $stdout
|
18
|
+
# logger.level = Logger::DEBUG
|
19
|
+
# ActiveRecord::Base.logger = logger
|
20
|
+
|
16
21
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
22
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
23
|
require 'table_warnings'
|
data/test/test_table_warnings.rb
CHANGED
@@ -1,18 +1,33 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class AutomobileMake < ActiveRecord::Base
|
4
|
+
col :name
|
5
|
+
col :fuel_efficiency, :type => :float
|
6
|
+
col :fuel_efficiency_units
|
7
|
+
|
4
8
|
warn_if_blanks_in :name
|
5
9
|
warn_if_blanks_in :fuel_efficiency
|
6
10
|
warn_unless_size_is :hundreds
|
7
|
-
|
11
|
+
warn do
|
12
|
+
if exists? ['fuel_efficiency < ?', 0]
|
13
|
+
"That's a strange looking fuel efficiency"
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
18
|
class AutomobileFuelType < ActiveRecord::Base
|
19
|
+
col :name
|
20
|
+
col :code
|
21
|
+
col :fuel_efficiency, :type => :float
|
22
|
+
col :fuel_efficiency_units
|
23
|
+
|
11
24
|
warn_if_any_blanks
|
12
|
-
warn_unless_size_is :few
|
13
25
|
warn_unless_size_is 1..6
|
14
26
|
end
|
15
27
|
|
28
|
+
AutomobileMake.auto_upgrade!
|
29
|
+
AutomobileFuelType.auto_upgrade!
|
30
|
+
|
16
31
|
class TestTableWarnings < Test::Unit::TestCase
|
17
32
|
def setup
|
18
33
|
AutomobileMake.delete_all
|
@@ -22,22 +37,28 @@ class TestTableWarnings < Test::Unit::TestCase
|
|
22
37
|
def test_001_warn_for_blanks_in_specific_columns
|
23
38
|
AutomobileMake.create! :name => ' ', :fuel_efficiency => nil, :fuel_efficiency_units => 'kilometres_per_litre'
|
24
39
|
AutomobileMake.create! :name => 'Alfa Romeo', :fuel_efficiency => 10.4075, :fuel_efficiency_units => 'kilometres_per_litre'
|
25
|
-
assert AutomobileMake.table_warnings.one? { |w| w =~ /blanks
|
26
|
-
assert AutomobileMake.table_warnings.one? { |w| w =~ /blanks
|
40
|
+
assert AutomobileMake.table_warnings.one? { |w| w =~ /blanks.*name.*column/ }
|
41
|
+
assert AutomobileMake.table_warnings.one? { |w| w =~ /blanks.*fuel_efficiency.*column/ }
|
27
42
|
end
|
28
43
|
|
29
44
|
def test_002_warn_of_size
|
30
|
-
|
31
|
-
assert
|
45
|
+
assert AutomobileMake.table_warnings.one? { |w| w =~ /expected.*100\.\.1000/ }
|
46
|
+
assert AutomobileFuelType.table_warnings.one? { |w| w =~ /expected.*1\.\.6/ }
|
32
47
|
end
|
33
48
|
|
34
49
|
def test_003_warn_for_blanks_in_any_column
|
35
50
|
AutomobileFuelType.create! :name => 'gas'
|
36
|
-
assert AutomobileFuelType.table_warnings.one? { |w| w =~ /blanks
|
51
|
+
assert AutomobileFuelType.table_warnings.one? { |w| w =~ /blanks.*code.*column/ }
|
52
|
+
assert AutomobileFuelType.table_warnings.many? { |w| w =~ /blanks.*fuel_efficiency.*column/ }
|
37
53
|
end
|
38
54
|
|
39
55
|
def test_004_dont_treat_0_as_blank
|
40
56
|
AutomobileMake.create! :name => 'Acme', :fuel_efficiency => 0
|
41
|
-
assert !AutomobileMake.table_warnings.any? { |w| w =~ /blanks
|
57
|
+
assert !AutomobileMake.table_warnings.any? { |w| w =~ /blanks.*fuel_efficiency.*column/ }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_005_warn_if_arbitrary_block
|
61
|
+
AutomobileMake.create! :name => 'Acme', :fuel_efficiency => -5
|
62
|
+
assert AutomobileMake.table_warnings.one? { |w| w =~ /strange looking fuel efficiency/ }
|
42
63
|
end
|
43
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_warnings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &2154426760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154426760
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: fastercsv
|
16
|
-
requirement: &
|
27
|
+
requirement: &2154426340 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *2154426340
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
37
|
+
name: rake
|
38
|
+
requirement: &2154425920 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,18 +43,29 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *2154425920
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
48
|
+
name: mini_record
|
49
|
+
requirement: &2154425500 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
42
53
|
- !ruby/object:Gem::Version
|
43
54
|
version: '0'
|
44
|
-
type: :
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2154425500
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: sqlite3
|
60
|
+
requirement: &2154425080 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
45
67
|
prerelease: false
|
46
|
-
version_requirements: *
|
68
|
+
version_requirements: *2154425080
|
47
69
|
description: Validate an entire [ActiveRecord] table, checking for things like blank
|
48
70
|
rows or total number of rows
|
49
71
|
email:
|
@@ -60,6 +82,7 @@ files:
|
|
60
82
|
- lib/table_warnings/config.rb
|
61
83
|
- lib/table_warnings/version.rb
|
62
84
|
- lib/table_warnings/warning.rb
|
85
|
+
- lib/table_warnings/warning/arbitrary.rb
|
63
86
|
- lib/table_warnings/warning/blank.rb
|
64
87
|
- lib/table_warnings/warning/size.rb
|
65
88
|
- table_warnings.gemspec
|
@@ -85,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
108
|
version: '0'
|
86
109
|
requirements: []
|
87
110
|
rubyforge_project: table_warnings
|
88
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.6
|
89
112
|
signing_key:
|
90
113
|
specification_version: 3
|
91
114
|
summary: It's called validations to remind people of per-record validations, but it
|