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
6562dfb8
Commit
6562dfb8
authored
Jul 06, 2017
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move TrialsController under admin namespace and add specs
parent
28df9ada
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
12 deletions
+60
-12
app/controllers/admin/trials_controller.rb
app/controllers/admin/trials_controller.rb
+7
-7
app/views/admin/licenses/missing.html.haml
app/views/admin/licenses/missing.html.haml
+1
-1
app/views/admin/trials/new.html.haml
app/views/admin/trials/new.html.haml
+1
-1
config/routes.rb
config/routes.rb
+0
-3
config/routes/admin.rb
config/routes/admin.rb
+3
-0
spec/controllers/admin/trials_controller_spec.rb
spec/controllers/admin/trials_controller_spec.rb
+48
-0
No files found.
app/controllers/trials_controller.rb
→
app/controllers/
admin/
trials_controller.rb
View file @
6562dfb8
class
TrialsController
<
ApplicationController
class
Admin::TrialsController
<
Admin
::
ApplicationController
before_action
:check_presence_of_license
def
new
...
...
@@ -8,15 +8,15 @@ class TrialsController < ApplicationController
build_license
if
save_license
redirect_to
admin_license_url
redirect_to
admin_license_url
,
notice:
'Your trial license was successfully activated'
else
flash
.
now
[
:alert
]
=
'An error occurred while generating the trial license, please try again a few minutes'
flash
.
now
[
:alert
]
=
"An error occurred while generating the trial license, please try again a few minutes.<br>
If the error persist please try by creating the license from
<a href='https://about.gitlab.com/free-trial/' target='_blank'>this page</a>."
.
html_safe
render
:new
end
end
private
def
build_license
@license
=
License
.
new
end
...
...
@@ -24,7 +24,7 @@ class TrialsController < ApplicationController
def
save_license
result
=
HTTParty
.
post
(
"
#{
Gitlab
::
SUBSCRIPTIONS_URL
}
/trials"
,
body:
params
)
if
result
.
ok?
if
false
@license
.
data
=
result
[
'license_key'
]
@license
.
save
else
...
...
@@ -37,7 +37,7 @@ class TrialsController < ApplicationController
def
check_presence_of_license
if
License
.
current
&
.
active?
redirect_to
admin_license_url
redirect_to
admin_license_url
,
alert:
'You already have an active license key installed on this server.'
end
end
end
app/views/admin/licenses/missing.html.haml
View file @
6562dfb8
...
...
@@ -11,5 +11,5 @@
%p
You can start a free trial of GitLab Enterprise Edition without any obligation or payment details.
=
link_to
'Start free trial'
,
new_
trial
_url
,
class:
"btn btn-new"
=
link_to
'Start free trial'
,
new_
admin_trials
_url
,
class:
"btn btn-new"
app/views/trials/new.html.haml
→
app/views/
admin/
trials/new.html.haml
View file @
6562dfb8
...
...
@@ -3,7 +3,7 @@
%main
{
:role
=>
"main"
}
.actions
=
form_tag
trials_path
,
method: :post
do
=
form_tag
admin_
trials_path
,
method: :post
do
.form-group
=
label_tag
:first_name
=
text_field_tag
:first_name
,
params
[
:first_name
],
class:
"form-control"
,
required:
true
...
...
config/routes.rb
View file @
6562dfb8
...
...
@@ -82,9 +82,6 @@ Rails.application.routes.draw do
# Notification settings
resources
:notification_settings
,
only:
[
:create
,
:update
]
# Trial licenses
resources
:trials
,
only:
[
:new
,
:create
]
draw
:import
draw
:uploads
draw
:explore
...
...
config/routes/admin.rb
View file @
6562dfb8
...
...
@@ -120,6 +120,9 @@ namespace :admin do
put
:clear_repository_check_states
end
## EE-specific
resource
:trials
,
only:
[
:new
,
:create
]
## EE-specific
resource
:license
,
only:
[
:show
,
:new
,
:create
,
:destroy
]
do
get
:download
,
on: :member
...
...
spec/controllers/admin/trials_controller_spec.rb
0 → 100644
View file @
6562dfb8
require
'spec_helper'
describe
Admin
::
TrialsController
do
let
(
:admin
)
{
create
(
:admin
)
}
before
do
sign_in
(
admin
)
end
describe
'POST #create'
do
context
'without an active license'
do
before
{
expect_any_instance_of
(
License
).
to
receive
(
:active?
).
and_return
(
false
)
}
context
'with a successful response from subscription endpoint'
do
it
'redirects to the license detail page'
do
allow_any_instance_of
(
Admin
::
TrialsController
).
to
receive
(
:save_license
).
and_return
(
true
)
post
:create
expect
(
response
).
to
redirect_to
admin_license_path
expect
(
flash
[
:notice
]).
to
eq
(
'Your trial license was successfully activated'
)
end
end
context
'with a failing response from subscription endpoint'
do
it
'shows an error message'
do
allow_any_instance_of
(
Admin
::
TrialsController
).
to
receive
(
:save_license
).
and_return
(
false
)
post
:create
expect
(
response
).
to
render_template
(
:new
)
expect
(
flash
[
:alert
]).
to
match
(
/An error occurred while generating the trial license/
)
end
end
end
context
'with an active license'
do
before
{
expect_any_instance_of
(
License
).
to
receive
(
:active?
).
and_return
(
true
)
}
it
'does not allow creating a trial license'
do
post
:create
expect
(
response
).
to
redirect_to
admin_license_url
expect
(
flash
[
:alert
]).
to
match
(
/You already have an active license/
)
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