Permalink
Browse files

Refactor voter registration form into a partial

  • Loading branch information...
1 parent 74914a6 commit 3b14af8d7ba0c4209aac86edad5c00d2ca50b6b1 @MDaubs committed Jan 3, 2012
@@ -0,0 +1,24 @@
+<%= form_for @registration do |f| %>
+ <fieldset>
+ <legend>
+ Voter Registration
+ </legend>
+ <div class="clearfix">
+ <%= f.label :voter_name %>
+ <div class="input">
+ <%= f.text_field :voter_name %>
+ </div>
+ </div>
+ <div class="clearfix">
+ <%= f.label :booth_id %>
+ <div class="input">
+ <%= f.select :booth_id, Booth.all.collect {|b| ["Voting Booth ##{b.id}", b.id] } %>
+ </div>
+ </div>
+ <div class="clearfix">
+ <div class="input">
+ <%= f.submit 'Register Voter', class: 'btn primary', disable_with: 'Loading...' %>
+ </div>
+ </div>
+ </fieldset>
+<% end %>
@@ -31,13 +31,6 @@
</table>
</div>
<div class="span8">
- <h3>Voter Registration</h3>
- <%= form_for @registration do |f| %>
- <%= f.label :voter_name %>
- <%= f.text_field :voter_name %>
- <%= f.label :booth_id %>
- <%= f.select :booth_id, Booth.all.collect {|b| ["Voting Booth ##{b.id}", b.id] } %>
- <%= f.submit 'Register Voter', class: 'btn primary', disable_with: 'Loading...' %>
- <% end %>
+ <%= render 'voter_registration' %>
</div>
</div>
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe "home/_voter_registration.html.erb" do
+ let(:registration) { mock_model(VoterRegistration, :booth_id => 12, :voter_name => 'Tom').as_new_record }
+
+ before do
+ assign(:registration, registration)
+ render
+ end
+
+ subject { Capybara.string(rendered) }
+
+ it { should have_selector('form#new_voter_registration') }
+end
@@ -2,16 +2,19 @@
describe "home/index.html.erb" do
let(:booths) { [stub_model(Booth, :id => 1), stub_model(Booth, :id => 2)] }
- let(:registration) { mock_model(VoterRegistration, :booth_id => 12, :voter_name => 'Tom').as_new_record }
before do
assign(:booths, booths)
- assign(:registration, registration)
+ stub_template 'home/_voter_registration.html.erb' => '[voter_registration]'
render
end
subject { Capybara.string(rendered) }
specify { subject.find('#booth_1').should have_button('Connect') }
specify { subject.find('#booth_2').should have_button('Connect') }
+
+ it "should render the voter_registration partial" do
+ rendered.should have_content('[voter_registration]')
+ end
end

0 comments on commit 3b14af8

Please sign in to comment.