Skip to content

Instantly share code, notes, and snippets.

@bryansray
Created August 21, 2008 02:05
Show Gist options
  • Save bryansray/6482 to your computer and use it in GitHub Desktop.
Save bryansray/6482 to your computer and use it in GitHub Desktop.
# My spec ...
it "should not put the value of the last <option> attributes in to the attributes of the select tag" do
content = select(:collection => %w(one two three), :selected => 'three')
content.should_not match_tag(:select, :value => "three", :selected => "selected")
end
def options(col, text_meth, value_meth, attrs, sel, b)
options = [b] + col.map do |item|
value = item.send(value_meth)
opt_attrs = {:value => value}
opt_attrs.merge!(:selected => "selected") if value == sel
tag(:option, item.send(text_meth), opt_attrs)
end
options.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment