Apply Trevor Lovett's patch (#364)

"I kick off a lot of small projects, and I often want to add actions right when I create the project. This is a simple tweak that provides a check box that allows you to immediately go to the project page after creating a new project."

Thanks, Trevor. Sorry it took so long!



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@474 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-03-10 04:10:53 +00:00
parent 18bb7ff16a
commit 84357b67d5
5 changed files with 35 additions and 1 deletions

View file

@ -46,6 +46,7 @@ class ProjectsController < ApplicationController
@project.attributes = params['project'] || params['request']['project']
params_are_invalid = false
end
@go_to_project = params['go_to_project']
@saved = @project.save
@project_not_done_counts = { @project.id => 0 }
@active_projects_count = @user.projects.count(:conditions => "state = 'active'")

View file

@ -1,4 +1,6 @@
if @saved
if @saved and @go_to_project
page.redirect_to project_path(@project)
elsif @saved
page.hide 'projects-empty-nd'
page.show 'list-active-projects-container'
page.replace_html "active-projects-count", @active_projects_count

View file

@ -25,6 +25,8 @@
<label for="project_description">Description (optional):</label><br />
<%= text_area 'project', 'description', "cols" => 30, "rows" => 4 %><br />
<%= check_box_tag 'go_to_project' %><label for="go_to_project">Go to the project page</label><br />
<input type="submit" value="Add" />

View file

@ -53,6 +53,13 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
assert_rjs :call, "Form.reset", "project-form"
assert_rjs :call, "Form.focusFirstElement", "project-form"
end
def test_create_project_and_go_to_project_page
num_projects = Project.count
xhr :post, :create, { :project => {:name => 'Immediate Project Planning Required'}, :go_to_project => 1}
assert_js_redirected_to '/projects/Immediate_Project_Planning_Required'
assert_equal num_projects + 1, Project.count
end
def test_create_with_slash_in_name_does_not_increment_number_of_projects
assert_ajax_create_does_not_increment_count 'foo/bar'

View file

@ -44,6 +44,28 @@ class Test::Unit::TestCase
1.week.from_now.utc.to_date
end
# Courtesy of http://habtm.com/articles/2006/02/20/assert-yourself-man-redirecting-with-rjs
def assert_js_redirected_to(options={}, message=nil)
clean_backtrace do
assert_response(:success, message)
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type'], 'Response should be Javascript content-type';
js_regexp = %r{(\w+://)?.*?(/|$|\\\?)(.*)}
url_regexp = %r{^window\.location\.href [=] ['"]#{js_regexp}['"][;]$}
redirected_to = @response.body.match(url_regexp)
assert_not_nil(redirected_to, message)
redirected_to = redirected_to[3]
msg = build_message(message, "expected a JS redirect to <?>, found one to <?>", options, redirected_to)
if options.is_a?(String)
assert_equal(options.gsub(/^\//, ''), redirected_to, message)
else
msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)", redirected_to)
assert_equal(@controller.url_for(options).match(js_regexp)[3], redirected_to, msg)
end
end
end
end
class ActionController::IntegrationTest