generic_form_for 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.
Files changed (150) hide show
  1. data/.document +5 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +123 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.textile +217 -0
  8. data/Rakefile +52 -0
  9. data/VERSION +1 -0
  10. data/generic_form_for.gemspec +232 -0
  11. data/generic_form_for.tmproj +166 -0
  12. data/lib/generators/generic_form_for/form_builder/form_builder_generator.rb +16 -0
  13. data/lib/generators/generic_form_for/form_builder/templates/form_builder.erb +37 -0
  14. data/lib/generators/generic_form_for/form_builder/templates/helper.erb +15 -0
  15. data/lib/generators/generic_form_for/install/install_generator.rb +20 -0
  16. data/lib/generators/generic_form_for/install/templates/_form.html.erb +11 -0
  17. data/lib/generators/generic_form_for/install/templates/_form.html.haml +8 -0
  18. data/lib/generators/generic_form_for/install/templates/form_for.en.yml +11 -0
  19. data/lib/generators/generic_form_for/install/templates/initializer.rb +5 -0
  20. data/lib/generic_form_for.rb +22 -0
  21. data/lib/generic_form_for/actions.rb +10 -0
  22. data/lib/generic_form_for/actions/base.rb +63 -0
  23. data/lib/generic_form_for/actions/base/icon.rb +24 -0
  24. data/lib/generic_form_for/actions/button_action.rb +14 -0
  25. data/lib/generic_form_for/actions/input_action.rb +11 -0
  26. data/lib/generic_form_for/engine.rb +11 -0
  27. data/lib/generic_form_for/form_builder.rb +111 -0
  28. data/lib/generic_form_for/helpers.rb +10 -0
  29. data/lib/generic_form_for/helpers/action_helper.rb +52 -0
  30. data/lib/generic_form_for/helpers/actions_helper.rb +35 -0
  31. data/lib/generic_form_for/helpers/fieldset_helper.rb +48 -0
  32. data/lib/generic_form_for/helpers/form_helper.rb +64 -0
  33. data/lib/generic_form_for/helpers/input_helper.rb +77 -0
  34. data/lib/generic_form_for/i18n.rb +44 -0
  35. data/lib/generic_form_for/inputs.rb +22 -0
  36. data/lib/generic_form_for/inputs/base.rb +98 -0
  37. data/lib/generic_form_for/inputs/base/error_message.rb +30 -0
  38. data/lib/generic_form_for/inputs/base/hint.rb +28 -0
  39. data/lib/generic_form_for/inputs/base/label.rb +42 -0
  40. data/lib/generic_form_for/inputs/base/number.rb +18 -0
  41. data/lib/generic_form_for/inputs/base/placeholder.rb +20 -0
  42. data/lib/generic_form_for/inputs/base/string.rb +17 -0
  43. data/lib/generic_form_for/inputs/base/validations.rb +42 -0
  44. data/lib/generic_form_for/inputs/boolean_input.rb +35 -0
  45. data/lib/generic_form_for/inputs/email_input.rb +19 -0
  46. data/lib/generic_form_for/inputs/file_input.rb +13 -0
  47. data/lib/generic_form_for/inputs/hidden_input.rb +23 -0
  48. data/lib/generic_form_for/inputs/number_input.rb +20 -0
  49. data/lib/generic_form_for/inputs/password_input.rb +13 -0
  50. data/lib/generic_form_for/inputs/phone_input.rb +19 -0
  51. data/lib/generic_form_for/inputs/range_input.rb +19 -0
  52. data/lib/generic_form_for/inputs/search_input.rb +19 -0
  53. data/lib/generic_form_for/inputs/select_input.rb +32 -0
  54. data/lib/generic_form_for/inputs/string_input.rb +13 -0
  55. data/lib/generic_form_for/inputs/text_input.rb +20 -0
  56. data/lib/generic_form_for/inputs/url_input.rb +19 -0
  57. data/sample_app/.gitignore +15 -0
  58. data/sample_app/Gemfile +15 -0
  59. data/sample_app/Gemfile.lock +130 -0
  60. data/sample_app/README.rdoc +261 -0
  61. data/sample_app/Rakefile +7 -0
  62. data/sample_app/app/assets/images/rails.png +0 -0
  63. data/sample_app/app/assets/javascripts/application.js +14 -0
  64. data/sample_app/app/assets/javascripts/posts.js.coffee +3 -0
  65. data/sample_app/app/assets/javascripts/samples.js.coffee +3 -0
  66. data/sample_app/app/assets/stylesheets/application.css +14 -0
  67. data/sample_app/app/assets/stylesheets/posts.css.scss +3 -0
  68. data/sample_app/app/assets/stylesheets/samples.css.scss +3 -0
  69. data/sample_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
  70. data/sample_app/app/controllers/application_controller.rb +3 -0
  71. data/sample_app/app/controllers/samples_controller.rb +83 -0
  72. data/sample_app/app/form_builders/sample_form_builder.rb +17 -0
  73. data/sample_app/app/helpers/application_helper.rb +2 -0
  74. data/sample_app/app/helpers/sample_form_builder_helper.rb +15 -0
  75. data/sample_app/app/helpers/samples_helper.rb +2 -0
  76. data/sample_app/app/mailers/.gitkeep +0 -0
  77. data/sample_app/app/models/.gitkeep +0 -0
  78. data/sample_app/app/models/sample.rb +29 -0
  79. data/sample_app/app/views/layouts/application.html.erb +16 -0
  80. data/sample_app/app/views/samples/_form.html.erb +49 -0
  81. data/sample_app/app/views/samples/edit.html.erb +6 -0
  82. data/sample_app/app/views/samples/index.html.erb +21 -0
  83. data/sample_app/app/views/samples/new.html.erb +5 -0
  84. data/sample_app/app/views/samples/show.html.erb +5 -0
  85. data/sample_app/config.ru +4 -0
  86. data/sample_app/config/application.rb +65 -0
  87. data/sample_app/config/boot.rb +6 -0
  88. data/sample_app/config/database.yml +25 -0
  89. data/sample_app/config/environment.rb +5 -0
  90. data/sample_app/config/environments/development.rb +37 -0
  91. data/sample_app/config/environments/production.rb +67 -0
  92. data/sample_app/config/environments/test.rb +37 -0
  93. data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
  94. data/sample_app/config/initializers/generic_form_for.rb +5 -0
  95. data/sample_app/config/initializers/inflections.rb +15 -0
  96. data/sample_app/config/initializers/mime_types.rb +5 -0
  97. data/sample_app/config/initializers/secret_token.rb +7 -0
  98. data/sample_app/config/initializers/session_store.rb +8 -0
  99. data/sample_app/config/initializers/wrap_parameters.rb +14 -0
  100. data/sample_app/config/locales/en.yml +22 -0
  101. data/sample_app/config/locales/form_for.en.yml +13 -0
  102. data/sample_app/config/routes.rb +61 -0
  103. data/sample_app/db/migrate/20120203082117_create_samples.rb +22 -0
  104. data/sample_app/db/schema.rb +36 -0
  105. data/sample_app/db/seeds.rb +7 -0
  106. data/sample_app/lib/assets/.gitkeep +0 -0
  107. data/sample_app/lib/tasks/.gitkeep +0 -0
  108. data/sample_app/lib/templates/erb/scaffold/_form.html.erb +11 -0
  109. data/sample_app/log/.gitkeep +0 -0
  110. data/sample_app/public/404.html +26 -0
  111. data/sample_app/public/422.html +26 -0
  112. data/sample_app/public/500.html +25 -0
  113. data/sample_app/public/favicon.ico +0 -0
  114. data/sample_app/public/robots.txt +5 -0
  115. data/sample_app/script/rails +6 -0
  116. data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
  117. data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
  118. data/sample_app/vendor/plugins/.gitkeep +0 -0
  119. data/spec/actions/base/icon_spec.rb +38 -0
  120. data/spec/actions/button_action_spec.rb +43 -0
  121. data/spec/actions/input_action_spec.rb +66 -0
  122. data/spec/helpers/action_helper_spec.rb +32 -0
  123. data/spec/helpers/actions_helper_spec.rb +60 -0
  124. data/spec/helpers/fieldset_helper_spec.rb +83 -0
  125. data/spec/helpers/form_helper_spec.rb +101 -0
  126. data/spec/helpers/input_helper_spec.rb +66 -0
  127. data/spec/i18n_spec.rb +46 -0
  128. data/spec/inputs/base/error_message_spec.rb +86 -0
  129. data/spec/inputs/base/hint_spec.rb +77 -0
  130. data/spec/inputs/base/label_spec.rb +99 -0
  131. data/spec/inputs/base/number_spec.rb +32 -0
  132. data/spec/inputs/base/placeholder_spec.rb +32 -0
  133. data/spec/inputs/base/string_spec.rb +25 -0
  134. data/spec/inputs/base/validations_spec.rb +53 -0
  135. data/spec/inputs/base_spec.rb +69 -0
  136. data/spec/inputs/boolean_input_spec.rb +95 -0
  137. data/spec/inputs/email_input_spec.rb +30 -0
  138. data/spec/inputs/file_input_spec.rb +30 -0
  139. data/spec/inputs/hidden_input_spec.rb +30 -0
  140. data/spec/inputs/number_input_spec.rb +37 -0
  141. data/spec/inputs/password_input_spec.rb +30 -0
  142. data/spec/inputs/phone_input_spec.rb +30 -0
  143. data/spec/inputs/range_input_spec.rb +37 -0
  144. data/spec/inputs/search_input_spec.rb +30 -0
  145. data/spec/inputs/select_input_spec.rb +51 -0
  146. data/spec/inputs/string_input_spec.rb +115 -0
  147. data/spec/inputs/text_input_spec.rb +30 -0
  148. data/spec/inputs/url_input_spec.rb +30 -0
  149. data/spec/spec_helper.rb +122 -0
  150. metadata +374 -0
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
File without changes
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Actions::Base::Icon' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should generate submit button with icon" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name))
14
+ concat(builder.action(:submit, :as => :button, :icon => "my-icon"))
15
+ end)
16
+ output_buffer.should have_selector("button[@type='submit'][@name='submit']", :content => "Submit")
17
+ output_buffer.should have_selector("span[@class='my-icon']")
18
+ end
19
+
20
+ it "should genearate button with icon with options" do
21
+ with_form_config do
22
+ GenericFormFor::FormBuilder.action_wrapper do
23
+ action_html :class => "my-button" do
24
+ icon_html :class => "real-icon"
25
+ end
26
+ end
27
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
28
+ concat(builder.fieldset(:my_legend) do
29
+ builder.input(:email)
30
+ concat(builder.action(:submit, :as => :button, :icon => "my-icon", :icon_html => {:id => "ic", :class => "icons"}))
31
+ end)
32
+ end)
33
+ output_buffer.should have_selector("button[@type='submit'][@name='submit']", :content => "Submit")
34
+ output_buffer.should have_selector("span#ic[@class='my-icon icons real-icon']")
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Actions::ButtonAction' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should generate submit button" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name))
14
+ concat(builder.action(:submit, :as => :button))
15
+ end)
16
+ output_buffer.should have_selector("button[@type='submit'][@name='submit']", :content => "Submit")
17
+ end
18
+
19
+ it "should accept custom options button" do
20
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
21
+ concat(builder.input(:name))
22
+ concat(builder.action(:submit, :as => :button, :class =>"mybutton", :type=> "unknown"))
23
+ end)
24
+ output_buffer.should have_selector("button[@type='unknown'][@class='mybutton'][@name='submit']", :content => "Submit")
25
+ end
26
+
27
+ it "should wrap in tag" do
28
+ with_form_config do
29
+ GenericFormFor::FormBuilder.action_wrapper do
30
+ wrap_in :class => "action" do
31
+ action_html :class => "my-button"
32
+ end
33
+ end
34
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
35
+ concat(builder.input(:name, :as => :string))
36
+ concat(builder.action(:submit, :as => :button))
37
+ end)
38
+ output_buffer.should have_selector("button[@type='submit'][@class='my-button'][@name='submit']", :content => "Submit")
39
+ output_buffer.should have_selector("div", :class => "button-action action")
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Actions::InputAction' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should generate submit input" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name))
14
+ concat(builder.action(:submit))
15
+ end)
16
+ output_buffer.should have_selector("input[@type='submit'][@value='Submit'][@name='submit']")
17
+ end
18
+
19
+ it "should accept custom options input" do
20
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
21
+ concat(builder.input(:name))
22
+ concat(builder.action(:submit, :class =>"mybutton", :type=> "unknown"))
23
+ end)
24
+ output_buffer.should have_selector("input[@type='unknown'][@class='mybutton'][@value='Submit'][@name='submit']")
25
+ end
26
+
27
+ it "should generate reset input" do
28
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
29
+ concat(builder.input(:name))
30
+ concat(builder.action(:reset))
31
+ end)
32
+ output_buffer.should have_selector("input[@type='reset'][@value='Reset'][@name='reset']")
33
+ end
34
+
35
+ it "should wrap in tag" do
36
+ with_form_config do
37
+ GenericFormFor::FormBuilder.action_wrapper do
38
+ wrap_in :class => "action" do
39
+ action_html :class => "my-button"
40
+ end
41
+ end
42
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
43
+ concat(builder.input(:name, :as => :string))
44
+ concat(builder.action(:submit))
45
+ end)
46
+ output_buffer.should have_selector("input[@type='submit'][@value='Submit'][@name='submit'][@class='my-button']")
47
+ output_buffer.should have_selector("div", :class => "input-action action")
48
+ end
49
+ end
50
+
51
+ it "should accept options" do
52
+ with_form_config do
53
+ GenericFormFor::FormBuilder.action_wrapper do
54
+ wrap_in :class => "action" do
55
+ action_html :class => "my-button"
56
+ end
57
+ end
58
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
59
+ concat(builder.input(:name, :as => :string))
60
+ concat(builder.action(:submit, :class => "someclass", :id => "qwerty"))
61
+ end)
62
+ output_buffer.should have_selector("input#qwerty[@type='submit'][@value='Submit'][@name='submit'][@class='someclass my-button']")
63
+ output_buffer.should have_selector("div", :class => "input-action action")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Helpers::ActionHelper' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ # it "should genearate submit action" do
12
+ # concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ # concat(builder.action(:submit))
14
+ # end)
15
+ # output_buffer.should have_selector("input[@id='my_model_name']")
16
+ # # output_buffer.should have_selector("label[@for='my_model_name']", :content => "Title")
17
+ # # output_buffer.should have_selector("div", :class => "controls string-input required")
18
+ # end
19
+
20
+ {
21
+ submit: :input,
22
+ cancel: :link,
23
+ reset: :input,
24
+ button: :button
25
+ }.each do |col, type|
26
+ it "should recognize #{col} actions as #{type}" do
27
+ my = Class.new
28
+ default_action_type(col).should == type
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Helpers::ActionsHelper' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate actions" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.actions do
14
+ builder.action(:submit)
15
+ end)
16
+ end)
17
+ output_buffer.should have_selector("div")
18
+ output_buffer.should have_selector("input[@value='Submit']")
19
+ end
20
+
21
+ it "should genearate actions with custom tag" do
22
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
23
+ concat(builder.actions(:tag => "content", :class => "actions") do
24
+ builder.action(:submit)
25
+ end)
26
+ end)
27
+ output_buffer.should have_selector("content[@class='actions']")
28
+ output_buffer.should have_selector("input[@value='Submit']")
29
+ end
30
+
31
+ it "should genearate actions with default options" do
32
+ with_form_config do
33
+ GenericFormFor::FormBuilder.actions_wrapper do
34
+ actions_html :class => "a-default", :id => "aid"
35
+ end
36
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
37
+ concat(builder.actions do
38
+ builder.action(:submit)
39
+ end)
40
+ end)
41
+ output_buffer.should have_selector("div#aid[@class='a-default']")
42
+ output_buffer.should have_selector("input[@value='Submit']")
43
+ end
44
+ end
45
+
46
+ it "should genearate fieldset and legend with default and custom options" do
47
+ with_form_config do
48
+ GenericFormFor::FormBuilder.actions_wrapper do
49
+ actions_html :class => "a-default", :id => "aid"
50
+ end
51
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
52
+ concat(builder.actions(:class => "my", :id =>"mid") do
53
+ builder.action(:submit)
54
+ end)
55
+ end)
56
+ output_buffer.should have_selector("div#mid[@class='my a-default']")
57
+ output_buffer.should have_selector("input[@value='Submit']")
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Helpers::FieldsetHelper' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate fieldset with attributes" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.fieldset(:class => :field) do
14
+ builder.input(:email)
15
+ end)
16
+ end)
17
+ output_buffer.should have_selector("fieldset[@class='field']")
18
+ output_buffer.should have_selector("input[@id='my_model_email']")
19
+ end
20
+
21
+ it "should genearate fieldset with custom tag" do
22
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
23
+ concat(builder.fieldset(:class => :field, :tag => "content"))
24
+ end)
25
+ output_buffer.should have_selector("content[@class='field']")
26
+ output_buffer.should_not have_selector("legend")
27
+ end
28
+
29
+ it "should genearate fieldset with legend" do
30
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
31
+ concat(builder.fieldset(:my_legend, :class => :field) do
32
+ builder.input(:email)
33
+ end)
34
+ end)
35
+ output_buffer.should have_selector("fieldset[@class='field']")
36
+ output_buffer.should have_selector("legend", :content => "MyLegend")
37
+ output_buffer.should have_selector("input[@id='my_model_email']")
38
+ end
39
+
40
+ it "should genearate fieldset and legend with default options" do
41
+ with_form_config do
42
+ GenericFormFor::FormBuilder.fieldset_wrapper do
43
+ fieldset_html :class => "f-default", :id => "fid" do
44
+ legend_html :class => "l-default", :id => "lid"
45
+ end
46
+ end
47
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
48
+ concat(builder.fieldset(:my_legend) do
49
+ builder.input(:email)
50
+ end)
51
+ end)
52
+ output_buffer.should have_selector("fieldset#fid[@class='f-default']")
53
+ output_buffer.should have_selector("legend#lid[@class='l-default']", :content => "MyLegend")
54
+ output_buffer.should have_selector("input[@id='my_model_email']")
55
+ end
56
+ end
57
+
58
+ it "should genearate fieldset and legend with default and custom options" do
59
+ with_form_config do
60
+ GenericFormFor::FormBuilder.fieldset_wrapper do
61
+ fieldset_html :class => "f-default" do
62
+ legend_html :class => "l-default"
63
+ end
64
+ end
65
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
66
+ concat(builder.fieldset(:my_legend, :class => :field, :id => "fid", :legend_html => {:class => "super", :id => "lid"}) do
67
+ builder.input(:email)
68
+ builder.fieldset(:my_legend1, :class => :field1, :legend_html => {:class => "super1"}) do
69
+ builder.input(:mobile)
70
+ end
71
+ end)
72
+ concat(builder.input(:cv))
73
+ end)
74
+ output_buffer.should have_selector("fieldset#fid[@class='field f-default']")
75
+ output_buffer.should have_selector("legend#lid[@class='super l-default']", :content => "MyLegend")
76
+ output_buffer.should have_selector("input[@id='my_model_email']")
77
+ output_buffer.should have_selector("fieldset[@class='field1 f-default']")
78
+ output_buffer.should have_selector("legend[@class='super1 l-default']", :content => "MyLegend1")
79
+ output_buffer.should have_selector("input[@id='my_model_mobile']")
80
+ output_buffer.should have_selector("textarea[@id='my_model_cv']")
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::FormBuilder' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it 'should yield an instance of GenericFormFor::FormBuilder' do
12
+ generic_form_for(@model, :url => '/hello') do |builder|
13
+ builder.class.should == GenericFormFor::FormBuilder
14
+ end
15
+ end
16
+
17
+ it 'should add "novalidate" attribute when configured' do
18
+ with_config :html5_browser_validate, false do
19
+ concat(generic_form_for(:user, :url => '/hello') do |builder|
20
+ end)
21
+ output_buffer.should have_selector("form[@novalidate]")
22
+ end
23
+ end
24
+
25
+ it 'should not add "novalidate" attribute when configured' do
26
+ with_config :html5_browser_validate, true do
27
+ concat(generic_form_for(:user, :url => '/hello') do |builder|
28
+ end)
29
+ output_buffer.should_not have_selector("form[@novalidate]")
30
+ end
31
+ end
32
+
33
+ it 'should not add "novalidate" attribute when told so' do
34
+ with_config :html5_browser_validate, true do
35
+ concat(generic_form_for(:user, :url => '/hello', :html => {:novalidate => false}) do |builder|
36
+ end)
37
+ output_buffer.should_not have_selector("form[@novalidate]")
38
+ end
39
+ end
40
+
41
+ it 'should add "novalidate" attribute when told so' do
42
+ with_config :html5_browser_validate, false do
43
+ concat(generic_form_for(:user, :url => '/hello', :html => {:novalidate => true}) do |builder|
44
+ end)
45
+ output_buffer.should have_selector("form[@novalidate]")
46
+ end
47
+ end
48
+ #
49
+ describe '#generic_fields_for' do
50
+ it 'should yield an instance of GenericFormFor::FormBuilder' do
51
+ generic_fields_for(:user) do |builder|
52
+ builder.class.should.kind_of?(GenericFormFor::FormBuilder)
53
+ end
54
+ end
55
+ it 'should yield an instance of GenericFormFor::FormBuilder within builder' do
56
+ with_config :html5_browser_validate, false do
57
+ concat(generic_form_for(:user, :url => '/hello', :html => {:novalidate => true}) do |builder|
58
+ builder.generic_fields_for(:user) do |fields|
59
+ fields.class.should.kind_of?(GenericFormFor::FormBuilder)
60
+ end
61
+ end)
62
+ end
63
+ end
64
+ end
65
+
66
+ describe 'generic_form DSL' do
67
+ it "should generate form" do
68
+ with_form_config do
69
+ GenericFormFor::FormBuilder.form_wrapper do
70
+ form_html
71
+ end
72
+ concat(generic_form_for(:user, :url => '/hello') do |builder|
73
+ end)
74
+ output_buffer.should have_selector("form[@action='/hello']")
75
+ end
76
+ end
77
+
78
+ it "should apply form options" do
79
+ with_form_config do
80
+ GenericFormFor::FormBuilder.form_wrapper do
81
+ form_html :class => "someform"
82
+ end
83
+ concat(generic_form_for(:user, :url => '/hello', :html => {:novalidate => true}) do |builder|
84
+ end)
85
+ output_buffer.should have_selector("form[@class='someform'][@novalidate]")
86
+ end
87
+ end
88
+
89
+ it "should apply custom form options" do
90
+ with_form_config do
91
+ GenericFormFor::FormBuilder.form_wrapper do
92
+ form_html :class => "someform"
93
+ end
94
+ concat(generic_form_for(:user, :url => '/hello', :html => {:novalidate => true, :class => "myform"}) do |builder|
95
+ end)
96
+ output_buffer.should have_selector("form[@class='myform someform'][@novalidate]")
97
+ end
98
+ end
99
+
100
+ end
101
+ end