Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/automated_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
services:
mysql:
# Use the Mysql docker image https://hub.docker.com/_/mysql
image: mysql:8.0
image: mysql:8.4
ports:
- 3306 # Default port mappings
# Monitor the health of the container to mesaure when it is ready
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
services:
mysql:
# Use the Mysql docker image https://hub.docker.com/_/mysql
image: mysql:8.0
image: mysql:8.4
ports:
- 3306 # Default port mappings
# Monitor the health of the container to mesaure when it is ready
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cucumber_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
services:
mysql:
# Use the Mysql docker image https://hub.docker.com/_/mysql
image: mysql:8.0
image: mysql:8.4
ports:
- 3306 # Default port mappings
# Monitor the health of the container to mesaure when it is ready
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rake_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
services:
mysql:
# Use the Mysql docker image https://hub.docker.com/_/mysql
image: mysql:8.0
image: mysql:8.4
ports:
- 3306 # Default port mappings
# Monitor the health of the container to mesaure when it is ready
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rspec_feature_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
services:
mysql:
# Use the Mysql docker image https://hub.docker.com/_/mysql
image: mysql:8.0
image: mysql:8.4
ports:
- 3306 # Default port mappings
# Monitor the health of the container to mesaure when it is ready
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rspec_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
services:
mysql:
# Use the Mysql docker image https://hub.docker.com/_/mysql
image: mysql:8.0
image: mysql:8.4
ports:
- 3306 # Default port mappings
# Monitor the health of the container to mesaure when it is ready
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/api/v2/plate_templates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Api
module V2
# Provides a JSON API controller for PlateTemplate
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation
class PlateTemplatesController < JSONAPI::ResourceController
# By default JSONAPI::ResourceController provides most the standard
# behaviour, and in many cases this file may be left empty.
end
end
end
14 changes: 13 additions & 1 deletion app/controllers/plate_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,22 @@ def update # rubocop:todo Metrics/AbcSize
redirect_to plate_templates_path
end

# rubocop:disable Metrics/MethodLength
def destroy
pattern = PlateTemplate.find(params[:id])
pattern.destroy
begin
ActiveRecord::Base.transaction do
pattern.wells.destroy_all
pattern.destroy!
end

flash[:notice] = 'Template deleted'
rescue ActiveRecord::DeleteRestrictionError, ActiveRecord::RecordNotDestroyed
flash[:error] = 'Template cannot be deleted because it has dependent records'
end

respond_to { |format| format.html { redirect_to(plate_templates_path) } }
end

# rubocop:enable Metrics/MethodLength
end
30 changes: 30 additions & 0 deletions app/resources/api/v2/plate_template_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Api
module V2
#
# Provides a JSON:API representation of {PlateTemplate}.
#
# A `PlateTemplate` represents a virtual plate used in Cherrypicking to block out empty wells
# or layout pre-assigned samples.

# @note This resource is accessed via the `/api/v2/plate_templates/` endpoint.
#
# @example GET request to retrieve all plate templates
# GET /api/v2/plate_templates/
#
# @example GET request to retrieve a specific plate template by ID
# GET /api/v2/plate_templates/123/
#
# For more information about JSON:API, see the [JSON:API Specifications](https://jsonapi.org/format/)
# or the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation
# of the JSON:API standard.
class PlateTemplateResource < BaseResource
include Api::V2::SharedBehaviour::Labware

model_name 'PlateTemplate'

default_includes :uuid_object
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
jsonapi_resources :plate_conversions, except: %i[update]
jsonapi_resources :plate_creations, except: %i[update]
jsonapi_resources :plate_purposes, except: %i[update]
jsonapi_resources :plate_templates
jsonapi_resources :plates, except: %i[update]
post 'plates/:id/register_stock_for_plate', to: 'plates#register_stock_for_plate'

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
retries: 5

mysql_server:
image: mysql:8.0
image: mysql:8.4
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD="yes"
healthcheck:
Expand Down
65 changes: 65 additions & 0 deletions spec/requests/api/v2/plate_templates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

require 'rails_helper'
require './spec/requests/api/v2/shared_examples/api_key_authenticatable'

describe 'PlateTemplates API', with: :api_v2 do
let(:base_endpoint) { '/api/v2/plate_templates' }

it_behaves_like 'ApiKeyAuthenticatable'

context 'with multiple PlateTemplates' do
before { create_list(:plate_template, 5) }

it 'responds successfully' do
api_get base_endpoint

# test for the 200 status-code
expect(response).to have_http_status(:success)
end

it 'returns the list of plate_templates' do
api_get base_endpoint

# check to make sure the right amount of messages are returned
expect(json['data'].length).to eq(5)
end
end

context 'with a PlateTemplate' do
let(:resource_model) { create(:plate_template) }

let(:payload) do
{
'data' => {
'id' => resource_model.id,
'type' => 'plate_templates',
'attributes' => {
# Set new attributes here
}
}
}
end

it 'responds successfully' do
api_get "#{base_endpoint}/#{resource_model.id}"
expect(response).to have_http_status(:success)
end

it 'sends an individual PlateTemplate' do
api_get "#{base_endpoint}/#{resource_model.id}"
expect(json.dig('data', 'type')).to eq('plate_templates')
end

# Remove if immutable
it 'responds successfully to update' do
api_patch "#{base_endpoint}/#{resource_model.id}", payload
expect(response).to have_http_status(:success)
end

it 'allows update of a PlateTemplate' do
api_patch "#{base_endpoint}/#{resource_model.id}", payload
expect(json.dig('data', 'type')).to eq('plate_templates')
end
end
end
2 changes: 2 additions & 0 deletions spec/support/user_login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def login_user(user)
fill_in 'Username', with: user.login
fill_in 'Password', with: 'password'
click_button 'Login'
# wait for the login to complete before returning, so ready for whatever is next
find_by_id('message_notice', text: 'Logged in successfully')
true
end
end
Loading