Changeset 1146

Show
Ignore:
Timestamp:
01/02/08 09:32:11 (9 months ago)
Author:
wayneesegu..@gmail.com
Message:

Applying Patch for ticket #383.
Patch also fixes #385.
Thanks to lancecarlson@gmail.com.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/merb_helpers/lib/merb_helpers/form_helpers.rb

    r1131 r1146  
    502502        self_closing_tag("input", attrs) 
    503503      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          
    505530      private 
     531 
    506532      # Fake out the browser to send back the method for RESTful stuff. 
    507533      # 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  
    656656  end 
    657657end 
     658 
     659 
     660describe "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 
     680end 
  • plugins/merb_helpers/specs/spec_helper.rb

    r1108 r1146  
    99  config.include(Merb::Test::Helper) 
    1010  config.include(Merb::Test::RspecMatchers) 
    11   config.include(Merb::Test::MerbRspecControllerRedirect)   
    1211end 
    1312