Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
44ebd77d745d
Commit
44ebd77d
authored
Oct 05, 2017
by
Bob Van Landuyt
Browse files
Use `alias_attribute` & `alias_method` to define parent-methods
parent
a758e11851d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
44ebd77d
...
...
@@ -82,6 +82,8 @@
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 @@
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
...
...
spec/models/project_spec.rb
View file @
44ebd77d
...
...
@@ -2095,6 +2095,13 @@
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
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment