Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make tests pass, cleanup routes

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...
commit f8a5680b5d24e48ce8654ef7d326b96d548f0785 1 parent 749666b
Jacob Burkhart jacobo authored
10 README.md
View
@@ -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 app/controllers/lists_controller.rb
View
@@ -7,7 +7,7 @@ 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
@@ -15,7 +15,7 @@ def destroy
@list.destroy
respond_to do |format|
- format.html { redirect_to(tasks_url) }
+ format.html { redirect_to(root_url) }
end
end
end
12 app/controllers/tasks_controller.rb
View
@@ -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
@@ -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
6 app/views/lists/edit.html.erb
View
@@ -1,6 +0,0 @@
-<h1>Editing list</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @list %> |
-<%= link_to 'Back', lists_path %>
23 app/views/lists/index.html.erb
View
@@ -1,23 +0,0 @@
-<h1>Listing lists</h1>
-
-<table>
- <tr>
- <th>Name</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
-<% @lists.each do |list| %>
- <tr>
- <td><%= list.name %></td>
- <td><%= link_to 'Show', list %></td>
- <td><%= link_to 'Edit', edit_list_path(list) %></td>
- <td></td>
- </tr>
-<% end %>
-</table>
-
-<br />
-
-<%= link_to 'New List', new_list_path %>
10 app/views/lists/show.html.erb
View
@@ -1,10 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <b>Name:</b>
- <%= @list.name %>
-</p>
-
-
-<%= link_to 'Edit', edit_list_path(@list) %> |
-<%= link_to 'Back', lists_path %>
6 app/views/tasks/edit.html.erb
View
@@ -1,6 +0,0 @@
-<h1>Editing task</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @task %> |
-<%= link_to 'Back', tasks_path %>
12 app/views/tasks/index.html.erb
View
@@ -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 }%>
@@ -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>
@@ -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 %>
@@ -88,7 +88,7 @@
</div>
-<% if listid = params[:list] %>
+<% if listid = params[:list_id] %>
<% prevlist = List.find listid %>
<% tabindex = @lists.index(prevlist) %>
<% end %>
@@ -101,7 +101,7 @@
$(function() {
var opts = {};
- <% if params[:list] %>
+ <% if params[:list_id] %>
opts.selected = <%= tabindex %>
<% end %>
$( "#tabs" ).tabs(opts);
5 config/routes.rb
View
@@ -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.
0  db/test.sqlite3
View
No changes.
0  log/test.log
View
No changes.
4 test/fixtures/lists.yml
View
@@ -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 test/fixtures/tasks.yml
View
@@ -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 test/functional/lists_controller_test.rb
View
@@ -5,38 +5,12 @@ 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
@@ -44,6 +18,6 @@ class ListsControllerTest < ActionController::TestCase
delete :destroy, :id => @list.to_param
end
- assert_redirected_to lists_path
+ assert_redirected_to root_path
end
end
30 test/functional/tasks_controller_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.