whyvalidationssuckin96 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +9 -3
- data/VERSION +1 -1
- data/lib/whyvalidationssuckin96/test/riot.rb +46 -0
- data/lib/whyvalidationssuckin96/validation_builder.rb +2 -0
- data/test/riot/macros_test.rb +51 -0
- data/test/validation_builder_test.rb +13 -0
- data/whyvalidationssuckin96.gemspec +5 -2
- metadata +5 -2
data/Rakefile
CHANGED
@@ -20,9 +20,15 @@ rescue LoadError
|
|
20
20
|
end
|
21
21
|
|
22
22
|
require 'rake/testtask'
|
23
|
-
Rake::TestTask.new(:
|
23
|
+
Rake::TestTask.new(:test_core) do |test|
|
24
24
|
test.libs << 'lib' << 'test'
|
25
|
-
test.test_files = FileList['test/**/*_test.rb'].exclude("test/rails/**/*_test.rb")
|
25
|
+
test.test_files = FileList['test/**/*_test.rb'].exclude("test/{rails,riot}/**/*_test.rb")
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test_riot) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.test_files = FileList["test/riot/**/*_test.rb"]
|
26
32
|
test.verbose = true
|
27
33
|
end
|
28
34
|
|
@@ -32,7 +38,7 @@ Rake::TestTask.new(:test_rails) do |test|
|
|
32
38
|
test.verbose = true
|
33
39
|
end
|
34
40
|
|
35
|
-
task :test => [:check_dependencies, :
|
41
|
+
task :test => [:check_dependencies, :test_core, :test_riot, :test_rails]
|
36
42
|
task :default => :test
|
37
43
|
|
38
44
|
begin
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module WhyValidationsSuckIn96
|
2
|
+
module Test
|
3
|
+
module Riot
|
4
|
+
class ValidationAssertionMacro < ::Riot::AssertionMacro
|
5
|
+
class << self
|
6
|
+
attr_accessor :validation_macro_name
|
7
|
+
end
|
8
|
+
|
9
|
+
WhyValidationsSuckIn96::ValidationBuilder::RegisteredMacros.keys.each do |macro_name|
|
10
|
+
Class.new(self) do
|
11
|
+
self.validation_macro_name = macro_name
|
12
|
+
register macro_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def evaluate(model, *validation_args)
|
17
|
+
attribute, options = validation_args
|
18
|
+
if has_validation?(model, attribute, options || {})
|
19
|
+
pass("#{model} #{validation_macro_name} #{attribute}")
|
20
|
+
else
|
21
|
+
fail("expected #{model} to #{validation_macro_name} #{attribute}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def validation_macro_name
|
26
|
+
self.class.validation_macro_name
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def has_validation?(klass, attribute, validation_opts)
|
32
|
+
v_klass = WhyValidationsSuckIn96::ValidationBuilder::RegisteredMacros[validation_macro_name]
|
33
|
+
raise "No registered validation exists for #{validation_macro_name}" unless v_klass
|
34
|
+
klass.validation_collection.any? do |(vc,opts)|
|
35
|
+
vc == v_klass && opts.all? do |k,v|
|
36
|
+
# @todo - this is a hack to skip the attribute based validation options
|
37
|
+
next(true) if k == :attribute && v == attribute
|
38
|
+
validation_opts[k] == v
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end # ValidationAssertionMacro
|
44
|
+
end # Riot
|
45
|
+
end # Test
|
46
|
+
end # WhyValidationsSuckIn96
|
@@ -2,6 +2,7 @@ require 'whyvalidationssuckin96/validation'
|
|
2
2
|
|
3
3
|
module WhyValidationsSuckIn96
|
4
4
|
class ValidationBuilder
|
5
|
+
RegisteredMacros = {}
|
5
6
|
|
6
7
|
# @param [Module, Class] klass_or_mod The Class or Module to add validations to
|
7
8
|
# @param [Proc] definition_block The block to evaluate to define validations
|
@@ -18,6 +19,7 @@ module WhyValidationsSuckIn96
|
|
18
19
|
# @param [Symbol] macro_name The name to register this macro with
|
19
20
|
# @param [Class] validation_class The class implementing the validation
|
20
21
|
def self.register_macro(macro_name, validation_class)
|
22
|
+
RegisteredMacros[macro_name] = validation_class
|
21
23
|
define_method(macro_name) do |*args|
|
22
24
|
attrs, options = extract_options(args)
|
23
25
|
attrs.each do |attr|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
require 'whyvalidationssuckin96/test/riot'
|
3
|
+
|
4
|
+
context "validation macro assertions" do
|
5
|
+
|
6
|
+
context "being registered" do
|
7
|
+
setup do
|
8
|
+
WhyValidationsSuckIn96::ValidationBuilder::RegisteredMacros
|
9
|
+
end
|
10
|
+
|
11
|
+
should "actually have more than one registered macro to ensure these tests are valid" do
|
12
|
+
topic.size > 1
|
13
|
+
end
|
14
|
+
|
15
|
+
should "add a riot assertion macro for each registered validation" do
|
16
|
+
WhyValidationsSuckIn96::ValidationBuilder::RegisteredMacros.keys.all? do |k|
|
17
|
+
Riot::Assertion.macros.has_key?(k.to_s)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end # being registered
|
21
|
+
|
22
|
+
context "asserting against a class" do
|
23
|
+
setup do
|
24
|
+
klass = Class.new do
|
25
|
+
include WhyValidationsSuckIn96::ValidationSupport
|
26
|
+
setup_validations do
|
27
|
+
validates_format_of :foo, :with => /[a-z]/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Riot::Assertion.new("test") { klass }
|
32
|
+
end
|
33
|
+
|
34
|
+
should "fail if there's no validation against the specified attribute" do
|
35
|
+
topic.validates_format_of(:ministry).run(Riot::Situation.new).first
|
36
|
+
end.equals(:fail)
|
37
|
+
|
38
|
+
should "fail if there's a validation against the specified attribute but no options are specified" do
|
39
|
+
topic.validates_format_of(:foo).run(Riot::Situation.new).first
|
40
|
+
end.equals(:fail)
|
41
|
+
|
42
|
+
should "fail if there's a validation against the specified attribute but bad options are specified" do
|
43
|
+
topic.validates_format_of(:foo, :with => //).run(Riot::Situation.new).first
|
44
|
+
end.equals(:fail)
|
45
|
+
|
46
|
+
should "pass if there's a validation against the specified attribute and good options are specified" do
|
47
|
+
topic.validates_format_of(:foo, :with => /[a-z]/).run(Riot::Situation.new).first
|
48
|
+
end.equals(:pass)
|
49
|
+
|
50
|
+
end # asserting against a class
|
51
|
+
end # validation macro assertions
|
@@ -59,4 +59,17 @@ context "validation builder" do
|
|
59
59
|
end.equals(1)
|
60
60
|
|
61
61
|
end # when defining multiple validations with the same name in the one validation definition
|
62
|
+
|
63
|
+
context "register_macro" do
|
64
|
+
should "add a key to the registered macros constant" do
|
65
|
+
WhyValidationsSuckIn96::ValidationBuilder.register_macro(:this_is_a_test_macro, Class.new)
|
66
|
+
WhyValidationsSuckIn96::ValidationBuilder::RegisteredMacros.has_key?(:this_is_a_test_macro)
|
67
|
+
end
|
68
|
+
|
69
|
+
should "store the validation class in the registered macros constant" do
|
70
|
+
klass = Class.new
|
71
|
+
WhyValidationsSuckIn96::ValidationBuilder.register_macro(:this_is_another_test_macro, klass)
|
72
|
+
WhyValidationsSuckIn96::ValidationBuilder::RegisteredMacros[:this_is_another_test_macro].object_id == klass.object_id
|
73
|
+
end
|
74
|
+
end # register_macro
|
62
75
|
end # validation builder
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{whyvalidationssuckin96}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["gabrielg", "douglasmeyer"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-30}
|
13
13
|
s.description = %q{A library for setting up model validations, such as in ActiveRecord.}
|
14
14
|
s.email = %q{gabriel.gironda@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -90,6 +90,7 @@ Gem::Specification.new do |s|
|
|
90
90
|
"lib/whyvalidationssuckin96/rails/macros.rb",
|
91
91
|
"lib/whyvalidationssuckin96/rails/macros/validates_uniqueness.rb",
|
92
92
|
"lib/whyvalidationssuckin96/skippable_validation.rb",
|
93
|
+
"lib/whyvalidationssuckin96/test/riot.rb",
|
93
94
|
"lib/whyvalidationssuckin96/validation.rb",
|
94
95
|
"lib/whyvalidationssuckin96/validation_builder.rb",
|
95
96
|
"lib/whyvalidationssuckin96/validation_collection.rb",
|
@@ -111,6 +112,7 @@ Gem::Specification.new do |s|
|
|
111
112
|
"test/rails/association_validation_test.rb",
|
112
113
|
"test/rails/base_validation_overrides_test.rb",
|
113
114
|
"test/rails/macros/validates_uniqueness_test.rb",
|
115
|
+
"test/riot/macros_test.rb",
|
114
116
|
"test/skippable_validation_test.rb",
|
115
117
|
"test/teststrap.rb",
|
116
118
|
"test/validation_builder_test.rb",
|
@@ -141,6 +143,7 @@ Gem::Specification.new do |s|
|
|
141
143
|
"test/rails/association_validation_test.rb",
|
142
144
|
"test/rails/base_validation_overrides_test.rb",
|
143
145
|
"test/rails/macros/validates_uniqueness_test.rb",
|
146
|
+
"test/riot/macros_test.rb",
|
144
147
|
"test/skippable_validation_test.rb",
|
145
148
|
"test/teststrap.rb",
|
146
149
|
"test/validation_builder_test.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whyvalidationssuckin96
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gabrielg
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-01-
|
13
|
+
date: 2010-01-30 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/whyvalidationssuckin96/rails/macros.rb
|
127
127
|
- lib/whyvalidationssuckin96/rails/macros/validates_uniqueness.rb
|
128
128
|
- lib/whyvalidationssuckin96/skippable_validation.rb
|
129
|
+
- lib/whyvalidationssuckin96/test/riot.rb
|
129
130
|
- lib/whyvalidationssuckin96/validation.rb
|
130
131
|
- lib/whyvalidationssuckin96/validation_builder.rb
|
131
132
|
- lib/whyvalidationssuckin96/validation_collection.rb
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- test/rails/association_validation_test.rb
|
148
149
|
- test/rails/base_validation_overrides_test.rb
|
149
150
|
- test/rails/macros/validates_uniqueness_test.rb
|
151
|
+
- test/riot/macros_test.rb
|
150
152
|
- test/skippable_validation_test.rb
|
151
153
|
- test/teststrap.rb
|
152
154
|
- test/validation_builder_test.rb
|
@@ -199,6 +201,7 @@ test_files:
|
|
199
201
|
- test/rails/association_validation_test.rb
|
200
202
|
- test/rails/base_validation_overrides_test.rb
|
201
203
|
- test/rails/macros/validates_uniqueness_test.rb
|
204
|
+
- test/riot/macros_test.rb
|
202
205
|
- test/skippable_validation_test.rb
|
203
206
|
- test/teststrap.rb
|
204
207
|
- test/validation_builder_test.rb
|