diff --git a/app/controllers/todos/todo_create_params_helper.rb b/app/controllers/todos/todo_create_params_helper.rb index 3fbfb8cd..32d1baab 100644 --- a/app/controllers/todos/todo_create_params_helper.rb +++ b/app/controllers/todos/todo_create_params_helper.rb @@ -146,9 +146,11 @@ module Todos end def set_id_by_name(group_type, set, name) - group = set.where(:name => name).first_or_create + group = set.where(:name => name).first_or_initialize + group_is_new = group.new_record? + group.save if group_is_new @attributes["#{group_type}_id"] = group.id - return group.new_record_before_save? + group_is_new end def set_id_by_id_string(group_type, set, id) diff --git a/app/models/context.rb b/app/models/context.rb index 7cc0cf2a..d8c9fb8d 100644 --- a/app/models/context.rb +++ b/app/models/context.rb @@ -45,10 +45,6 @@ class Context < ApplicationRecord name end - def new_record_before_save? - @new_record_before_save - end - def no_active_todos? return todos.active.count == 0 end diff --git a/app/models/project.rb b/app/models/project.rb index c5553f70..0b053536 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -118,10 +118,6 @@ class Project < ApplicationRecord end end - def new_record_before_save? - @new_record_before_save - end - def age_in_days @age_in_days ||= (Time.current.to_date - created_at.to_date).to_i + 1 end diff --git a/test/models/context_test.rb b/test/models/context_test.rb index 92630c38..8d9234c8 100644 --- a/test/models/context_test.rb +++ b/test/models/context_test.rb @@ -61,12 +61,6 @@ class ContextTest < ActiveSupport::TestCase assert_equal '', c.name end - def test_new_record_before_save - assert !@agenda.new_record_before_save?, "existing records should not be new_record" - c = Context.where(:name => "I do not exist").first_or_create - assert c.new_record_before_save?, "newly created record should be new_record" - end - def test_hide_context assert @agenda.active? @agenda.hide! diff --git a/test/models/project_test.rb b/test/models/project_test.rb index c676f14b..0feeaa2c 100644 --- a/test/models/project_test.rb +++ b/test/models/project_test.rb @@ -174,12 +174,6 @@ class ProjectTest < ActiveSupport::TestCase assert_equal 3, @moremoney.todos.not_completed.count end - def test_new_record_before_save - assert !@timemachine.new_record_before_save?, "existing records should not be new_record" - p = Project.where(:name => "I do not exist").first_or_create - assert p.new_record_before_save?, "newly created record should be new_record" - end - def test_shortened_name s = "project"*7 # len=49 p = users(:admin_user).projects.create(:name => s)