mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 15:50:13 +01:00
Remove private variable usage from models
It seems that `@new_record_before_save` as an instance variable has been present since around 2007 and it wasn't until Rails 5.1 that things were changed in such a way to make this inaccessible now.
This commit is contained in:
parent
78742d15b8
commit
32d267d6cd
5 changed files with 4 additions and 22 deletions
|
|
@ -146,9 +146,11 @@ module Todos
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_id_by_name(group_type, set, name)
|
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
|
@attributes["#{group_type}_id"] = group.id
|
||||||
return group.new_record_before_save?
|
group_is_new
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_id_by_id_string(group_type, set, id)
|
def set_id_by_id_string(group_type, set, id)
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,6 @@ class Context < ApplicationRecord
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_record_before_save?
|
|
||||||
@new_record_before_save
|
|
||||||
end
|
|
||||||
|
|
||||||
def no_active_todos?
|
def no_active_todos?
|
||||||
return todos.active.count == 0
|
return todos.active.count == 0
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -118,10 +118,6 @@ class Project < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_record_before_save?
|
|
||||||
@new_record_before_save
|
|
||||||
end
|
|
||||||
|
|
||||||
def age_in_days
|
def age_in_days
|
||||||
@age_in_days ||= (Time.current.to_date - created_at.to_date).to_i + 1
|
@age_in_days ||= (Time.current.to_date - created_at.to_date).to_i + 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,6 @@ class ContextTest < ActiveSupport::TestCase
|
||||||
assert_equal '', c.name
|
assert_equal '', c.name
|
||||||
end
|
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
|
def test_hide_context
|
||||||
assert @agenda.active?
|
assert @agenda.active?
|
||||||
@agenda.hide!
|
@agenda.hide!
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,6 @@ class ProjectTest < ActiveSupport::TestCase
|
||||||
assert_equal 3, @moremoney.todos.not_completed.count
|
assert_equal 3, @moremoney.todos.not_completed.count
|
||||||
end
|
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
|
def test_shortened_name
|
||||||
s = "project"*7 # len=49
|
s = "project"*7 # len=49
|
||||||
p = users(:admin_user).projects.create(:name => s)
|
p = users(:admin_user).projects.create(:name => s)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue