Skip to content

Instantly share code, notes, and snippets.

@don-smith
Created October 7, 2010 17:00
Show Gist options
  • Save don-smith/615455 to your computer and use it in GitHub Desktop.
Save don-smith/615455 to your computer and use it in GitHub Desktop.
# app/views/talks/_form.html.erb
<%= form_for([@event, @talk]) do |f| %>
<% if @talk.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@talk.errors.count, "error") %> prohibited this talk from being saved:</h2>
<ul>
<% @talk.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :abstract %><br />
<%= f.text_area :abstract %>
</div>
<div class="field">
<%= f.label :level %><br />
<%= f.text_field :level %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Need to include once I can 'bundle install'
# spec/views/talks/new.html.erb_spec.rb
require 'spec_helper'
describe 'talks/new.html.erb' do
before(:each) do
assign(:talk, stub_model(Talk,
:new_record? => true,
:event_id => 12
))
view.stub!(:event_talks_path).and_return {'/events/12/talks'}
end
it 'renders new talk form' do
render
rendered.should have_selector('form', :action => talks_path, :method => 'post') do |form|
form.should have_selector('input#talk_title', :name => 'talk[title]')
form.should have_selector('textarea#talk_abstract', :name => 'talk[abstract]')
form.should have_selector('input#talk_level', :name => 'talk[level]')
end
end
end
@don-smith
Copy link
Author

I don't think it matters, but I am using the 0.7.2.pre branch of webrat at http://github.com/kalv/webrat.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment