Skip to content

Instantly share code, notes, and snippets.

@jswanner
Created May 30, 2009 18:31
Show Gist options
  • Save jswanner/120597 to your computer and use it in GitHub Desktop.
Save jswanner/120597 to your computer and use it in GitHub Desktop.
class AddCategories < ActiveRecord::Migration
def self.up
add_column :tasks, :category, :string
end
def self.down
remove_column :tasks, :category
end
end
Feature: Edit Tasks
So I can capture everything I need to do
As a person with things to do
I need to be able to add and edit tasks
Scenario: Add a task with a category
Given I am on the homepage
When I follow "New Task"
And I create a task "Submit TPS Reports" in category "Work Tasks"
And I go to the homepage
Then I should see "Submit TPS Reports"
And I should see "Work Tasks"
Scenario: Must Enter a Name
Given I am on the homepage
When I follow "New Task"
And I press "Create"
Then I should see "Name can't be blank"
<h1>Things to Do</h1>
<table>
<tr>
<th>Task</th>
<th>Category</th>
</tr>
<% @tasks.each do |task| %>
<tr>
<td><%=h task.name %></td>
<td><%=h task.category %></td>
<td><%= link_to 'Show', task %></td>
<td><%= link_to 'Edit', edit_task_path(task) %></td>
<td><%= link_to 'Destroy', task, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New task', new_task_path %>
<h1>New task</h1>
<% form_for(@task) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :category %><br />
<%= f.text_field :category %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', tasks_path %>
class Task < ActiveRecord::Base
validates_presence_of :name
end
Given /^a task called ("[^\"]*)"$/ do |task_name|
@task = Task.create!(:name => task_name)
end
When /^I browse the tasks page$/ do
visit tasks_path
end
When /^the task is set to the category "([^\"]*)"$/ do |category|
@task.category = category
@task.save!
end
When /^I create a task "([^\"]*)" in category "([^\"]*)"$/ do |task, category|
fill_in "Name", :with => task
fill_in "Category", :with => category
click_button "Create"
end
Feature: View Tasks
So I can see at a glance my tasks
As a person with things to do
I want to see a list of my tasks
Scenario: Add Task to List
Given a task called "Take out the trash"
When I browse the tasks page
Then I should see "Take out the trash"
Scenario: See Tasks on Home Page
Given a task called "Take out the trash"
When I go to the homepage
Then I should see "Take out the trash"
Scenario: See Categories with Task
Given a task called "Take out the trash"
When the task is set to the category "Honey-Do"
And I go to the homepage
Then I should see "Take out the trash"
And I should see "Honey-Do"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment