padrino-helpers 0.9.16 → 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,11 +40,13 @@ module Padrino
40
40
  def form_tag(url, options={}, &block)
41
41
  desired_method = options[:method]
42
42
  data_method = options.delete(:method) if options[:method].to_s !~ /get|post/i
43
- options.reverse_merge!(:method => 'post', :action => url)
43
+ options.reverse_merge!(:method => "post", :action => url)
44
44
  options[:enctype] = "multipart/form-data" if options.delete(:multipart)
45
45
  options["data-remote"] = "true" if options.delete(:remote)
46
46
  options["data-method"] = data_method if data_method
47
- inner_form_html = hidden_form_method_field(desired_method) + capture_html(&block)
47
+ options["accept-charset"] = "UTF-8"
48
+ inner_form_html = hidden_form_method_field(desired_method)
49
+ inner_form_html += hidden_field_tag(:"_utf8", :value => "☃") + capture_html(&block)
48
50
  concat_content content_tag('form', inner_form_html, options)
49
51
  end
50
52
 
@@ -375,13 +377,13 @@ module Padrino
375
377
  configured_builder
376
378
  end
377
379
 
378
-
380
+
379
381
  #
380
382
  # Returns whether the option should be selected or not
381
383
  #
382
384
  def option_is_selected?(value, caption, selected_value)
383
385
  if selected_value.is_a? Array
384
- selected_value.any? do |selected|
386
+ selected_value.any? do |selected|
385
387
  selected.to_s =~ /^(#{value}|#{caption})$/
386
388
  end
387
389
  else
@@ -21,54 +21,54 @@ class TestFormBuilder < Test::Unit::TestCase
21
21
 
22
22
  context 'for #form_for method' do
23
23
  should "display correct form html" do
24
- actual_html = form_for(@user, '/register', :id => 'register', :method => 'post') { "Demo" }
25
- assert_has_tag('form', :action => '/register', :id => 'register', :method => 'post', :content => "Demo") { actual_html }
24
+ actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "utf-8", :method => 'post') { "Demo" }
25
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/register', :id => 'register', :method => 'post', :content => "Demo") { actual_html }
26
26
  assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
27
27
  end
28
28
 
29
29
  should "display correct form html with fake object" do
30
- actual_html = form_for(:markup_user, '/register', :id => 'register', :method => 'post') { |f| f.text_field :username }
31
- assert_has_tag('form', :action => '/register', :id => 'register', :method => 'post') { actual_html }
30
+ actual_html = form_for(:markup_user, '/register', :id => 'register', :"accept-charset" => "utf-8", :method => 'post') { |f| f.text_field :username }
31
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/register', :id => 'register', :method => 'post') { actual_html }
32
32
  assert_has_tag('form input', :type => 'text', :name => 'markup_user[username]') { actual_html }
33
33
  assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
34
34
  end
35
35
 
36
36
  should "display correct form html for namespaced object" do
37
- actual_html = form_for(Outer::UserAccount.new, '/register', :method => 'post') { |f| f.text_field :username }
38
- assert_has_tag('form', :action => '/register', :method => 'post') { actual_html }
37
+ actual_html = form_for(Outer::UserAccount.new, '/register', :"accept-charset" => "utf-8", :method => 'post') { |f| f.text_field :username }
38
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/register', :method => 'post') { actual_html }
39
39
  assert_has_tag('form input', :type => 'text', :name => 'outer-user_account[username]') { actual_html }
40
40
  end
41
41
 
42
42
  should "display correct form html with remote option" do
43
- actual_html = form_for(@user, '/update', :remote => true) { "Demo" }
44
- assert_has_tag('form', :action => '/update', :method => 'post', "data-remote" => 'true') { actual_html }
43
+ actual_html = form_for(@user, '/update', :"accept-charset" => "utf-8", :remote => true) { "Demo" }
44
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/update', :method => 'post', "data-remote" => 'true') { actual_html }
45
45
  end
46
46
 
47
47
  should "display correct form html with remote option and method put" do
48
- actual_html = form_for(@user, '/update', :remote => true, :method => 'put') { "Demo" }
49
- assert_has_tag('form', :method => 'post', "data-method" => 'put', "data-remote" => 'true') { actual_html }
48
+ actual_html = form_for(@user, '/update', :"accept-charset" => "utf-8", :remote => true, :method => 'put') { "Demo" }
49
+ assert_has_tag('form', :"accept-charset" => "utf-8", :method => 'post', "data-method" => 'put', "data-remote" => 'true') { actual_html }
50
50
  assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
51
51
  end
52
52
 
53
53
  should "display correct form html with method :put" do
54
- actual_html = form_for(@user, '/update', :method => 'put') { "Demo" }
55
- assert_has_tag('form', :action => '/update', :method => 'post') { actual_html }
54
+ actual_html = form_for(@user, '/update', :"accept-charset" => "utf-8", :method => 'put') { "Demo" }
55
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/update', :method => 'post') { actual_html }
56
56
  assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
57
57
  end
58
58
 
59
59
  should "display correct form html with method :delete" do
60
- actual_html = form_for(@user, '/destroy', :method => 'delete') { "Demo" }
61
- assert_has_tag('form', :action => '/destroy', :method => 'post') { actual_html }
60
+ actual_html = form_for(@user, '/destroy', :"accept-charset" => "utf-8", :method => 'delete') { "Demo" }
61
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/destroy', :method => 'post') { actual_html }
62
62
  assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
63
63
  end
64
64
 
65
65
  should "display correct form html with multipart" do
