Skip to content

Commit

Permalink
make tests pass, cleanup routes
Browse files Browse the repository at this point in the history
Delete tests of un-used controller actions
Delete views for un-used controller actions
Cleanup gitignored things
Readme notes about test running
make valid fixtures
  • Loading branch information
Jacob Burkhart & Thom Mahoney committed Nov 8, 2011
1 parent 749666b commit f8a5680
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 116 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -2,4 +2,12 @@

Simple GTD app for task tracking.

Supports all Rubies and many stacks (passenger, unicorn, trinidad/jruby).
Supports all Rubies and many stacks (passenger, unicorn, trinidad/jruby).

# To run individual tests: (for example)

bundle exec ruby -Itest test/functional/lists_controller_test.rb

# To run specific tests: (for example)

bundle exec ruby -Itest test/functional/lists_controller_test.rb --name test_should_create_list
4 changes: 2 additions & 2 deletions app/controllers/lists_controller.rb
Expand Up @@ -7,15 +7,15 @@ def create
else
flash[:alert] = "There was an error creating your list."
end
redirect_to(tasks_url(:list => @list.id))
redirect_to(list_tasks_url(@list))
end

def destroy
@list = List.find(params[:id])
@list.destroy

respond_to do |format|
format.html { redirect_to(tasks_url) }
format.html { redirect_to(root_url) }
end
end
end
12 changes: 7 additions & 5 deletions app/controllers/tasks_controller.rb
Expand Up @@ -14,22 +14,24 @@ def index


def create
@task = Task.new(params[:task])
@list = List.find(params[:list_id])
@task = @list.tasks.new(params[:task])
if @task.save
flash[:notice] = "Your task was created."
else
flash[:alert] = "There was an error creating your task."
end
redirect_to(tasks_url(:list => params[:task][:list_id]))
redirect_to(list_tasks_url(@list))
end


def update
@task = Task.find(params[:id])
@list = List.find(params[:list_id])
@task = @list.tasks.find(params[:id])

respond_to do |format|
if @task.update_attributes(params[:task])
format.html { redirect_to( tasks_url(:list => @task.list.id), :notice => 'Task was successfully updated.') }
format.html { redirect_to( list_tasks_url(@list), :notice => 'Task was successfully updated.') }
else
format.html { render :action => "edit" }
end
Expand All @@ -42,7 +44,7 @@ def destroy
@task.destroy

respond_to do |format|
format.html { redirect_to(tasks_url(:list => @task.list_id)) }
format.html { redirect_to(list_tasks_url(@list)) }
end
end

Expand Down
6 changes: 0 additions & 6 deletions app/views/lists/edit.html.erb

This file was deleted.

23 changes: 0 additions & 23 deletions app/views/lists/index.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/lists/show.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/tasks/edit.html.erb

This file was deleted.

12 changes: 6 additions & 6 deletions app/views/tasks/index.html.erb
Expand Up @@ -19,7 +19,7 @@
<div id='tabs-<%= @count %>' class="tab">

<div class="new-task">
<%= simple_form_for(@task) do |f| %>
<%= simple_form_for(@task, :url => list_tasks_url(list)) do |f| %>
<%= f.input :done , :as => :hidden, :input_html => {:value => false }%>
<%= f.input :list_id , :as => :hidden, :input_html => {:value => list.id }%>
Expand All @@ -40,14 +40,14 @@
<% list.tasks.each do |task| %>
<% unless task.done %>
<%= simple_form_for(task) do |f| %>
<%= simple_form_for(task, :url => list_task_url(list, task)) do |f| %>

<li>
<%= f.input :done , :input_html => { :class => 'box' } , :label => false %>
<%= f.button :submit , :class => 'hidden' %>
<%= auto_link( h(task.name) ) %>
<p class="delete-task">
<%= link_to 'X', task, :confirm => 'Are you sure?', :method => :delete %>
<%= link_to 'X', list_task_url(list, task), :confirm => 'Are you sure?', :method => :delete %>
</p>
</li>

