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
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base::Validations' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should identify require fields" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name))
14
+ end)
15
+ output_buffer.should have_selector("input", :id => "my_model_name", :required => "required")
16
+ end
17
+
18
+ it "should use custom require attribute false" do
19
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
20
+ concat(builder.input(:home_page, :required => false))
21
+ end)
22
+ output_buffer.should_not have_selector("input", :id => "my_model_home_page", :required => "required")
23
+ end
24
+
25
+ it "should use custom require attribute true" do
26
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
27
+ concat(builder.input(:home_page, :required => true))
28
+ end)
29
+ output_buffer.should have_selector("input", :id => "my_model_home_page", :required => "required")
30
+ end
31
+
32
+ it "should identify limit from db" do
33
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
34
+ concat(builder.input(:name))
35
+ end)
36
+ output_buffer.should have_selector("input", :id => "my_model_name", :maxlength => "255")
37
+ end
38
+
39
+ it "should identify min and max values from validations" do
40
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
41
+ concat(builder.input(:money))
42
+ end)
43
+ output_buffer.should have_selector("input", :id => "my_model_money", :min => "5", :max => "99.99")
44
+ end
45
+
46
+ it "should not identify min and max values from validations" do
47
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
48
+ concat(builder.input(:age))
49
+ end)
50
+ # stupid
51
+ output_buffer.should_not have_selector("input", :id => "my_model_ages", :min => "5")
52
+ end
53
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should be required if set so in model" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name))
14
+ end)
15
+ output_buffer.should have_selector("input[@id='my_model_name'][@required='required']")
16
+ end
17
+
18
+ it "should not be required if set so in options" do
19
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
20
+ concat(builder.input(:name, :required => false))
21
+ end)
22
+ output_buffer.should_not have_selector("input[@id='my_model_name'][@required='required']")
23
+ end
24
+
25
+ it "should take hint as placeholder" do
26
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
27
+ concat(builder.input(:name, :placeholder => "Yes"))
28
+ end)
29
+ output_buffer.should have_selector("input[@id='my_model_name'][@placeholder='Yes']")
30
+ end
31
+
32
+ it "should add autofocus to first element" do
33
+ with_config :html5_browser_autofocus, true do
34
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
35
+ concat(builder.input(:name))
36
+ end)
37
+ end
38
+ output_buffer.should have_selector("input[@id='my_model_name'][@autofocus='autofocus']")
39
+ end
40
+
41
+ it "should skip autofocus if configured so" do
42
+ with_config :html5_browser_autofocus, false do
43
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
44
+ concat(builder.input(:name))
45
+ end)
46
+ end
47
+ output_buffer.should_not have_selector("input[@id='my_model_name'][@autofocus='autofocus']")
48
+ end
49
+
50
+ it "should add autofocus to first element if set on form" do
51
+ with_config :html5_browser_autofocus, false do
52
+ concat(generic_form_for(@model, :url => "/hello", :autofocus => true) do |builder|
53
+ concat(builder.input(:name))
54
+ end)
55
+ end
56
+ output_buffer.should have_selector("input[@id='my_model_name'][@autofocus='autofocus']")
57
+ end
58
+
59
+ it "should add autofocus specified element" do
60
+ with_config :html5_browser_autofocus, false do
61
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
62
+ concat(builder.input(:name))
63
+ concat(builder.input(:home_page, :autofocus => true))
64
+ end)
65
+ end
66
+ output_buffer.should_not have_selector("input[@id='my_model_name'][@autofocus='autofocus']")
67
+ output_buffer.should have_selector("input[@id='my_model_home_page'][@autofocus='autofocus']")
68
+ end
69
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::BooleanInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :active, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:active))
23
+ end)
24
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden']")
25
+ output_buffer.should have_selector("input[@id='my_model_active'][@type='checkbox'][@name='my_model[active]']")
26
+ output_buffer.should have_selector("label[@for='my_model_active']", :content => "Active")
27
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
28
+ output_buffer.should have_selector("div", :class => "boolean-input controls")
29
+ end
30
+ end
31
+
32
+ it "should accept checked_value" do
33
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
34
+ concat(builder.input :active, :checked_value => "Yes")
35
+ end)
36
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden'][@value='0']")
37
+ output_buffer.should have_selector("input[@id='my_model_active'][@name='my_model[active]'][@type='checkbox'][@value='Yes']")
38
+ output_buffer.should have_selector("div", :class => "boolean-input")
39
+ end
40
+
41
+ it "should accept checked_value and unchecked_value" do
42
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
43
+ concat(builder.input :active, :checked_value => "Yes", :unchecked_value => "No")
44
+ end)
45
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden'][@value='No']")
46
+ output_buffer.should have_selector("input[@id='my_model_active'][@name='my_model[active]'][@type='checkbox'][@value='Yes']")
47
+ output_buffer.should have_selector("div", :class => "boolean-input")
48
+ end
49
+
50
+ it "should accept checked" do
51
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
52
+ concat(builder.input :active, :checked => true)
53
+ end)
54
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden'][@value='0']")
55
+ output_buffer.should have_selector("input[@id='my_model_active'][@name='my_model[active]'][@type='checkbox'][@value='1'][@checked='checked']")
56
+ output_buffer.should have_selector("div", :class => "boolean-input")
57
+ end
58
+
59
+ it "should be checked" do
60
+ @model.active = 1
61
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
62
+ concat(builder.input :active)
63
+ end)
64
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden'][@value='0']")
65
+ output_buffer.should have_selector("input[@id='my_model_active'][@name='my_model[active]'][@type='checkbox'][@value='1'][@checked='checked']")
66
+ output_buffer.should have_selector("div", :class => "boolean-input")
67
+ end
68
+
69
+ it "should override default checked" do
70
+ @model.active = 1
71
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
72
+ concat(builder.input :active, :checked => false)
73
+ end)
74
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden'][@value='0']")
75
+ output_buffer.should_not have_selector("input[@id='my_model_active'][@name='my_model[active]'][@type='checkbox'][@value='1'][@checked='checked']")
76
+ output_buffer.should have_selector("div", :class => "boolean-input")
77
+ end
78
+
79
+ it "should accept value" do
80
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
81
+ concat(builder.input :active, :checked_value => "Yes", :value => "Yes")
82
+ end)
83
+ output_buffer.should have_selector("input[@name='my_model[active]'][@type='hidden'][@value='0']")
84
+ output_buffer.should have_selector("input[@id='my_model_active'][@name='my_model[active]'][@type='checkbox'][@value='Yes'][@checked='checked']")
85
+ output_buffer.should have_selector("div", :class => "boolean-input")
86
+ end
87
+
88
+ it "should accept options from params" do
89
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
90
+ concat(builder.input(:active, :disabled => true))
91
+ end)
92
+ output_buffer.should have_selector("input[@id='my_model_active'][@type='checkbox'][@disabled='disabled']")
93
+ output_buffer.should have_selector("div", :class => "boolean-input")
94
+ end
95
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::EmailInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :email, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:email))
23
+ end)
24
+ output_buffer.should have_selector("input[@id='my_model_email'][@type='email']")
25
+ output_buffer.should have_selector("label[@for='my_model_email']", :content => "Email")
26
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
27
+ output_buffer.should have_selector("div", :class => "email-input controls")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::FileInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :cv, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:cv, :as => :file))
23
+ end)
24
+ output_buffer.should have_selector("input[@id='my_model_cv'][@type='file']")
25
+ output_buffer.should have_selector("label[@for='my_model_cv']", :content => "Cv")
26
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
27
+ output_buffer.should have_selector("div", :class => "file-input controls")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::HiddenInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :password, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:password, :as => :hidden))
23
+ end)
24
+ output_buffer.should have_selector("input[@id='my_model_password'][@type='hidden']")
25
+ output_buffer.should_not have_selector("label[@for='my_model_password']", :content => "Password")
26
+ output_buffer.should_not have_selector("span[@class='error']", :content => "My mistake")
27
+ output_buffer.should have_selector("div", :class => "hidden-input controls")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::NumberInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :age, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:age))
23
+ concat(builder.input(:money))
24
+ end)
25
+ output_buffer.should have_selector("input[@id='my_model_age'][@type='number']")
26
+ output_buffer.should have_selector("label[@for='my_model_age']", :content => "Age")
27
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
28
+
29
+ output_buffer.should have_selector("input[@id='my_model_money'][@type='number'][@step='0.01'][@min='5'][@max='99.99']")
30
+ output_buffer.should have_selector("label[@for='my_model_money']", :content => "Money")
31
+
32
+ output_buffer.should have_selector("div", :class => "number-input controls")
33
+
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::PasswordInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :password, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:password))
23
+ end)
24
+ output_buffer.should have_selector("input[@id='my_model_password'][@type='password']")
25
+ output_buffer.should have_selector("label[@for='my_model_password']", :content => "Password")
26
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
27
+ output_buffer.should have_selector("div", :class => "password-input controls")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::PhoneInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :mobile, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:mobile))
23
+ end)
24
+ output_buffer.should have_selector("input[@id='my_model_mobile'][@type='tel']")
25
+ output_buffer.should have_selector("label[@for='my_model_mobile']", :content => "Mobile")
26
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
27
+ output_buffer.should have_selector("div", :class => "phone-input controls")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::RangeInput' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate wrapped input with label" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ wrap_in :class => "controls" do
15
+ label_html
16
+ input_html
17
+ error_html
18
+ end
19
+ end
20
+ @model.errors.add :age, "My mistake"
21
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
22
+ concat(builder.input(:age, :as => :range))
23
+ concat(builder.input(:money, :as => :range))
24
+ end)
25
+ output_buffer.should have_selector("input[@id='my_model_age'][@type='range']")
26
+ output_buffer.should have_selector("label[@for='my_model_age']", :content => "Age")
27
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
28
+
29
+ output_buffer.should have_selector("input[@id='my_model_money'][@type='range'][@step='0.01'][@min='5'][@max='99.99']")
30
+ output_buffer.should have_selector("label[@for='my_model_money']", :content => "Money")
31
+
32
+ output_buffer.should have_selector("div", :class => "range-input controls")
33
+
34
+ end
35
+ end
36
+
37
+ end