Class: DynamicFormTest
- Inherits:
-
ActionView::TestCase
- Object
- ActionView::TestCase
- DynamicFormTest
- Defined in:
- lib/dynamic_form/test/dynamic_form_test.rb
Defined Under Namespace
Classes: DirtyPost
Instance Attribute Summary collapse
-
#form_authenticity_token ⇒ Object
Returns the value of attribute form_authenticity_token.
-
#request_forgery_protection_token ⇒ Object
Returns the value of attribute request_forgery_protection_token.
Class Method Summary collapse
- .column_for_attribute(attr_name) ⇒ Object
- .errors ⇒ Object
- .new_record? ⇒ Boolean
- .persisted? ⇒ Boolean
- .to_param ⇒ Object
Instance Method Summary collapse
- #form_for ⇒ Object
- #protect_against_forgery? ⇒ Boolean
- #setup ⇒ Object
- #setup_post ⇒ Object
- #setup_user ⇒ Object
- #test_default_form_builder_no_instance_variable ⇒ Object
- #test_default_form_builder_with_dynamic_form_helpers ⇒ Object
- #test_error_for_block ⇒ Object
- #test_error_message_on ⇒ Object
- #test_error_message_on_escapes_html ⇒ Object
- #test_error_message_on_handles_empty_errors ⇒ Object
- #test_error_message_on_handles_nil ⇒ Object
- #test_error_message_on_no_instance_variable ⇒ Object
- #test_error_message_on_with_options_hash ⇒ Object
- #test_error_message_on_with_tag_option_in_options_hash ⇒ Object
- #test_error_messages_for_escapes_html ⇒ Object
- #test_error_messages_for_handles_nil ⇒ Object
- #test_error_messages_for_many_objects ⇒ Object
- #test_error_messages_for_model_objects ⇒ Object
- #test_error_messages_for_non_instance_variable ⇒ Object
- #test_field_error_proc ⇒ Object
- #test_form_with_action_option ⇒ Object
- #test_form_with_date ⇒ Object
- #test_form_with_datetime ⇒ Object
- #test_form_with_method_option ⇒ Object
- #test_form_with_protect_against_forgery ⇒ Object
- #test_form_with_string ⇒ Object
- #test_form_with_string_multipart ⇒ Object
- #test_generic_input_tag ⇒ Object
- #test_text_area_with_errors ⇒ Object
- #test_text_field_with_errors ⇒ Object
- #url_for(options) ⇒ Object
Instance Attribute Details
#form_authenticity_token ⇒ Object
Returns the value of attribute form_authenticity_token.
118 119 120 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 118 def form_authenticity_token @form_authenticity_token end |
#request_forgery_protection_token ⇒ Object
Returns the value of attribute request_forgery_protection_token.
118 119 120 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 118 def request_forgery_protection_token @request_forgery_protection_token end |
Class Method Details
.column_for_attribute(attr_name) ⇒ Object
75 76 77 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 75 def @post.column_for_attribute(attr_name) Post.content_columns.select { |column| column.name == attr_name }.first end |
.errors ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 54 def @post.errors Class.new { def [](field) case field.to_s when "author_name" ["can't be empty"] when "body" ['foo'] else [] end end def empty?() false end def count() 1 end def () [ "Author name can't be empty" ] end }.new end |
.new_record? ⇒ Boolean
101 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 101 def @user.new_record?() true end |
.persisted? ⇒ Boolean
72 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 72 def @post.persisted?() false end |
.to_param ⇒ Object
73 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 73 def @post.to_param() nil end |
Instance Method Details
#form_for ⇒ Object
7 8 9 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 7 def form_for(*) @output_buffer = super end |
#protect_against_forgery? ⇒ Boolean
115 116 117 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 115 def protect_against_forgery? @protect_against_forgery ? true : false end |
#setup ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 120 def setup super setup_post setup_user @response = ActionController::TestResponse.new end |
#setup_post ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 52 def setup_post @post = Post.new def @post.errors Class.new { def [](field) case field.to_s when "author_name" ["can't be empty"] when "body" ['foo'] else [] end end def empty?() false end def count() 1 end def () [ "Author name can't be empty" ] end }.new end def @post.persisted?() false end def @post.to_param() nil end def @post.column_for_attribute(attr_name) Post.content_columns.select { |column| column.name == attr_name }.first end silence_warnings do def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end end @post.title = "Hello World" @post. = "" @post.body = "Back to the hill and over it again!" @post.secret = 1 @post.written_on = Date.new(2004, 6, 15) end |
#setup_user ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 90 def setup_user @user = User.new def @user.errors Class.new { def [](field) field == "email" ? ['nonempty'] : [] end def empty?() false end def count() 1 end def () [ "User email can't be empty" ] end }.new end def @user.new_record?() true end def @user.to_param() nil end def @user.column_for_attribute(attr_name) User.content_columns.select { |column| column.name == attr_name }.first end silence_warnings do def User.content_columns() [ Column.new(:string, "email", "Email") ] end end @user.email = "" end |
#test_default_form_builder_no_instance_variable ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 354 def test_default_form_builder_no_instance_variable post = @post @post = nil form_for(post, :as => :post, :url => {}) do |f| concat f.('author_name') concat f. end expected = %(<form class="post_new" method="post" action="" id="post_new">) + %(<div class="formError">can't be empty</div>) + %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(</form>) assert_dom_equal expected, output_buffer end |
#test_default_form_builder_with_dynamic_form_helpers ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 340 def test_default_form_builder_with_dynamic_form_helpers form_for(@post, :as => :post, :url => {}) do |f| concat f.('author_name') concat f. end expected = %(<form class="post_new" method="post" action="" id="post_new">) + %(<div class="formError">can't be empty</div>) + %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(</form>) assert_dom_equal expected, output_buffer end |
#test_error_for_block ⇒ Object
234 235 236 237 238 239 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 234 def test_error_for_block assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), ("post") assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), ("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1") assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), ("post", :class => nil, :id => "errorDeathById", :header_tag => "h1") assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), ("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1") end |
#test_error_message_on ⇒ Object
259 260 261 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 259 def assert_dom_equal "<div class=\"formError\">can't be empty</div>", (:post, :author_name) end |
#test_error_message_on_escapes_html ⇒ Object
250 251 252 253 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 250 def @dirty_post = DirtyPost.new assert_dom_equal "<div class=\"formError\">can't be <em>empty</em></div>", (:dirty_post, :author_name) end |
#test_error_message_on_handles_empty_errors ⇒ Object
276 277 278 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 276 def assert_equal "", (@post, :tag) end |
#test_error_message_on_handles_nil ⇒ Object
255 256 257 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 255 def assert_equal "", ("notthere", "notthere") end |
#test_error_message_on_no_instance_variable ⇒ Object
263 264 265 266 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 263 def other_post = @post assert_dom_equal "<div class=\"formError\">can't be empty</div>", (other_post, :author_name) end |
#test_error_message_on_with_options_hash ⇒ Object
268 269 270 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 268 def assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", (:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') end |
#test_error_message_on_with_tag_option_in_options_hash ⇒ Object
272 273 274 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 272 def assert_dom_equal "<span class=\"differentError\">beforecan't be emptyafter</span>", (:post, :author_name, :html_tag => "span", :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') end |
#test_error_messages_for_escapes_html ⇒ Object
241 242 243 244 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 241 def @dirty_post = DirtyPost.new assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this dirty post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be <em>empty</em></li></ul></div>), ("dirty_post") end |
#test_error_messages_for_handles_nil ⇒ Object
246 247 248 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 246 def assert_equal "", ("notthere") end |
#test_error_messages_for_many_objects ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 280 def assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), ("post", "user") # reverse the order, error order changes and so does the title assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), ("user", "post") # add the default to put post back in the title assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), ("user", "post", :object_name => "post") # symbols work as well assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), (:user, :post, :object_name => :post) # any default works too assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), (:user, :post, :object_name => "monkey") # should space object name assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), (:user, :post, :object_name => "chunky_bacon") # hide header and explanation messages with nil or empty string assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), (:user, :post, :header_message => nil, :message => "") # override header and explanation messages = "Yikes! Some errors" = "Please fix the following fields and resubmit:" assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{}</h2><p>#{}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), (:user, :post, :header_message => , :message => ) end |
#test_error_messages_for_model_objects ⇒ Object
323 324 325 326 327 328 329 330 331 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 323 def error = (@post) assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error error = (@user, @post) assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error end |
#test_error_messages_for_non_instance_variable ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 307 def actual_user = @user actual_post = @post @user = nil @post = nil #explicitly set object assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), ("post", :object => actual_post) #multiple objects assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), ("user", "post", :object => [actual_user, actual_post]) #nil object assert_equal '', ('user', :object => nil) end |
#test_field_error_proc ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 153 def test_field_error_proc old_proc = ActionView::Base.field_error_proc ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| %(<div class=\"fieldWithErrors\">#{html_tag} <span class="error">#{[instance.].join(', ')}</span></div>).html_safe end assert_dom_equal( %(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /> <span class="error">can't be empty</span></div>), text_field("post", "author_name") ) ensure ActionView::Base.field_error_proc = old_proc if old_proc end |
#test_form_with_action_option ⇒ Object
204 205 206 207 208 209 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 204 def test_form_with_action_option output_buffer << form("post", :action => "sign") assert_select "form[action=sign]" do |form| assert_select "input[type=submit][value=Sign]" end end |
#test_form_with_date ⇒ Object
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 211 def test_form_with_date silence_warnings do def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end end assert_dom_equal( %(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>), form("post") ) end |
#test_form_with_datetime ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 222 def test_form_with_datetime silence_warnings do def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end end @post.written_on = Time.gm(2004, 6, 15, 16, 30) assert_dom_equal( %(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n — <select id="post_written_on_4i" name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_written_on_5i" name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>), form("post") ) end |
#test_form_with_method_option ⇒ Object
197 198 199 200 201 202 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 197 def test_form_with_method_option assert_dom_equal( %(<form action="create" method="get"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), form("post", :method=>'get') ) end |
#test_form_with_protect_against_forgery ⇒ Object
187 188 189 190 191 192 193 194 195 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 187 def test_form_with_protect_against_forgery @protect_against_forgery = true @request_forgery_protection_token = 'authenticity_token' @form_authenticity_token = '123' assert_dom_equal( %(<form action="create" method="post"><div style='margin:0;padding:0;display:inline'><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), form("post") ) end |
#test_form_with_string ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 167 def test_form_with_string assert_dom_equal( %(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), form("post") ) silence_warnings do class << @post def persisted?() true end def to_param() id end def id() 1 end end end assert_dom_equal( %(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>), form("post") ) end |
#test_form_with_string_multipart ⇒ Object
333 334 335 336 337 338 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 333 def test_form_with_string_multipart assert_dom_equal( %(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), form("post", :multipart => true) ) end |
#test_generic_input_tag ⇒ Object
133 134 135 136 137 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 133 def test_generic_input_tag assert_dom_equal( %(<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />), input("post", "title") ) end |
#test_text_area_with_errors ⇒ Object
139 140 141 142 143 144 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 139 def test_text_area_with_errors assert_dom_equal( %(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>), text_area("post", "body") ) end |
#test_text_field_with_errors ⇒ Object
146 147 148 149 150 151 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 146 def test_text_field_with_errors assert_dom_equal( %(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /></div>), text_field("post", "author_name") ) end |
#url_for(options) ⇒ Object
128 129 130 131 |
# File 'lib/dynamic_form/test/dynamic_form_test.rb', line 128 def url_for() = .symbolize_keys [[:action], [:id].to_param].compact.join('/') end |