Permalink
Browse files

Finished leg_controller tests

  • Loading branch information...
maxwellE committed Mar 2, 2012
1 parent 09c485b commit 1e7bd9dc04f495034b7fefc0e60374a7da42f4dd
View
@@ -1,4 +1,10 @@
class Leg < ActiveRecord::Base
validates_presence_of :location, :on => :create, :message => "can't be blank"
-
+ validates_presence_of :depart_arrive, :on => :create, :message => "can't be blank"
+ validate :depart_or_arrive, :on => :create
+ def depart_or_arrive
+ if depart_arrive_type != 'Departure' && depart_arrive_type != 'Arrival'
+ errors.add(:depart_arrive_type, "must be either 'Depart' or 'Arrive'")
+ end
+ end
end
@@ -11,15 +11,16 @@
</div>
<% end %>
<div class="field">
- <%= f.label :location %><br />
- <%= f.text_field :location %>
+ <%= f.label :location, "Location:" %><br />
+ <%= f.text_field :location %><br />
- <%= f.label :depart_arrive_type %><br />
- <%= f.select :depart_arrive_type, ["Departure", "Arrival"] %>
-
- <%= f.label :depart_arrive %><br />
- <%= f.datetime_select :depart_arrive %>
+ <%= f.label :depart_arrive_type, "Departure or Arrival?" %><br />
+ <%= f.select :depart_arrive_type, ["Departure", "Arrival"] %><br />
+ <%= f.label :depart_arrive, "Departure/Arrival Date:" %><br />
+ <%= f.datetime_select :depart_arrive %> <br />
+ <%= f.label :details, "Leg details:" %> <br />
+ <%= f.text_field :details %>
</div>
<div class="actions">
<%= f.submit %>
@@ -3,14 +3,17 @@
<table>
<tr>
<th>Location</th>
- <th></th>
- <th></th>
- <th></th>
+ <th>Departure/Arrival</th>
+ <th>Departure/Arrival time</th>
+ <th>Details</th>
</tr>
<% @legs.each do |leg| %>
<tr>
<td><%= leg.location %></td>
+ <td><%= leg.depart_arrive_type %></td>
+ <td><%= leg.depart_arrive%></td>
+ <td><%= leg.details %></td>
<td><%= link_to 'Show', leg %></td>
<td><%= link_to 'Edit', edit_leg_path(leg) %></td>
<td><%= link_to 'Destroy', leg, :confirm => 'Are you sure?', :method => :delete %></td>
@@ -1,4 +1,4 @@
-<h1>New leg</h1>
+<h1>New Trip Leg</h1>
<%= render 'form' %>
View
@@ -1,3 +1,4 @@
+# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
View
@@ -1,26 +1,36 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
- location: MyString
+ location: MyString
+ depart_arrive_type: 'Departure'
+ depart_arrive: "Monday, March 5 2012"
two:
- location: MyString
+ location: MyString
+ depart_arrive_type: "Departure"
+ depart_arrive: "Monday, March 5 2012"
texas:
location: Texas
depart_arrive: "Monday, March 5 2012"
- depart_arrive_type: "depart"
+ depart_arrive_type: "Departure"
details: "My trip to texas"
invalid:
location:
depart_arrive: "Monday, March 5 2012"
- depart_arrive_type: "depart"
+ depart_arrive_type: "Departure"
details: "IM INVALID"
-invalid_depart_arrive:
+invalid_depart_arrive_type:
location: Kansas
depart_arrive: "Tuesday December 5 2020"
depart_arrive_type: "pizza"
details: "IM VERY INVALID"
+
+invalid_depart_arrive:
+ location: Kansas
+ depart_arrive:
+ depart_arrive_type: "Arrival"
+ details: "My DATE IS INVALID"
@@ -5,6 +5,8 @@ class LegsControllerTest < ActionController::TestCase
@leg = legs(:one)
@texas = legs(:texas)
@invalid = legs(:invalid)
+ @invalid_depart_arrive_type = legs(:invalid_depart_arrive_type)
+ @invalid_depart_arrive = legs(:invalid_depart_arrive)
end
test "should create a filled out leg" do
assert_difference('Leg.count', 1) do
@@ -22,7 +24,17 @@ class LegsControllerTest < ActionController::TestCase
post :create, :leg => @invalid.attributes
end
end
-
+ test "it should not make a leg without a depart/arrival noted" do
+ assert_no_difference('Leg.count') do
+ post :create, :leg => @invalid_depart_arrive_type.attributes
+ end
+ end
+ test "it should not make a leg without a date noted" do
+ assert_no_difference('Leg.count') do
+ post :create, :leg => @invalid_depart_arrive.attributes
+ end
+ end
+
test "should get new" do
get :new
assert_response :success

0 comments on commit 1e7bd9d

Please sign in to comment.