Expand All @@ -63,7 +63,7 @@
<li class="finished">
<%= auto_link( h(task.name) ) %>
<p class="delete-task">
<%= link_to 'X', task, :confirm => 'Are you sure?', :method => :delete %>
<%= link_to 'X', list_task_url(list, task), :confirm => 'Are you sure?', :method => :delete %>
</p>
</li>
<% end %>
Expand All @@ -88,7 +88,7 @@
</div>


<% if listid = params[:list] %>
<% if listid = params[:list_id] %>
<% prevlist = List.find listid %>
<% tabindex = @lists.index(prevlist) %>
<% end %>
Expand All @@ -101,7 +101,7 @@

$(function() {
var opts = {};
<% if params[:list] %>
<% if params[:list_id] %>
opts.selected = <%= tabindex %>
<% end %>
$( "#tabs" ).tabs(opts);
Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
@@ -1,7 +1,8 @@
Listr::Application.routes.draw do
resources :lists

resources :tasks
resources :lists, :only => [:create, :destroy] do
resources :tasks, :except => [:new, :edit, :show]
end

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
Empty file removed db/test.sqlite3
Empty file.
Empty file removed log/test.log
Empty file.
4 changes: 2 additions & 2 deletions test/fixtures/lists.yml
@@ -1,7 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
name: MyString
name: ListOne

two:
name: MyString
name: ListTwo
6 changes: 4 additions & 2 deletions test/fixtures/tasks.yml
@@ -1,9 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
name: MyString
name: TaskOne
done: false
list: one

two:
name: MyString
name: TaskTwo
done: false
list: one
32 changes: 3 additions & 29 deletions test/functional/lists_controller_test.rb
Expand Up @@ -5,45 +5,19 @@ class ListsControllerTest < ActionController::TestCase
@list = lists(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:lists)
end

test "should get new" do
get :new
assert_response :success
end

test "should create list" do
assert_difference('List.count') do
post :create, :list => @list.attributes
post :create, :list => {:name => "NewList"}
end

assert_redirected_to list_path(assigns(:list))
end

test "should show list" do
get :show, :id => @list.to_param
assert_response :success
end

test "should get edit" do
get :edit, :id => @list.to_param
assert_response :success
end

test "should update list" do
put :update, :id => @list.to_param, :list => @list.attributes
assert_redirected_to list_path(assigns(:list))
assert_redirected_to list_tasks_path(assigns(:list))
end

test "should destroy list" do
assert_difference('List.count', -1) do
delete :destroy, :id => @list.to_param
end

assert_redirected_to lists_path
assert_redirected_to root_path
end
end
30 changes: 8 additions & 22 deletions test/functional/tasks_controller_test.rb
Expand Up @@ -2,48 +2,34 @@

class TasksControllerTest < ActionController::TestCase
setup do
@list = lists(:one)
@task = tasks(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:tasks)
end

test "should get new" do
get :new
assert_response :success
assert_not_nil assigns(:lists)
end

test "should create task" do
assert_difference('Task.count') do
post :create, :task => @task.attributes
post :create, :task => @task.attributes, :list_id => @list.id
end

assert_redirected_to task_path(assigns(:task))
end

test "should show task" do
get :show, :id => @task.to_param
assert_response :success
end

test "should get edit" do
get :edit, :id => @task.to_param
assert_response :success
assert_redirected_to list_tasks_path(@list)
end

test "should update task" do
put :update, :id => @task.to_param, :task => @task.attributes
assert_redirected_to task_path(assigns(:task))
put :update, :id => @task.to_param, :task => @task.attributes, :list_id => @list.id
assert_redirected_to list_tasks_path(@list)
end

test "should destroy task" do
assert_difference('Task.count', -1) do
delete :destroy, :id => @task.to_param
delete :destroy, :id => @task.to_param, :list_id => @list.id
end

assert_redirected_to tasks_path
assert_redirected_to list_tasks_path(@list)
end
end

0 comments on commit f8a5680

Please sign in to comment.