Commit eb0ae22d authored by jejacks0n's avatar jejacks0n

Add new experiment class to house experiment logic

- This adds an experiment class and moves all inline logic into the
experiment implementation.
parent 23971e4a
# frozen_string_literal: true
class NewProjectReadmeContentExperiment < ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass
TEMPLATE_PATH = Rails.root.join('app', 'experiments', 'templates', 'new_project_readme_content')
def run_with(project, variant: nil)
@project = project
record!
run(variant)
end
def control_behavior
template('readme_basic.md')
end
def advanced_behavior
template('readme_advanced.md')
end
private
def template(name)
ERB.new(File.read(TEMPLATE_PATH.join("#{name}.tt")), trim_mode: '<>').result(binding)
end
end
......@@ -2,6 +2,7 @@
<%= @project.description %>
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
......
......@@ -3,7 +3,6 @@
module Projects
class CreateService < BaseService
include ValidatesClassificationLabel
TEMPLATE_PATH = Rails.root.join('app', 'services', 'projects', 'create_service', 'templates')
def initialize(user, params)
@current_user = user
......@@ -152,21 +151,12 @@ module Projects
branch_name: @default_branch.presence || @project.default_branch_or_main,
commit_message: 'Initial commit',
file_path: 'README.md',
file_content: experiment(:new_project_readme_content, namespace: @project.namespace) do |e|
e.control { template('readme_basic.md') }
e.try(:advanced) { template('readme_advanced.md') }
e.record!
e.run
end
file_content: experiment(:new_project_readme_content, namespace: @project.namespace).run_with(@project)
}
Files::CreateService.new(@project, current_user, commit_attrs).execute
end
def template(name)
ERB.new(File.read(TEMPLATE_PATH.join("#{name}.tt")), trim_mode: '<>').result(binding)
end
def skip_wiki?
!@project.feature_available?(:wiki, current_user) || @skip_wiki
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe NewProjectReadmeContentExperiment, :experiment do
subject { described_class.new(namespace: project.namespace) }
let(:project) { create(:project, name: 'Experimental', description: 'An experiment project') }
it "renders the basic template" do
expect(subject.run_with(project)).to eq(<<~MARKDOWN.strip)
# Experimental
An experiment project
MARKDOWN
end
it "renders the advanced template" do
expect(subject.run_with(project, variant: :advanced)).to include(<<~MARKDOWN.strip)
# Experimental
An experiment project
## Getting started
MARKDOWN
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