mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
Fasterer: Use &:symbol is faster
Calling argumentless methods within blocks is slower than using symbol to proc.
This commit is contained in:
parent
8a378aa2c4
commit
ddd9c07d3b
6 changed files with 51 additions and 51 deletions
|
|
@ -130,7 +130,7 @@ class ContextsController < ApplicationController
|
||||||
# actions in the context will also be deleted.
|
# actions in the context will also be deleted.
|
||||||
def destroy
|
def destroy
|
||||||
# make sure the deleted recurrence patterns are removed from associated todos
|
# make sure the deleted recurrence patterns are removed from associated todos
|
||||||
@context.recurring_todos.each { |rt| rt.clear_todos_association } unless @context.recurring_todos.nil?
|
@context.recurring_todos.each(&:clear_todos_association) unless @context.recurring_todos.nil?
|
||||||
|
|
||||||
@context.destroy
|
@context.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,7 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@project.recurring_todos.each {|rt| rt.remove_from_project!}
|
@project.recurring_todos.each(&:remove_from_project!)
|
||||||
@project.destroy
|
@project.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ class Todo < ActiveRecord::Base
|
||||||
|
|
||||||
def touch_predecessors
|
def touch_predecessors
|
||||||
self.touch
|
self.touch
|
||||||
predecessors.each { |p| p.touch_predecessors }
|
predecessors.each(&:touch_predecessors)
|
||||||
end
|
end
|
||||||
|
|
||||||
def removed_predecessors
|
def removed_predecessors
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,47 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ProjectsControllerTest < ActionController::TestCase
|
class ProjectsControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_projects_list
|
def test_projects_list
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_exposes_deferred_todos
|
def test_show_exposes_deferred_todos
|
||||||
p = projects(:timemachine)
|
p = projects(:timemachine)
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :show, :id => p.to_param
|
get :show, :id => p.to_param
|
||||||
assert_not_nil assigns['deferred_todos']
|
assert_not_nil assigns['deferred_todos']
|
||||||
assert_equal 1, assigns['deferred_todos'].size
|
assert_equal 1, assigns['deferred_todos'].size
|
||||||
|
|
||||||
t = p.todos.not_completed[0]
|
t = p.todos.not_completed[0]
|
||||||
t.show_from = 1.days.from_now.utc
|
t.show_from = 1.days.from_now.utc
|
||||||
t.save!
|
t.save!
|
||||||
|
|
||||||
get :show, :id => p.to_param
|
get :show, :id => p.to_param
|
||||||
assert_equal 2, assigns['deferred_todos'].size
|
assert_equal 2, assigns['deferred_todos'].size
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_exposes_next_project_in_same_state
|
def test_show_exposes_next_project_in_same_state
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :show, :id => projects(:timemachine).to_param
|
get :show, :id => projects(:timemachine).to_param
|
||||||
assert_equal(projects(:moremoney), assigns['next_project'])
|
assert_equal(projects(:moremoney), assigns['next_project'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_exposes_previous_project_in_same_state
|
def test_show_exposes_previous_project_in_same_state
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :show, :id => projects(:moremoney).to_param
|
get :show, :id => projects(:moremoney).to_param
|
||||||
assert_equal(projects(:timemachine), assigns['previous_project'])
|
assert_equal(projects(:timemachine), assigns['previous_project'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_project_via_ajax_increments_number_of_projects
|
def test_create_project_via_ajax_increments_number_of_projects
|
||||||
login_as :other_user
|
login_as :other_user
|
||||||
assert_ajax_create_increments_count 'My New Project'
|
assert_ajax_create_increments_count 'My New Project'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_todo_state_is_project_hidden_after_hiding_project
|
def test_todo_state_is_project_hidden_after_hiding_project
|
||||||
p = projects(:timemachine)
|
p = projects(:timemachine)
|
||||||
todos = p.todos.active
|
todos = p.todos.active
|
||||||
|
|
@ -52,7 +52,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
assert p.reload().hidden?
|
assert p.reload().hidden?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_not_done_counts_after_hiding_and_unhiding_project
|
def test_not_done_counts_after_hiding_and_unhiding_project
|
||||||
p = projects(:timemachine)
|
p = projects(:timemachine)
|
||||||
todos = p.todos.active
|
todos = p.todos.active
|
||||||
|
|
@ -64,15 +64,15 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
assert p.reload().active?
|
assert p.reload().active?
|
||||||
end
|
end
|
||||||
|
|
||||||
# RSS
|
# RSS
|
||||||
|
|
||||||
def test_rss_feed_content
|
def test_rss_feed_content
|
||||||
login_as(:admin_user)
|
login_as(:admin_user)
|
||||||
get :index, { :format => "rss" }
|
get :index, { :format => "rss" }
|
||||||
assert_equal 'application/rss+xml', @response.content_type
|
assert_equal 'application/rss+xml', @response.content_type
|
||||||
#puts @response.body
|
#puts @response.body
|
||||||
|
|
||||||
assert_xml_select 'rss[version="2.0"]' do
|
assert_xml_select 'rss[version="2.0"]' do
|
||||||
assert_select 'channel' do
|
assert_select 'channel' do
|
||||||
assert_select '>title', 'Tracks Projects'
|
assert_select '>title', 'Tracks Projects'
|
||||||
|
|
@ -94,31 +94,31 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rss_feed_not_accessible_to_anonymous_user_without_token
|
def test_rss_feed_not_accessible_to_anonymous_user_without_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "rss" }
|
get :index, { :format => "rss" }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "rss", :token => 'foo' }
|
get :index, { :format => "rss", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "rss", :token => users(:admin_user).token }
|
get :index, { :format => "rss", :token => users(:admin_user).token }
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_atom_feed_content
|
def test_atom_feed_content
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :index, { :format => "atom" }
|
get :index, { :format => "atom" }
|
||||||
assert_equal 'application/atom+xml', @response.content_type
|
assert_equal 'application/atom+xml', @response.content_type
|
||||||
# puts @response.body
|
# puts @response.body
|
||||||
|
|
||||||
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
|
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
|
||||||
assert_select '>title', 'Tracks Projects'
|
assert_select '>title', 'Tracks Projects'
|
||||||
assert_select '>subtitle', "Lists all the projects for #{users(:admin_user).display_name}"
|
assert_select '>subtitle', "Lists all the projects for #{users(:admin_user).display_name}"
|
||||||
|
|
@ -133,70 +133,70 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "atom" }
|
get :index, { :format => "atom" }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "atom", :token => 'foo' }
|
get :index, { :format => "atom", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "atom", :token => users(:admin_user).token }
|
get :index, { :format => "atom", :token => users(:admin_user).token }
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_feed_content
|
def test_text_feed_content
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :index, { :format => "txt" }
|
get :index, { :format => "txt" }
|
||||||
assert_equal 'text/plain', @response.content_type
|
assert_equal 'text/plain', @response.content_type
|
||||||
assert !(/ /.match(@response.body))
|
assert !(/ /.match(@response.body))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_feed_content_for_projects_with_no_actions
|
def test_text_feed_content_for_projects_with_no_actions
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
p = projects(:timemachine)
|
p = projects(:timemachine)
|
||||||
p.todos.each { |t| t.destroy }
|
p.todos.each(&:destroy)
|
||||||
|
|
||||||
get :index, { :format => "txt", :only_active_with_no_next_actions => true }
|
get :index, { :format => "txt", :only_active_with_no_next_actions => true }
|
||||||
assert (/^\s*BUILD A WORKING TIME MACHINE\s+0 actions. Project is active.\s*$/.match(@response.body))
|
assert (/^\s*BUILD A WORKING TIME MACHINE\s+0 actions. Project is active.\s*$/.match(@response.body))
|
||||||
assert !(/[1-9] actions/.match(@response.body))
|
assert !(/[1-9] actions/.match(@response.body))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "txt" }
|
get :index, { :format => "txt" }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "txt", :token => 'foo' }
|
get :index, { :format => "txt", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "txt", :token => users(:admin_user).token }
|
get :index, { :format => "txt", :token => users(:admin_user).token }
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_actionize_sorts_active_projects_by_number_of_tasks
|
def test_actionize_sorts_active_projects_by_number_of_tasks
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
u = users(:admin_user)
|
u = users(:admin_user)
|
||||||
post :actionize, :state => "active", :format => 'js'
|
post :actionize, :state => "active", :format => 'js'
|
||||||
|
|
||||||
assert_equal 1, projects(:gardenclean).position
|
assert_equal 1, projects(:gardenclean).position
|
||||||
assert_equal 2, projects(:moremoney).position
|
assert_equal 2, projects(:moremoney).position
|
||||||
assert_equal 3, projects(:timemachine).position
|
assert_equal 3, projects(:timemachine).position
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_alphabetize_sorts_active_projects_alphabetically
|
def test_alphabetize_sorts_active_projects_alphabetically
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
u = users(:admin_user)
|
u = users(:admin_user)
|
||||||
|
|
@ -205,13 +205,13 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
assert_equal 2, projects(:gardenclean).position
|
assert_equal 2, projects(:gardenclean).position
|
||||||
assert_equal 3, projects(:moremoney).position
|
assert_equal 3, projects(:moremoney).position
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_alphabetize_assigns_state
|
def test_alphabetize_assigns_state
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
post :alphabetize, :state => "active", :format => 'js'
|
post :alphabetize, :state => "active", :format => 'js'
|
||||||
assert_equal "active", assigns['state']
|
assert_equal "active", assigns['state']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_alphabetize_assigns_projects
|
def test_alphabetize_assigns_projects
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
post :alphabetize, :state => "active", :format => 'js'
|
post :alphabetize, :state => "active", :format => 'js'
|
||||||
|
|
@ -223,12 +223,12 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
# XML (REST API)
|
# XML (REST API)
|
||||||
|
|
||||||
def test_xml_content
|
def test_xml_content
|
||||||
login_as(:admin_user)
|
login_as(:admin_user)
|
||||||
get :index, { :format => "xml" }
|
get :index, { :format => "xml" }
|
||||||
assert_equal 'application/xml', @response.content_type
|
assert_equal 'application/xml', @response.content_type
|
||||||
|
|
||||||
assert_xml_select 'projects' do
|
assert_xml_select 'projects' do
|
||||||
assert_select 'project', 3 do
|
assert_select 'project', 3 do
|
||||||
assert_select 'name', /.+/
|
assert_select 'name', /.+/
|
||||||
|
|
@ -236,23 +236,23 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_xml_not_accessible_to_anonymous_user_without_token
|
def test_xml_not_accessible_to_anonymous_user_without_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "xml" }
|
get :index, { :format => "xml" }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_xml_not_accessible_to_anonymous_user_with_invalid_token
|
def test_xml_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "xml", :token => 'foo' }
|
get :index, { :format => "xml", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_xml_not_accessible_to_anonymous_user_with_valid_token
|
def test_xml_not_accessible_to_anonymous_user_with_valid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "xml", :token => users(:admin_user).token }
|
get :index, { :format => "xml", :token => users(:admin_user).token }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,21 +13,21 @@ class ContextTest < ActiveSupport::TestCase
|
||||||
# only check that acts_as_list is present in the model
|
# only check that acts_as_list is present in the model
|
||||||
assert @agenda.respond_to?(:move_to_bottom)
|
assert @agenda.respond_to?(:move_to_bottom)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validate_presence_of_name
|
def test_validate_presence_of_name
|
||||||
@agenda.name = ""
|
@agenda.name = ""
|
||||||
assert !@agenda.save
|
assert !@agenda.save
|
||||||
assert_equal 1, @agenda.errors.count
|
assert_equal 1, @agenda.errors.count
|
||||||
assert_equal "context must have a name", @agenda.errors[:name][0]
|
assert_equal "context must have a name", @agenda.errors[:name][0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validate_name_is_less_than_256
|
def test_validate_name_is_less_than_256
|
||||||
@agenda.name = generate_random_string(256)
|
@agenda.name = generate_random_string(256)
|
||||||
assert !@agenda.save
|
assert !@agenda.save
|
||||||
assert_equal 1, @agenda.errors.count
|
assert_equal 1, @agenda.errors.count
|
||||||
assert_equal "context name must be less than 256 characters", @agenda.errors[:name][0]
|
assert_equal "context name must be less than 256 characters", @agenda.errors[:name][0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validate_name_is_unique
|
def test_validate_name_is_unique
|
||||||
newcontext = Context.new
|
newcontext = Context.new
|
||||||
newcontext.name = contexts(:agenda).name
|
newcontext.name = contexts(:agenda).name
|
||||||
|
|
@ -36,7 +36,7 @@ class ContextTest < ActiveSupport::TestCase
|
||||||
assert_equal 1, newcontext.errors.count
|
assert_equal 1, newcontext.errors.count
|
||||||
assert_equal "already exists", newcontext.errors[:name][0]
|
assert_equal "already exists", newcontext.errors[:name][0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete_context_deletes_todos_within_it
|
def test_delete_context_deletes_todos_within_it
|
||||||
assert_equal 7, @agenda.todos.count
|
assert_equal 7, @agenda.todos.count
|
||||||
agenda_todo_ids = @agenda.todos.collect{|t| t.id }
|
agenda_todo_ids = @agenda.todos.collect{|t| t.id }
|
||||||
|
|
@ -45,11 +45,11 @@ class ContextTest < ActiveSupport::TestCase
|
||||||
assert !Todo.exists?(todo_id)
|
assert !Todo.exists?(todo_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_param_returns_id
|
def test_to_param_returns_id
|
||||||
assert_equal '1', @agenda.to_param
|
assert_equal '1', @agenda.to_param
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_title_reader_returns_name
|
def test_title_reader_returns_name
|
||||||
assert_equal @agenda.name, @agenda.title
|
assert_equal @agenda.name, @agenda.title
|
||||||
end
|
end
|
||||||
|
|
@ -79,14 +79,14 @@ class ContextTest < ActiveSupport::TestCase
|
||||||
@agenda.close!
|
@agenda.close!
|
||||||
end
|
end
|
||||||
|
|
||||||
@agenda.todos.active.each {|t| t.complete! }
|
@agenda.todos.active.each(&:complete!)
|
||||||
@agenda.close!
|
@agenda.close!
|
||||||
assert @agenda.closed?
|
assert @agenda.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_activating_closed_context
|
def test_activating_closed_context
|
||||||
# given a context @agenda that is closed
|
# given a context @agenda that is closed
|
||||||
@agenda.todos.active.each {|t| t.complete! }
|
@agenda.todos.active.each(&:complete!)
|
||||||
@agenda.close!
|
@agenda.close!
|
||||||
assert @agenda.closed?
|
assert @agenda.closed?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ class ProjectTest < ActiveSupport::TestCase
|
||||||
assert !p.stalled?, "completed projects are not stalled"
|
assert !p.stalled?, "completed projects are not stalled"
|
||||||
|
|
||||||
p.activate!
|
p.activate!
|
||||||
p.todos.each{|t| t.complete!}
|
p.todos.each(&:complete!)
|
||||||
assert p.todos.reload.active.empty?, "project should not have active todos"
|
assert p.todos.reload.active.empty?, "project should not have active todos"
|
||||||
assert p.todos.reload.deferred_or_blocked.empty?, "there should not be deferred or blocked todos"
|
assert p.todos.reload.deferred_or_blocked.empty?, "there should not be deferred or blocked todos"
|
||||||
assert p.reload.stalled?, "project should be stalled"
|
assert p.reload.stalled?, "project should be stalled"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue