Merge pull request #2477 from TracksApp/fix/#2471_todo_add_fail_context_view

#2471: Adding todo fails in context view
This commit is contained in:
Jyri-Petteri Paloposki 2020-09-06 04:19:37 +03:00 committed by GitHub
commit d7f5854d42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View file

@ -309,7 +309,7 @@ class TodosController < ApplicationController
@source_view = params['_source_view'] || 'todo'
# Create a (unsaved) copy of the original todo, before it was toggled
@original_item = current_user.todos.build(@todo.attributes)
@original_item = current_user.todos.build(@todo.attributes)
@original_completed_period = DoneTodos.completed_period(@todo.completed_at)
@todo_was_completed_from_deferred_or_blocked_state =
@ -940,7 +940,7 @@ end
@down_count = current_user.todos.active.not_hidden.count
end
from.context do
context_id = @original_item.context_id || @todo.context_id
context_id = @original_item ? @original_item.context_id || @todo.context_id : @todo.context_id
todos = current_user.contexts.find(context_id).todos.not_completed
if @todo.context.hidden?

View file

@ -223,14 +223,33 @@ class TodosControllerTest < ActionController::TestCase
login_as(:admin_user)
assert_difference 'Todo.count' do
put :create, xhr: true, params: {
"context_name"=>"library",
"project_name"=>"Build a working time machine",
"context_name" => "library",
"project_name" => "Build a working time machine",
"todo" => {
"notes"=>"",
"notes" => "",
"description" => "Call Warren Buffet to find out how much he makes per day",
"due"=>"30/11/2006"
"due" => "30/11/2006"
},
"tag_list"=>"foo bar"
"tag_list" => "foo bar"
}
assert_response 200
end
end
def test_create_todo_via_xhr_context_view
login_as(:admin_user)
assert_difference 'Todo.count' do
put :create, xhr: true, params: {
"context_name" => "library",
"project_name" => "",
"todo" => {
"notes" => "",
"description" => "Read Warren Buffet's book",
"due" => "30/12/2006"
},
"_source_view" => "context",
"default_context_name" => "library",
"tag_list" => "bar foo"
}
assert_response 200
end