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 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 definitely a work in progress. I use this gem in two of my applications and will continue to add stuff to it, as well as fixing bugs._
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
@@ -5,6 +5,7 @@ class HelperExtension
5
5
  attr_accessor :current_methods, :output_buffer
6
6
 
7
7
  def initialize(name)
8
+ @output_buffer = ''
8
9
  @current_methods ||= []
9
10
  # Remove existing instance methods.
10
11
  @current_methods.each do |method_name|
@@ -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(attribute_name)
6
- it "validates_presence_of :#{attribute_name.to_s.parameterize.underscore}" do
7
- subject.send "#{attribute_name}=".to_sym, nil
8
- subject.valid?.must_equal false
9
- subject.errors.messages[attribute_name.to_sym].must_include "can't be blank"
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
- def must_validate_uniqueness_of(attribute_name)
14
- it "validates_uniqueness_of :#{attribute_name.to_s.parameterize.underscore}" do
15
- other = subject.class.new
16
- other.send "#{attribute_name}=".to_sym, subject.send(attribute_name)
17
- other.valid?.must_equal false
18
- other.errors.messages[attribute_name.to_sym].must_include "has already been taken"
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
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-15 00:00:00.000000000 Z
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/b4mboo/minitest_rails_tools
27
+ homepage: http://github.com/openSUSE/minitest_rails_tools
28
28
  licenses: []
29
29
  post_install_message:
30
30
  rdoc_options: []