Use alias_attribute
& alias_method
to define parent-methods
This commit is contained in:
parent
e013d39875
commit
b3acd5459c
2 changed files with 9 additions and 8 deletions
|
@ -82,6 +82,8 @@ class Project < ActiveRecord::Base
|
|||
belongs_to :creator, class_name: 'User'
|
||||
belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id'
|
||||
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_many :boards, before_add: :validate_board_limit
|
||||
|
@ -1521,14 +1523,6 @@ class Project < ActiveRecord::Base
|
|||
map.public_path_for_source_path(path)
|
||||
end
|
||||
|
||||
def parent
|
||||
namespace
|
||||
end
|
||||
|
||||
def parent_id
|
||||
namespace_id
|
||||
end
|
||||
|
||||
def parent_changed?
|
||||
namespace_id_changed?
|
||||
end
|
||||
|
|
|
@ -2095,6 +2095,13 @@ describe Project do
|
|||
it { expect(project.parent).to eq(project.namespace) }
|
||||
end
|
||||
|
||||
describe '#parent_id' do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
it { expect(project.parent_id).to eq(project.namespace_id) }
|
||||
end
|
||||
|
||||
|
||||
describe '#parent_changed?' do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue