custom_error_messages 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +94 -0
- data/LICENSE.txt +20 -0
- data/README +36 -0
- data/README.rdoc +49 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/custom_error_message.gemspec +77 -0
- data/custom_error_messages.gemspec +78 -0
- data/lib/custom_error_message.rb +46 -0
- data/spec/custom_error_messages_spec.rb +93 -0
- data/spec/spec_helper.rb +5 -0
- metadata +185 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", "2.11.3"
|
10
|
+
gem "bundler", "1.0.10"
|
11
|
+
gem "jeweler", "1.5.2"
|
12
|
+
gem "rcov", "0.9.9"
|
13
|
+
gem "rspec", "2.5.0"
|
14
|
+
gem "rails", "3.0.4"
|
15
|
+
gem "facets"
|
16
|
+
end
|
17
|
+
|
18
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.4)
|
6
|
+
actionpack (= 3.0.4)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.4)
|
9
|
+
activemodel (= 3.0.4)
|
10
|
+
activesupport (= 3.0.4)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.4)
|
19
|
+
activesupport (= 3.0.4)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.4)
|
23
|
+
activemodel (= 3.0.4)
|
24
|
+
activesupport (= 3.0.4)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.4)
|
28
|
+
activemodel (= 3.0.4)
|
29
|
+
activesupport (= 3.0.4)
|
30
|
+
activesupport (3.0.4)
|
31
|
+
arel (2.0.8)
|
32
|
+
builder (2.1.2)
|
33
|
+
diff-lcs (1.1.2)
|
34
|
+
erubis (2.6.6)
|
35
|
+
abstract (>= 1.0.0)
|
36
|
+
facets (2.9.0)
|
37
|
+
git (1.2.5)
|
38
|
+
i18n (0.5.0)
|
39
|
+
jeweler (1.5.2)
|
40
|
+
bundler (~> 1.0.0)
|
41
|
+
git (>= 1.2.5)
|
42
|
+
rake
|
43
|
+
mail (2.2.15)
|
44
|
+
activesupport (>= 2.3.6)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.16)
|
49
|
+
polyglot (0.3.1)
|
50
|
+
rack (1.2.1)
|
51
|
+
rack-mount (0.6.13)
|
52
|
+
rack (>= 1.0.0)
|
53
|
+
rack-test (0.5.7)
|
54
|
+
rack (>= 1.0)
|
55
|
+
rails (3.0.4)
|
56
|
+
actionmailer (= 3.0.4)
|
57
|
+
actionpack (= 3.0.4)
|
58
|
+
activerecord (= 3.0.4)
|
59
|
+
activeresource (= 3.0.4)
|
60
|
+
activesupport (= 3.0.4)
|
61
|
+
bundler (~> 1.0)
|
62
|
+
railties (= 3.0.4)
|
63
|
+
railties (3.0.4)
|
64
|
+
actionpack (= 3.0.4)
|
65
|
+
activesupport (= 3.0.4)
|
66
|
+
rake (>= 0.8.7)
|
67
|
+
thor (~> 0.14.4)
|
68
|
+
rake (0.8.7)
|
69
|
+
rcov (0.9.9)
|
70
|
+
rspec (2.5.0)
|
71
|
+
rspec-core (~> 2.5.0)
|
72
|
+
rspec-expectations (~> 2.5.0)
|
73
|
+
rspec-mocks (~> 2.5.0)
|
74
|
+
rspec-core (2.5.1)
|
75
|
+
rspec-expectations (2.5.0)
|
76
|
+
diff-lcs (~> 1.1.2)
|
77
|
+
rspec-mocks (2.5.0)
|
78
|
+
shoulda (2.11.3)
|
79
|
+
thor (0.14.6)
|
80
|
+
treetop (1.4.9)
|
81
|
+
polyglot (>= 0.3.1)
|
82
|
+
tzinfo (0.3.24)
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
ruby
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
bundler (= 1.0.10)
|
89
|
+
facets
|
90
|
+
jeweler (= 1.5.2)
|
91
|
+
rails (= 3.0.4)
|
92
|
+
rcov (= 0.9.9)
|
93
|
+
rspec (= 2.5.0)
|
94
|
+
shoulda (= 2.11.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Nathan Wise
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Custom Error Message
|
2
|
+
====================
|
3
|
+
|
4
|
+
This plugin gives you the option to not have your custom validation error message
|
5
|
+
prefixed with the attribute name. Ordinarily, if you have, say:
|
6
|
+
|
7
|
+
validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service'
|
8
|
+
|
9
|
+
You'll get the following error message:
|
10
|
+
|
11
|
+
Accepted terms Please accept the terms of service
|
12
|
+
|
13
|
+
This plugin allows you to omit the attribute name for specific messages. All you have to do
|
14
|
+
is begin the message with a '^' character. Example:
|
15
|
+
|
16
|
+
validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
17
|
+
|
18
|
+
The plugin also lets you use procs instead of strings. Example:
|
19
|
+
|
20
|
+
validates_acceptance_of :accepted_terms, :message => Proc.new {|service| "You must accept the terms of the service #{service.name}" }
|
21
|
+
|
22
|
+
Detail
|
23
|
+
------
|
24
|
+
|
25
|
+
Redefines method:
|
26
|
+
|
27
|
+
ActiveRecord::Errors::full_messages
|
28
|
+
|
29
|
+
Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
30
|
+
Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
|
31
|
+
in which case the attribute name is omitted.
|
32
|
+
|
33
|
+
Source
|
34
|
+
------
|
35
|
+
|
36
|
+
http://github.com/nwise/custom-error-message/tree
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= custom_error_message
|
2
|
+
|
3
|
+
This plugin gives you the option to not have your custom validation error message
|
4
|
+
prefixed with the attribute name. Ordinarily, if you have, say:
|
5
|
+
|
6
|
+
validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service'
|
7
|
+
|
8
|
+
You'll get the following error message:
|
9
|
+
|
10
|
+
Accepted terms Please accept the terms of service
|
11
|
+
|
12
|
+
This plugin allows you to omit the attribute name for specific messages. All you have to do
|
13
|
+
is begin the message with a '^' character. Example:
|
14
|
+
|
15
|
+
validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
16
|
+
|
17
|
+
The plugin also lets you use procs instead of strings. Example:
|
18
|
+
|
19
|
+
validates_acceptance_of :accepted_terms, :message => Proc.new {|service| "You must accept the terms of the service #{service.name}" }
|
20
|
+
|
21
|
+
== Detail
|
22
|
+
|
23
|
+
Redefines method:
|
24
|
+
|
25
|
+
ActiveRecord::Errors::full_messages
|
26
|
+
|
27
|
+
Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
28
|
+
Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
|
29
|
+
in which case the attribute name is omitted.
|
30
|
+
|
31
|
+
== Source
|
32
|
+
|
33
|
+
http://github.com/nwise/custom-error-message/tree
|
34
|
+
|
35
|
+
== Contributing to custom_error_message
|
36
|
+
|
37
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
38
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
39
|
+
* Fork the project
|
40
|
+
* Start a feature/bugfix branch
|
41
|
+
* Commit and push until you are happy with your contribution
|
42
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
43
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2011 Nathan Wise. See LICENSE.txt for
|
48
|
+
further details.
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "custom_error_messages"
|
16
|
+
gem.homepage = "http://github.com/nwise/custom_error_message"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{This plugin gives you the option to not have your custom validation error message
|
19
|
+
prefixed with the attribute name.}
|
20
|
+
gem.description = %Q{This plugin allows you to omit the attribute name for specific messages. All you have to do
|
21
|
+
is begin the message with a '^' character.}
|
22
|
+
gem.email = "nathanwise@gmail.com"
|
23
|
+
gem.authors = ["Nathan Wise"]
|
24
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
26
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rspec/core'
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "custom_error_message #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{custom_error_message}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nathan Wise"]
|
12
|
+
s.date = %q{2011-02-23}
|
13
|
+
s.description = %q{This plugin allows you to omit the attribute name for specific messages. All you have to do
|
14
|
+
is begin the message with a '^' character.}
|
15
|
+
s.email = %q{nathanwise@gmail.com}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README",
|
28
|
+
"README.rdoc",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"custom_error_message.gemspec",
|
32
|
+
"lib/custom_error_message.rb",
|
33
|
+
"spec/custom_error_messages_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/nwise/custom_error_message}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{This plugin gives you the option to not have your custom validation error message prefixed with the attribute name.}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/custom_error_messages_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.11.3"])
|
52
|
+
s.add_development_dependency(%q<bundler>, ["= 1.0.10"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["= 1.5.2"])
|
54
|
+
s.add_development_dependency(%q<rcov>, ["= 0.9.9"])
|
55
|
+
s.add_development_dependency(%q<rspec>, ["= 2.5.0"])
|
56
|
+
s.add_development_dependency(%q<rails>, ["= 3.0.4"])
|
57
|
+
s.add_development_dependency(%q<facets>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.3"])
|
60
|
+
s.add_dependency(%q<bundler>, ["= 1.0.10"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["= 1.5.2"])
|
62
|
+
s.add_dependency(%q<rcov>, ["= 0.9.9"])
|
63
|
+
s.add_dependency(%q<rspec>, ["= 2.5.0"])
|
64
|
+
s.add_dependency(%q<rails>, ["= 3.0.4"])
|
65
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.3"])
|
69
|
+
s.add_dependency(%q<bundler>, ["= 1.0.10"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["= 1.5.2"])
|
71
|
+
s.add_dependency(%q<rcov>, ["= 0.9.9"])
|
72
|
+
s.add_dependency(%q<rspec>, ["= 2.5.0"])
|
73
|
+
s.add_dependency(%q<rails>, ["= 3.0.4"])
|
74
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{custom_error_messages}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nathan Wise"]
|
12
|
+
s.date = %q{2011-03-01}
|
13
|
+
s.description = %q{This plugin allows you to omit the attribute name for specific messages. All you have to do
|
14
|
+
is begin the message with a '^' character.}
|
15
|
+
s.email = %q{nathanwise@gmail.com}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README",
|
28
|
+
"README.rdoc",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"custom_error_message.gemspec",
|
32
|
+
"custom_error_messages.gemspec",
|
33
|
+
"lib/custom_error_message.rb",
|
34
|
+
"spec/custom_error_messages_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/nwise/custom_error_message}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{This plugin gives you the option to not have your custom validation error message prefixed with the attribute name.}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/custom_error_messages_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.11.3"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["= 1.0.10"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["= 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, ["= 0.9.9"])
|
56
|
+
s.add_development_dependency(%q<rspec>, ["= 2.5.0"])
|
57
|
+
s.add_development_dependency(%q<rails>, ["= 3.0.4"])
|
58
|
+
s.add_development_dependency(%q<facets>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.3"])
|
61
|
+
s.add_dependency(%q<bundler>, ["= 1.0.10"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["= 1.5.2"])
|
63
|
+
s.add_dependency(%q<rcov>, ["= 0.9.9"])
|
64
|
+
s.add_dependency(%q<rspec>, ["= 2.5.0"])
|
65
|
+
s.add_dependency(%q<rails>, ["= 3.0.4"])
|
66
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.3"])
|
70
|
+
s.add_dependency(%q<bundler>, ["= 1.0.10"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["= 1.5.2"])
|
72
|
+
s.add_dependency(%q<rcov>, ["= 0.9.9"])
|
73
|
+
s.add_dependency(%q<rspec>, ["= 2.5.0"])
|
74
|
+
s.add_dependency(%q<rails>, ["= 3.0.4"])
|
75
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CustomErrorMessage
|
2
|
+
def self.included(receiver)
|
3
|
+
receiver.send :include, InstanceMethods
|
4
|
+
receiver.class_eval do
|
5
|
+
alias_method_chain :full_messages, :tilde
|
6
|
+
alias_method_chain :add, :procs
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
# Redefine the full_messages method:
|
12
|
+
# Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
13
|
+
# Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
|
14
|
+
# in which case the attribute name is omitted.
|
15
|
+
# E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
16
|
+
|
17
|
+
private
|
18
|
+
def full_messages_with_tilde
|
19
|
+
full_messages = full_messages_without_tilde
|
20
|
+
full_messages.map do |message|
|
21
|
+
if starts_with_humanized_column_followed_by_circumflex? message
|
22
|
+
message.gsub(/^.+\^/, '')
|
23
|
+
else
|
24
|
+
message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_with_procs(attribute, message = nil, options = {})
|
30
|
+
if options[:default].respond_to? :to_proc
|
31
|
+
options[:default] = "^#{options[:default].to_proc.call(@base)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
add_without_procs(attribute, message, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def starts_with_humanized_column_followed_by_circumflex?(message)
|
38
|
+
keys.any? do |column|
|
39
|
+
humanized = @base.class.human_attribute_name column.to_s.gsub('.','_')
|
40
|
+
message.match(/^#{humanized} \^/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ActiveModel::Errors.send(:include, CustomErrorMessage)
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def class_builder(field, message)
|
4
|
+
|
5
|
+
test_class = Class.new do
|
6
|
+
include ActiveModel::Validations
|
7
|
+
include ActiveModel::Conversion
|
8
|
+
extend ActiveModel::Naming
|
9
|
+
|
10
|
+
validates_presence_of field, :message => message
|
11
|
+
attr_accessor field
|
12
|
+
|
13
|
+
def initialize(attributes={})
|
14
|
+
attributes.each do |name, value|
|
15
|
+
send("#{name}", value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def persisted?; false; end
|
19
|
+
def self.model_name; ActiveModel::Name.new(Class); end
|
20
|
+
end
|
21
|
+
|
22
|
+
return test_class.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def class_without_validations(field)
|
26
|
+
|
27
|
+
test_class = Class.new do
|
28
|
+
include ActiveModel::Validations
|
29
|
+
include ActiveModel::Conversion
|
30
|
+
extend ActiveModel::Naming
|
31
|
+
|
32
|
+
attr_accessor field
|
33
|
+
|
34
|
+
def initialize(attributes={})
|
35
|
+
attributes.each do |name, value|
|
36
|
+
send("#{name}", value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
def persisted?; false; end
|
40
|
+
def self.model_name; ActiveModel::Name.new(Class); end
|
41
|
+
end
|
42
|
+
|
43
|
+
return test_class.new
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'CustomErrorMessage using declarative validation' do
|
47
|
+
|
48
|
+
it 'without a caret, should not change behavior' do
|
49
|
+
model = class_builder :email, 'is not present'
|
50
|
+
model.valid?
|
51
|
+
model.errors.full_messages.should include "Email is not present"
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'with a caret, should allow for custom message' do
|
55
|
+
model = class_builder :email, "^Please provide an email address"
|
56
|
+
model.valid?
|
57
|
+
model.errors.full_messages.should include "Please provide an email address"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'with caret not in the beginning, should leave original behaviour' do
|
61
|
+
model = class_builder :email, 'is not ^ present'
|
62
|
+
model.valid?
|
63
|
+
model.errors.full_messages.should include "Email is not ^ present"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'CustomErrorMessage using the errors.add method' do
|
68
|
+
|
69
|
+
before :each do
|
70
|
+
@model = class_without_validations(:name)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'query of error without caret should not change behavior' do
|
74
|
+
@model.errors.add(:name, 'is too long')
|
75
|
+
@model.errors[:name].should == ["is too long"]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'added error without caret should not change behavior' do
|
79
|
+
@model.errors.add(:name, "is too long")
|
80
|
+
@model.errors.full_messages.should include "Name is too long"
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'query of error with caret should show the message' do
|
84
|
+
@model.errors.add(:name, "^You forgot the name")
|
85
|
+
@model.errors[:name].should == ["^You forgot the name"]
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'added error with caret should only show the message' do
|
89
|
+
@model.errors.add(:name, '^You forgot the name')
|
90
|
+
@model.errors.full_messages.should include "You forgot the name"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: custom_error_messages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nathan Wise
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-01 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 11
|
30
|
+
- 3
|
31
|
+
version: 2.11.3
|
32
|
+
type: :development
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - "="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 10
|
46
|
+
version: 1.0.10
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: jeweler
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - "="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 5
|
60
|
+
- 2
|
61
|
+
version: 1.5.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rcov
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - "="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
- 9
|
75
|
+
- 9
|
76
|
+
version: 0.9.9
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - "="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 2
|
89
|
+
- 5
|
90
|
+
- 0
|
91
|
+
version: 2.5.0
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rails
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - "="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 3
|
104
|
+
- 0
|
105
|
+
- 4
|
106
|
+
version: 3.0.4
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: facets
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: *id007
|
123
|
+
description: |-
|
124
|
+
This plugin allows you to omit the attribute name for specific messages. All you have to do
|
125
|
+
is begin the message with a '^' character.
|
126
|
+
email: nathanwise@gmail.com
|
127
|
+
executables: []
|
128
|
+
|
129
|
+
extensions: []
|
130
|
+
|
131
|
+
extra_rdoc_files:
|
132
|
+
- LICENSE.txt
|
133
|
+
- README
|
134
|
+
- README.rdoc
|
135
|
+
files:
|
136
|
+
- .document
|
137
|
+
- .rspec
|
138
|
+
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
141
|
+
- README
|
142
|
+
- README.rdoc
|
143
|
+
- Rakefile
|
144
|
+
- VERSION
|
145
|
+
- custom_error_message.gemspec
|
146
|
+
- custom_error_messages.gemspec
|
147
|
+
- lib/custom_error_message.rb
|
148
|
+
- spec/custom_error_messages_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
has_rdoc: true
|
151
|
+
homepage: http://github.com/nwise/custom_error_message
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
hash: 933679054970416217
|
165
|
+
segments:
|
166
|
+
- 0
|
167
|
+
version: "0"
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
requirements: []
|
177
|
+
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 1.3.7
|
180
|
+
signing_key:
|
181
|
+
specification_version: 3
|
182
|
+
summary: This plugin gives you the option to not have your custom validation error message prefixed with the attribute name.
|
183
|
+
test_files:
|
184
|
+
- spec/custom_error_messages_spec.rb
|
185
|
+
- spec/spec_helper.rb
|