minitest_rails_tools 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/helper_extension.rb +1 -0
- data/lib/validation_matchers.rb +36 -11
- metadata +3 -3
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
This is a collection of little helpers to make working with Rails and Minitest a bit easier.
|
5
5
|
|
6
|
-
_NOTE: This is
|
6
|
+
_NOTE: This is a work in progress. I'm using this gem in two of my applications and I'm going to continue to add stuff to it, as well as fixing bugs._
|
7
7
|
|
8
8
|
|
9
9
|
## Installation
|
data/lib/helper_extension.rb
CHANGED
data/lib/validation_matchers.rb
CHANGED
@@ -2,19 +2,44 @@
|
|
2
2
|
# Expects 'subject' to be defined. E.g.
|
3
3
|
# subject { FactoryGirl.create :foo }
|
4
4
|
|
5
|
-
def must_validate_presence_of(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def must_validate_presence_of(attribute, options = {})
|
6
|
+
spec(__method__, attribute, options, "can't be blank", nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
def must_validate_uniqueness_of(attribute, options = {})
|
10
|
+
spec(__method__, attribute, options, "has already been taken", :not_uniq) do
|
11
|
+
other_instance = self.to_s.rstrip.constantize.new
|
12
|
+
other_instance.send "#{attribute}=".to_sym, :not_uniq
|
13
|
+
other_instance.save!(:validate => false)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def must_validate_length_of(attribute, options = {})
|
18
|
+
if options[:minimum]
|
19
|
+
spec(
|
20
|
+
__method__, attribute, options.except(:maximum),
|
21
|
+
"is too short (minimum is #{options[:minimum]}", (0..options[:minimum] - 1).to_a
|
22
|
+
)
|
23
|
+
end
|
24
|
+
if options[:maximum]
|
25
|
+
spec(
|
26
|
+
__method__, attribute, options.except(:minimum),
|
27
|
+
"is too long (maximum is #{options[:maximum]}", (0..options[:maximum] + 1).to_a
|
28
|
+
)
|
10
29
|
end
|
11
30
|
end
|
12
31
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def spec(name, attribute, options, default_message, value)
|
36
|
+
title = "#{name.to_s[4..-1]} :#{attribute.to_s.parameterize.underscore}"
|
37
|
+
title += options.to_s[1..-2].gsub('=>', ' => ') unless options.blank?
|
38
|
+
it title do
|
39
|
+
yield if block_given?
|
40
|
+
subject.send "#{attribute}=".to_sym, value
|
41
|
+
subject.wont_be :valid?
|
42
|
+
message = options[:message] || default_message
|
43
|
+
subject.errors.messages[attribute.to_sym].must_include message
|
19
44
|
end
|
20
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest_rails_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A collection of little helpers to make working with Rails and Minitest
|
15
15
|
a bit easier.
|
@@ -24,7 +24,7 @@ files:
|
|
24
24
|
- lib/helper_extension.rb
|
25
25
|
- lib/association_matchers.rb
|
26
26
|
- lib/validation_matchers.rb
|
27
|
-
homepage: http://github.com/
|
27
|
+
homepage: http://github.com/openSUSE/minitest_rails_tools
|
28
28
|
licenses: []
|
29
29
|
post_install_message:
|
30
30
|
rdoc_options: []
|