mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 22:41:48 +01:00
Gathered up calls to init and init_todos in before_filters, as suggested by <a href="http://www.therailsway.com/2006/11/16/tracks-part-2">Part 2</a> of the RailsWay article series.
There are a couple of test errors that I can't seem to fix. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@363 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
ad6616d161
commit
9c37b40f3d
5 changed files with 9 additions and 23 deletions
|
|
@ -3,6 +3,8 @@ class ContextController < ApplicationController
|
|||
helper :todo
|
||||
|
||||
prepend_before_filter :login_required
|
||||
before_filter :init, :except => [:create, :destroy, :order]
|
||||
before_filter :init_todos, :only => :show
|
||||
layout "standard", :except => :date_preview
|
||||
|
||||
def index
|
||||
|
|
@ -14,7 +16,6 @@ class ContextController < ApplicationController
|
|||
# Set page title, and collect existing contexts in @contexts
|
||||
#
|
||||
def list
|
||||
self.init
|
||||
@page_title = "TRACKS::List Contexts"
|
||||
respond_to do |wants|
|
||||
wants.html
|
||||
|
|
@ -26,9 +27,6 @@ class ContextController < ApplicationController
|
|||
# e.g. <home>/context/<context_name> shows just <context_name>.
|
||||
#
|
||||
def show
|
||||
init
|
||||
check_user_set_context
|
||||
init_todos
|
||||
@page_title = "TRACKS::Context: #{@context.name}"
|
||||
end
|
||||
|
||||
|
|
@ -64,7 +62,6 @@ class ContextController < ApplicationController
|
|||
# Edit the details of the context
|
||||
#
|
||||
def update
|
||||
self.init
|
||||
check_user_set_context
|
||||
params['context'] ||= {}
|
||||
success_text = if params['field'] == 'name' && params['value']
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class FeedController < ApplicationController
|
|||
|
||||
before_filter :check_token_against_user_word, :except => 'index'
|
||||
prepend_before_filter :login_required, :only => 'index'
|
||||
before_filter :prepare_for_feed, :only => [:rss, :text, :ical]
|
||||
|
||||
|
||||
def index
|
||||
|
|
@ -18,7 +19,6 @@ class FeedController < ApplicationController
|
|||
|
||||
# Build an RSS feed
|
||||
def rss
|
||||
prepare_for_feed
|
||||
headers["Content-Type"] = "text/xml; charset=utf-8"
|
||||
end
|
||||
|
||||
|
|
@ -31,7 +31,6 @@ class FeedController < ApplicationController
|
|||
# curl [url from "TXT" link on todo/list]
|
||||
#
|
||||
def text
|
||||
prepare_for_feed
|
||||
if params.key?('context')
|
||||
@contexts = [ @user.contexts.find(params['context']) ]
|
||||
else
|
||||
|
|
@ -45,7 +44,6 @@ class FeedController < ApplicationController
|
|||
# Due dates are supported, and notes are included.
|
||||
#
|
||||
def ical
|
||||
prepare_for_feed
|
||||
if params.key?('context')
|
||||
@contexts = [ @user.contexts.find(params['context']) ]
|
||||
else
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ class ProjectController < ApplicationController
|
|||
|
||||
helper :todo
|
||||
prepend_before_filter :login_required
|
||||
before_filter :init, :except => [:create, :destroy, :order, :toggle_project_done]
|
||||
before_filter :init_todos, :only => :show
|
||||
|
||||
layout "standard", :except => :date_preview
|
||||
|
||||
|
|
@ -16,7 +18,6 @@ class ProjectController < ApplicationController
|
|||
# Set page title, and collect existing projects in @projects
|
||||
#
|
||||
def list
|
||||
init
|
||||
init_project_hidden_todo_counts
|
||||
@page_title = "TRACKS::List Projects"
|
||||
respond_to do |wants|
|
||||
|
|
@ -29,8 +30,6 @@ class ProjectController < ApplicationController
|
|||
# e.g. <home>/project/show/<project_name> shows just <project_name>.
|
||||
#
|
||||
def show
|
||||
init
|
||||
init_todos
|
||||
@notes = @project.notes
|
||||
@page_title = "TRACKS::Project: #{@project.name}"
|
||||
|
||||
|
|
@ -89,7 +88,6 @@ class ProjectController < ApplicationController
|
|||
# Edit the details of the project
|
||||
#
|
||||
def update
|
||||
self.init
|
||||
check_user_set_project
|
||||
params['project'] ||= {}
|
||||
if params['project']['state']
|
||||
|
|
|
|||
|
|
@ -3,18 +3,17 @@ class TodoController < ApplicationController
|
|||
model :user
|
||||
model :project
|
||||
model :context
|
||||
|
||||
|
||||
helper :todo
|
||||
|
||||
prepend_before_filter :login_required
|
||||
append_before_filter :init, :except => [ :destroy, :completed, :completed_archive ]
|
||||
append_before_filter :init, :except => [ :destroy, :completed, :completed_archive, :check_tickler ]
|
||||
layout "standard", :except => :date_preview
|
||||
|
||||
# Main method for listing tasks
|
||||
# Set page title, and fill variables with contexts and done and not-done tasks
|
||||
# Number of completed actions to show is determined by a setting in settings.yml
|
||||
def index
|
||||
init
|
||||
@projects = @user.projects.find(:all, :include => [ :todos ])
|
||||
@contexts = @user.contexts.find(:all, :include => [ :todos ])
|
||||
|
||||
|
|
@ -60,7 +59,6 @@ class TodoController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
init
|
||||
@item = @user.todos.build
|
||||
p = params['request'] || params
|
||||
@item.attributes = p['todo']
|
||||
|
|
@ -113,12 +111,10 @@ class TodoController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
init
|
||||
@item = check_user_return_item
|
||||
end
|
||||
|
||||
def show
|
||||
init
|
||||
item = check_user_return_item
|
||||
respond_to do |wants|
|
||||
wants.xml { render :xml => item.to_xml( :root => 'todo', :except => :user_id ) }
|
||||
|
|
@ -128,7 +124,6 @@ class TodoController < ApplicationController
|
|||
# Toggles the 'done' status of the action
|
||||
#
|
||||
def toggle_check
|
||||
init
|
||||
@item = check_user_return_item
|
||||
@item.toggle_completion()
|
||||
@saved = @item.save
|
||||
|
|
@ -149,7 +144,6 @@ class TodoController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
init
|
||||
@item = check_user_return_item
|
||||
@original_item_context_id = @item.context_id
|
||||
@original_item_project_id = @item.project_id
|
||||
|
|
@ -244,7 +238,6 @@ class TodoController < ApplicationController
|
|||
end
|
||||
|
||||
def tickler
|
||||
init
|
||||
@source_view = 'deferred'
|
||||
@page_title = "TRACKS::Tickler"
|
||||
@tickles = @user.todos.find_in_state(:all, :deferred, :order => "show_from ASC")
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ class TodoControllerTest < Test::Unit::TestCase
|
|||
def test_update_item
|
||||
t = Todo.find(1)
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"11/30/2006"}
|
||||
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"2006-11-30"}
|
||||
#assert_rjs :page, "item-1-container", :visual_effect, :highlight, :duration => '1'
|
||||
t = Todo.find(1)
|
||||
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
|
||||
assert_equal Date.parse("11/30/2006"), t.due
|
||||
assert_equal "2006-11-30", t.due
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue