Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e2eb9487
Commit
e2eb9487
authored
Feb 06, 2020
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure settings are created when you access them
parent
2d15c330
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
1 deletion
+11
-1
app/models/project.rb
app/models/project.rb
+1
-1
app/models/project_settings.rb
app/models/project_settings.rb
+4
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+6
-0
No files found.
app/models/project.rb
View file @
e2eb9487
...
@@ -190,7 +190,7 @@ class Project < ApplicationRecord
...
@@ -190,7 +190,7 @@ class Project < ApplicationRecord
has_one
:error_tracking_setting
,
inverse_of: :project
,
class_name:
'ErrorTracking::ProjectErrorTrackingSetting'
has_one
:error_tracking_setting
,
inverse_of: :project
,
class_name:
'ErrorTracking::ProjectErrorTrackingSetting'
has_one
:metrics_setting
,
inverse_of: :project
,
class_name:
'ProjectMetricsSetting'
has_one
:metrics_setting
,
inverse_of: :project
,
class_name:
'ProjectMetricsSetting'
has_one
:grafana_integration
,
inverse_of: :project
has_one
:grafana_integration
,
inverse_of: :project
has_one
:settings
,
inverse_of: :project
,
class_name:
'ProjectSettings'
has_one
:settings
,
->
(
project
)
{
where_or_create_by
(
project:
project
)
},
inverse_of: :project
,
class_name:
'ProjectSettings'
# Merge Requests for target project should be removed with it
# Merge Requests for target project should be removed with it
has_many
:merge_requests
,
foreign_key:
'target_project_id'
,
inverse_of: :target_project
has_many
:merge_requests
,
foreign_key:
'target_project_id'
,
inverse_of: :target_project
...
...
app/models/project_settings.rb
View file @
e2eb9487
...
@@ -4,4 +4,8 @@ class ProjectSettings < ApplicationRecord
...
@@ -4,4 +4,8 @@ class ProjectSettings < ApplicationRecord
belongs_to
:project
,
inverse_of: :settings
belongs_to
:project
,
inverse_of: :settings
self
.
primary_key
=
:project_id
self
.
primary_key
=
:project_id
def
self
.
where_or_create_by
(
attrs
)
where
(
primary_key
=>
safe_find_or_create_by
(
attrs
))
end
end
end
spec/models/project_spec.rb
View file @
e2eb9487
...
@@ -156,6 +156,12 @@ describe Project do
...
@@ -156,6 +156,12 @@ describe Project do
expect
(
project
.
pages_metadatum
).
to
be_an_instance_of
(
ProjectPagesMetadatum
)
expect
(
project
.
pages_metadatum
).
to
be_an_instance_of
(
ProjectPagesMetadatum
)
expect
(
project
.
pages_metadatum
).
to
be_persisted
expect
(
project
.
pages_metadatum
).
to
be_persisted
end
end
it
'creates settings if needed when accessed'
do
expect
do
expect
(
project
.
settings
).
to
be_persisted
end
.
to
change
{
ProjectSettings
.
count
}.
by
(
1
)
end
end
end
context
'updating cd_cd_settings'
do
context
'updating cd_cd_settings'
do
...
...
Write
Preview
Markdown
is supported
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