Skip to content
This repository has been archived by the owner on Jan 1, 2018. It is now read-only.

Commit

Permalink
Merge a8ec7a1 into d78cac2
Browse files Browse the repository at this point in the history
  • Loading branch information
notmarkmiranda committed Dec 31, 2017
2 parents d78cac2 + a8ec7a1 commit 6c12e26
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/models/club.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Club < ApplicationRecord
belongs_to :creator, class_name: 'User', foreign_key: 'user_id'
has_many :user_club_roles
has_many :leagues
has_many :users, through: :user_club_roles do
def members
where('user_club_roles.role = ?', 0)
Expand Down
7 changes: 7 additions & 0 deletions app/models/league.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class League < ApplicationRecord
belongs_to :club

validates :name, presence: true, uniqueness: { scope: :club_id }
validates :slug, presence: true
validates :club_id, presence: true
end
12 changes: 12 additions & 0 deletions db/migrate/20171230225609_create_league.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateLeague < ActiveRecord::Migration[5.1]
def change
create_table :leagues do |t|
t.string :name
t.string :slug
t.references :club, foreign_key: true
t.boolean :privated, default: true

t.timestamps null: false
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: 20171230222530) do
ActiveRecord::Schema.define(version: 20171230225609) do

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

create_table "leagues", force: :cascade do |t|
t.string "name"
t.string "slug"
t.bigint "club_id"
t.boolean "privated", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["club_id"], name: "index_leagues_on_club_id"
end

create_table "user_club_roles", force: :cascade do |t|
t.bigint "user_id"
t.bigint "club_id"
Expand All @@ -47,6 +57,7 @@
end

add_foreign_key "clubs", "users"
add_foreign_key "leagues", "clubs"
add_foreign_key "user_club_roles", "clubs"
add_foreign_key "user_club_roles", "users"
end
15 changes: 15 additions & 0 deletions spec/factories/leagues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FactoryBot.define do
factory :league do
sequence :name { |n| "League Number #{n}" }
sequence :slug { |n| "league-number-#{n}" }
club

trait :private do
privated true
end

trait :not_private do
privated false
end
end
end
2 changes: 1 addition & 1 deletion spec/models/club_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
it { should belong_to :creator }
it { should have_many :user_club_roles }
it { should have_many :users }
it { should have_many :leagues }
context '#users.members' do

it 'returns members' do
member
expect(club.users.members).to match_array([member])
Expand Down
15 changes: 15 additions & 0 deletions spec/models/league_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

describe League, type: :model do
context 'relationships' do
it { should belong_to :club }
end

context 'validations' do
it { should validate_presence_of :name }
it { should validate_uniqueness_of(:name).scoped_to(:club_id) }
it { should validate_presence_of :slug }
it { should validate_presence_of :club_id }
end
context 'methods'
end

0 comments on commit 6c12e26

Please sign in to comment.