Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introduct ActiveModel::Serializers
- Add modeling for: - LeaguePlayers - Players - Teams - Roseter Slots - Create a RosterManager that should end up responsible for all roster changes
- Loading branch information
Showing
34 changed files
with
398 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Api | ||
module V1 | ||
class TeamsController < ApplicationController | ||
def show | ||
team = Team.includes({ roster_slots: [:player, :league_position] }).find_by({ id: params[:id] }) | ||
|
||
if team | ||
render({ json: team }) | ||
else | ||
head :not_found | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class LeaguePlayer < ActiveRecord::Base | ||
belongs_to :league | ||
belongs_to :league_position | ||
belongs_to :player | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class LeagueTemplate < ActiveRecord::Base | ||
has_many :leagues | ||
has_many :players | ||
has_many :point_categories | ||
has_many :positions | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Player < ActiveRecord::Base | ||
belongs_to :league_template | ||
belongs_to :position | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class RosterSlot < ActiveRecord::Base | ||
belongs_to :team | ||
belongs_to :league_position | ||
belongs_to :player | ||
|
||
enum({ status: [:active, :inactive] }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Team < ActiveRecord::Base | ||
belongs_to :league | ||
has_many :roster_slots | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class LeaguePositionSerializer < ActiveModel::Serializer | ||
attributes :id, :title | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class PlayerSerializer < ActiveModel::Serializer | ||
attributes :id, :first_name, :last_name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class RosterSlotSerializer < ActiveModel::Serializer | ||
attributes :id, :status | ||
|
||
has_one :player | ||
has_one :league_position | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class TeamSerializer < ActiveModel::Serializer | ||
attributes :id, :title | ||
|
||
has_many :roster_slots | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ActiveModel::Serializer.setup do |config| | ||
config.embed = :ids | ||
config.embed_in_root = true | ||
config.include = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateTeams < ActiveRecord::Migration | ||
def change | ||
create_table :teams do |t| | ||
t.belongs_to :league, index: true, foreign_key: true | ||
t.string :title | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreatePlayers < ActiveRecord::Migration | ||
def change | ||
create_table :players do |t| | ||
t.string :first_name | ||
t.string :last_name | ||
t.belongs_to :league_template, index: true, foreign_key: true | ||
t.belongs_to :position, index: true, foreign_key: true | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateLeaguePlayers < ActiveRecord::Migration | ||
def change | ||
create_table :league_players do |t| | ||
t.string :first_name | ||
t.string :last_name | ||
t.belongs_to :league, index: true, foreign_key: true | ||
t.belongs_to :league_position, index: true, foreign_key: true | ||
t.belongs_to :player, index: true, foreign_key: true | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateRosterSlots < ActiveRecord::Migration | ||
def change | ||
create_table :roster_slots do |t| | ||
t.belongs_to :team, index: true, foreign_key: true | ||
t.belongs_to :league_position, index: true, foreign_key: true | ||
t.belongs_to :player, index: true, foreign_key: true | ||
t.integer :status, default: 0 | ||
t.datetime :active_at | ||
t.datetime :inactive_at | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,60 @@ | ||
require "roster_manager" | ||
|
||
class BadCelebs | ||
def self.seed! | ||
league_template = setup_league_template | ||
league = setup_league(league_template) | ||
setup_team(league) | ||
end | ||
|
||
def self.setup_league_template | ||
league_template = LeagueTemplate.find_or_create_by!({ title: "Bad Celebrity" }) | ||
|
||
[["Legal", "foo", 10]].each do |group, title, value| | ||
unless league_template.point_categories.find_by({ title: title, group: group }) | ||
league_template.point_categories.create!({ title: title, group: group, suggested_value: value }) | ||
end | ||
next if league_template.point_categories.find_by({ title: title, group: group }) | ||
|
||
league_template.point_categories.create!({ title: title, group: group, suggested_value: value }) | ||
end | ||
|
||
[["Actor", 2]].each do |title, count| | ||
unless league_template.positions.find_by({ title: title }) | ||
league_template.positions.create!({ title: title, suggested_count: count }) | ||
end | ||
[["Actor", 2], ["Bench", 2]].each do |title, count| | ||
next if league_template.positions.find_by({ title: title }) | ||
|
||
league_template.positions.create!({ title: title, suggested_count: count }) | ||
end | ||
|
||
[["James", "Franco", "Actor"], | ||
["Leonardo", "DiCaprio", "Actor"], | ||
["Paul", "Giamati", "Actor"], | ||
["Russel", "Crow", "Actor"]].each do |first, last, pos| | ||
next if league_template.players.find_by({ first_name: first, last_name: last }) | ||
|
||
league_template.players.create!({ | ||
first_name: first, | ||
last_name: last, | ||
position: Position.find_by({ title: pos }) | ||
}) | ||
end | ||
|
||
league_template | ||
end | ||
|
||
def self.setup_league(league_template) | ||
league = League.find_or_create_by!({ title: "Sample league", league_template: league_template }) | ||
league.create_point_categories_from_league_template! | ||
league.create_positions_from_league_template! | ||
league.create_players_from_league_template! | ||
|
||
league | ||
end | ||
|
||
def self.setup_team(league) | ||
team = league.teams.find_or_create_by!({ title: "New Team" }) | ||
|
||
roster_manager = RosterManager.new(team) | ||
players = Player.pluck(:id).shuffle | ||
positions = league.all_positions | ||
roster_manager.set_roster(players.zip(positions.map(&:id))) | ||
|
||
team | ||
end | ||
end |
Submodule fantasy-celebrity-front-end
updated
15 files
+3 −0 | Brocfile.js | |
+8 −0 | app/adapters/application.js | |
+1 −125 | app/leagues/teams/show/route.js | |
+11 −11 | app/leagues/teams/show/template.hbs | |
+1 −1 | app/models/league-position.js | |
+6 −0 | app/models/player.js | |
+7 −0 | app/models/roster-slot.js | |
+6 −0 | app/models/team.js | |
+1 −1 | app/templates/application.hbs | |
+1 −1 | bower.json | |
+12 −0 | tests/unit/models/league-position-test.js | |
+1 −1 | tests/unit/models/player-test.js | |
+12 −0 | tests/unit/models/roster-slot-test.js | |
+12 −0 | tests/unit/models/team-test.js | |
+ − | vendor/profile.jpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "roster_manager" | ||
|
||
Given(/^I have a team in that league$/) do | ||
@team = @league.teams.create!({ title: "New Team" }) | ||
end | ||
|
||
Given(/^I have set up that team with players$/) do | ||
roster_manager = RosterManager.new(@team) | ||
players = Player.pluck(:id).shuffle | ||
positions = @league.all_positions | ||
roster_manager.set_roster(players.zip(positions.map(&:id))) | ||
end | ||
|
||
When(/^I go to my team$/) do | ||
visit "/leagues/#{@league.id}/teams/#{@team.id}" | ||
end | ||
|
||
Then(/^I should see my team's players$/) do | ||
@team.roster_slots.each do |roster_slot| | ||
expect(page).to have_content(roster_slot.player.first_name) | ||
expect(page).to have_content(roster_slot.player.last_name) | ||
expect(page).to have_content(roster_slot.league_position.title) | ||
end | ||
end |
Oops, something went wrong.