Skip to content

Instantly share code, notes, and snippets.

@wjbuys
Created December 13, 2010 19:25
Show Gist options
  • Save wjbuys/739453 to your computer and use it in GitHub Desktop.
Save wjbuys/739453 to your computer and use it in GitHub Desktop.
describe Template do
it "pulls out parameters from the template body" do
template = Template.new("Look at my template with {Adjective} many {Noun}!")
template.parameters.should == ["Adjective", "Noun"]
message = Message.new(template)
message.parameters.should == {
"Adjective" => nil,
"Noun" => nil
}
message.parameters["Adjective"] = "extremely"
message.parameters["Noun"] = "parts"
message.to_s.should == "Look at my template with extremely many parts!"
end
end
describe TemplateHelper do
it "builds a form with a field for each parameter" do
include TemplateHelper
message = Message.new
message.parameters = {
"MyParam" => "My Initial Value",
"OtherParam" => "My Initial Value Too"
}
form = template_form_for(@message, "url", :method => :post)
form.should == '
<form action="url" method="post">
<label>MyParam</label><input type="text" name="message[MyParam]" value="My Initial Value"/>
<label>OtherParam</label><input type="text" name="message[OtherParam]" value="My Initial Value Too"/>
</form>
'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment