Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix multiple parameter bug for part() method.

When passing multiple parameters to the part() method, all but
the fist parameter was lost.

Fixed specs for Ruby 1.9.1 to pass.

[#192 status:resolved]
  • Loading branch information...
commit 4d3f18d305a6fb1945b2be18fe974bfefb5f73d8 1 parent c3ebec4
@pk pk authored
View
4 lib/merb_parts/mixins/parts_mixin.rb
@@ -30,7 +30,7 @@ def part(opts = {})
k.respond_to?(:ancestors) && k.ancestors.include?(Merb::PartController)
end
- opts = opts.empty? ? {} : Hash[*(opts.first)]
+ opts = opts.inject({}) {|h,v| h[v.first] = v.last; h}
res = klasses.inject([]) do |memo,(klass,action)|
memo << klass.new(self, opts)._dispatch(action)
@@ -39,4 +39,4 @@ def part(opts = {})
end
end
-end
+end
View
6 spec/fixtures/controllers/main.rb
@@ -19,11 +19,11 @@ def index4
end
def part_with_params
- part(TodoPart => :part_with_params, :my_param => "my_value")
+ part(TodoPart => :part_with_params, :my_param => "my_value", :my_second_param => "my_value")
end
def part_with_arrays_in_params
- part(TodoPart => :part_with_params, :my_param => ['my_first_value', 'my_second_value'])
+ part(TodoPart => :part_with_params, :my_param => ['my_first_value', 'my_second_value'], :my_second_param => "my_value")
end
def part_within_view
@@ -34,4 +34,4 @@ def parth_with_absolute_template
part(TodoPart => :parth_with_absolute_template)
end
-end
+end
View
8 spec/merb-parts_spec.rb
@@ -3,8 +3,8 @@
describe "A Merb PartController" do
before(:each) do
- Merb::Router.prepare do |r|
- r.default_routes
+ Merb::Router.prepare do
+ default_routes
end
end
@@ -45,11 +45,13 @@
it "should provide params when calling a part" do
controller = dispatch_to(Main, :part_with_params)
controller.body.should match( /my_param = my_value/)
+ controller.body.should match( /my_second_param = my_value/)
end
it "should provide arrays from params when calling a part" do
controller = dispatch_to(Main, :part_with_arrays_in_params)
controller.body.should match(/my_param = my_first_value, my_second_value/)
+ controller.body.should match( /my_second_param = my_value/)
end
it "should render from inside a view" do
@@ -86,4 +88,4 @@ def new_url_controller(route, params = {:action => 'show', :controller => 'Test'
TodoPart._template_root.should == DonePart._template_root
end
-end
+end
View
7 spec/spec_helper.rb
@@ -5,8 +5,11 @@
# Require the fixtures
Dir[File.join(File.dirname(__FILE__), "fixtures", "*/**.rb")].each{|f| require f }
-Merb.start :environment => 'test', :adapter => 'runner'
+Merb.start :environment => 'test',
+ :adapter => 'runner',
+ :log_level => :error,
+ :disabled_components => [:json]
Spec::Runner.configure do |config|
config.include Merb::Test::RequestHelper
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.