Changeset 1146
- Timestamp:
- 01/02/08 09:32:11 (9 months ago)
- Files:
-
- plugins/merb_helpers/lib/merb_helpers/form_helpers.rb (modified) (1 diff)
- plugins/merb_helpers/specs/merb_helpers_spec.rb (modified) (1 diff)
- plugins/merb_helpers/specs/spec_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/merb_helpers/lib/merb_helpers/form_helpers.rb
r1131 r1146 502 502 self_closing_tag("input", attrs) 503 503 end 504 504 505 # Generates a delete button inside of a form. 506 # 507 # <%= delete_button :news_post, @news_post, 'Remove' %> 508 # 509 # The HTML generated for this would be: 510 # 511 # <form method="post" action="/news_posts/4"> 512 # <input type="hidden" value="delete" name="_method"/> 513 # <button type="submit">Remove</button> 514 # </form> 515 def delete_button(symbol, obj, contents = 'Delete', form_attrs = {}, button_attrs = {}) 516 button_attrs.merge!(:type => 'submit') 517 form_attrs.merge!(:action => url(symbol, obj), :method => :delete) 518 519 obj = obj_from_ivar_or_sym(symbol) 520 fake_form_method = set_form_method(form_attrs, obj) 521 522 output = "" 523 output << open_tag("form", form_attrs) 524 output << generate_fake_form_method(fake_form_method) 525 output << tag("button", contents, button_attrs) 526 output << "</form>" 527 output 528 end 529 505 530 private 531 506 532 # Fake out the browser to send back the method for RESTful stuff. 507 533 # Fall silently back to post if a method is given that is not supported here plugins/merb_helpers/specs/merb_helpers_spec.rb
r1108 r1146 656 656 end 657 657 end 658 659 660 describe "delete_button" do 661 before(:each) do 662 @obj = mock("a model") 663 Merb::Router.prepare do |r| 664 r.resources :objs 665 end 666 end 667 668 it "should return a button inside of a form for the object" do 669 result = delete_button(:obj, @obj) 670 result.should match_tag(:form, :action => "/objs/#{@obj.id}", :method => "post") 671 result.should match_tag(:input, :type => "hidden", :value => "delete", :name => "_method") 672 result.should match_tag(:button, :type => "submit") 673 result.should match(/<button.*>Delete<\/button>/) 674 end 675 676 it "should allow you to modify it's contents" do 677 result = delete_button(:obj, @obj, "Remove") 678 result.should match(/<button.*>Remove<\/button>/) 679 end 680 end plugins/merb_helpers/specs/spec_helper.rb
r1108 r1146 9 9 config.include(Merb::Test::Helper) 10 10 config.include(Merb::Test::RspecMatchers) 11 config.include(Merb::Test::MerbRspecControllerRedirect)12 11 end 13 12
