Commit 867a1acc authored by Alessio Caiazza's avatar Alessio Caiazza

Move Projects::ReleasesController under Tags

Rename Projects::ReleasesController to
Projects::Tags::ReleasesController
parent 9004e18e
...@@ -4,30 +4,11 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -4,30 +4,11 @@ class Projects::ReleasesController < Projects::ApplicationController
# Authorize # Authorize
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :authorize_push_code!, except: [:index] before_action :check_releases_page_feature_flag
before_action :tag, except: [:index]
before_action :release, except: [:index]
before_action :check_releases_page_feature_flag, only: [:index]
def index def index
end end
def edit
end
def update
# Release belongs to Tag which is not active record object,
# it exists only to save a description to each Tag.
# If description is empty we should destroy the existing record.
if release_params[:description].present?
release.update(release_params)
else
release.destroy
end
redirect_to project_tag_path(@project, @tag.name)
end
private private
def check_releases_page_feature_flag def check_releases_page_feature_flag
...@@ -35,18 +16,4 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -35,18 +16,4 @@ class Projects::ReleasesController < Projects::ApplicationController
push_frontend_feature_flag(:releases_page) push_frontend_feature_flag(:releases_page)
end end
def tag
@tag ||= @repository.find_tag(params[:tag_id])
end
# rubocop: disable CodeReuse/ActiveRecord
def release
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
end
# rubocop: enable CodeReuse/ActiveRecord
def release_params
params.require(:release).permit(:description)
end
end end
# frozen_string_literal: true
class Projects::Tags::ReleasesController < Projects::ApplicationController
# Authorize
before_action :require_non_empty_project
before_action :authorize_download_code!
before_action :authorize_push_code!
before_action :tag
before_action :release
def edit
end
def update
# Release belongs to Tag which is not active record object,
# it exists only to save a description to each Tag.
# If description is empty we should destroy the existing record.
if release_params[:description].present?
release.update(release_params)
else
release.destroy
end
redirect_to project_tag_path(@project, @tag.name)
end
private
def tag
@tag ||= @repository.find_tag(params[:tag_id])
end
# rubocop: disable CodeReuse/ActiveRecord
def release
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
end
# rubocop: enable CodeReuse/ActiveRecord
def release_params
params.require(:release).permit(:description)
end
end
...@@ -42,7 +42,7 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -42,7 +42,7 @@ class Projects::TagsController < Projects::ApplicationController
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def create def create
result = Tags::CreateService.new(@project, current_user) result = ::Tags::CreateService.new(@project, current_user)
.execute(params[:tag_name], params[:ref], params[:message], params[:release_description]) .execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
if result[:status] == :success if result[:status] == :success
...@@ -58,7 +58,7 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -58,7 +58,7 @@ class Projects::TagsController < Projects::ApplicationController
end end
def destroy def destroy
result = Tags::DestroyService.new(project, current_user).execute(params[:id]) result = ::Tags::DestroyService.new(project, current_user).execute(params[:id])
respond_to do |format| respond_to do |format|
if result[:status] == :success if result[:status] == :success
......
...@@ -55,7 +55,7 @@ scope format: false do ...@@ -55,7 +55,7 @@ scope format: false do
resources :branches, only: [:index, :new, :create, :destroy] resources :branches, only: [:index, :new, :create, :destroy]
delete :merged_branches, controller: 'branches', action: :destroy_all_merged delete :merged_branches, controller: 'branches', action: :destroy_all_merged
resources :tags, only: [:index, :show, :new, :create, :destroy] do resources :tags, only: [:index, :show, :new, :create, :destroy] do
resource :release, only: [:edit, :update] resource :release, controller: 'tags/releases', only: [:edit, :update]
end end
resources :protected_branches, only: [:index, :show, :create, :update, :destroy] resources :protected_branches, only: [:index, :show, :create, :update, :destroy]
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Projects::ReleasesController do describe Projects::ReleasesController do
let!(:project) { create(:project, :repository) } let!(:project) { create(:project, :repository, :public) }
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:release) { create(:release, project: project) }
let!(:tag) { release.tag }
before do before do
project.add_developer(user) stub_feature_flags(releases_page: true)
sign_in(user)
end end
describe 'GET #edit' do describe 'GET #index' do
it 'initializes a new release' do it 'renders a 200' do
tag_id = release.tag get_index
project.releases.destroy_all # rubocop: disable DestroyAll
get :edit, namespace_id: project.namespace, project_id: project, tag_id: tag_id expect(response.status).to eq(200)
release = assigns(:release)
expect(release).not_to be_nil
expect(release).not_to be_persisted
end end
it 'retrieves an existing release' do context 'when the project is private' do
get :edit, namespace_id: project.namespace, project_id: project, tag_id: release.tag let!(:project) { create(:project, :repository, :private) }
it 'renders a 302' do
get_index
release = assigns(:release) expect(response.status).to eq(302)
expect(release).not_to be_nil
expect(release).to be_persisted
end end
it 'renders a 200 for a logged in developer' do
project.add_developer(user)
sign_in(user)
get_index
expect(response.status).to eq(200)
end end
describe 'PUT #update' do it 'renders a 404 when logged in but not in the project' do
it 'updates release note description' do sign_in(user)
update_release('description updated')
get_index
release = project.releases.find_by_tag(tag) expect(response.status).to eq(404)
expect(release.description).to eq("description updated") end
end end
it 'deletes release note when description is null' do context 'when releases_page feature flag is disabled' do
expect { update_release('') }.to change(project.releases, :count).by(-1) before do
stub_feature_flags(releases_page: false)
end
it 'renders a 404' do
get_index
expect(response.status).to eq(404)
end end
end end
end
private
def update_release(description) def get_index
put :update, get :index, namespace_id: project.namespace, project_id: project
namespace_id: project.namespace.to_param,
project_id: project,
tag_id: release.tag,
release: { description: description }
end end
end end
# frozen_string_literal: true
require 'spec_helper'
describe Projects::Tags::ReleasesController do
let!(:project) { create(:project, :repository) }
let!(:user) { create(:user) }
let!(:release) { create(:release, project: project) }
let!(:tag) { release.tag }
before do
project.add_developer(user)
sign_in(user)
end
describe 'GET #edit' do
it 'initializes a new release' do
tag_id = release.tag
project.releases.destroy_all # rubocop: disable DestroyAll
get :edit, namespace_id: project.namespace, project_id: project, tag_id: tag_id
release = assigns(:release)
expect(release).not_to be_nil
expect(release).not_to be_persisted
end
it 'retrieves an existing release' do
get :edit, namespace_id: project.namespace, project_id: project, tag_id: release.tag
release = assigns(:release)
expect(release).not_to be_nil
expect(release).to be_persisted
end
end
describe 'PUT #update' do
it 'updates release note description' do
update_release('description updated')
release = project.releases.find_by_tag(tag)
expect(release.description).to eq("description updated")
end
it 'deletes release note when description is null' do
expect { update_release('') }.to change(project.releases, :count).by(-1)
end
end
def update_release(description)
put :update,
namespace_id: project.namespace.to_param,
project_id: project,
tag_id: release.tag,
release: { description: description }
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