Skip to content

Commit bdd26a1

Browse files
author
Steve Polito
committed
Create Total model.
1 parent df0a775 commit bdd26a1

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

app/models/total.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Total < ApplicationRecord
2+
belongs_to :user
3+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateTotals < ActiveRecord::Migration[6.0]
2+
def change
3+
create_table :totals do |t|
4+
t.references :user, null: false, foreign_key: true
5+
t.date :date, null: false
6+
t.integer :duration, default: 0
7+
t.decimal :distance, default: 0
8+
9+
t.timestamps
10+
end
11+
end
12+
end

db/schema.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2020_08_17_111403) do
13+
ActiveRecord::Schema.define(version: 2020_08_21_110618) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -63,6 +63,16 @@
6363
t.index ["user_id"], name: "index_activities_on_user_id"
6464
end
6565

66+
create_table "totals", force: :cascade do |t|
67+
t.bigint "user_id", null: false
68+
t.date "date", null: false
69+
t.integer "duration", default: 0
70+
t.decimal "distance", default: "0.0"
71+
t.datetime "created_at", precision: 6, null: false
72+
t.datetime "updated_at", precision: 6, null: false
73+
t.index ["user_id"], name: "index_totals_on_user_id"
74+
end
75+
6676
create_table "users", force: :cascade do |t|
6777
t.string "email", default: "", null: false
6878
t.string "encrypted_password", default: "", null: false
@@ -83,4 +93,5 @@
8393

8494
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
8595
add_foreign_key "activities", "users"
96+
add_foreign_key "totals", "users"
8697
end

test/fixtures/totals.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
user: one
5+
date: 2020-08-21
6+
duration: 1
7+
distance: 9.99
8+
9+
two:
10+
user: two
11+
date: 2020-08-21
12+
duration: 1
13+
distance: 9.99

test/models/total_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class TotalTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)