Skip to content

Commit

Permalink
Merge aede0db into 71409d5
Browse files Browse the repository at this point in the history
  • Loading branch information
notmarkmiranda committed Jan 6, 2018
2 parents 71409d5 + aede0db commit b964e65
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/league.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def members
where('user_league_roles.role = ?', 0)
end
end
has_many :seasons

validates :name, presence: true, uniqueness: true
validates :slug, presence: true
Expand Down
5 changes: 5 additions & 0 deletions app/models/season.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Season < ApplicationRecord
belongs_to :league

validates :league_id, presence: true
end
11 changes: 11 additions & 0 deletions db/migrate/20180106023335_create_season.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateSeason < ActiveRecord::Migration[5.1]
def change
create_table :seasons do |t|
t.boolean :active, default: true
t.boolean :completed, default: false
t.references :league, foreign_key: true

t.timestamps null: false
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20180106025119_create_game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateGame < ActiveRecord::Migration[5.1]
def change
create_table :games do |t|
t.references :season, foreign_key: true
t.integer :attendees
t.integer :buy_in
t.references :user, foreign_key: true
t.boolean :privated, default: false
t.timestamps null: false
end
end
end
26 changes: 25 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180104154437) do
ActiveRecord::Schema.define(version: 20180106025119) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "games", force: :cascade do |t|
t.bigint "season_id"
t.integer "attendees"
t.integer "buy_in"
t.bigint "user_id"
t.boolean "privated", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["season_id"], name: "index_games_on_season_id"
t.index ["user_id"], name: "index_games_on_user_id"
end

create_table "leagues", force: :cascade do |t|
t.string "name"
t.string "slug"
Expand All @@ -25,6 +37,15 @@
t.index ["user_id"], name: "index_leagues_on_user_id"
end

create_table "seasons", force: :cascade do |t|
t.boolean "active", default: true
t.boolean "completed", default: false
t.bigint "league_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["league_id"], name: "index_seasons_on_league_id"
end

create_table "user_league_roles", force: :cascade do |t|
t.bigint "user_id"
t.bigint "league_id"
Expand All @@ -47,7 +68,10 @@
t.index ["token"], name: "index_users_on_token", unique: true
end

add_foreign_key "games", "seasons"
add_foreign_key "games", "users"
add_foreign_key "leagues", "users"
add_foreign_key "seasons", "leagues"
add_foreign_key "user_league_roles", "leagues"
add_foreign_key "user_league_roles", "users"
end
1 change: 1 addition & 0 deletions spec/models/league_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
end
end
end
it { should have_many :seasons }
end

context 'validations' do
Expand Down
13 changes: 13 additions & 0 deletions spec/models/season_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails_helper'

describe Season, type: :model do
context 'relationships' do
it { should belong_to :league }
end

context 'validations' do
it { should validate_presence_of :league_id }
end

context 'methods'
end
15 changes: 15 additions & 0 deletions spec/support/seasons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FactoryBot.define do
factory :season do
league

trait :completed do
completed true
end

trait :inactive do
active false
end

factory :inactive_and_complete, traits: [:inactive, :complete]
end
end

0 comments on commit b964e65

Please sign in to comment.