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.
@@ -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.pre2"
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 = ["{{message}}"]
13
+ keys.push('{{message}}')
14
+
9
15
  options.merge!(:default => self.message[1..-1])
10
- end
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 "validating attributes" do
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
- it "should return the message specified without a prefix" do
35
- @user = User.create
36
- @user.errors.full_messages.should include "Your email is invalid"
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 "validating nested attributes" do
40
- it "should return the message specified without a prefix" do
41
- @user = User.create(:roles_attributes => [{}])
42
- @user.errors.full_messages.should include "You must enter a role"
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
- end
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
@@ -1,6 +1,6 @@
1
1
  ActiveRecord::Schema.define(:version => 0) do
2
2
  create_table :users, :force => true do |t|
3
- t.string :email, :password, :roles
3
+ t.string :name, :email, :password, :roles
4
4
  end
5
5
 
6
6
  create_table :roles, :force => true do |t|
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: -1876988167
4
+ hash: -1876988186
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 0
10
- - pre2
11
- version: 1.1.0.pre2
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-17 00:00:00 -05:00
20
+ date: 2010-12-20 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies: []
23
23