Commit 49909390 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'onboarding-experiment-create-learn-gitlab-project' into 'master'

Create Learn GitLab project

See merge request gitlab-org/gitlab!33413
parents 326ac507 9adf18c2
......@@ -15,7 +15,8 @@ module Registrations
@project = ::Projects::CreateService.new(current_user, project_params).execute
if @project.saved?
redirect_to project_path(@project)
create_learn_gitlab_project
redirect_to users_sign_up_experience_level_path
else
render :new
end
......@@ -23,6 +24,16 @@ module Registrations
private
def create_learn_gitlab_project
File.open(learn_gitlab_template_path) do |archive|
::Projects::GitlabProjectsImportService.new(current_user, namespace_id: @project.namespace_id, file: archive, name: s_('Learn GitLab')).execute
end
end
def learn_gitlab_template_path
Rails.root.join('vendor', 'project_templates', 'learn_gitlab.tar.gz')
end
def check_experiment_enabled
access_denied! unless experiment_enabled?(:onboarding_issues)
end
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Registrations::ProjectsController do
let_it_be(:user) { create(:user) }
let_it_be(:namespace) { create(:group, path: 'group-path') }
let_it_be(:namespace) { create(:group) }
describe 'GET #new' do
subject { get :new }
......@@ -50,7 +50,7 @@ RSpec.describe Registrations::ProjectsController do
describe 'POST #create' do
subject { post :create, params: { project: params } }
let(:params) { { namespace_id: namespace.id, name: 'Project name', path: 'project-path', visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
let(:params) { { namespace_id: namespace.id, name: 'New project', path: 'project-path', visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
context 'with an unauthenticated user' do
it { is_expected.to have_gitlab_http_status(:redirect) }
......@@ -64,12 +64,15 @@ RSpec.describe Registrations::ProjectsController do
stub_experiment_for_user(onboarding_issues: true)
end
it 'creates a project' do
expect { subject }.to change { Project.count }.by(1)
end
it 'creates a new project, a "Learn GitLab" project and redirects to the experience level page' do
expect { subject }.to change { namespace.projects.pluck(:name) }.from([]).to(['New project', s_('Learn GitLab')])
it { is_expected.to have_gitlab_http_status(:redirect) }
it { is_expected.to redirect_to('/group-path/project-path') }
Sidekiq::Worker.drain_all
expect(subject).to have_gitlab_http_status(:redirect)
expect(subject).to redirect_to(users_sign_up_experience_level_path)
expect(namespace.projects.find_by_name(s_('Learn GitLab'))).to be_import_finished
end
context 'when the project cannot be saved' do
let(:params) { { name: '', path: '' } }
......
......@@ -12,8 +12,8 @@
#
# To enable the experiment for 10% of the users:
#
# chatops: `/chatops run feature set experiment_key_experiment_percentage 10 --actors`
# console: `Feature.enable_percentage_of_actors(:experiment_key_experiment_percentage, 10)`
# chatops: `/chatops run feature set experiment_key_experiment_percentage 10`
# console: `Feature.enable_percentage_of_time(:experiment_key_experiment_percentage, 10)`
#
# To disable the experiment:
#
......@@ -26,7 +26,7 @@
# console: `Feature.get(:experiment_key_experiment_percentage).percentage_of_time_value`
#
# TODO: rewrite that
# TODO: see https://gitlab.com/gitlab-org/gitlab/-/issues/217490
module Gitlab
module Experimentation
EXPERIMENTS = {
......
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