-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2f3cc
commit 125cd92
Showing
15 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ActiveAdmin.register Tag do | ||
permit_params :name | ||
|
||
index do | ||
id_column | ||
column :name | ||
column :created_at | ||
actions | ||
end | ||
|
||
filter :id | ||
filter :name | ||
filter :created_at | ||
|
||
controller do | ||
def destroy | ||
tag = Tag.find(params[:id]) | ||
if tag.destroy | ||
flash[:notice] = "Tag '#{tag.name}' successfully deleted" | ||
else | ||
flash[:error] = "Couldn't delete tag '#{tag.name}'. Is it currently being used by any Lab Record Import?" | ||
end | ||
redirect_to action: :index | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,7 @@ | |
form#edit_site fieldset > ol > li.boolean label { | ||
padding-left: 0; | ||
} | ||
|
||
.tags_list li { | ||
list-style: none; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class LabRecordImportsTag < ApplicationRecord | ||
belongs_to :lab_record_import | ||
belongs_to :tag | ||
|
||
validates :tag_id, uniqueness: { scope: [:lab_record_import_id] } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Tag < ApplicationRecord | ||
validates :name, presence: true, uniqueness: true | ||
has_many :lab_record_imports_tags, dependent: :restrict_with_error | ||
has_many :lab_record_imports, through: :lab_record_imports_tags | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,7 @@ | |
|
||
en: | ||
hello: "Hello world" | ||
active_admin: | ||
resources: | ||
lab_record_import: | ||
edit: "Edit tags" |
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,10 @@ | ||
class CreateTags < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :tags do |t| | ||
t.string :name, :null => false | ||
t.timestamps | ||
|
||
t.index [:name], unique: true | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrate/20201117224218_create_lab_record_imports_tags.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,11 @@ | ||
class CreateLabRecordImportsTags < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :lab_record_imports_tags do |t| | ||
t.references :lab_record_import, foreign_key: true, :null => false | ||
t.references :tag, foreign_key: true, :null => false | ||
t.timestamps | ||
|
||
t.index [ :lab_record_import_id, :tag_id ], :unique => true, :name => 'index_on_lab_record_import_id_and_tag_id' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FactoryBot.define do | ||
factory :lab_record_imports_tag do | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :tag do | ||
name { FFaker::Tweet.tags } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe LabRecordImportsTag, type: :model do | ||
subject do | ||
l = create(:lab_record_import) | ||
t = create(:tag) | ||
build(:lab_record_imports_tag, lab_record_import_id: l.id, tag_id: t.id) | ||
end | ||
|
||
it { is_expected.to validate_uniqueness_of(:tag_id).scoped_to(:lab_record_import_id) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Tag, type: :model do | ||
subject { build :tag } | ||
|
||
it { is_expected.to be_valid } | ||
it { is_expected.to validate_presence_of(:name) } | ||
it { is_expected.to validate_uniqueness_of(:name) } | ||
it { is_expected.to have_many(:lab_record_imports).through(:lab_record_imports_tags) } | ||
it { is_expected.to have_many(:lab_record_imports_tags).dependent(:restrict_with_error) } | ||
end |