brtraducao 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/MIT-LICENSE +20 -0
- data/README +0 -0
- data/Rakefile +100 -0
- data/TODO +5 -0
- data/lib/brtraducao/action_view_portuguese.rb +30 -0
- data/lib/brtraducao/active_record_portuguese.rb +49 -0
- data/lib/brtraducao/inflector_portuguese.rb +64 -0
- data/lib/brtraducao/version.rb +9 -0
- data/lib/brtraducao.rb +17 -0
- data/test/action_view_test.rb +134 -0
- data/test/active_record_test.rb +38 -0
- data/test/test_helper.rb +20 -0
- metadata +95 -0
data/CHANGELOG
ADDED
File without changes
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
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
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/contrib/sshpublisher'
|
8
|
+
require File.join(File.dirname(__FILE__), 'lib', 'brtraducao', 'version')
|
9
|
+
|
10
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
11
|
+
PKG_NAME = 'brtraducao'
|
12
|
+
PKG_VERSION = BrTraducao::VERSION::STRING + PKG_BUILD
|
13
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
14
|
+
|
15
|
+
RELEASE_NAME = "REL #{PKG_VERSION}"
|
16
|
+
|
17
|
+
RUBY_FORGE_PROJECT = "brtraducao"
|
18
|
+
RUBY_FORGE_USER = "tapajos"
|
19
|
+
|
20
|
+
desc "Default Task"
|
21
|
+
task :default => [ :test ]
|
22
|
+
|
23
|
+
# Run the unit tests
|
24
|
+
Rake::TestTask.new { |t|
|
25
|
+
t.libs << "test"
|
26
|
+
t.pattern = 'test/*_test.rb'
|
27
|
+
t.verbose = true
|
28
|
+
t.warning = false
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
# Generate the RDoc documentation
|
33
|
+
# Rake::RDocTask.new { |rdoc|
|
34
|
+
# rdoc.rdoc_dir = 'doc'
|
35
|
+
# rdoc.title = "Action Mailer -- Easy email delivery and testing"
|
36
|
+
# rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
37
|
+
# rdoc.options << '--charset' << 'utf-8'
|
38
|
+
# rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
39
|
+
# rdoc.rdoc_files.include('README', 'CHANGELOG')
|
40
|
+
# rdoc.rdoc_files.include('lib/action_mailer.rb')
|
41
|
+
# rdoc.rdoc_files.include('lib/action_mailer/*.rb')
|
42
|
+
# }
|
43
|
+
|
44
|
+
|
45
|
+
# Create compressed packages
|
46
|
+
spec = Gem::Specification.new do |s|
|
47
|
+
s.platform = Gem::Platform::RUBY
|
48
|
+
s.name = PKG_NAME
|
49
|
+
s.summary = "brtraducao é uma das gems que compoem o Brazilian Rails"
|
50
|
+
s.description = %q{brtraducao é uma das gems que compoem o Brazilian Rails}
|
51
|
+
s.version = PKG_VERSION
|
52
|
+
|
53
|
+
s.author = "Marcos Tapajós"
|
54
|
+
s.email = "tapajos@gmail.com"
|
55
|
+
s.rubyforge_project = "brtraducao"
|
56
|
+
s.homepage = "http://www.improveit.com.br/software_livre/brazilian_rails"
|
57
|
+
|
58
|
+
s.add_dependency('actionpack', '>= 1.4.2')
|
59
|
+
s.add_dependency('activerecord', '>= 1.15.3')
|
60
|
+
s.add_dependency('activesupport', '>= 1.4.2')
|
61
|
+
|
62
|
+
s.has_rdoc = true
|
63
|
+
s.requirements << 'none'
|
64
|
+
s.require_path = 'lib'
|
65
|
+
|
66
|
+
s.files = [ "Rakefile", "README", "CHANGELOG", "TODO", "MIT-LICENSE" ]
|
67
|
+
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
68
|
+
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
69
|
+
end
|
70
|
+
|
71
|
+
Rake::GemPackageTask.new(spec) do |p|
|
72
|
+
p.gem_spec = spec
|
73
|
+
p.need_tar = true
|
74
|
+
p.need_zip = true
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# desc "Publish the API documentation"
|
79
|
+
# task :pgem => [:package] do
|
80
|
+
# Rake::SshFilePublisher.new("wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# desc "Publish the API documentation"
|
84
|
+
# task :pdoc => [:rdoc] do
|
85
|
+
# Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/am", "doc").upload
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
|
89
|
+
desc "Publish the release files to RubyForge."
|
90
|
+
task :release => [ :package ] do
|
91
|
+
require 'rubyforge'
|
92
|
+
require 'rake/contrib/rubyforgepublisher'
|
93
|
+
|
94
|
+
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
95
|
+
|
96
|
+
rubyforge = RubyForge.new
|
97
|
+
rubyforge.configure
|
98
|
+
rubyforge.login
|
99
|
+
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
|
100
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActionView::Helpers::ActiveRecordHelper
|
2
|
+
# Traduz as mensagens de erro do ActiveRecord
|
3
|
+
def error_messages_for(*params)
|
4
|
+
options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
|
5
|
+
objects = params.collect { |object_name| instance_variable_get('@'+object_name.to_s()) }
|
6
|
+
objects.compact!
|
7
|
+
count = objects.inject(0) {|sum, object| sum + object.errors.count }
|
8
|
+
unless count.zero?
|
9
|
+
html = {}
|
10
|
+
[:id, :class].each do |key|
|
11
|
+
if options.include?(key)
|
12
|
+
value = options[key]
|
13
|
+
html[key] = value unless value.blank?
|
14
|
+
else
|
15
|
+
html[key] = 'errorExplanation'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
header_message = "#{pluralize(count, 'erro')} para #{(options[:object_name] || params.first).to_s.gsub('_', ' ')}"
|
19
|
+
error_messages = objects.map { |object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }
|
20
|
+
content_tag(:div,
|
21
|
+
content_tag(options[:header_tag] || :h2, header_message) <<
|
22
|
+
content_tag(:p, 'Foram detectados os seguintes erros:') <<
|
23
|
+
content_tag(:ul, error_messages),
|
24
|
+
html
|
25
|
+
)
|
26
|
+
else
|
27
|
+
''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
# Traduz as mensagens de erro do ActiveRecord::Errors
|
3
|
+
#
|
4
|
+
# :inclusion => "não está incluído na lista"
|
5
|
+
# :exclusion => "é reservado"
|
6
|
+
# :invalid => "é inválido"
|
7
|
+
# :confirmation => "não corresponde à confirmação"
|
8
|
+
# :accepted => "deve ser aceito"
|
9
|
+
# :empty => "deve ser preenchido"
|
10
|
+
# :blank => "deve ser preenchido"
|
11
|
+
# :too_long => "deve ter até %d caractere(s)"
|
12
|
+
# :too_short => "deve ter no mínimo %d caractere(s)"
|
13
|
+
# :wrong_length => "deve ter %d caractere(s)"
|
14
|
+
# :taken => "já está em uso"
|
15
|
+
# :not_a_number => "não é um número"
|
16
|
+
# :greater_than => "deve ser maior que %d"
|
17
|
+
# :greater_than_or_equal_to => "deve ser maior ou igual a %d"
|
18
|
+
# :equal_to => "deve ser igual a %d"
|
19
|
+
# :less_than => "deve ser menor que %d"
|
20
|
+
# :less_than_or_equal_to => "deve ser menor ou igual a %d"
|
21
|
+
# :odd => "deve ser impar"
|
22
|
+
# :even => "deve ser par"
|
23
|
+
class Errors
|
24
|
+
@@default_error_messages = {
|
25
|
+
:inclusion => "não está incluído(a) na lista",
|
26
|
+
:exclusion => "é reservado(a)",
|
27
|
+
:invalid => "é inválido(a)",
|
28
|
+
:confirmation => "não corresponde à confirmação",
|
29
|
+
:accepted => "deve ser aceito(a)",
|
30
|
+
:empty => "deve ser preenchido(a)",
|
31
|
+
:blank => "deve ser preenchido(a)",
|
32
|
+
:too_long => "deve ter até %d caractere(s)",
|
33
|
+
:too_short => "deve ter no mínimo %d caractere(s)",
|
34
|
+
:wrong_length => "deve ter %d caractere(s)",
|
35
|
+
:taken => "já está em uso",
|
36
|
+
:not_a_number => "não é um número",
|
37
|
+
:greater_than => "deve ser maior que %d",
|
38
|
+
:greater_than_or_equal_to => "deve ser maior ou igual a %d",
|
39
|
+
:equal_to => "deve ser igual a %d",
|
40
|
+
:less_than => "deve ser menor que %d",
|
41
|
+
:less_than_or_equal_to => "deve ser menor ou igual a %d",
|
42
|
+
:odd => "deve ser impar",
|
43
|
+
:even => "deve ser par"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Inflector
|
2
|
+
Inflector.inflections do |inflect|
|
3
|
+
inflect.singular(/^(.*)s$/i, '\1')
|
4
|
+
inflect.singular(/^(.*)s$/i, '\1')
|
5
|
+
inflect.singular(/^(.*)s$/i, '\1')
|
6
|
+
inflect.singular(/^(.*)s$/i, '\1')
|
7
|
+
inflect.singular(/^(.*)s$/i, '\1')
|
8
|
+
|
9
|
+
inflect.plural(/^(.*[z|r])$/i, '\1es')
|
10
|
+
inflect.singular(/^(.*[r|z])es$/i, '\1')
|
11
|
+
|
12
|
+
inflect.plural(/^(.*)al$/i, '\1ais')
|
13
|
+
inflect.plural(/^(.*)el$/i, '\1eis')
|
14
|
+
inflect.plural(/^(.*)ol$/i, '\1ois')
|
15
|
+
inflect.plural(/^(.*)ul$/i, '\1uis')
|
16
|
+
inflect.singular(/^(.*)ais$/i, '\1al')
|
17
|
+
inflect.singular(/^(.*)eis$/i, '\1el')
|
18
|
+
inflect.singular(/^(.*)ois$/i, '\1ol')
|
19
|
+
inflect.singular(/^(.*)uis$/i, '\1ul')
|
20
|
+
|
21
|
+
inflect.plural(/^(.*)il$/i, '\1is')
|
22
|
+
|
23
|
+
inflect.plural(/^(.*)m$/i, '\1ns')
|
24
|
+
inflect.singular(/^(.*)ns$/i, '\1m')
|
25
|
+
|
26
|
+
inflect.plural(/^(.*s)$/i, '\1es')
|
27
|
+
inflect.plural(/^(.*)ás$/i, '\1ases')
|
28
|
+
inflect.plural(/^(.*)ês$/i, '\1eses')
|
29
|
+
inflect.singular(/^(.*)sses$/i, '\1sse')
|
30
|
+
inflect.singular(/^(.*[^s]s)es$/i, '\1')
|
31
|
+
|
32
|
+
inflect.plural(/^(.*)ão$/i, '\1ões')
|
33
|
+
inflect.singular(/^(.*)ões$/i, '\1ão')
|
34
|
+
|
35
|
+
inflect.plural(/^(.*)ao$/i, '\1oes')
|
36
|
+
inflect.singular(/^(.*)aos$/i, '\1ao')
|
37
|
+
|
38
|
+
inflect.singular(/^(.*)ães$/i, '\1ão')
|
39
|
+
inflect.singular(/^(.*)ãos$/i, '\1ão')
|
40
|
+
inflect.singular(/^(.*)oes$/i, '\1ao')
|
41
|
+
inflect.singular(/^(.*)aes$/i, '\1ao')
|
42
|
+
|
43
|
+
# #irregulares
|
44
|
+
irregulares = { "cão" => 'cães',
|
45
|
+
"pão" => 'pães',
|
46
|
+
"mão" => 'mãos',
|
47
|
+
"alemão" => 'alemães',
|
48
|
+
"cao" => 'caes',
|
49
|
+
"pao" => 'paes',
|
50
|
+
"mao" => 'maos',
|
51
|
+
"alemao" => 'alemaes',
|
52
|
+
"mail" => 'mails',
|
53
|
+
"email" => 'emails'
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
irregulares.each do |key, value|
|
58
|
+
inflect.plural(/^#{key.to_s}$/, value)
|
59
|
+
inflect.singular(/^#{value}$/, key.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
inflect.uncountable %w( tórax tênis ônibus lápis fênix )
|
63
|
+
end
|
64
|
+
end
|
data/lib/brtraducao.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'html/document'
|
7
|
+
require 'active_support'
|
8
|
+
require 'action_view'
|
9
|
+
# require 'action_pack'
|
10
|
+
|
11
|
+
%w(action_view_portuguese
|
12
|
+
version
|
13
|
+
active_record_portuguese).each {|req| require File.dirname(__FILE__) + "/brtraducao/#{req}"}
|
14
|
+
|
15
|
+
|
16
|
+
module BrTraducao
|
17
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
class ActionViewTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include ActionView::Helpers::FormHelper
|
7
|
+
include ActionView::Helpers::ActiveRecordHelper
|
8
|
+
include ActionView::Helpers::TextHelper
|
9
|
+
include ActionView::Helpers::TagHelper
|
10
|
+
include ActionView::Helpers::UrlHelper
|
11
|
+
include ActionView::Helpers::FormTagHelper
|
12
|
+
include ActionView::Helpers::DateHelper
|
13
|
+
include ActionView::Helpers::FormOptionsHelper
|
14
|
+
|
15
|
+
silence_warnings do
|
16
|
+
Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
|
17
|
+
Post.class_eval do
|
18
|
+
alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
|
19
|
+
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
|
20
|
+
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
|
21
|
+
end
|
22
|
+
|
23
|
+
User = Struct.new("User", :email)
|
24
|
+
User.class_eval do
|
25
|
+
alias_method :email_before_type_cast, :email unless respond_to?(:email_before_type_cast)
|
26
|
+
end
|
27
|
+
|
28
|
+
Column = Struct.new("Column", :type, :name, :human_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup_post
|
32
|
+
@post = Post.new
|
33
|
+
def @post.errors
|
34
|
+
Class.new {
|
35
|
+
def on(field) field == "author_name" || field == "body" end
|
36
|
+
def empty?() false end
|
37
|
+
def count() 1 end
|
38
|
+
def full_messages() [ "Author name can't be empty" ] end
|
39
|
+
}.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def @post.new_record?() true end
|
43
|
+
def @post.to_param() nil end
|
44
|
+
|
45
|
+
def @post.column_for_attribute(attr_name)
|
46
|
+
Post.content_columns.select { |column| column.name == attr_name }.first
|
47
|
+
end
|
48
|
+
|
49
|
+
silence_warnings do
|
50
|
+
def Post.content_columns() [ Column.new(:string, "title", "Title"),
|
51
|
+
Column.new(:text, "body", "Body") ]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
@post.title = "Hello World"
|
56
|
+
@post.author_name = ""
|
57
|
+
@post.body = "Back to the hill and over it again!"
|
58
|
+
@post.secret = 1
|
59
|
+
@post.written_on = Date.new(2004, 6, 15)
|
60
|
+
end
|
61
|
+
|
62
|
+
def setup_user
|
63
|
+
@user = User.new
|
64
|
+
def @user.errors
|
65
|
+
Class.new {
|
66
|
+
def on(field) field == "email" end
|
67
|
+
def empty?() false end
|
68
|
+
def count() 1 end
|
69
|
+
def full_messages() [ "User email can't be empty" ] end
|
70
|
+
}.new
|
71
|
+
end
|
72
|
+
|
73
|
+
def @user.new_record?() true end
|
74
|
+
def @user.to_param() nil end
|
75
|
+
|
76
|
+
def @user.column_for_attribute(attr_name)
|
77
|
+
User.content_columns.select { |column| column.name == attr_name }.first
|
78
|
+
end
|
79
|
+
|
80
|
+
silence_warnings do
|
81
|
+
def User.content_columns() [ Column.new(:string, "email", "Email") ] end
|
82
|
+
end
|
83
|
+
|
84
|
+
@user.email = ""
|
85
|
+
end
|
86
|
+
|
87
|
+
def setup
|
88
|
+
setup_post
|
89
|
+
setup_user
|
90
|
+
|
91
|
+
@controller = Object.new
|
92
|
+
def @controller.url_for(options)
|
93
|
+
options = options.symbolize_keys
|
94
|
+
|
95
|
+
[options[:action], options[:id].to_param].compact.join('/')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_error_for_block
|
100
|
+
assert_dom_equal %(<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>1 erro para post</h2><p>Foram detectados os seguintes erros:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
|
101
|
+
assert_equal %(<div class=\"errorDeathByClass\" id=\"errorDeathById\"><h1>1 erro para post</h1><p>Foram detectados os seguintes erros:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
|
102
|
+
assert_equal %(<div id=\"errorDeathById\"><h1>1 erro para post</h1><p>Foram detectados os seguintes erros:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
|
103
|
+
assert_equal %(<div class=\"errorDeathByClass\"><h1>1 erro para post</h1><p>Foram detectados os seguintes erros:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_error_messages_for_handles_nil
|
107
|
+
assert_equal "", error_messages_for("notthere")
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_error_message_on_handles_nil
|
111
|
+
assert_equal "", error_message_on("notthere", "notthere")
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_error_message_on
|
115
|
+
assert error_message_on(:post, :author_name)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_error_messages_for_many_objects
|
119
|
+
assert_dom_equal %(<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>2 erros para post</h2><p>Foram detectados os seguintes erros:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
|
120
|
+
|
121
|
+
# reverse the order, error order changes and so does the title
|
122
|
+
assert_dom_equal %(<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>2 erros para user</h2><p>Foram detectados os seguintes erros:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post")
|
123
|
+
|
124
|
+
# add the default to put post back in the title
|
125
|
+
assert_dom_equal %(<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>2 erros para post</h2><p>Foram detectados os seguintes erros:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post")
|
126
|
+
|
127
|
+
# symbols work as well
|
128
|
+
assert_dom_equal %(<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>2 erros para post</h2><p>Foram detectados os seguintes erros:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post)
|
129
|
+
|
130
|
+
# any default works too
|
131
|
+
assert_dom_equal %(<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>2 erros para monkey</h2><p>Foram detectados os seguintes erros:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ActiveRecordTestable < ActiveRecord::Errors
|
4
|
+
|
5
|
+
def self.default_error_messages
|
6
|
+
@@default_error_messages
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActiveRecordTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def test_active_record_messages
|
14
|
+
errors = ActiveRecordTestable.default_error_messages
|
15
|
+
assert_equal "não está incluído(a) na lista", errors[:inclusion]
|
16
|
+
assert_equal "é reservado(a)", errors[:exclusion]
|
17
|
+
assert_equal "é inválido(a)", errors[:invalid]
|
18
|
+
assert_equal "não corresponde à confirmação", errors[:confirmation]
|
19
|
+
assert_equal "deve ser aceito(a)", errors[:accepted]
|
20
|
+
assert_equal "deve ser preenchido(a)", errors[:empty]
|
21
|
+
assert_equal "deve ser preenchido(a)", errors[:blank]
|
22
|
+
assert_equal "deve ter até %d caractere(s)", errors[:too_long]
|
23
|
+
assert_equal "deve ter no mínimo %d caractere(s)", errors[:too_short]
|
24
|
+
assert_equal "deve ter %d caractere(s)", errors[:wrong_length]
|
25
|
+
assert_equal "já está em uso", errors[:taken]
|
26
|
+
assert_equal "não é um número", errors[:not_a_number]
|
27
|
+
assert_equal "deve ser maior que %d", errors[:greater_than]
|
28
|
+
assert_equal "deve ser maior ou igual a %d", errors[:greater_than_or_equal_to]
|
29
|
+
assert_equal "deve ser igual a %d", errors[:equal_to]
|
30
|
+
assert_equal "deve ser menor que %d", errors[:less_than]
|
31
|
+
assert_equal "deve ser menor ou igual a %d", errors[:less_than_or_equal_to]
|
32
|
+
assert_equal "deve ser impar", errors[:odd]
|
33
|
+
assert_equal "deve ser par", errors[:even]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/brtraducao'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/brtraducao/inflector_portuguese'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'action_pack'
|
7
|
+
require 'action_controller/assertions'
|
8
|
+
|
9
|
+
def tornar_metodos_publicos(clazz)
|
10
|
+
clazz.class_eval do
|
11
|
+
private_instance_methods.each { |instance_method| public instance_method }
|
12
|
+
private_methods.each { |method| public_class_method method }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def p80 text
|
17
|
+
p '*'*80
|
18
|
+
p text
|
19
|
+
p '*'*80
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brtraducao
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Marcos Tapaj\xC3\xB3s"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-23 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionpack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.4.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activerecord
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.15.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.4.2
|
44
|
+
version:
|
45
|
+
description: "brtraducao \xC3\xA9 uma das gems que compoem o Brazilian Rails"
|
46
|
+
email: tapajos@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- Rakefile
|
55
|
+
- README
|
56
|
+
- CHANGELOG
|
57
|
+
- TODO
|
58
|
+
- MIT-LICENSE
|
59
|
+
- lib/brtraducao
|
60
|
+
- lib/brtraducao/action_view_portuguese.rb
|
61
|
+
- lib/brtraducao/active_record_portuguese.rb
|
62
|
+
- lib/brtraducao/inflector_portuguese.rb
|
63
|
+
- lib/brtraducao/version.rb
|
64
|
+
- lib/brtraducao.rb
|
65
|
+
- test/action_view_test.rb
|
66
|
+
- test/active_record_test.rb
|
67
|
+
- test/test_helper.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://www.improveit.com.br/software_livre/brazilian_rails
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
requirements:
|
88
|
+
- none
|
89
|
+
rubyforge_project: brtraducao
|
90
|
+
rubygems_version: 1.2.0
|
91
|
+
signing_key:
|
92
|
+
specification_version: 2
|
93
|
+
summary: "brtraducao \xC3\xA9 uma das gems que compoem o Brazilian Rails"
|
94
|
+
test_files: []
|
95
|
+
|