minitest-ar-assertions 0.0.4 → 0.1.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/VERSION +1 -1
- data/lib/minitest_activerecord_assertions.rb +24 -0
- data/minitest-ar-assertions.gemspec +3 -3
- data/test/test_minitest_activerecord_assertions.rb +29 -0
- metadata +11 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -37,6 +37,30 @@ module MiniTest
|
|
37
37
|
end
|
38
38
|
assert has_validator, "#{clazz} does not validate_uniqueness_of #{attributes}"
|
39
39
|
end
|
40
|
+
|
41
|
+
def assert_validates_numericality_of(clazz, attribute, options = {})
|
42
|
+
assert_includes clazz._validators[attribute].map{ |v| v.class },
|
43
|
+
::ActiveModel::Validations::NumericalityValidator,
|
44
|
+
"#{clazz} does not validate_numericality_of #{attribute}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def assert_validates_inclusion_of(clazz, attribute, options = {})
|
48
|
+
validators = clazz._validators[attribute]
|
49
|
+
refute validators.empty?, "#{clazz} does not have validations for #{attribute}"
|
50
|
+
inclusion_validator = ::ActiveModel::Validations::InclusionValidator
|
51
|
+
validator_classes = validators.map { |v| v.class }
|
52
|
+
|
53
|
+
if options.size > 0
|
54
|
+
index = validators.index {|c| c if c.class == ActiveModel::Validations::InclusionValidator }
|
55
|
+
validator = validators[index]
|
56
|
+
assert validator_classes.include?(inclusion_validator) && validator.options == options,
|
57
|
+
"#{clazz} does not validate_inclusion_of #{attribute} with options #{options}"
|
58
|
+
|
59
|
+
else
|
60
|
+
assert validator_classes.include?(inclusion_validator),
|
61
|
+
"#{clazz} does not validate_inclusion_of #{attribute}"
|
62
|
+
end
|
63
|
+
end
|
40
64
|
|
41
65
|
end
|
42
66
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "minitest-ar-assertions"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Steve Laing"]
|
12
|
-
s.date = "
|
11
|
+
s.authors = ["Steve Laing", "Stahelin Ismael"]
|
12
|
+
s.date = "2013-07-11"
|
13
13
|
s.description = "A collection of assertions for use with minitest and activerecord. Simplifies testing associations and validations by introspecting associations and validations for you models."
|
14
14
|
s.email = "steve.laing@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -11,11 +11,13 @@ class User < ActiveRecord::Base
|
|
11
11
|
has_many :likes, :as => :likeable
|
12
12
|
validates_presence_of :email
|
13
13
|
validates_uniqueness_of :username, :email
|
14
|
+
validates_inclusion_of :can_like, :in => [true, false]
|
14
15
|
end
|
15
16
|
|
16
17
|
class Like < ActiveRecord::Base
|
17
18
|
belongs_to :likeable, :polymorphic => true
|
18
19
|
belongs_to :user
|
20
|
+
validates_numericality_of :user_id
|
19
21
|
validates_presence_of :email
|
20
22
|
validates_uniqueness_of :username, :email
|
21
23
|
end
|
@@ -64,3 +66,30 @@ describe "assert_validates_uniqueness_of assertion" do
|
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
69
|
+
describe "assert_validates_numericality_of assertion" do
|
70
|
+
it "should fail for models with no validations" do
|
71
|
+
assert_raises MiniTest::Assertion do
|
72
|
+
assert_validates_numericality_of UnvalidatedThing, :user_id
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should pass for models with validates_numericality_of validations" do
|
77
|
+
assert assert_validates_numericality_of(Like, :user_id)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "assert_validates_inclusion_of assertion" do
|
82
|
+
it "should fail for models with no validations" do
|
83
|
+
assert_raises MiniTest::Assertion do
|
84
|
+
assert_validates_inclusion_of UnvalidatedThing, :can_like, :in => [true, false]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should pass for models with validates_inclusion_of validations" do
|
89
|
+
assert assert_validates_inclusion_of(User, :can_like)
|
90
|
+
assert assert_validates_inclusion_of(User, :can_like, :in => [true, false])
|
91
|
+
assert_raises MiniTest::Assertion do
|
92
|
+
assert_validates_inclusion_of(User, :can_like, :in => [true, true])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-ar-assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Steve Laing
|
9
|
+
- Stahelin Ismael
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rdoc
|
16
|
-
requirement: &
|
17
|
+
requirement: &82688240 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
@@ -21,10 +22,10 @@ dependencies:
|
|
21
22
|
version: '3.12'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *82688240
|
25
26
|
- !ruby/object:Gem::Dependency
|
26
27
|
name: bundler
|
27
|
-
requirement: &
|
28
|
+
requirement: &82687590 !ruby/object:Gem::Requirement
|
28
29
|
none: false
|
29
30
|
requirements:
|
30
31
|
- - ~>
|
@@ -32,10 +33,10 @@ dependencies:
|
|
32
33
|
version: 1.0.0
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
+
version_requirements: *82687590
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
name: jeweler
|
38
|
-
requirement: &
|
39
|
+
requirement: &82686950 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
42
|
- - ~>
|
@@ -43,10 +44,10 @@ dependencies:
|
|
43
44
|
version: 1.8.3
|
44
45
|
type: :development
|
45
46
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
+
version_requirements: *82686950
|
47
48
|
- !ruby/object:Gem::Dependency
|
48
49
|
name: activerecord
|
49
|
-
requirement: &
|
50
|
+
requirement: &82685990 !ruby/object:Gem::Requirement
|
50
51
|
none: false
|
51
52
|
requirements:
|
52
53
|
- - ! '>='
|
@@ -54,7 +55,7 @@ dependencies:
|
|
54
55
|
version: '0'
|
55
56
|
type: :development
|
56
57
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
+
version_requirements: *82685990
|
58
59
|
description: A collection of assertions for use with minitest and activerecord. Simplifies
|
59
60
|
testing associations and validations by introspecting associations and validations
|
60
61
|
for you models.
|