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
1c62f762
Commit
1c62f762
authored
Mar 11, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create / remove dependent OAuth application for a GeoNode
parent
5b90f894
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
6 deletions
+54
-6
app/models/geo_node.rb
app/models/geo_node.rb
+14
-6
spec/models/geo_node_spec.rb
spec/models/geo_node_spec.rb
+40
-0
No files found.
app/models/geo_node.rb
View file @
1c62f762
...
...
@@ -12,7 +12,7 @@
class
GeoNode
<
ActiveRecord
::
Base
belongs_to
:geo_node_key
,
dependent: :destroy
belongs_to
:oauth_application
,
class_name:
'Doorkeeper::Application'
belongs_to
:oauth_application
,
class_name:
'Doorkeeper::Application'
,
dependent: :destroy
default_values
schema:
'http'
,
host:
lambda
{
Gitlab
.
config
.
gitlab
.
host
},
...
...
@@ -23,14 +23,14 @@ class GeoNode < ActiveRecord::Base
accepts_nested_attributes_for
:geo_node_key
validates
:host
,
host:
true
,
presence:
true
,
uniqueness:
{
case_sensitive:
false
,
scope: :port
}
validates
:primary
,
uniqueness:
{
message:
'
primary
node already exists'
},
if: :primary
validates
:primary
,
uniqueness:
{
message:
'node already exists'
},
if: :primary
validates
:schema
,
inclusion:
%w(http https)
validates
:relative_url_root
,
length:
{
minimum:
0
,
allow_nil:
false
}
after_initialize
:
check_geo_node_key
after_initialize
:
build_dependents
after_save
:refresh_bulk_notify_worker_status
after_destroy
:refresh_bulk_notify_worker_status
before_validation
:
change_geo_node_key_title
before_validation
:
update_dependents_attributes
def
uri
if
relative_url_root
...
...
@@ -66,12 +66,15 @@ class GeoNode < ActiveRecord::Base
end
end
def
check_geo_node_key
def
build_dependents
self
.
build_geo_node_key
if
geo_node_key
.
nil?
self
.
build_oauth_application
if
oauth_application
.
nil?
end
def
change_geo_node_key_title
def
update_dependents_attributes
self
.
geo_node_key
.
title
=
"Geo node:
#{
self
.
url
}
"
if
self
.
geo_node_key
self
.
oauth_application
.
name
=
"Geo node:
#{
self
.
url
}
"
if
self
.
geo_node_key
self
.
oauth_application
.
redirect_uri
=
oauth_callback_url
end
def
validate
(
record
)
...
...
@@ -82,4 +85,9 @@ class GeoNode < ActiveRecord::Base
record
.
errors
[
:base
]
<<
'Current node must be the primary node or you will be locking yourself out'
end
end
def
oauth_callback_url
url_helpers
=
Rails
.
application
.
routes
.
url_helpers
URI
.
join
(
uri
,
"
#{
uri
.
path
}
/"
,
url_helpers
.
oauth_geo_callback_path
).
to_s
end
end
spec/models/geo_node_spec.rb
View file @
1c62f762
...
...
@@ -5,6 +5,7 @@ describe GeoNode, type: :model do
context
'associations'
do
it
{
is_expected
.
to
belong_to
(
:geo_node_key
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
belong_to
(
:oauth_application
).
dependent
(
:destroy
)
}
end
context
'default values'
do
...
...
@@ -44,6 +45,45 @@ describe GeoNode, type: :model do
end
end
context
'dependent models for GeoNode'
do
let
(
:geo_node_key_attributes
)
{
FactoryGirl
.
build
(
:geo_node_key
).
attributes
}
subject
{
GeoNode
.
new
(
schema:
'https'
,
host:
'localhost'
,
port:
3000
,
relative_url_root:
'gitlab'
)
}
context
'on initialize'
do
before
(
:each
)
do
subject
.
geo_node_key_attributes
=
geo_node_key_attributes
end
it
'initializes a corresponding key'
do
expect
(
subject
.
geo_node_key
).
to
be_present
end
it
'initializes a corresponding oauth application'
do
expect
(
subject
.
oauth_application
).
to
be_present
end
it
'is valid'
do
expect
(
subject
).
to
be_valid
end
end
context
'on create'
do
before
(
:each
)
do
subject
.
geo_node_key_attributes
=
geo_node_key_attributes
subject
.
save!
end
it
'saves a corresponding key'
do
expect
(
subject
.
geo_node_key
).
to
be_persisted
end
it
'saves a corresponding oauth application'
do
expect
(
subject
.
oauth_application
).
to
be_persisted
end
end
end
describe
'#uri'
do
context
'when all fields are filled'
do
subject
{
GeoNode
.
new
(
schema:
'https'
,
host:
'localhost'
,
port:
3000
,
relative_url_root:
'gitlab'
)
}
...
...
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