From f201f5a1ffd3877dc910c8ed75f47475a558bc8c Mon Sep 17 00:00:00 2001 From: Shay Arnett Date: Tue, 3 Jun 2008 12:38:46 -0400 Subject: [PATCH] allow delete_button to accept local variables --- merb_helpers/lib/merb_helpers/form_helpers.rb | 2 +- merb_helpers/spec/merb_helpers_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/merb_helpers/lib/merb_helpers/form_helpers.rb b/merb_helpers/lib/merb_helpers/form_helpers.rb index e69fe67..49fedd7 100644 --- a/merb_helpers/lib/merb_helpers/form_helpers.rb +++ b/merb_helpers/lib/merb_helpers/form_helpers.rb @@ -587,7 +587,7 @@ module Merb # # def delete_button(symbol_or_string, obj = nil, contents = 'Delete', form_attrs = {}, button_attrs = {}) - obj = instance_variable_get("@#{symbol_or_string}") if symbol_or_string.kind_of?(Symbol) + obj ||= instance_variable_get("@#{symbol_or_string}") if symbol_or_string.kind_of?(Symbol) button_attrs[:type] = :submit diff --git a/merb_helpers/spec/merb_helpers_spec.rb b/merb_helpers/spec/merb_helpers_spec.rb index c1aaf6d..ff494b3 100644 --- a/merb_helpers/spec/merb_helpers_spec.rb +++ b/merb_helpers/spec/merb_helpers_spec.rb @@ -779,8 +779,11 @@ end describe 'delete_button' do before :each do @obj = mock 'a model' + @obj.stub!(:object_id).and_return("1") + Merb::Router.prepare do |r| r.resources :objs + r.resources :foos end def url(sym, obj) "/objs/#{obj.object_id}" @@ -803,6 +806,11 @@ describe 'delete_button' do delete_button(:obj).should == delete_button(:obj, @obj) end + it "should allow you to use a local variable as is common in a .each loop" do + foo = @obj + delete_button(:foo, foo).should == delete_button(:obj) + end + it 'should allow you to modify the action so you can use routes with multiple params' do result = delete_button('/objs/2/subobjs/1') result.should match_tag(:form, :action => "/objs/2/subobjs/1", :method => "post") -- 1.5.3.8