jnunemaker-validatable 1.8.2 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@ module Validatable
20
20
  end
21
21
 
22
22
  # call-seq: on(attribute)
23
- #
23
+ #
24
24
  # * Returns nil, if no errors are associated with the specified +attribute+.
25
25
  # * Returns the error message, if one error is associated with the specified +attribute+.
26
26
  # * Returns an array of error messages, if more than one error is associated with the specified +attribute+.
@@ -28,8 +28,11 @@ module Validatable
28
28
  return nil if errors[attribute.to_sym].nil?
29
29
  errors[attribute.to_sym].size == 1 ? errors[attribute.to_sym].first : errors[attribute.to_sym]
30
30
  end
31
-
32
- alias [] on
31
+
32
+ # Rails 3 API for errors, always return array.
33
+ def [](attribute)
34
+ errors[attribute.to_sym] || []
35
+ end
33
36
 
34
37
  def add(attribute, message) #:nodoc:
35
38
  errors[attribute.to_sym] = [] if errors[attribute.to_sym].nil?
@@ -42,19 +45,19 @@ module Validatable
42
45
  end
43
46
 
44
47
  # call-seq: replace(attribute)
45
- #
48
+ #
46
49
  # * Replaces the errors value for the given +attribute+
47
50
  def replace(attribute, value)
48
51
  errors[attribute.to_sym] = value
49
52
  end
50
53
 
51
54
  # call-seq: raw(attribute)
52
- #
55
+ #
53
56
  # * Returns an array of error messages associated with the specified +attribute+.
54
57
  def raw(attribute)
55
58
  errors[attribute.to_sym]
56
59
  end
57
-
60
+
58
61
  def errors #:nodoc:
59
62
  @errors ||= {}
60
63
  end
@@ -64,7 +67,7 @@ module Validatable
64
67
  end
65
68
 
66
69
  # call-seq: full_messages -> an_array_of_messages
67
- #
70
+ #
68
71
  # Returns an array containing the full list of error messages.
69
72
  def full_messages
70
73
  full_messages = []
@@ -82,7 +85,7 @@ module Validatable
82
85
  end
83
86
  full_messages
84
87
  end
85
-
88
+
86
89
  def humanize(lower_case_and_underscored_word) #:nodoc:
87
90
  lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
88
91
  end
data/lib/validatable.rb CHANGED
@@ -24,5 +24,5 @@ require 'validatable/validations/validates_each'
24
24
  require 'validatable/validations/validates_associated'
25
25
 
26
26
  module Validatable
27
- Version = '1.8.2'
27
+ Version = '1.8.3'
28
28
  end
@@ -62,9 +62,21 @@ Expectations do
62
62
  errors.count
63
63
  end
64
64
 
65
- expect "message" do
65
+ expect [] do
66
+ errors = Validatable::Errors.new
67
+ errors[:attribute]
68
+ end
69
+
70
+ expect ["message"] do
66
71
  errors = Validatable::Errors.new
67
72
  errors.add(:attribute, "message")
68
73
  errors[:attribute]
69
74
  end
75
+
76
+ expect ["message1", "message2"] do
77
+ errors = Validatable::Errors.new
78
+ errors.add(:attribute, "message1")
79
+ errors.add(:attribute, "message2")
80
+ errors[:attribute]
81
+ end
70
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-validatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Fields
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-28 00:00:00 -05:00
13
+ date: 2010-03-01 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies: []
16
16