2019-09-10 07:28:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe ReleasesHelper do
|
2019-09-10 07:28:43 +00:00
|
|
|
describe '#illustration' do
|
|
|
|
it 'returns the correct image path' do
|
|
|
|
expect(helper.illustration).to match(/illustrations\/releases-(\w+)\.svg/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#help_page' do
|
|
|
|
it 'returns the correct link to the help page' do
|
|
|
|
expect(helper.help_page).to include('user/project/releases/index')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'url helpers' do
|
|
|
|
let(:project) { build(:project, namespace: create(:group)) }
|
2019-11-12 18:06:57 +00:00
|
|
|
let(:release) { create(:release, project: project) }
|
2020-03-13 12:09:22 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:can_user_create_release) { false }
|
2020-09-15 15:10:08 +00:00
|
|
|
let(:common_keys) { [:project_id, :project_path, :illustration_path, :documentation_path] }
|
2019-09-10 07:28:43 +00:00
|
|
|
|
2020-07-09 15:08:59 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-09-10 07:28:43 +00:00
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
2019-11-12 18:06:57 +00:00
|
|
|
helper.instance_variable_set(:@release, release)
|
2020-03-13 12:09:22 +00:00
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:can?)
|
|
|
|
.with(user, :create_release, project)
|
|
|
|
.and_return(can_user_create_release)
|
2019-09-10 07:28:43 +00:00
|
|
|
end
|
2020-07-09 15:08:59 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2019-09-10 07:28:43 +00:00
|
|
|
|
|
|
|
describe '#data_for_releases_page' do
|
2020-03-13 12:09:22 +00:00
|
|
|
it 'includes the required data for displaying release blocks' do
|
|
|
|
expect(helper.data_for_releases_page.keys).to contain_exactly(*common_keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is allowed to create a new release' do
|
|
|
|
let(:can_user_create_release) { true }
|
|
|
|
|
|
|
|
it 'includes new_release_path' do
|
|
|
|
expect(helper.data_for_releases_page.keys).to contain_exactly(*common_keys, :new_release_path)
|
2020-07-09 15:08:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'points new_release_path to the "New Release" page' do
|
|
|
|
expect(helper.data_for_releases_page[:new_release_path]).to eq(new_project_release_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the "new_release_page" feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(new_release_page: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'points new_release_path to the "New Tag" page' do
|
|
|
|
expect(helper.data_for_releases_page[:new_release_path]).to eq(new_project_tag_path(project))
|
|
|
|
end
|
2020-03-13 12:09:22 +00:00
|
|
|
end
|
2019-09-10 07:28:43 +00:00
|
|
|
end
|
|
|
|
end
|
2019-11-12 18:06:57 +00:00
|
|
|
|
|
|
|
describe '#data_for_edit_release_page' do
|
|
|
|
it 'has the needed data to display the "edit release" page' do
|
|
|
|
keys = %i(project_id
|
2020-10-16 09:09:06 +00:00
|
|
|
project_path
|
2019-11-12 18:06:57 +00:00
|
|
|
tag_name
|
|
|
|
markdown_preview_path
|
|
|
|
markdown_docs_path
|
|
|
|
releases_page_path
|
2020-04-01 12:08:00 +00:00
|
|
|
update_release_api_docs_path
|
2020-05-07 21:09:26 +00:00
|
|
|
release_assets_docs_path
|
|
|
|
manage_milestones_path
|
|
|
|
new_milestone_path)
|
2020-07-09 15:08:59 +00:00
|
|
|
|
|
|
|
expect(helper.data_for_edit_release_page.keys).to match_array(keys)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#data_for_new_release_page' do
|
|
|
|
it 'has the needed data to display the "new release" page' do
|
|
|
|
keys = %i(project_id
|
2020-10-16 09:09:06 +00:00
|
|
|
project_path
|
2020-08-11 21:10:09 +00:00
|
|
|
releases_page_path
|
2020-07-09 15:08:59 +00:00
|
|
|
markdown_preview_path
|
|
|
|
markdown_docs_path
|
|
|
|
update_release_api_docs_path
|
|
|
|
release_assets_docs_path
|
|
|
|
manage_milestones_path
|
|
|
|
new_milestone_path
|
|
|
|
default_branch)
|
|
|
|
|
|
|
|
expect(helper.data_for_new_release_page.keys).to match_array(keys)
|
2019-11-12 18:06:57 +00:00
|
|
|
end
|
|
|
|
end
|
2020-10-16 09:09:06 +00:00
|
|
|
|
|
|
|
describe '#data_for_show_page' do
|
|
|
|
it 'has the needed data to display the individual "release" page' do
|
|
|
|
keys = %i(project_id
|
|
|
|
project_path
|
|
|
|
tag_name)
|
|
|
|
|
|
|
|
expect(helper.data_for_show_page.keys).to match_array(keys)
|
|
|
|
end
|
|
|
|
end
|
2019-09-10 07:28:43 +00:00
|
|
|
end
|
|
|
|
end
|