Commit 6562dfb8 authored by Ruben Davila's avatar Ruben Davila

Move TrialsController under admin namespace and add specs

parent 28df9ada
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
......@@ -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"
......@@ -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
......
......@@ -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
......
......@@ -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
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment