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
d10b5ebd
Commit
d10b5ebd
authored
Feb 27, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed GeoNode bugous URI initialization and added more tests
parent
5bf83afb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
12 deletions
+33
-12
app/models/geo_node.rb
app/models/geo_node.rb
+10
-6
spec/models/geo_node_spec.rb
spec/models/geo_node_spec.rb
+23
-6
No files found.
app/models/geo_node.rb
View file @
d10b5ebd
...
@@ -13,10 +13,11 @@
...
@@ -13,10 +13,11 @@
class
GeoNode
<
ActiveRecord
::
Base
class
GeoNode
<
ActiveRecord
::
Base
belongs_to
:geo_node_key
belongs_to
:geo_node_key
default_value_for
:schema
,
'http'
default_values
schema:
'http'
,
default_value_for
:port
,
80
host:
lambda
{
Gitlab
.
config
.
gitlab
.
host
},
default_value_for
:relative_url_root
,
''
port:
80
,
default_value_for
:primary
,
false
relative_url_root:
''
,
primary:
false
accepts_nested_attributes_for
:geo_node_key
accepts_nested_attributes_for
:geo_node_key
...
@@ -29,8 +30,11 @@ class GeoNode < ActiveRecord::Base
...
@@ -29,8 +30,11 @@ class GeoNode < ActiveRecord::Base
after_destroy
:destroy_orphaned_geo_node_key
after_destroy
:destroy_orphaned_geo_node_key
def
uri
def
uri
relative_url
=
relative_url_root
[
0
]
==
'/'
?
relative_url_root
[
1
..-
1
]
:
relative_url_root
if
relative_url_root
URI
.
parse
(
"
#{
schema
}
://
#{
host
}
:
#{
port
}
/
#{
relative_url
}
"
)
relative_url
=
relative_url_root
.
starts_with?
(
'/'
)
?
relative_url_root
:
relative_url_root
.
prepend
(
'/'
)
end
URI
.
parse
(
URI
::
Generic
.
build
(
scheme:
schema
,
host:
host
,
port:
port
,
path:
relative_url
).
normalize
.
to_s
)
end
end
def
url
def
url
...
...
spec/models/geo_node_spec.rb
View file @
d10b5ebd
...
@@ -3,10 +3,17 @@ require 'spec_helper'
...
@@ -3,10 +3,17 @@ require 'spec_helper'
describe
GeoNode
,
type: :model
do
describe
GeoNode
,
type: :model
do
context
'default values'
do
context
'default values'
do
let
(
:gitlab_host
)
{
'gitlabhost'
}
before
(
:each
)
{
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:host
)
{
gitlab_host
}
}
it
'defines a default schema'
do
it
'defines a default schema'
do
expect
(
subject
.
schema
).
to
eq
(
'http'
)
expect
(
subject
.
schema
).
to
eq
(
'http'
)
end
end
it
'defines a default host'
do
expect
(
subject
.
host
).
to
eq
(
gitlab_host
)
end
it
'defines a default port'
do
it
'defines a default port'
do
expect
(
subject
.
port
).
to
eq
(
80
)
expect
(
subject
.
port
).
to
eq
(
80
)
end
end
...
@@ -17,15 +24,25 @@ describe GeoNode, type: :model do
...
@@ -17,15 +24,25 @@ describe GeoNode, type: :model do
end
end
describe
'#uri'
do
describe
'#uri'
do
subject
{
GeoNode
.
new
(
schema:
'https'
,
host:
'localhost'
,
port:
3000
,
relative_url_root:
'gitlab'
)
}
context
'when all fields are filled'
do
subject
{
GeoNode
.
new
(
schema:
'https'
,
host:
'localhost'
,
port:
3000
,
relative_url_root:
'gitlab'
)
}
it
'returns an URI object'
do
it
'returns an URI object'
do
expect
(
subject
.
uri
).
to
be_a
URI
expect
(
subject
.
uri
).
to
be_a
URI
end
it
'includes schema home port and relative_url'
do
expected_uri
=
URI
.
parse
(
'https://localhost:3000/gitlab'
)
expect
(
subject
.
uri
).
to
eq
(
expected_uri
)
end
end
end
it
'includes schema home port and relative_url'
do
context
'when required fields are not filled'
do
expected_uri
=
URI
.
parse
(
'https://localhost:3000/gitlab'
)
subject
{
GeoNode
.
new
(
schema:
nil
,
host:
nil
,
port:
nil
,
relative_url_root:
nil
)
}
expect
(
subject
.
uri
).
to
eq
(
expected_uri
)
it
'returns an URI object'
do
expect
(
subject
.
uri
).
to
be_a
URI
end
end
end
end
end
...
...
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