Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

registration validation (all fields are required)

  • Loading branch information...
commit 31e450e834a5f21194f45ca3d68c1854c795f636 1 parent 6093d7f
@croaky croaky authored
View
2  .gitignore
@@ -1,7 +1,7 @@
.bundle
db/*.sqlite3
log/*.log
-tmp/**/*
+tmp
db/schema.rb
public/system
*.DS_Store
View
9 app/controllers/registrations_controller.rb
@@ -5,8 +5,11 @@ def new
def create
@registration = Registration.new(params[:registration])
- @registration.save
- flash[:success] = "Thanks for registering! We can't wait to see you!"
- redirect_to root_path
+ if @registration.save
+ flash[:success] = "Thanks for registering! We can't wait to see you!"
+ redirect_to root_path
+ else
+ render :action => :new
+ end
end
end
View
1  app/models/registration.rb
@@ -1,4 +1,5 @@
class Registration < ActiveRecord::Base
validates_presence_of :twitter, :name, :school, :why, :role
validates_uniqueness_of :twitter
+ validates_inclusion_of :role, :in => %w(Designer Developer)
end
View
16 app/views/registrations/new.html.erb
@@ -158,15 +158,9 @@
</div>
<%= semantic_form_for @registration, :html => { :name => "Event Registration", :id => "event-registration" } do |form| %>
<ol class="left">
- <li>
- <p><%= form.input :twitter, :label => "Twitter Name" %></p>
- </li>
- <li>
- <p><%= form.input :name, :label => "Full Name" %></p>
- </li>
- <li>
- <p><%= form.input :school %></p>
- </li>
+ <li><p><%= form.input :twitter, :label => "Twitter Name" %></p></li>
+ <li><p><%= form.input :name, :label => "Full Name" %></p></li>
+ <li><p><%= form.input :school, :label => "School" %></p></li>
</ol>
<ol class="right">
<li id="description">
@@ -175,10 +169,10 @@
<li id="radio">
<label>Weapon of choice:</label>
<p class="radio developer">
- <%= form.radio_button :role, :developer %>Developer
+ <%= form.radio_button :role, "Developer" %>Developer
</p>
<p class="radio designer">
- <%= form.radio_button :role, :designer %>Designer
+ <%= form.radio_button :role, "Designer" %>Designer
</p>
</li>
<li id="submit-button">
View
5 features/register.feature
@@ -13,3 +13,8 @@ Feature: As a student, I want to register for D4
And I choose the "Developer" role
And I press "Register"
Then I should see "Thanks for registering! We can't wait to see you!"
+
+ Scenario: Student does not fill in all fields on register form
+ Given I am on the home page
+ And I press "Register"
+ Then I should see "can't be blank" on all text inputs of the registration form
View
6 features/step_definitions/registration_steps.rb
@@ -1,3 +1,9 @@
When /^I choose the "([^"]*)" role$/ do |role|
choose "registration_role_#{role.downcase}"
end
+
+Then /^I should see "([^"]*)" on all text inputs of the registration form$/ do |content|
+ %w(twitter name school why).each do |field|
+ with_scope("#registration_#{field}_input") { page.should have_content(content) }
+ end
+end
View
10 spec/controllers/registrations_controller_spec.rb
@@ -1,10 +0,0 @@
-require 'spec_helper'
-
-describe RegistrationsController do
- context "#new" do
- before { get :new }
- it { should respond_with(:success) }
- it { should render_template(:new) }
- it { should assign_to(:registration) }
- end
-end
View
14 spec/models/registration_spec.rb
@@ -4,10 +4,16 @@
subject { Factory(:registration) }
it { should validate_presence_of(:twitter) }
- it { should validate_presence_of(:name) }
- it { should validate_presence_of(:school) }
- it { should validate_presence_of(:why) }
- it { should validate_presence_of(:role) }
+ it { should validate_presence_of(:name) }
+ it { should validate_presence_of(:school) }
+ it { should validate_presence_of(:why) }
+ it { should validate_presence_of(:role) }
it { should validate_uniqueness_of(:twitter) }
+
+ it { should allow_value("Developer").for(:role) }
+ it { should allow_value("Designer"). for(:role) }
+
+ it { should_not allow_value("Recruiter"). for(:role) }
+ it { should_not allow_value("Social Media Expert").for(:role) }
end
Please sign in to comment.
Something went wrong with that request. Please try again.