mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-20 17:20:12 +01:00
a previous commit introduced a bug where hiding a project did not hide the todos in it. Fixes #832
This commit is contained in:
parent
8076f4fe72
commit
07426ebe54
5 changed files with 25 additions and 31 deletions
|
|
@ -106,9 +106,9 @@ class ProjectsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
params['project'] ||= {}
|
params['project'] ||= {}
|
||||||
if params['project']['state']
|
if params['project']['state']
|
||||||
@state_changed = @project.state != params['project']['state']
|
@new_state = params['project']['state']
|
||||||
|
@state_changed = @project.state != @new_state
|
||||||
logger.info "@state_changed: #{@project.state} == #{params['project']['state']} != #{@state_changed}"
|
logger.info "@state_changed: #{@project.state} == #{params['project']['state']} != #{@state_changed}"
|
||||||
@project.transition_to(params['project']['state'])
|
|
||||||
params['project'].delete('state')
|
params['project'].delete('state')
|
||||||
end
|
end
|
||||||
success_text = if params['field'] == 'name' && params['value']
|
success_text = if params['field'] == 'name' && params['value']
|
||||||
|
|
@ -117,6 +117,7 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
@project.attributes = params['project']
|
@project.attributes = params['project']
|
||||||
if @project.save
|
if @project.save
|
||||||
|
@project.transition_to(@new_state) if @state_changed
|
||||||
if boolean_param('wants_render')
|
if boolean_param('wants_render')
|
||||||
if (@project.hidden?)
|
if (@project.hidden?)
|
||||||
@project_project_hidden_todo_counts = Hash.new
|
@project_project_hidden_todo_counts = Hash.new
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ class TodosController < ApplicationController
|
||||||
@todo.context_id = context.id
|
@todo.context_id = context.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@todo.update_state_from_project
|
||||||
@saved = @todo.save
|
@saved = @todo.save
|
||||||
unless (@saved == false) || p.tag_list.blank?
|
unless (@saved == false) || p.tag_list.blank?
|
||||||
@todo.tag_with(p.tag_list)
|
@todo.tag_with(p.tag_list)
|
||||||
|
|
@ -257,7 +258,10 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
@project_changed = @original_item_project_id != @todo.project_id
|
@project_changed = @original_item_project_id != @todo.project_id
|
||||||
if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = current_user.projects.find(@original_item_project_id).not_done_todo_count; end
|
if (@project_changed && !@original_item_project_id.nil?) then
|
||||||
|
@todo.update_state_from_project
|
||||||
|
@remaining_undone_in_project = current_user.projects.find(@original_item_project_id).not_done_todo_count
|
||||||
|
end
|
||||||
determine_down_count
|
determine_down_count
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,6 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
before_validation :update_state_from_project
|
|
||||||
|
|
||||||
def update_state_from_project
|
def update_state_from_project
|
||||||
if state == 'project_hidden' and !project.hidden?
|
if state == 'project_hidden' and !project.hidden?
|
||||||
self.state = 'active'
|
self.state = 'active'
|
||||||
|
|
|
||||||
|
|
@ -136,31 +136,6 @@ describe Todo do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when update_state_from_project is called' do
|
|
||||||
it "should unhide when project is active" do
|
|
||||||
project = mock_model(Project, :hidden? => false)
|
|
||||||
todo = Todo.new(:state => 'project_hidden', :project => project)
|
|
||||||
todo.should be_project_hidden
|
|
||||||
todo.save
|
|
||||||
todo.should be_active
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should unhide when project is null" do
|
|
||||||
todo = Todo.new(:state => 'project_hidden', :project => nil)
|
|
||||||
todo.should be_project_hidden
|
|
||||||
todo.save
|
|
||||||
todo.should be_active
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should hide when project is hidden" do
|
|
||||||
project = mock_model(Project, :hidden? => true)
|
|
||||||
todo = Todo.new(:state => 'active', :project => project)
|
|
||||||
todo.should be_active
|
|
||||||
todo.save
|
|
||||||
todo.should be_project_hidden
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'when toggling completion' do
|
describe 'when toggling completion' do
|
||||||
it 'toggles to active when completed' do
|
it 'toggles to active when completed' do
|
||||||
todo = create_todo
|
todo = create_todo
|
||||||
|
|
|
||||||
|
|
@ -505,4 +505,20 @@ class TodosControllerTest < Test::Rails::TestCase
|
||||||
assert next_todo.due > @todo.due
|
assert next_todo.due > @todo.due
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_removing_hidden_project_activates_todo
|
||||||
|
login_as(:admin_user)
|
||||||
|
|
||||||
|
# get a project and hide it, todos in the project should be hidden
|
||||||
|
p = projects(:timemachine)
|
||||||
|
p.hide!
|
||||||
|
assert p.reload().hidden?
|
||||||
|
todo = p.todos.first
|
||||||
|
assert "project_hidden", todo.state
|
||||||
|
|
||||||
|
# clear project from todo: the todo should be unhidden
|
||||||
|
xhr :post, :update, :id => 1, :_source_view => 'todo', "project_name"=>"None", "todo"=>{}
|
||||||
|
todo.reload()
|
||||||
|
assert "active", todo.state
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue