-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attachments: Concatenations Controller (#262)
* chore: added in scaffold and basic tests for Samples Attachments Concatenation controller * chore: update concatenations controller to call concatenation service, update concatenation service params and response * chore: fix tests for concatenation controller * chore: fix tests
- Loading branch information
Showing
11 changed files
with
174 additions
and
50 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
app/controllers/projects/samples/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Projects | ||
module Samples | ||
# Base Controller Samples | ||
class ApplicationController < Projects::ApplicationController | ||
before_action :sample | ||
|
||
private | ||
|
||
def sample | ||
@sample = @project.samples.find_by(id: params[:sample_id]) || not_found | ||
end | ||
end | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
app/controllers/projects/samples/attachments/concatenations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Projects | ||
module Samples | ||
module Attachments | ||
# Controller actions for Project Samples Attachments Concatenation | ||
class ConcatenationsController < Projects::Samples::ApplicationController | ||
respond_to :turbo_stream | ||
|
||
def new | ||
authorize! @project, to: :update_sample? | ||
|
||
render turbo_stream: [], status: :ok | ||
end | ||
|
||
def create | ||
authorize! @project, to: :update_sample? | ||
|
||
@concatenated_attachments = ::Attachments::ConcatenationService.new(current_user, @sample, | ||
concatenation_params).execute | ||
|
||
if @sample.errors.empty? | ||
render turbo_stream: [], status: :ok | ||
else | ||
@errors = @sample.errors.full_messages_for(:base) | ||
render turbo_stream: [], status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def concatenation_params | ||
params.permit(:basename, :delete_originals, attachment_ids: []) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/controllers/projects/samples/attachments/concatenations_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Projects | ||
module Samples | ||
module Attachments | ||
class ConcatenationControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
sign_in users(:john_doe) | ||
@sample1 = samples(:sample1) | ||
@project1 = projects(:project1) | ||
@namespace = groups(:group_one) | ||
@attachment1 = attachments(:attachment1) | ||
@attachment2 = attachments(:attachment2) | ||
end | ||
|
||
test 'should get new for a member with role >= maintainer' do | ||
get new_namespace_project_sample_attachments_concatenation_path(@namespace, @project1, @sample1, | ||
format: :turbo_stream) | ||
assert_response :success | ||
end | ||
|
||
test 'should not get new if not a member' do | ||
user = users(:micha_doe) | ||
login_as user | ||
|
||
get new_namespace_project_sample_attachments_concatenation_path(@namespace, @project1, @sample1, | ||
format: :turbo_stream) | ||
assert_response :unauthorized | ||
end | ||
|
||
test 'should create sample attachments concatenation for a member with role >= maintainer' do | ||
post namespace_project_sample_attachments_concatenation_path(@namespace, @project1, @sample1, | ||
format: :turbo_stream), | ||
params: { | ||
basename: 'blah', | ||
attachment_ids: [@attachment1.id, @attachment2.id] | ||
} | ||
|
||
assert_response :success | ||
end | ||
|
||
test 'should not create sample attachments concatenation for a non member' do | ||
user = users(:micha_doe) | ||
login_as user | ||
|
||
post namespace_project_sample_attachments_concatenation_path(@namespace, @project1, @sample1, | ||
format: :turbo_stream) | ||
assert_response :unauthorized | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters