Use `alias_attribute` & `alias_method` to define parent-methods
This commit is contained in:
parent
e013d39875
commit
b3acd5459c
|
@ -82,6 +82,8 @@ class Project < ActiveRecord::Base
|
||||||
belongs_to :creator, class_name: 'User'
|
belongs_to :creator, class_name: 'User'
|
||||||
belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id'
|
belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id'
|
||||||
belongs_to :namespace
|
belongs_to :namespace
|
||||||
|
alias_method :parent, :namespace
|
||||||
|
alias_attribute :parent_id, :namespace_id
|
||||||
|
|
||||||
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event'
|
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event'
|
||||||
has_many :boards, before_add: :validate_board_limit
|
has_many :boards, before_add: :validate_board_limit
|
||||||
|
@ -1521,14 +1523,6 @@ class Project < ActiveRecord::Base
|
||||||
map.public_path_for_source_path(path)
|
map.public_path_for_source_path(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent
|
|
||||||
namespace
|
|
||||||
end
|
|
||||||
|
|
||||||
def parent_id
|
|
||||||
namespace_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def parent_changed?
|
def parent_changed?
|
||||||
namespace_id_changed?
|
namespace_id_changed?
|
||||||
end
|
end
|
||||||
|
|
|
@ -2095,6 +2095,13 @@ describe Project do
|
||||||
it { expect(project.parent).to eq(project.namespace) }
|
it { expect(project.parent).to eq(project.namespace) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#parent_id' do
|
||||||
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
|
it { expect(project.parent_id).to eq(project.namespace_id) }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe '#parent_changed?' do
|
describe '#parent_changed?' do
|
||||||
let(:project) { create(:project) }
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue