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,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Helpers::InputHelper' 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
+ 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']")
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
+ it "should set default modelless object type to string" do
21
+ default_input_type(:anything).should == :string
22
+ end
23
+
24
+ {
25
+ password: :password,
26
+ email: :email,
27
+ website: :url,
28
+ phone: :phone,
29
+ search: :search
30
+ }.each do |col, type|
31
+ it "should recognize #{col} as #{type}" do
32
+ my = Class.new
33
+ my.stub!(:type){:string}
34
+ stub!(:column_for){my}
35
+ default_input_type(col).should == type
36
+ end
37
+ end
38
+
39
+ {
40
+ one: :integer,
41
+ two: :float,
42
+ three: :decimal
43
+ }.each do |col, type|
44
+ it "should recognize #{type} as number" do
45
+ my = Class.new
46
+ my.stub!(:type){type}
47
+ stub!(:column_for){my}
48
+ default_input_type(col).should == :number
49
+ end
50
+ end
51
+
52
+ it "should recognize timestamp as datetime" do
53
+ my = Class.new
54
+ my.stub!(:type){:timestamp}
55
+ stub!(:column_for){my}
56
+ default_input_type(:created_at).should == :datetime
57
+ end
58
+
59
+ it "should recognize anything else as db column type" do
60
+ my = Class.new
61
+ my.stub!(:type){:mytype}
62
+ stub!(:column_for){my}
63
+ default_input_type(:created_at).should == :mytype
64
+ end
65
+
66
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::I18n' do
4
+ include GenericFormForSpecHelper
5
+ include GenericFormFor::I18n
6
+
7
+ describe "without translation" do
8
+
9
+ it "should return camelized string" do
10
+ with_config :use_translations, false do
11
+ translate(:my) do
12
+ "translated"
13
+ end.should eq("My")
14
+ end
15
+ end
16
+
17
+ it "should return unmodified string" do
18
+ with_config :use_translations, false do
19
+ translate("my") do
20
+ "translated"
21
+ end.should eq("my")
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ describe "with translation" do
28
+
29
+ it "should yield if symbol given" do
30
+ with_config :use_translations, true do
31
+ translate(:my) do
32
+ "translated"
33
+ end.should eq("translated")
34
+ end
35
+ end
36
+
37
+ it "should return parameter if not symbol" do
38
+ with_config :use_translations, true do
39
+ translate("my") do
40
+ "translated"
41
+ end.should eq("my")
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base::ErrorMessage' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should use error_html options" do
12
+ with_form_config do
13
+ GenericFormFor::FormBuilder.input_wrapper do
14
+ error_html
15
+ end
16
+ @model.errors.add :name, "My mistake"
17
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
18
+ concat(builder.input(:name, :error_html => {:class => "my-error", :id => "wrong"}))
19
+ end)
20
+ output_buffer.should have_selector("span[@class='error my-error'][@id='wrong']", :content => "My mistake")
21
+ end
22
+ end
23
+
24
+ it "should use custom options" do
25
+ with_form_config do
26
+ GenericFormFor::FormBuilder.input_wrapper do
27
+ error_html :class => "my_error", :data => {:url => "/my_url"}
28
+ end
29
+ @model.errors.add :name, "My mistake"
30
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
31
+ concat(builder.input(:name))
32
+ end)
33
+ output_buffer.should have_selector("span[@class='error my_error'][@data-url='/my_url']", :content => "My mistake")
34
+ end
35
+ end
36
+
37
+ it "should use custom options and label_html" do
38
+ with_form_config do
39
+ GenericFormFor::FormBuilder.input_wrapper do
40
+ error_html :class => "my_error"
41
+ end
42
+ @model.errors.add :name, "My mistake"
43
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
44
+ concat(builder.input(:name, :error_html => {:class => "supererror", :data => {:url => "/my_url"}}))
45
+ end)
46
+ output_buffer.should have_selector("span[@class='error supererror my_error'][@data-url='/my_url']", :content => "My mistake")
47
+ end
48
+ end
49
+
50
+ it "should override custom options and label_html" do
51
+ with_form_config do
52
+ GenericFormFor::FormBuilder.input_wrapper do
53
+ wrap_in :class => "controls" do
54
+ error_html :class => "my_error", :data => {:url => "/my_url"}
55
+ label_html
56
+ input_html
57
+ end
58
+ end
59
+ @model.errors.add :name, "My mistake"
60
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
61
+ concat(
62
+ builder.input(:name, :error_html => {:class => "supererror", :data => {:url => "/my_url2"}})+
63
+ builder.input(:email, :as => :string)
64
+ )
65
+ end)
66
+ output_buffer.should have_selector("span[@class='error supererror my_error'][@data-url='/my_url2']", :content => "My mistake")
67
+ end
68
+ end
69
+
70
+ it "should identify errors on field" do
71
+ @model.errors.add :name, "My mistake"
72
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
73
+ concat(builder.input(:name))
74
+ end)
75
+ output_buffer.should have_selector("input", :id => "my_model_name", :class => "string errors")
76
+ end
77
+
78
+ it "should not identify errors on other field" do
79
+ @model.errors.add :home_page, "My mistake"
80
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
81
+ concat(builder.input(:name))
82
+ end)
83
+ output_buffer.should_not have_selector("input", :id => "my_model_name", :class => "errors")
84
+ end
85
+
86
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base:Hint' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should set hint if provided" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name, :hint => "My hint"))
14
+ end)
15
+ output_buffer.should have_selector("input[@id='my_model_name']")
16
+ output_buffer.should have_selector("p", :content => "My hint")
17
+ end
18
+
19
+ it "should set translated hint if provided" do
20
+ #
21
+ with_config :use_translations, true do
22
+ ::I18n.stub!(:translate).with(:name, anything()) {"Title"}
23
+ ::I18n.stub!(:translate).with(:my_hint, anything()) {"This is real"}
24
+
25
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
26
+ concat(builder.input(:name, :hint => :my_hint))
27
+ end)
28
+ end
29
+ output_buffer.should have_selector("input[@id='my_model_name']")
30
+ output_buffer.should_not have_selector("input[@id='my_model_name']", :hint => "This is real")
31
+
32
+ end
33
+
34
+ it "should genearate hint with custom tag" do
35
+ with_form_config do
36
+ GenericFormFor::FormBuilder.input_wrapper do
37
+ wrap_in :class => "controls" do
38
+ label_html
39
+ input_html
40
+ error_html
41
+ hint_html :tag => :div, :class => "hints"
42
+ end
43
+ end
44
+ @model.errors.add :name, "My mistake"
45
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
46
+ concat(builder.input(:name, :as => :string, :hint => "Hi there"))
47
+ end)
48
+ output_buffer.should have_selector("input[@id='my_model_name'][@type='text']")
49
+ output_buffer.should have_selector("label[@for='my_model_name']", :content => "Name")
50
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
51
+ output_buffer.should have_selector("div", :class => "string-input controls")
52
+ output_buffer.should have_selector("div[@class='hints']", :content => "Hi there")
53
+ end
54
+ end
55
+
56
+ it "should accept hint options" do
57
+ with_form_config do
58
+ GenericFormFor::FormBuilder.input_wrapper do
59
+ wrap_in :class => "controls" do
60
+ label_html
61
+ input_html
62
+ error_html
63
+ hint_html :tag => :div, :class => "hints"
64
+ end
65
+ end
66
+ @model.errors.add :name, "My mistake"
67
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
68
+ concat(builder.input(:name, :as => :string, :hint => "Hi there", :hint_html => {:class => "myhint"}))
69
+ end)
70
+ output_buffer.should have_selector("input[@id='my_model_name'][@type='text']")
71
+ output_buffer.should have_selector("label[@for='my_model_name']", :content => "Name")
72
+ output_buffer.should have_selector("span[@class='error']", :content => "My mistake")
73
+ output_buffer.should have_selector("div", :class => "string-input controls")
74
+ output_buffer.should have_selector("div[@class='myhint hints']", :content => "Hi there")
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base:Label' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should use label_html options" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name, :label_html => {:class => "mylable", :for => "wrong"}))
14
+ end)
15
+ output_buffer.should have_selector("label[@class='mylable'][@for='wrong']")
16
+ end
17
+
18
+ it "should use custom options" do
19
+ with_form_config do
20
+ GenericFormFor::FormBuilder.input_wrapper do
21
+ label_html :class => "my_label", :data => {:url => "/my_url"}
22
+ end
23
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
24
+ concat(builder.input(:name))
25
+ end)
26
+ output_buffer.should have_selector("label[@for='my_model_name'][@class='my_label'][@data-url='/my_url']")
27
+ end
28
+ end
29
+
30
+ it "should use custom options and label_html" do
31
+ with_form_config do
32
+ GenericFormFor::FormBuilder.input_wrapper do
33
+ label_html :class => "my_label"
34
+ end
35
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
36
+ concat(builder.input(:name, :label_html => {:class => "superlabel", :data => {:url => "/my_url"}}))
37
+ end)
38
+ output_buffer.should have_selector("label[@for='my_model_name'][@class='superlabel my_label'][@data-url='/my_url']")
39
+ end
40
+ end
41
+
42
+ it "should override custom options and label_html" do
43
+ with_form_config do
44
+ GenericFormFor::FormBuilder.input_wrapper do
45
+ label_html :class => "my_label", :data => {:url => "/my_url"}
46
+ end
47
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
48
+ concat(builder.input(:name, :label_html => {:class => "superlabel", :data => {:url => "/my_url2"}}))
49
+ end)
50
+ output_buffer.should have_selector("label[@for='my_model_name'][@class='superlabel my_label'][@data-url='/my_url2']")
51
+ end
52
+ end
53
+
54
+ it "should use required string" do
55
+ with_config :required_string, "*" do
56
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
57
+ concat(builder.input(:name))
58
+ end)
59
+ end
60
+ output_buffer.should have_selector("label[@for='my_model_name']", :content => "Name*")
61
+ end
62
+
63
+ it "should use required proc" do
64
+ with_config :required_string, Proc.new{"***"} do
65
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
66
+ concat(builder.input(:name))
67
+ end)
68
+ end
69
+ output_buffer.should have_selector("label[@for='my_model_name']", :content => "Name***")
70
+ end
71
+
72
+ it "should use required option" do
73
+ with_config :required_string, "<abbr>*</abbr>" do
74
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
75
+ concat(builder.input(:name, :required => false))
76
+ end)
77
+ end
78
+ output_buffer.should have_selector("label[@for='my_model_name']", :content => "Name")
79
+ end
80
+
81
+ it "should use translated label" do
82
+ with_config :use_translations, true do
83
+ ::I18n.stub!(:translate).with(:name, anything()) {"My Name"}
84
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
85
+ concat(builder.input(:name))
86
+ end)
87
+ end
88
+ output_buffer.should have_selector("label[@for='my_model_name']", :content => "My Name")
89
+
90
+ end
91
+
92
+ it "should not render lable at all" do
93
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
94
+ concat(builder.input(:name, :label => false))
95
+ end)
96
+ output_buffer.should_not have_selector("label")
97
+
98
+ end
99
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base::Number' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate number attributes" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:age, :as => :number, :placeholder => "My name", :hint => "Yo"))
14
+ end)
15
+ output_buffer.should have_selector("input", :id => "my_model_age", :type => "number", :placeholder => "My name", :step => "1")
16
+ output_buffer.should have_selector("p", :content=>"Yo")
17
+ end
18
+
19
+ it "should genearate decimal attributes" do
20
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
21
+ concat(builder.input(:money, :as => :number))
22
+ end)
23
+ output_buffer.should have_selector("input", :id => "my_model_money", :type => "number", :step => "0.01", :max=>"99.99", :min=>"5")
24
+ end
25
+
26
+ it "should genearate number with custom attributes" do
27
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
28
+ concat(builder.input(:age, :as => :number, :min => "33", :max => "123"))
29
+ end)
30
+ output_buffer.should have_selector("input", :id => "my_model_age", :type => "number", :max => "123", :min => "33")
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base::Placeholder' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should set placeholer if provided" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name, :placeholder => "My hint"))
14
+ end)
15
+ output_buffer.should have_selector("input[@id='my_model_name'][@placeholder='My hint']")
16
+ end
17
+
18
+ it "should set translated placeholer if provided" do
19
+
20
+ with_config :use_translations, true do
21
+ ::I18n.stub!(:translate).with(:name, anything()) {"Name"}
22
+ ::I18n.stub!(:translate).with(:my_placeholder, anything()) {"This is real"}
23
+
24
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
25
+ concat(builder.input(:name, :placeholder => :my_placeholder))
26
+ end)
27
+ end
28
+ output_buffer.should have_selector("input[@id='my_model_name']", :placeholder => "This is real")
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GenericFormFor::Inputs::Base::String' do
4
+ include GenericFormForSpecHelper
5
+
6
+ before do
7
+ @model = MyModel.new
8
+ @output_buffer = ''
9
+ end
10
+
11
+ it "should genearate string attributes" do
12
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
13
+ concat(builder.input(:name, :as => :string, :placeholder => "My name", :hint => "Yo"))
14
+ end)
15
+ output_buffer.should have_selector("input", :id => "my_model_name", :type => "text", :placeholder => "My name", :maxlength => "255", :size => GenericFormFor::FormBuilder.default_text_field_size.to_s)
16
+ output_buffer.should have_selector("p",:content => "Yo")
17
+ end
18
+
19
+ it "should genearate string with custom attributes" do
20
+ concat(generic_form_for(@model, :url => "/hello") do |builder|
21
+ concat(builder.input(:name, :as => :string, :size => "33", :maxlength => "123"))
22
+ end)
23
+ output_buffer.should have_selector("input", :id => "my_model_name", :type => "text", :maxlength => "123", :size => "33")
24
+ end
25
+ end