Commit b3acd545 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Use `alias_attribute` & `alias_method` to define parent-methods

parent e013d398
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment