padrino-helpers 0.9.7 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +1 -1
- data/lib/padrino-helpers/form_helpers.rb +12 -5
- data/padrino-helpers.gemspec +5 -5
- data/test/fixtures/markup_app/app.rb +1 -9
- data/test/test_asset_tag_helpers.rb +2 -2
- data/test/test_form_builder.rb +22 -15
- data/test/test_form_helpers.rb +12 -8
- data/test/test_format_helpers.rb +10 -6
- data/test/test_output_helpers.rb +2 -2
- data/test/test_render_helpers.rb +2 -2
- data/test/test_tag_helpers.rb +2 -2
- metadata +5 -5
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.9
|
@@ -103,7 +103,7 @@ module Padrino
|
|
103
103
|
def error_messages_for(*objects)
|
104
104
|
options = objects.extract_options!.symbolize_keys
|
105
105
|
objects = objects.collect {|object_name| object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name }.compact
|
106
|
-
count = objects.inject(0) {|sum, object| sum + object.errors.
|
106
|
+
count = objects.inject(0) {|sum, object| sum + object.errors.size }
|
107
107
|
|
108
108
|
unless count.zero?
|
109
109
|
html = {}
|
@@ -122,12 +122,18 @@ module Padrino
|
|
122
122
|
header_message = if options.include?(:header_message)
|
123
123
|
options[:header_message]
|
124
124
|
else
|
125
|
-
object_name = options[:object_name].to_s.gsub('_', ' ')
|
126
|
-
object_name = I18n.t(
|
125
|
+
object_name = options[:object_name].to_s.underscore.gsub('_', ' ')
|
126
|
+
object_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1)
|
127
127
|
locale.t :header, :count => count, :model => object_name
|
128
128
|
end
|
129
129
|
message = options.include?(:message) ? options[:message] : locale.t(:body)
|
130
|
-
error_messages = objects.map {|object|
|
130
|
+
error_messages = objects.map { |object|
|
131
|
+
object_name = options[:object_name].to_s.underscore.gsub('_', ' ')
|
132
|
+
object.errors.map { |f, msg|
|
133
|
+
field = I18n.t(f, :default => object_name.humanize, :scope => [:models, object_name, :attributes])
|
134
|
+
content_tag(:li, "%s %s" % [field, msg])
|
135
|
+
}
|
136
|
+
}.join
|
131
137
|
|
132
138
|
contents = ''
|
133
139
|
contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
|
@@ -167,7 +173,8 @@ module Padrino
|
|
167
173
|
if error
|
168
174
|
options.reverse_merge!(:tag => :span, :class => :error)
|
169
175
|
tag = options.delete(:tag)
|
170
|
-
|
176
|
+
# Array(error).first is necessary because some orm give us an array others directly a value
|
177
|
+
error = [options.delete(:prepend), Array(error).first, options.delete(:append)].compact.join(" ")
|
171
178
|
content_tag(tag, error, options)
|
172
179
|
else
|
173
180
|
''
|
data/padrino-helpers.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-helpers}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-29}
|
13
13
|
s.description = %q{Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino}
|
14
14
|
s.email = %q{padrinorb@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -84,14 +84,14 @@ Gem::Specification.new do |s|
|
|
84
84
|
s.specification_version = 3
|
85
85
|
|
86
86
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
87
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.
|
87
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.9"])
|
88
88
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
89
89
|
s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
|
90
90
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
91
91
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
92
92
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
93
93
|
else
|
94
|
-
s.add_dependency(%q<padrino-core>, ["= 0.9.
|
94
|
+
s.add_dependency(%q<padrino-core>, ["= 0.9.9"])
|
95
95
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
96
96
|
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
97
97
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
@@ -99,7 +99,7 @@ Gem::Specification.new do |s|
|
|
99
99
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
100
100
|
end
|
101
101
|
else
|
102
|
-
s.add_dependency(%q<padrino-core>, ["= 0.9.
|
102
|
+
s.add_dependency(%q<padrino-core>, ["= 0.9.9"])
|
103
103
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
104
104
|
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
105
105
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
@@ -41,7 +41,7 @@ class MarkupDemo < Sinatra::Base
|
|
41
41
|
end
|
42
42
|
|
43
43
|
class MarkupUser
|
44
|
-
def errors;
|
44
|
+
def errors; { :fake => "must be valid", :second => "must be present", :third => "must be a number", :email => "must be a email"}; end
|
45
45
|
def session_id; 45; end
|
46
46
|
def gender; 'male'; end
|
47
47
|
def remember_me; '1'; end
|
@@ -53,14 +53,6 @@ class Permission
|
|
53
53
|
def can_delete; false; end
|
54
54
|
end
|
55
55
|
|
56
|
-
class Errors < Array
|
57
|
-
def initialize; self << [:fake, :second, :third]; end
|
58
|
-
def [](fake); true if fake == :email; end
|
59
|
-
def full_messages
|
60
|
-
["This is a fake error", "This is a second fake error", "This is a third fake error"]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
56
|
module Outer
|
65
57
|
class UserAccount; end
|
66
58
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
3
|
|
4
4
|
class TestAssetTagHelpers < Test::Unit::TestCase
|
5
5
|
include Padrino::Helpers::AssetTagHelpers
|
data/test/test_form_builder.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
3
|
|
4
4
|
class TestFormBuilder < Test::Unit::TestCase
|
5
5
|
include Padrino::Helpers::FormHelpers
|
@@ -9,11 +9,10 @@ class TestFormBuilder < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def setup
|
12
|
-
error_stub = stub(:full_messages => ["1", "2"], :count => 2, :[] => [])
|
13
12
|
role_types = [stub(:name => 'Admin', :id => 1), stub(:name => 'Moderate', :id => 2), stub(:name => 'Limited', :id => 3)]
|
14
|
-
@user = stub(:errors =>
|
13
|
+
@user = stub(:errors => {:a => "must be present", :b => "must be valid"}, :class => 'User', :first_name => "Joe", :session_id => 54)
|
15
14
|
@user.stubs(:role_types => role_types, :role => "1")
|
16
|
-
@user_none = stub(:errors =>
|
15
|
+
@user_none = stub(:errors => {}, :class => 'User')
|
17
16
|
end
|
18
17
|
|
19
18
|
def standard_builder(object=@user)
|
@@ -131,27 +130,35 @@ class TestFormBuilder < Test::Unit::TestCase
|
|
131
130
|
should "display correct form html with valid record" do
|
132
131
|
actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved", :style => "foo:bar", :class => "mine")
|
133
132
|
assert_has_tag('#field-errors h2', :content => "Demo form cannot be saved") { actual_html }
|
134
|
-
assert_has_tag('#field-errors ul li', :content => "
|
135
|
-
assert_has_tag('#field-errors ul li', :content => "
|
133
|
+
assert_has_tag('#field-errors ul li', :content => "User must be valid") { actual_html }
|
134
|
+
assert_has_tag('#field-errors ul li', :content => "User must be present") { actual_html }
|
136
135
|
assert_has_tag('#field-errors', :style => "foo:bar") { actual_html }
|
137
136
|
assert_has_tag('#field-errors', :class => "mine") { actual_html }
|
138
137
|
end
|
139
138
|
|
140
139
|
should "display correct form in haml" do
|
141
140
|
visit '/haml/form_for'
|
142
|
-
assert_have_selector '#demo div.field-errors h2',
|
143
|
-
assert_have_selector '#demo div.field-errors ul li',
|
144
|
-
assert_have_selector '#
|
145
|
-
assert_have_selector '#
|
141
|
+
assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
142
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Markup user must be valid"
|
143
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Markup user must be present"
|
144
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Markup user must be a number"
|
145
|
+
assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
146
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Markup user must be valid"
|
147
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Markup user must be present"
|
148
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Markup user must be a number"
|
146
149
|
assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
|
147
150
|
end
|
148
151
|
|
149
152
|
should "display correct form in erb" do
|
150
153
|
visit '/erb/form_for'
|
151
|
-
assert_have_selector '#demo div.field-errors h2',
|
152
|
-
assert_have_selector '#demo div.field-errors ul li',
|
153
|
-
assert_have_selector '#
|
154
|
-
assert_have_selector '#
|
154
|
+
assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
155
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Markup user must be valid"
|
156
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Markup user must be present"
|
157
|
+
assert_have_selector '#demo div.field-errors ul li', :content => "Markup user must be a number"
|
158
|
+
assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
|
159
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Markup user must be valid"
|
160
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Markup user must be present"
|
161
|
+
assert_have_selector '#demo2 div.field-errors ul li', :content => "Markup user must be a number"
|
155
162
|
assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'invalid'
|
156
163
|
end
|
157
164
|
end
|
data/test/test_form_helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
3
|
|
4
4
|
class TestFormHelpers < Test::Unit::TestCase
|
5
5
|
include Padrino::Helpers::FormHelpers
|
@@ -76,7 +76,7 @@ class TestFormHelpers < Test::Unit::TestCase
|
|
76
76
|
|
77
77
|
context 'for #error_messages_for method' do
|
78
78
|
should "display correct error messages list in ruby" do
|
79
|
-
user = stub(:class => "User", :errors =>
|
79
|
+
user = stub(:class => "User", :errors => { :a => "1", :b => "2" }, :blank? => false)
|
80
80
|
actual_html = error_messages_for(user)
|
81
81
|
assert_has_tag('div.field-errors') { actual_html }
|
82
82
|
assert_has_tag('div.field-errors h2', :content => "2 errors prohibited this User from being saved") { actual_html }
|
@@ -92,8 +92,10 @@ class TestFormHelpers < Test::Unit::TestCase
|
|
92
92
|
assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
|
93
93
|
assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
|
94
94
|
assert_have_selector 'form.advanced-form .field-errors ul'
|
95
|
-
assert_have_selector 'form.advanced-form .field-errors ul li', :count =>
|
96
|
-
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "
|
95
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
|
96
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Markup user must be valid"
|
97
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Markup user must be present"
|
98
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Markup user must be a number"
|
97
99
|
end
|
98
100
|
|
99
101
|
should "display correct error messages list in haml" do
|
@@ -101,10 +103,12 @@ class TestFormHelpers < Test::Unit::TestCase
|
|
101
103
|
assert_have_no_selector 'form.simple-form .field-errors'
|
102
104
|
assert_have_selector 'form.advanced-form .field-errors'
|
103
105
|
assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
|
104
|
-
assert_have_selector 'form.advanced-form .field-errors p',
|
106
|
+
assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
|
105
107
|
assert_have_selector 'form.advanced-form .field-errors ul'
|
106
|
-
assert_have_selector 'form.advanced-form .field-errors ul li', :count =>
|
107
|
-
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "
|
108
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
|
109
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Markup user must be valid"
|
110
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Markup user must be present"
|
111
|
+
assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Markup user must be a number"
|
108
112
|
end
|
109
113
|
end
|
110
114
|
|
data/test/test_format_helpers.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
3
|
|
4
4
|
class TestFormatHelpers < Test::Unit::TestCase
|
5
5
|
def app
|
6
6
|
MarkupDemo.tap { |app| app.set :environment, :test }
|
7
7
|
end
|
8
8
|
|
9
|
+
def setup
|
10
|
+
Time.stubs(:now).returns(Time.utc(1983, 11, 9, 5))
|
11
|
+
end
|
12
|
+
|
9
13
|
include Padrino::Helpers::FormatHelpers
|
10
14
|
|
11
15
|
context 'for #simple_format method' do
|
@@ -54,10 +58,10 @@ class TestFormatHelpers < Test::Unit::TestCase
|
|
54
58
|
assert_equal "Once\nupon\na\ntime", actual_text
|
55
59
|
end
|
56
60
|
should "return proper formatting for default width" do
|
57
|
-
actual_text = word_wrap(1
|
58
|
-
assert_equal 1
|
59
|
-
actual_text = word_wrap(1
|
60
|
-
assert_equal 1
|
61
|
+
actual_text = word_wrap((1..50).to_a.join(" "))
|
62
|
+
assert_equal (1..30).to_a.join(" ") + "\n" + (31..50).to_a.join(" "), actual_text
|
63
|
+
actual_text = word_wrap((1..50).to_a.join(" "), 80)
|
64
|
+
assert_equal (1..30).to_a.join(" ") + "\n" + (31..50).to_a.join(" "), actual_text
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
data/test/test_output_helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
3
|
|
4
4
|
class TestOutputHelpers < Test::Unit::TestCase
|
5
5
|
def app
|
data/test/test_render_helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/render_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/render_app/app')
|
3
3
|
|
4
4
|
class TestRenderHelpers < Test::Unit::TestCase
|
5
5
|
def app
|
data/test/test_tag_helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/markup_app/app'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
3
3
|
|
4
4
|
class TestTagHelpers < Test::Unit::TestCase
|
5
5
|
def app
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 9
|
9
|
+
version: 0.9.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Padrino Team
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-03-
|
20
|
+
date: 2010-03-29 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -30,8 +30,8 @@ dependencies:
|
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 9
|
33
|
-
-
|
34
|
-
version: 0.9.
|
33
|
+
- 9
|
34
|
+
version: 0.9.9
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|