Skip to content

Commit

Permalink
Library types can be inactive, have external_identifiers
Browse files Browse the repository at this point in the history
https://github.com/sanger/traction-service/issues/730 also
makes some requirements wrt library_type.
  • Loading branch information
James Glover committed Jun 10, 2022
1 parent 06c0348 commit a8f0c94
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/library_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class LibraryType < ApplicationRecord

validates :pipeline, presence: true
validates :name, presence: true, uniqueness: { scope: :pipeline }

scope :active, -> { where(active: true) }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

# Reminded of
# https://github.com/sanger/traction-service/issues/730
class AddApplicationActiveToLibraryType < ActiveRecord::Migration[7.0]
def change
add_column :library_types, :external_identifier, :string
add_column :library_types, :active, :boolean, default: 1, null: false
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2022_06_10_094347) do
ActiveRecord::Schema[7.0].define(version: 2022_06_10_122339) do
create_table "container_materials", charset: "utf8mb3", force: :cascade do |t|
t.string "container_type", null: false
t.bigint "container_id", null: false
Expand Down Expand Up @@ -46,6 +46,8 @@
t.integer "pipeline", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "external_identifier"
t.boolean "active", default: true, null: false
t.index ["pipeline", "name"], name: "index_library_types_on_pipeline_and_name", unique: true
t.index ["pipeline"], name: "index_library_types_on_pipeline"
end
Expand Down
Binary file modified erd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions spec/models/library_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
end
end

describe '::active' do
subject { described_class.active }

let!(:active_library_type) { create :library_type, active: true }
let!(:inactive_library_type) { create :library_type, active: false }

it { is_expected.to include(active_library_type) }
it { is_expected.not_to include(inactive_library_type) }
end

it 'must have a pipeline' do
expect(build(:library_type, pipeline: nil)).not_to be_valid
end
Expand Down

0 comments on commit a8f0c94

Please sign in to comment.