Compare commits
No commits in common. "8a5ed6efc760828515cbc6205e3fcae9f0d72a26" and "497744d165ec49e0d00052d67e750eca94db4038" have entirely different histories.
8a5ed6efc7
...
497744d165
12 changed files with 2 additions and 179 deletions
|
|
@ -1,21 +0,0 @@
|
||||||
class DayLogsController < ApplicationController
|
|
||||||
def new
|
|
||||||
@day_log = DayLog.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@day_log = Current.user.day_logs.build(day_log_params)
|
|
||||||
|
|
||||||
if @day_log.save
|
|
||||||
redirect_to root_path
|
|
||||||
else
|
|
||||||
render :new, status: :unprocessable_entity
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def day_log_params
|
|
||||||
params.expect(day_log: [ :day, :info ])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
class DayLog < ApplicationRecord
|
|
||||||
belongs_to :user
|
|
||||||
|
|
||||||
validates :day, presence: true
|
|
||||||
validates :info, presence: true
|
|
||||||
end
|
|
||||||
|
|
@ -3,7 +3,6 @@ class User < ApplicationRecord
|
||||||
has_many :sessions, dependent: :destroy
|
has_many :sessions, dependent: :destroy
|
||||||
has_many :moods, -> { order "recorded_at" }
|
has_many :moods, -> { order "recorded_at" }
|
||||||
has_many :modes
|
has_many :modes
|
||||||
has_many :day_logs
|
|
||||||
|
|
||||||
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
%h1 Nouveau journal
|
|
||||||
|
|
||||||
= form_with model: @day_log do |f|
|
|
||||||
- @day_log.errors.full_messages.each do |msg|
|
|
||||||
%p= msg
|
|
||||||
|
|
||||||
.field
|
|
||||||
= f.label :day
|
|
||||||
= f.date_field :day
|
|
||||||
|
|
||||||
.field
|
|
||||||
= f.label :info
|
|
||||||
= f.text_area :info
|
|
||||||
|
|
||||||
= f.submit
|
|
||||||
|
|
@ -21,6 +21,4 @@ Rails.application.routes.draw do
|
||||||
patch "/invite/:token", to: "invitations#update", as: :invitation
|
patch "/invite/:token", to: "invitations#update", as: :invitation
|
||||||
|
|
||||||
get "/moods", to: "moods#index", as: :dashboard
|
get "/moods", to: "moods#index", as: :dashboard
|
||||||
|
|
||||||
resources :day_logs, only: [ :new, :create ]
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
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.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2026_03_19_181607) do
|
ActiveRecord::Schema[8.0].define(version: 2026_03_15_183258) do
|
||||||
create_table "active_storage_attachments", force: :cascade do |t|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
|
|
@ -39,16 +39,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_19_181607) do
|
||||||
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
|
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
|
||||||
end
|
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|
|
create_table "modes", force: :cascade do |t|
|
||||||
t.string "label"
|
t.string "label"
|
||||||
t.string "color"
|
t.string "color"
|
||||||
|
|
@ -102,7 +92,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_19_181607) do
|
||||||
|
|
||||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
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 "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "day_logs", "users"
|
|
||||||
add_foreign_key "modes", "users"
|
add_foreign_key "modes", "users"
|
||||||
add_foreign_key "moods", "modes"
|
add_foreign_key "moods", "modes"
|
||||||
add_foreign_key "moods", "users"
|
add_foreign_key "moods", "users"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
FactoryBot.define do
|
|
||||||
factory :day_log do
|
|
||||||
day { "2026-03-19" }
|
|
||||||
info { "Arrivée à Paris" }
|
|
||||||
user { association :user }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
sequence(:email_address) { |n| "user#{n}@example.com" }
|
sequence(:email_address) { |n| "user#{n}@example.com" }
|
||||||
sequence(:username) { |n| "user#{n}" }
|
password_digest { BCrypt::Password.create('password123') }
|
||||||
password { "obanonalors" }
|
|
||||||
password_digest { BCrypt::Password.create(password) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
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
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe "DayLogs", type: :request do
|
|
||||||
let(:user) { create(:user) }
|
|
||||||
let(:day) { Date.new(2026, 1, 15) }
|
|
||||||
|
|
||||||
describe "GET /day_logs/new" do
|
|
||||||
context "when not authenticated" do
|
|
||||||
it "redirects to the login page" do
|
|
||||||
get new_day_log_path
|
|
||||||
expect(response).to redirect_to(new_session_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when authenticated" do
|
|
||||||
before { login_as(user) }
|
|
||||||
|
|
||||||
it "returns http success" do
|
|
||||||
get new_day_log_path
|
|
||||||
expect(response).to have_http_status(:success)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "POST /day_logs" do
|
|
||||||
context "when not authenticated" do
|
|
||||||
it "redirects to the login page" do
|
|
||||||
post day_logs_path, params: { day_log: { day: day, info: "Une info" } }
|
|
||||||
expect(response).to redirect_to(new_session_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when authenticated" do
|
|
||||||
before { login_as(user) }
|
|
||||||
|
|
||||||
context "with valid params" do
|
|
||||||
it "creates a day_log" do
|
|
||||||
expect {
|
|
||||||
post day_logs_path, params: { day_log: { day: day, info: "Une info" } }
|
|
||||||
}.to change(DayLog, :count).by(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "redirects after creation" do
|
|
||||||
post day_logs_path, params: { day_log: { day: day, info: "Une info" } }
|
|
||||||
expect(response).to have_http_status(:redirect)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with invalid params" do
|
|
||||||
it "does not create a day_log" do
|
|
||||||
expect {
|
|
||||||
post day_logs_path, params: { day_log: { day: nil, info: nil } }
|
|
||||||
}.not_to change(DayLog, :count)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns unprocessable entity" do
|
|
||||||
post day_logs_path, params: { day_log: { day: nil, info: nil } }
|
|
||||||
expect(response).to have_http_status(:unprocessable_entity)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
module AuthenticationHelper
|
|
||||||
def login_as(user)
|
|
||||||
post session_path, params: {
|
|
||||||
email_address: user.email_address,
|
|
||||||
password: user.password
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
|
||||||
config.include AuthenticationHelper, type: :request
|
|
||||||
end
|
|
||||||
Loading…
Add table
Reference in a new issue