Permalink
Browse files

[merb-helpers] Select the correct field in select tags

  • Loading branch information...
teamon authored and snusnu committed Oct 26, 2009
1 parent fcf8ced commit e2e3866efa39e5a307fdd406005e0012c02e3c90
@@ -164,7 +164,7 @@ def update_bound_check_box(method, attrs)
def update_bound_select(method, attrs)
attrs[:value_method] ||= method
attrs[:text_method] ||= attrs[:value_method] || :to_s
- attrs[:selected] ||= control_value(attrs[:value_method])
+ attrs[:selected] ||= control_value(method)
end
def update_unbound_controls(attrs, type)
@@ -0,0 +1,3 @@
+<%= form_for @obj do %>
+<%= select( :bar, :collection => @collection, :text_method => :bar, :value_method => :foo ) %>
+<% end =%>
@@ -984,6 +984,19 @@
form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
end
+ it "should render a select tag with correct field selected" do
+ a = FakeModel3.new; a.bar = "A"; a.foo = 4
+ b = FakeModel3.new; b.bar = "B"; b.foo = 2
+ c = FakeModel3.new; c.bar = "C"; c.foo = 7
+
+ @c.instance_variable_set(:@collection, [a,b,c])
+
+ r = @c.render :selected
+ r.should_not have_selector("select[id=fake_model_bar] option[selected]:contains('A')")
+ r.should_not have_selector("select[id=fake_model_bar] option[selected]:contains('B')")
+ r.should have_selector("select[id=fake_model_bar] option[selected]:contains('C')")
+ end
+
# Not sure how this makes any sense
# ---------------------------------
#

0 comments on commit e2e3866

Please sign in to comment.