66
- actual_html = form_for(@user, '/register', :multipart => true) { "Demo" }
67
- assert_has_tag('form', :action => '/register', :enctype => "multipart/form-data") { actual_html }
66
+ actual_html = form_for(@user, '/register', :"accept-charset" => "utf-8", :multipart => true) { "Demo" }
67
+ assert_has_tag('form', :"accept-charset" => "utf-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
68
68
  end
69
69
 
70
70
  should "support changing form builder type" do
71
- form_html = proc { form_for(@user, '/register', :builder => "AbstractFormBuilder") { |f| f.text_field_block(:name) } }
71
+ form_html = proc { form_for(@user, '/register', :"accept-charset" => "utf-8", :builder => "AbstractFormBuilder") { |f| f.text_field_block(:name) } }
72
72
  assert_raise(NoMethodError) { form_html.call }
73
73
  end
74
74
 
@@ -10,42 +10,49 @@ class TestFormHelpers < Test::Unit::TestCase
10
10
 
11
11
  context 'for #form_tag method' do
12
12
  should "display correct forms in ruby" do
13
- actual_html = form_tag('/register', :class => 'test', :method => "post") { "Demo" }
14
- assert_has_tag(:form, :class => "test") { actual_html }
13
+ actual_html = form_tag('/register', :"accept-charset" => "utf-8", :class => 'test', :method => "post") { "Demo" }
14
+ assert_has_tag(:form, :"accept-charset" => "utf-8", :class => "test") { actual_html }
15
15
  assert_has_tag('form input', :type => 'hidden', :name => '_method', :count => 0) { actual_html }
16
16
  end
17
17
 
18
18
  should "display correct text inputs within form_tag" do
19
- actual_html = form_tag('/register', :class => 'test') { text_field_tag(:username) }
19
+ actual_html = form_tag('/register', :"accept-charset" => "utf-8", :class => 'test') { text_field_tag(:username) }
20
20
  assert_has_tag('form input', :type => 'text', :name => "username") { actual_html }
21
21
  end
22
22
 
23
23
  should "display correct form with remote" do
24
- actual_html = form_tag('/update', :class => 'put-form', :remote => true) { "Demo" }
25
- assert_has_tag(:form, :class => "put-form", "data-remote" => 'true') { actual_html }
24
+ actual_html = form_tag('/update', :"accept-charset" => "utf-8", :class => 'put-form', :remote => true) { "Demo" }
25
+ assert_has_tag(:form, :class => "put-form", :"accept-charset" => "utf-8", "data-remote" => 'true') { actual_html }
26
26
  assert_has_no_tag(:form, "data-method" => 'post') { actual_html }
27
27
  end
28
28
 
29
29
  should "display correct form with remote and method is put" do
30
- actual_html = form_tag('/update', :method => 'put', :remote => true) { "Demo" }
31
- assert_has_tag(:form, "data-remote" => 'true', "data-method" => 'put') { actual_html }
30
+ actual_html = form_tag('/update', :"accept-charset" => "utf-8", :method => 'put', :remote => true) { "Demo" }
31
+ assert_has_tag(:form, "data-remote" => 'true', :"accept-charset" => "utf-8", "data-method" => 'put') { actual_html }
32
32
  assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
33
33
  end
34
34
 
35
35
  should "display correct form with method :put" do
36
- actual_html = form_tag('/update', :class => 'put-form', :method => "put") { "Demo" }
37
- assert_has_tag(:form, :class => "put-form", :method => 'post') { actual_html }
36
+ actual_html = form_tag('/update', :"accept-charset" => "utf-8", :class => 'put-form', :method => "put") { "Demo" }
37
+ assert_has_tag(:form, :class => "put-form", :"accept-charset" => "utf-8", :method => 'post') { actual_html }
38
38
  assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
39
39
  end
40
40
 
41
- should "display correct form with method :delete" do
42
- actual_html = form_tag('/remove', :class => 'delete-form', :method => "delete") { "Demo" }
43
- assert_has_tag(:form, :class => "delete-form", :method => 'post') { actual_html }
41
+ should "display correct form with method :delete and charset" do
42
+ actual_html = form_tag('/remove', :"accept-charset" => "utf-8", :class => 'delete-form', :method => "delete") { "Demo" }
43
+ assert_has_tag(:form, :class => "delete-form", :"accept-charset" => "utf-8", :method => 'post') { actual_html }
44
44
  assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
45
+ assert_has_tag('form input', :type => 'hidden', :name => "_utf8") { actual_html }
46
+ end
47
+
48
+ should "display correct form with charset" do
49
+ actual_html = form_tag('/charset', :"accept-charset" => "utf-8", :class => 'charset-form') { "Demo" }
50
+ assert_has_tag(:form, :class => "charset-form", :"accept-charset" => "utf-8", :method => 'post') { actual_html }
51
+ assert_has_tag('form input', :type => 'hidden', :name => "_utf8") { actual_html }
45
52
  end
46
53
 
47
54
  should "display correct form with multipart encoding" do
48
- actual_html = form_tag('/remove', :multipart => true) { "Demo" }
55
+ actual_html = form_tag('/remove', :"accept-charset" => "utf-8", :multipart => true) { "Demo" }
49
56
  assert_has_tag(:form, :enctype => "multipart/form-data") { actual_html }
50
57
  end
51
58
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 16
10
- version: 0.9.16
9
+ - 17
10
+ version: 0.9.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-09-24 00:00:00 +02:00
21
+ date: 2010-10-04 00:00:00 +02:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -29,12 +29,12 @@ dependencies:
29
29
  requirements:
30
30
  - - "="
31
31
  - !ruby/object:Gem::Version
32
- hash: 27
32
+ hash: 25
33
33
  segments:
34
34
  - 0
35
35
  - 9
36
- - 16
37
- version: 0.9.16
36
+ - 17
37
+ version: 0.9.17
38
38
  type: :runtime
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency