Skip to content

Commit

Permalink
Create Total model.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Polito committed Aug 21, 2020
1 parent df0a775 commit bdd26a1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/total.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Total < ApplicationRecord
belongs_to :user
end
12 changes: 12 additions & 0 deletions db/migrate/20200821110618_create_totals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateTotals < ActiveRecord::Migration[6.0]
def change
create_table :totals do |t|
t.references :user, null: false, foreign_key: true
t.date :date, null: false
t.integer :duration, default: 0
t.decimal :distance, default: 0

t.timestamps
end
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_08_17_111403) do
ActiveRecord::Schema.define(version: 2020_08_21_110618) do

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

create_table "totals", force: :cascade do |t|
t.bigint "user_id", null: false
t.date "date", null: false
t.integer "duration", default: 0
t.decimal "distance", default: "0.0"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_totals_on_user_id"
end

create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
Expand All @@ -83,4 +93,5 @@

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "activities", "users"
add_foreign_key "totals", "users"
end
13 changes: 13 additions & 0 deletions test/fixtures/totals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
user: one
date: 2020-08-21
duration: 1
distance: 9.99

two:
user: two
date: 2020-08-21
duration: 1
distance: 9.99
7 changes: 7 additions & 0 deletions test/models/total_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class TotalTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit bdd26a1

Please sign in to comment.