Init Record model

This commit is contained in:
Lou 2021-05-12 00:04:34 +02:00
commit b3d44cd4b0
8 changed files with 54 additions and 6 deletions

View file

@ -1,10 +1,9 @@
class Activity < ApplicationRecord
belongs_to :author, class_name: "User"
has_one :joined_user_activity
has_one :user, :through => :joined_user_activity
has_many :tasks
has_many :records
validates :name, presence: true
validates :author, presence: true

4
app/models/record.rb Normal file
View file

@ -0,0 +1,4 @@
class Record < ApplicationRecord
belongs_to :user
belongs_to :task
end

View file

@ -5,11 +5,10 @@ class User < ApplicationRecord
validates :password_digest, presence: true
has_many :created_activities, foreign_key: 'author_id', class_name: 'Activity', dependent: :destroy
has_many :joined_user_activities
has_many :activities, :through => :joined_user_activities
has_many :tasks
has_many :records
has_secure_password
end

View file

@ -0,0 +1,13 @@
class CreateRecords < ActiveRecord::Migration[6.1]
def change
create_table :records do |t|
t.integer :duration, null: false
t.boolean :is_handled, default: false
t.references :handled_by, default: :null
t.references :user, null: false
t.references :task, null: false
t.timestamps
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_05_10_133939) do
ActiveRecord::Schema.define(version: 2021_05_11_212634) do
create_table "activities", force: :cascade do |t|
t.string "name", null: false
@ -32,6 +32,19 @@ ActiveRecord::Schema.define(version: 2021_05_10_133939) do
t.index ["user_id"], name: "index_joined_user_activities_on_user_id"
end
create_table "records", force: :cascade do |t|
t.integer "duration", null: false
t.boolean "is_handled", default: false
t.integer "handled_by_id"
t.integer "user_id", null: false
t.integer "task_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["handled_by_id"], name: "index_records_on_handled_by_id"
t.index ["task_id"], name: "index_records_on_task_id"
t.index ["user_id"], name: "index_records_on_user_id"
end
create_table "tasks", force: :cascade do |t|
t.string "name", null: false
t.text "description"

BIN
erd.pdf

Binary file not shown.

13
test/fixtures/records.yml vendored Normal file
View file

@ -0,0 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
duration: 2021-05-11 23:26:34
handled: false
user: one
task: one
two:
duration: 2021-05-11 23:26:34
handled: false
user: two
task: two

View file

@ -0,0 +1,7 @@
require "test_helper"
class RecordTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end