mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 13:14:29 +08:00
Split DateTime and DateTimeRange column types, rename DateType table
This commit is contained in:
parent
d1f23d008a
commit
f39af1916f
20 changed files with 224 additions and 279 deletions
|
@ -14,12 +14,12 @@ class RepositoryCell < ActiveRecord::Base
|
|||
.where(repository_cells: { value_type: 'RepositoryTextValue' })
|
||||
end),
|
||||
optional: true, foreign_key: :value_id
|
||||
belongs_to :repository_date_value,
|
||||
belongs_to :repository_date_time_value,
|
||||
(lambda do
|
||||
includes(:repository_cell)
|
||||
.where(repository_cells: { value_type: 'RepositoryDateValue' })
|
||||
end),
|
||||
optional: true, foreign_key: :value_id
|
||||
optional: true, foreign_key: :value_id, inverse_of: :repository_cell
|
||||
belongs_to :repository_list_value,
|
||||
(lambda do
|
||||
includes(:repository_cell)
|
||||
|
@ -47,6 +47,13 @@ class RepositoryCell < ActiveRecord::Base
|
|||
end),
|
||||
optional: true, foreign_key: :value_id, inverse_of: :repository_cell
|
||||
|
||||
belongs_to :repository_date_time_range_value,
|
||||
(lambda do
|
||||
includes(:repository_cell)
|
||||
.where(repository_cells: { value_type: 'RepositoryDateTimeRangeValue' })
|
||||
end),
|
||||
optional: true, foreign_key: :value_id, inverse_of: :repository_cell
|
||||
|
||||
validates_inclusion_of :repository_column,
|
||||
in: (lambda do |cell|
|
||||
cell.repository_row&.repository&.repository_columns || []
|
||||
|
|
|
@ -18,8 +18,6 @@ class RepositoryColumn < ApplicationRecord
|
|||
length: { maximum: Constants::NAME_MAX_LENGTH },
|
||||
uniqueness: { scope: :repository_id, case_sensitive: 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
|
||||
|
|
23
app/models/repository_date_time_range_value.rb
Normal file
23
app/models/repository_date_time_range_value.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryDateTimeRangeValue < ApplicationRecord
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User', optional: true,
|
||||
inverse_of: :created_repositroy_date_time_values
|
||||
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User', optional: true,
|
||||
inverse_of: :modified_repositroy_date_time_values
|
||||
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :repository_date_time_value
|
||||
accepts_nested_attributes_for :repository_cell
|
||||
|
||||
validates :repository_cell, :start_time, :end_time, presence: true
|
||||
|
||||
SORTABLE_COLUMN_NAME = 'repository_date_time_values.start_time'
|
||||
SORTABLE_VALUE_INCLUDE = :repository_date_time_range_value
|
||||
|
||||
def formatted
|
||||
data
|
||||
end
|
||||
|
||||
def data
|
||||
[start_time, end_time].compact.join(' - ')
|
||||
end
|
||||
end
|
|
@ -1,8 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryDateTimeValue < ApplicationRecord
|
||||
enum datetime_type: { datetime: 0, date: 1, time: 2, datetime_range: 3, date_range: 4, time_range: 5 }
|
||||
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User', optional: true,
|
||||
inverse_of: :created_repositroy_date_time_values
|
||||
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User', optional: true,
|
||||
|
@ -10,18 +8,28 @@ class RepositoryDateTimeValue < ApplicationRecord
|
|||
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :repository_date_time_value
|
||||
accepts_nested_attributes_for :repository_cell
|
||||
|
||||
validates :repository_cell, :datetime_type, :start_time, presence: true
|
||||
validates :end_time, presence: true, if: ->(record) { record.datetime_type.to_s.include?('_range') }
|
||||
validates :end_time, absence: true, unless: ->(record) { record.datetime_type.to_s.include?('_range') }
|
||||
validates :repository_cell, :data, presence: true
|
||||
|
||||
SORTABLE_COLUMN_NAME = 'repository_date_time_values.start_time'
|
||||
SORTABLE_COLUMN_NAME = 'repository_date_time_values.data'
|
||||
SORTABLE_VALUE_INCLUDE = :repository_date_time_value
|
||||
|
||||
def formatted
|
||||
data
|
||||
end
|
||||
|
||||
def data
|
||||
[start_time, end_time].compact.join(' - ')
|
||||
def data_changed?(new_data)
|
||||
new_data != data
|
||||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
self.data = new_data
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
value.data = payload
|
||||
value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryDateValue < ApplicationRecord
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||
has_one :repository_cell, as: :value, dependent: :destroy
|
||||
accepts_nested_attributes_for :repository_cell
|
||||
|
||||
validates :repository_cell, presence: true
|
||||
validates :data, presence: true
|
||||
|
||||
SORTABLE_COLUMN_NAME = 'repository_date_values.data'
|
||||
SORTABLE_VALUE_INCLUDE = :repository_date_value
|
||||
|
||||
def formatted
|
||||
data
|
||||
end
|
||||
|
||||
def data_changed?(new_data)
|
||||
new_data != data
|
||||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
self.data = new_data
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
value.data = payload
|
||||
value
|
||||
end
|
||||
end
|
|
@ -57,7 +57,7 @@ module RepositoryActions
|
|||
|
||||
def duplicate_repository_date_value
|
||||
old_value = @cell.value
|
||||
RepositoryDateValue.create(
|
||||
RepositoryDateTimeValue.create(
|
||||
old_value.attributes.merge(
|
||||
id: nil, created_by: @user, last_modified_by: @user,
|
||||
repository_cell_attributes: {
|
||||
|
|
|
@ -47,7 +47,11 @@ class Extends
|
|||
RepositoryListValue: 2,
|
||||
RepositoryAssetValue: 3,
|
||||
RepositoryStatusValue: 4,
|
||||
RepositoryDateTimeValue: 5 }
|
||||
RepositoryDateTimeValue: 5,
|
||||
RepositoryTimeValue: 6,
|
||||
RepositoryDateTimeRangeValue: 7,
|
||||
RepositoryTimeRangeValue: 8,
|
||||
RepositoryDateRangeValue: 9 }
|
||||
|
||||
# Data types which can be imported to repository,
|
||||
# name should match record in REPOSITORY_DATA_TYPES
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateRepositoryDateTimeValues < ActiveRecord::Migration[6.0]
|
||||
class CreateRepositoryDateTimeRangeValues < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :repository_date_time_values do |t|
|
||||
create_table :repository_date_time_range_values do |t|
|
||||
t.datetime :start_time, index: true
|
||||
t.datetime :end_time, index: true
|
||||
t.integer :datetime_type, index: true
|
||||
t.references :last_modified_by, index: true, foreign_key: { to_table: :users }
|
||||
t.references :created_by, index: true, foreign_key: { to_table: :users }
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# rename existing table for consistency
|
||||
rename_table :repository_date_values, :repository_date_time_values
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddRangeToRepositoryColumn < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :repository_columns, :range, :boolean
|
||||
end
|
||||
end
|
174
db/structure.sql
174
db/structure.sql
|
@ -1202,7 +1202,6 @@ CREATE TABLE public.repository_columns (
|
|||
data_type integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
range boolean,
|
||||
delimiter character varying
|
||||
);
|
||||
|
||||
|
@ -1226,19 +1225,51 @@ CREATE SEQUENCE public.repository_columns_id_seq
|
|||
ALTER SEQUENCE public.repository_columns_id_seq OWNED BY public.repository_columns.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.repository_date_time_range_values (
|
||||
id bigint NOT NULL,
|
||||
start_time timestamp without time zone,
|
||||
end_time timestamp without time zone,
|
||||
last_modified_by_id bigint,
|
||||
created_by_id bigint,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.repository_date_time_range_values_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.repository_date_time_range_values_id_seq OWNED BY public.repository_date_time_range_values.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_values; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.repository_date_time_values (
|
||||
id bigint NOT NULL,
|
||||
start_time timestamp without time zone,
|
||||
end_time timestamp without time zone,
|
||||
datetime_type integer,
|
||||
last_modified_by_id bigint,
|
||||
created_by_id bigint,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
data timestamp without time zone,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
created_by_id bigint NOT NULL,
|
||||
last_modified_by_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -1261,39 +1292,6 @@ CREATE SEQUENCE public.repository_date_time_values_id_seq
|
|||
ALTER SEQUENCE public.repository_date_time_values_id_seq OWNED BY public.repository_date_time_values.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.repository_date_values (
|
||||
id bigint NOT NULL,
|
||||
data timestamp without time zone,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
created_by_id bigint NOT NULL,
|
||||
last_modified_by_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.repository_date_values_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.repository_date_values_id_seq OWNED BY public.repository_date_values.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_list_items; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2891,6 +2889,13 @@ ALTER TABLE ONLY public.repository_cells ALTER COLUMN id SET DEFAULT nextval('pu
|
|||
ALTER TABLE ONLY public.repository_columns ALTER COLUMN id SET DEFAULT nextval('public.repository_columns_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_time_range_values ALTER COLUMN id SET DEFAULT nextval('public.repository_date_time_range_values_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_values id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2898,13 +2903,6 @@ ALTER TABLE ONLY public.repository_columns ALTER COLUMN id SET DEFAULT nextval('
|
|||
ALTER TABLE ONLY public.repository_date_time_values ALTER COLUMN id SET DEFAULT nextval('public.repository_date_time_values_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_values ALTER COLUMN id SET DEFAULT nextval('public.repository_date_values_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_list_items id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -3440,6 +3438,14 @@ ALTER TABLE ONLY public.repository_columns
|
|||
ADD CONSTRAINT repository_columns_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values repository_date_time_range_values_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_time_range_values
|
||||
ADD CONSTRAINT repository_date_time_range_values_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_values repository_date_time_values_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -3448,14 +3454,6 @@ ALTER TABLE ONLY public.repository_date_time_values
|
|||
ADD CONSTRAINT repository_date_time_values_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values repository_date_values_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_values
|
||||
ADD CONSTRAINT repository_date_values_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_list_items repository_list_items_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -4605,38 +4603,31 @@ CREATE INDEX index_repository_columns_on_repository_id ON public.repository_colu
|
|||
|
||||
|
||||
--
|
||||
-- Name: index_repository_date_time_values_on_created_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_repository_date_time_range_values_on_created_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_date_time_values_on_created_by_id ON public.repository_date_time_values USING btree (created_by_id);
|
||||
CREATE INDEX index_repository_date_time_range_values_on_created_by_id ON public.repository_date_time_range_values USING btree (created_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_date_time_values_on_datetime_type; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_repository_date_time_range_values_on_end_time; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_date_time_values_on_datetime_type ON public.repository_date_time_values USING btree (datetime_type);
|
||||
CREATE INDEX index_repository_date_time_range_values_on_end_time ON public.repository_date_time_range_values USING btree (end_time);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_date_time_values_on_end_time; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_repository_date_time_range_values_on_last_modified_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_date_time_values_on_end_time ON public.repository_date_time_values USING btree (end_time);
|
||||
CREATE INDEX index_repository_date_time_range_values_on_last_modified_by_id ON public.repository_date_time_range_values USING btree (last_modified_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_date_time_values_on_last_modified_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_repository_date_time_range_values_on_start_time; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_date_time_values_on_last_modified_by_id ON public.repository_date_time_values USING btree (last_modified_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_date_time_values_on_start_time; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_date_time_values_on_start_time ON public.repository_date_time_values USING btree (start_time);
|
||||
CREATE INDEX index_repository_date_time_range_values_on_start_time ON public.repository_date_time_range_values USING btree (start_time);
|
||||
|
||||
|
||||
--
|
||||
|
@ -5793,18 +5784,10 @@ ALTER TABLE ONLY public.repository_list_items
|
|||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_values fk_rails_54bbbbe979; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
-- Name: repository_date_time_values fk_rails_5d809fca2c; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_time_values
|
||||
ADD CONSTRAINT fk_rails_54bbbbe979 FOREIGN KEY (last_modified_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values fk_rails_5d809fca2c; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_values
|
||||
ADD CONSTRAINT fk_rails_5d809fca2c FOREIGN KEY (created_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
|
@ -6016,6 +5999,14 @@ ALTER TABLE ONLY public.report_elements
|
|||
ADD CONSTRAINT fk_rails_831f89b951 FOREIGN KEY (checklist_id) REFERENCES public.checklists(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values fk_rails_87cdb60fa9; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_time_range_values
|
||||
ADD CONSTRAINT fk_rails_87cdb60fa9 FOREIGN KEY (created_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: checklist_items fk_rails_887d280d4d; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6096,14 +6087,6 @@ ALTER TABLE ONLY public.result_tables
|
|||
ADD CONSTRAINT fk_rails_9269d5e204 FOREIGN KEY (result_id) REFERENCES public.results(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_values fk_rails_92c52d4449; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_time_values
|
||||
ADD CONSTRAINT fk_rails_92c52d4449 FOREIGN KEY (created_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tables fk_rails_943e1b03e5; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6425,10 +6408,10 @@ ALTER TABLE ONLY public.result_texts
|
|||
|
||||
|
||||
--
|
||||
-- Name: repository_date_values fk_rails_cfb9b16b76; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
-- Name: repository_date_time_values fk_rails_cfb9b16b76; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_values
|
||||
ALTER TABLE ONLY public.repository_date_time_values
|
||||
ADD CONSTRAINT fk_rails_cfb9b16b76 FOREIGN KEY (last_modified_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
|
@ -6608,6 +6591,14 @@ ALTER TABLE ONLY public.oauth_access_tokens
|
|||
ADD CONSTRAINT fk_rails_ee63f25419 FOREIGN KEY (resource_owner_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_date_time_range_values fk_rails_efe428fafe; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_date_time_range_values
|
||||
ADD CONSTRAINT fk_rails_efe428fafe FOREIGN KEY (last_modified_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: protocol_protocol_keywords fk_rails_f04cc911dd; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6854,7 +6845,6 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20191007144622'),
|
||||
('20191009146101'),
|
||||
('20191105143702'),
|
||||
('20191115143747'),
|
||||
('20191118150111');
|
||||
('20191115143747');
|
||||
|
||||
|
||||
|
|
14
spec/factories/repositor_date_time_range_values.rb
Normal file
14
spec/factories/repositor_date_time_range_values.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :repository_date_time_range_value do
|
||||
created_by { create :user }
|
||||
last_modified_by { created_by }
|
||||
start_time { Time.zone.now }
|
||||
end_time { Faker::Time.between(from: start_time, to: Time.zone.now + 3.days) }
|
||||
|
||||
after(:build) do |value|
|
||||
value.repository_cell ||= build(:repository_cell, :date_time_range_value, repository_date_time_range_value: value)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,10 +11,10 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :date_value do
|
||||
repository_column { create :repository_column, :date_type, repository: repository_row.repository }
|
||||
trait :date_time_value do
|
||||
repository_column { create :repository_column, :date_time_type, repository: repository_row.repository }
|
||||
after(:build) do |repository_cell|
|
||||
repository_cell.value ||= build(:repository_date_value, repository_cell: repository_cell)
|
||||
repository_cell.value ||= build(:repository_date_time_value, repository_cell: repository_cell)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,10 +39,10 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :date_time_value do
|
||||
repository_column { create :repository_column, :date_time_type, repository: repository_row.repository }
|
||||
trait :date_time_range_value do
|
||||
repository_column { create :repository_column, :date_time_range_type, repository: repository_row.repository }
|
||||
after(:build) do |repository_cell|
|
||||
repository_cell.value ||= build(:repository_date_time_value, repository_cell: repository_cell)
|
||||
repository_cell.value ||= build(:repository_date_time_range_value, repository_cell: repository_cell)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,10 +11,6 @@ FactoryBot.define do
|
|||
data_type { :RepositoryTextValue }
|
||||
end
|
||||
|
||||
trait :date_type do
|
||||
data_type { :RepositoryDateValue }
|
||||
end
|
||||
|
||||
trait :list_type do
|
||||
data_type { :RepositoryListValue }
|
||||
end
|
||||
|
@ -29,7 +25,26 @@ FactoryBot.define do
|
|||
|
||||
trait :date_time_type do
|
||||
data_type { :RepositoryDateTimeValue }
|
||||
range { false }
|
||||
end
|
||||
|
||||
trait :date_type do
|
||||
data_type { :RepositoryDateValue }
|
||||
end
|
||||
|
||||
trait :time_type do
|
||||
data_type { :RepositoryTimeValue }
|
||||
end
|
||||
|
||||
trait :date_time_range_type do
|
||||
data_type { :RepositoryDateTimeRangeValue }
|
||||
end
|
||||
|
||||
trait :date_range_type do
|
||||
data_type { :RepositoryDateRangeValue }
|
||||
end
|
||||
|
||||
trait :time_range_type do
|
||||
data_type { :RepositoryTimeRangeValue }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,42 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# rubocop:disable Metrics/BlockLength
|
||||
FactoryBot.define do
|
||||
factory :repository_date_time_value do
|
||||
created_by { create :user }
|
||||
last_modified_by { created_by }
|
||||
start_time { Time.zone.now }
|
||||
|
||||
trait :datetime do
|
||||
datetime_type { :datetime }
|
||||
end
|
||||
|
||||
trait :date do
|
||||
datetime_type { :date }
|
||||
end
|
||||
|
||||
trait :time do
|
||||
datetime_type { :time }
|
||||
end
|
||||
|
||||
trait :datetime_range do
|
||||
datetime_type { :datetime_range }
|
||||
end_time { Faker::Time.between(from: start_time, to: Time.zone.now + 3.days) }
|
||||
end
|
||||
|
||||
trait :date_range do
|
||||
datetime_type { :date_range }
|
||||
end_time { Faker::Time.between(from: start_time, to: Time.zone.now + 3.days) }
|
||||
end
|
||||
|
||||
trait :time_range do
|
||||
datetime_type { :time_range }
|
||||
end_time { Faker::Time.between(from: start_time, to: Time.zone.now + 3.days) }
|
||||
end
|
||||
data { Time.zone.now }
|
||||
|
||||
after(:build) do |value|
|
||||
value.repository_cell ||= build(:repository_cell, :date_time_value, repository_date_time_value: value)
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/BlockLength
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :repository_date_value do
|
||||
created_by { create :user }
|
||||
last_modified_by { created_by }
|
||||
data { Time.now }
|
||||
after(:build) do |repository_date_value|
|
||||
repository_date_value.repository_cell ||= build(:repository_cell,
|
||||
:date_value,
|
||||
repository_date_value: repository_date_value)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,10 +5,11 @@ require 'rails_helper'
|
|||
describe RepositoryCell, type: :model do
|
||||
let(:repository_cell) { build :repository_cell }
|
||||
let(:repository_cell_t) { build :repository_cell, :text_value }
|
||||
let(:repository_cell_d) { build :repository_cell, :date_value }
|
||||
let(:repository_cell_d) { build :repository_cell, :date_time_value }
|
||||
let(:repository_cell_l) { build :repository_cell, :list_value }
|
||||
let(:repository_cell_a) { build :repository_cell, :asset_value }
|
||||
let(:repository_cell_s) { build :repository_cell, :status_value }
|
||||
let(:repository_cell_d_r) { build :repository_cell, :date_time_range_value }
|
||||
|
||||
context 'when do not have value' do
|
||||
it 'is not valid' do
|
||||
|
@ -21,7 +22,7 @@ describe RepositoryCell, type: :model do
|
|||
expect(repository_cell_t).to be_valid
|
||||
end
|
||||
|
||||
it 'is valid for data value' do
|
||||
it 'is valid for data time value' do
|
||||
expect(repository_cell_d).to be_valid
|
||||
end
|
||||
|
||||
|
@ -33,9 +34,13 @@ describe RepositoryCell, type: :model do
|
|||
expect(repository_cell_a).to be_valid
|
||||
end
|
||||
|
||||
it 'is valid for asset value' do
|
||||
it 'is valid for status value' do
|
||||
expect(repository_cell_s).to be_valid
|
||||
end
|
||||
|
||||
it 'is valid for date time range value' do
|
||||
expect(repository_cell_d_r).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be of class RepositoryCell' do
|
||||
|
|
|
@ -48,19 +48,5 @@ 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
|
||||
|
|
31
spec/models/repository_date_time_range_value_spec.rb
Normal file
31
spec/models/repository_date_time_range_value_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe RepositoryDateTimeRangeValue, type: :model do
|
||||
let(:repository_date_time_range_value) { create :repository_date_time_range_value }
|
||||
|
||||
it 'is valid' do
|
||||
expect(repository_date_time_range_value).to be_valid
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
describe '#repository_cell' do
|
||||
it { is_expected.to validate_presence_of(:repository_cell) }
|
||||
end
|
||||
|
||||
describe '#start_time' do
|
||||
it { is_expected.to validate_presence_of(:start_time) }
|
||||
end
|
||||
|
||||
describe '#end_time' do
|
||||
it { is_expected.to validate_presence_of(:end_time) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:created_by).optional }
|
||||
it { is_expected.to belong_to(:last_modified_by).optional }
|
||||
it { is_expected.to have_one(:repository_cell) }
|
||||
end
|
||||
end
|
|
@ -3,39 +3,19 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe RepositoryDateTimeValue, type: :model do
|
||||
let(:repository_date_time_value) { create :repository_date_time_value, :datetime }
|
||||
let(:repository_date_time_value) { create :repository_date_time_value }
|
||||
|
||||
it 'is valid' do
|
||||
expect(repository_date_time_value).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class RepositoryDateTimeValue' do
|
||||
expect(subject.class).to eq RepositoryDateTimeValue
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
describe '#repository_cell' do
|
||||
it { is_expected.to validate_presence_of(:repository_cell) }
|
||||
end
|
||||
|
||||
describe '#datetime_type' do
|
||||
it { is_expected.to validate_presence_of(:datetime_type) }
|
||||
end
|
||||
|
||||
describe '#start_time' do
|
||||
it { is_expected.to validate_presence_of(:start_time) }
|
||||
end
|
||||
|
||||
describe '#end_time' do
|
||||
context 'when not range' do
|
||||
it { is_expected.to validate_absence_of(:end_time) }
|
||||
end
|
||||
context 'when range' do
|
||||
it do
|
||||
subject.datetime_type = :datetime_range
|
||||
is_expected.to validate_presence_of(:end_time)
|
||||
end
|
||||
end
|
||||
describe '#data' do
|
||||
it { is_expected.to validate_presence_of(:data) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe RepositoryDateValue, type: :model do
|
||||
let(:repository_date_value) { build :repository_date_value }
|
||||
|
||||
it 'is valid' do
|
||||
expect(repository_date_value).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class RepositoryDateValue' do
|
||||
expect(subject.class).to eq RepositoryDateValue
|
||||
end
|
||||
|
||||
describe 'Database table' do
|
||||
it { should have_db_column :data }
|
||||
it { should have_db_column :created_at }
|
||||
it { should have_db_column :updated_at }
|
||||
it { should have_db_column :created_by_id }
|
||||
it { should have_db_column :last_modified_by_id }
|
||||
end
|
||||
|
||||
describe 'Relations' do
|
||||
it { should belong_to(:created_by).class_name('User') }
|
||||
it { should belong_to(:last_modified_by).class_name('User') }
|
||||
it { should have_one :repository_cell }
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
it { should validate_presence_of :repository_cell }
|
||||
it { should validate_presence_of :data }
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue