mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Add range column to RepositoryColumn
This commit is contained in:
parent
fe4aa12ced
commit
2a20ad68a3
4 changed files with 37 additions and 5 deletions
|
@ -15,12 +15,11 @@ class RepositoryColumn < ApplicationRecord
|
|||
|
||||
auto_strip_attributes :name, nullify: false
|
||||
validates :name,
|
||||
presence: true,
|
||||
length: { maximum: Constants::NAME_MAX_LENGTH },
|
||||
uniqueness: { scope: :repository_id, case_sensitive: true }
|
||||
validates :created_by, presence: true
|
||||
validates :repository, presence: true
|
||||
validates :data_type, presence: true
|
||||
validates :name, :data_type, :repository, :created_by, presence: true
|
||||
validates :range, inclusion: { in: [true, false] }, if: :repository_date_time_value?
|
||||
validates :range, absence: true, unless: :repository_date_time_value?
|
||||
|
||||
after_create :update_repository_table_states_with_new_column
|
||||
around_destroy :update_repository_table_states_with_removed_column
|
||||
|
@ -33,6 +32,13 @@ class RepositoryColumn < ApplicationRecord
|
|||
where('repository_columns.name ILIKE ?', "%#{query}%")
|
||||
end
|
||||
|
||||
# Add enum check method with underscores (eg repository_list_value)
|
||||
data_types.each do |k, _|
|
||||
define_method "#{k.underscore}?" do
|
||||
public_send "#{k}?"
|
||||
end
|
||||
end
|
||||
|
||||
def update_repository_table_states_with_new_column
|
||||
service = RepositoryTableStateColumnUpdateService.new
|
||||
service.update_states_with_new_column(repository)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddRangeToRepositoryColumn < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :repository_columns, :range, :boolean
|
||||
end
|
||||
end
|
|
@ -1202,7 +1202,11 @@ CREATE TABLE public.repository_columns (
|
|||
data_type integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
<<<<<<< HEAD
|
||||
delimiter character varying
|
||||
=======
|
||||
range boolean
|
||||
>>>>>>> eedcec279... Add range column to RepositoryColumn
|
||||
);
|
||||
|
||||
|
||||
|
@ -6853,6 +6857,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20191007144622'),
|
||||
('20191009146101'),
|
||||
('20191105143702'),
|
||||
('20191115143747');
|
||||
('20191115143747'),
|
||||
('20191118150111');
|
||||
|
||||
|
||||
|
|
|
@ -48,5 +48,19 @@ describe RepositoryColumn, type: :model do
|
|||
describe '#data_type' do
|
||||
it { is_expected.to validate_presence_of :data_type }
|
||||
end
|
||||
|
||||
describe '#range' do
|
||||
it do
|
||||
allow(subject).to receive(:repository_date_time_value?).and_return(true)
|
||||
|
||||
expect(subject).to allow_value([true, false]).for(:range)
|
||||
end
|
||||
|
||||
it do
|
||||
allow(subject).to receive(:repository_date_time_value?).and_return(false)
|
||||
|
||||
expect(subject).to allow_value(nil).for(:range)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue