add day_log model
This commit is contained in:
parent
497744d165
commit
962915829f
5 changed files with 62 additions and 1 deletions
6
app/models/day_log.rb
Normal file
6
app/models/day_log.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class DayLog < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
validates :day, presence: true
|
||||
validates :info, presence: true
|
||||
end
|
||||
13
db/migrate/20260319181607_create_day_logs.rb
Normal file
13
db/migrate/20260319181607_create_day_logs.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class CreateDayLogs < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :day_logs do |t|
|
||||
t.date :day, null: false
|
||||
t.text :info, null: false
|
||||
t.references :user, null: false, foreign_key: true
|
||||
|
||||
t.index :day, unique: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
13
db/schema.rb
generated
13
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_03_15_183258) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_03_19_181607) do
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
|
|
@ -39,6 +39,16 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_15_183258) do
|
|||
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
|
||||
end
|
||||
|
||||
create_table "day_logs", force: :cascade do |t|
|
||||
t.date "day", null: false
|
||||
t.text "info", null: false
|
||||
t.integer "user_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["day"], name: "index_day_logs_on_day", unique: true
|
||||
t.index ["user_id"], name: "index_day_logs_on_user_id"
|
||||
end
|
||||
|
||||
create_table "modes", force: :cascade do |t|
|
||||
t.string "label"
|
||||
t.string "color"
|
||||
|
|
@ -92,6 +102,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_15_183258) do
|
|||
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "day_logs", "users"
|
||||
add_foreign_key "modes", "users"
|
||||
add_foreign_key "moods", "modes"
|
||||
add_foreign_key "moods", "users"
|
||||
|
|
|
|||
7
spec/factories/day_logs.rb
Normal file
7
spec/factories/day_logs.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
FactoryBot.define do
|
||||
factory :day_log do
|
||||
day { "2026-03-19" }
|
||||
info { "Arrivée à Paris" }
|
||||
user { association :user }
|
||||
end
|
||||
end
|
||||
24
spec/models/day_log_spec.rb
Normal file
24
spec/models/day_log_spec.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe DayLog, type: :model do
|
||||
subject { build(:day_log) }
|
||||
|
||||
it { is_expected.to be_valid }
|
||||
|
||||
describe "validations" do
|
||||
it "is invalid without a day" do
|
||||
subject.day = nil
|
||||
expect(subject).not_to be_valid
|
||||
end
|
||||
|
||||
it "is invalid without info" do
|
||||
subject.info = nil
|
||||
expect(subject).not_to be_valid
|
||||
end
|
||||
|
||||
it "is invalid without a user" do
|
||||
subject.user = nil
|
||||
expect(subject).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue