custom_error_message 1.1.0.pre2 → 1.1.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/custom_error_message.gemspec +2 -2
- data/lib/rails/extensions/active_record.rb +12 -2
- data/spec/custom_error_message_spec.rb +19 -9
- data/spec/db/schema.rb +1 -1
- metadata +4 -4
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'custom_error_message'
|
5
|
-
s.version = "1.1.0.
|
5
|
+
s.version = "1.1.0.pre3"
|
6
6
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["David Easley", "Jeremy Durham"]
|
@@ -16,4 +16,4 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.require_paths = ["lib"]
|
19
|
-
end
|
19
|
+
end
|
@@ -4,11 +4,21 @@ module ActiveRecord
|
|
4
4
|
protected
|
5
5
|
|
6
6
|
def generate_full_message(options = {})
|
7
|
+
keys = [
|
8
|
+
:"full_messages.#{@message}",
|
9
|
+
:'full_messages.format'
|
10
|
+
]
|
11
|
+
|
7
12
|
if self.message =~ /^\^/
|
8
|
-
keys
|
13
|
+
keys.push('{{message}}')
|
14
|
+
|
9
15
|
options.merge!(:default => self.message[1..-1])
|
10
|
-
|
16
|
+
else
|
17
|
+
keys.push('%{attribute} %{message}')
|
11
18
|
|
19
|
+
options.merge!(:default => keys, :message => self.message)
|
20
|
+
end
|
21
|
+
|
12
22
|
I18n.translate(keys.shift, options)
|
13
23
|
end
|
14
24
|
end
|
@@ -6,6 +6,7 @@ class User < ActiveRecord::Base
|
|
6
6
|
has_many :user_roles
|
7
7
|
has_many :roles, :through => :user_roles
|
8
8
|
|
9
|
+
validates_presence_of :name
|
9
10
|
validates_presence_of :email, :message => "^Your email is invalid"
|
10
11
|
|
11
12
|
accepts_nested_attributes_for :roles
|
@@ -25,21 +26,30 @@ end
|
|
25
26
|
|
26
27
|
require 'custom_error_message'
|
27
28
|
|
28
|
-
describe "
|
29
|
+
describe "error messages" do
|
29
30
|
before do
|
30
31
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
31
32
|
load File.join(File.dirname(__FILE__), 'db', 'schema.rb')
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
describe "with standard messages" do
|
36
|
+
it "should return a standard error message" do
|
37
|
+
@user = User.create
|
38
|
+
@user.errors.full_messages.should include "Name can't be blank"
|
39
|
+
end
|
37
40
|
end
|
38
41
|
|
39
|
-
describe "
|
40
|
-
it "should return the message specified
|
41
|
-
@user = User.create
|
42
|
-
@user.errors.full_messages.should include "
|
42
|
+
describe "with custom messages" do
|
43
|
+
it "should return the full message specified" do
|
44
|
+
@user = User.create
|
45
|
+
@user.errors.full_messages.should include "Your email is invalid"
|
43
46
|
end
|
44
|
-
|
47
|
+
|
48
|
+
describe "on nested attributes" do
|
49
|
+
it "should return the full message specified" do
|
50
|
+
@user = User.create(:roles_attributes => [{}])
|
51
|
+
@user.errors.full_messages.should include "You must enter a role"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
45
55
|
end
|
data/spec/db/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_error_message
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -1876988186
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.1.0.
|
10
|
+
- pre3
|
11
|
+
version: 1.1.0.pre3
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- David Easley
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-12-
|
20
|
+
date: 2010-12-20 00:00:00 -05:00
|
21
21
|
default_executable:
|
22
22
|
dependencies: []
|
23
23
|
|