-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a model which will capture the dates for a particular session, it's a one-to-many relationship with a unique constraint on the session and date value. This will eventually replace the single date column on sessions as the latest designs have sessions across multiple dates.
- Loading branch information
1 parent
27dd4fd
commit 69d6851
Showing
7 changed files
with
98 additions
and
1 deletion.
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 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: session_dates | ||
# | ||
# id :bigint not null, primary key | ||
# value :date not null | ||
# session_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_session_dates_on_session_id (session_id) | ||
# index_session_dates_on_session_id_and_value (session_id,value) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (session_id => sessions.id) | ||
# | ||
class SessionDate < ApplicationRecord | ||
audited | ||
|
||
belongs_to :session | ||
|
||
validates :value, uniqueness: { scope: :session } | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateSessionDates < ActiveRecord::Migration[7.2] | ||
def change | ||
# rubocop:disable Rails/CreateTableWithTimestamps | ||
create_table :session_dates do |t| | ||
t.references :session, foreign_key: true, null: false | ||
t.date :value, null: false | ||
t.index %i[session_id value], unique: true | ||
end | ||
# rubocop:enable Rails/CreateTableWithTimestamps | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: session_dates | ||
# | ||
# id :bigint not null, primary key | ||
# value :date not null | ||
# session_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_session_dates_on_session_id (session_id) | ||
# index_session_dates_on_session_id_and_value (session_id,value) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (session_id => sessions.id) | ||
# | ||
FactoryBot.define do | ||
factory :session_date do | ||
session | ||
value { Date.current } | ||
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: session_dates | ||
# | ||
# id :bigint not null, primary key | ||
# value :date not null | ||
# session_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_session_dates_on_session_id (session_id) | ||
# index_session_dates_on_session_id_and_value (session_id,value) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (session_id => sessions.id) | ||
# | ||
describe SessionDate do | ||
subject(:session_date) { build(:session_date) } | ||
|
||
it { should be_valid } | ||
end |