From de40ec53e8b80d8d880214183f19ea93172a0026 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 27 Feb 2014 17:02:10 -0500 Subject: give tournaments a game type --- app/controllers/tournaments_controller.rb | 2 +- app/models/tournament.rb | 1 + app/views/tournaments/_form.html.erb | 4 ++++ app/views/tournaments/index.html.erb | 2 ++ app/views/tournaments/index.json.jbuilder | 2 +- app/views/tournaments/show.html.erb | 5 +++++ app/views/tournaments/show.json.jbuilder | 2 +- db/migrate/20140304015013_create_servers.rb | 8 -------- db/migrate/20140304015015_create_tournaments.rb | 8 -------- db/migrate/20140304015017_create_matches.rb | 9 --------- db/migrate/20140304015019_create_teams.rb | 8 -------- db/migrate/20140304015021_create_users.rb | 11 ----------- db/migrate/20140304015023_create_user_team_pairs.rb | 10 ---------- db/migrate/20140304015026_create_team_match_pairs.rb | 10 ---------- db/migrate/20140304015028_create_alerts.rb | 10 ---------- db/migrate/20140304015030_create_pms.rb | 11 ----------- db/migrate/20140304015032_create_games.rb | 9 --------- db/migrate/20140304015034_create_game_attributes.rb | 11 ----------- db/migrate/20140304015036_create_server_settings.rb | 8 -------- db/migrate/20140304015042_create_tournament_options.rb | 8 -------- db/migrate/20140304015051_create_servers.rb | 8 ++++++++ db/migrate/20140304015053_create_tournaments.rb | 9 +++++++++ db/migrate/20140304015055_create_matches.rb | 9 +++++++++ db/migrate/20140304015057_create_teams.rb | 8 ++++++++ db/migrate/20140304015059_create_users.rb | 11 +++++++++++ db/migrate/20140304015102_create_user_team_pairs.rb | 10 ++++++++++ db/migrate/20140304015104_create_team_match_pairs.rb | 10 ++++++++++ db/migrate/20140304015106_create_alerts.rb | 10 ++++++++++ db/migrate/20140304015108_create_pms.rb | 11 +++++++++++ db/migrate/20140304015110_create_games.rb | 9 +++++++++ db/migrate/20140304015112_create_game_attributes.rb | 11 +++++++++++ db/migrate/20140304015114_create_server_settings.rb | 8 ++++++++ db/migrate/20140304015120_create_tournament_options.rb | 8 ++++++++ db/schema.rb | 5 ++++- generate.sh | 2 +- test/controllers/tournaments_controller_test.rb | 4 ++-- test/fixtures/tournaments.yml | 14 +++++--------- 37 files changed, 149 insertions(+), 137 deletions(-) delete mode 100644 db/migrate/20140304015013_create_servers.rb delete mode 100644 db/migrate/20140304015015_create_tournaments.rb delete mode 100644 db/migrate/20140304015017_create_matches.rb delete mode 100644 db/migrate/20140304015019_create_teams.rb delete mode 100644 db/migrate/20140304015021_create_users.rb delete mode 100644 db/migrate/20140304015023_create_user_team_pairs.rb delete mode 100644 db/migrate/20140304015026_create_team_match_pairs.rb delete mode 100644 db/migrate/20140304015028_create_alerts.rb delete mode 100644 db/migrate/20140304015030_create_pms.rb delete mode 100644 db/migrate/20140304015032_create_games.rb delete mode 100644 db/migrate/20140304015034_create_game_attributes.rb delete mode 100644 db/migrate/20140304015036_create_server_settings.rb delete mode 100644 db/migrate/20140304015042_create_tournament_options.rb create mode 100644 db/migrate/20140304015051_create_servers.rb create mode 100644 db/migrate/20140304015053_create_tournaments.rb create mode 100644 db/migrate/20140304015055_create_matches.rb create mode 100644 db/migrate/20140304015057_create_teams.rb create mode 100644 db/migrate/20140304015059_create_users.rb create mode 100644 db/migrate/20140304015102_create_user_team_pairs.rb create mode 100644 db/migrate/20140304015104_create_team_match_pairs.rb create mode 100644 db/migrate/20140304015106_create_alerts.rb create mode 100644 db/migrate/20140304015108_create_pms.rb create mode 100644 db/migrate/20140304015110_create_games.rb create mode 100644 db/migrate/20140304015112_create_game_attributes.rb create mode 100644 db/migrate/20140304015114_create_server_settings.rb create mode 100644 db/migrate/20140304015120_create_tournament_options.rb diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index ea3857c..720305f 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -69,6 +69,6 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params[:tournament] + params.require(:tournament).permit(:game_id) end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index da3da0e..cc915a0 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,2 +1,3 @@ class Tournament < ActiveRecord::Base + belongs_to :game end diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 8996266..1fd63e9 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -11,6 +11,10 @@ <% end %> +
+ <%= f.label :game_id %>
+ <%= f.text_field :game_id %> +
<%= f.submit %>
diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 7124111..ad2b7cf 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -3,6 +3,7 @@ + @@ -12,6 +13,7 @@ <% @tournaments.each do |tournament| %> + diff --git a/app/views/tournaments/index.json.jbuilder b/app/views/tournaments/index.json.jbuilder index 28d6960..e6f3b49 100644 --- a/app/views/tournaments/index.json.jbuilder +++ b/app/views/tournaments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@tournaments) do |tournament| - json.extract! tournament, :id + json.extract! tournament, :id, :game_id json.url tournament_url(tournament, format: :json) end diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 2c280ba..30df788 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,4 +1,9 @@

<%= notice %>

+

+ Game: + <%= @tournament.game %> +

+ <%= link_to 'Edit', edit_tournament_path(@tournament) %> | <%= link_to 'Back', tournaments_path %> diff --git a/app/views/tournaments/show.json.jbuilder b/app/views/tournaments/show.json.jbuilder index 211799a..0fe65a6 100644 --- a/app/views/tournaments/show.json.jbuilder +++ b/app/views/tournaments/show.json.jbuilder @@ -1 +1 @@ -json.extract! @tournament, :id, :created_at, :updated_at +json.extract! @tournament, :id, :game_id, :created_at, :updated_at diff --git a/db/migrate/20140304015013_create_servers.rb b/db/migrate/20140304015013_create_servers.rb deleted file mode 100644 index f33241a..0000000 --- a/db/migrate/20140304015013_create_servers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServers < ActiveRecord::Migration - def change - create_table :servers do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015015_create_tournaments.rb b/db/migrate/20140304015015_create_tournaments.rb deleted file mode 100644 index 2095590..0000000 --- a/db/migrate/20140304015015_create_tournaments.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournaments < ActiveRecord::Migration - def change - create_table :tournaments do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015017_create_matches.rb b/db/migrate/20140304015017_create_matches.rb deleted file mode 100644 index 6c0c157..0000000 --- a/db/migrate/20140304015017_create_matches.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateMatches < ActiveRecord::Migration - def change - create_table :matches do |t| - t.references :tournament, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015019_create_teams.rb b/db/migrate/20140304015019_create_teams.rb deleted file mode 100644 index dd8397d..0000000 --- a/db/migrate/20140304015019_create_teams.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTeams < ActiveRecord::Migration - def change - create_table :teams do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015021_create_users.rb b/db/migrate/20140304015021_create_users.rb deleted file mode 100644 index 6a500e5..0000000 --- a/db/migrate/20140304015021_create_users.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateUsers < ActiveRecord::Migration - def change - create_table :users do |t| - t.text :name - t.text :pw_hash - t.integer :groups - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015023_create_user_team_pairs.rb b/db/migrate/20140304015023_create_user_team_pairs.rb deleted file mode 100644 index 2c492ac..0000000 --- a/db/migrate/20140304015023_create_user_team_pairs.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateUserTeamPairs < ActiveRecord::Migration - def change - create_table :user_team_pairs do |t| - t.references :user, index: true - t.references :team, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015026_create_team_match_pairs.rb b/db/migrate/20140304015026_create_team_match_pairs.rb deleted file mode 100644 index 8fac07e..0000000 --- a/db/migrate/20140304015026_create_team_match_pairs.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateTeamMatchPairs < ActiveRecord::Migration - def change - create_table :team_match_pairs do |t| - t.references :team, index: true - t.references :match, index: true - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015028_create_alerts.rb b/db/migrate/20140304015028_create_alerts.rb deleted file mode 100644 index 68a8e10..0000000 --- a/db/migrate/20140304015028_create_alerts.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAlerts < ActiveRecord::Migration - def change - create_table :alerts do |t| - t.references :author, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015030_create_pms.rb b/db/migrate/20140304015030_create_pms.rb deleted file mode 100644 index 93bb5c6..0000000 --- a/db/migrate/20140304015030_create_pms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePms < ActiveRecord::Migration - def change - create_table :pms do |t| - t.references :author, index: true - t.references :recipient, index: true - t.text :message - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015032_create_games.rb b/db/migrate/20140304015032_create_games.rb deleted file mode 100644 index fc54709..0000000 --- a/db/migrate/20140304015032_create_games.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateGames < ActiveRecord::Migration - def change - create_table :games do |t| - t.text :name - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015034_create_game_attributes.rb b/db/migrate/20140304015034_create_game_attributes.rb deleted file mode 100644 index b63f134..0000000 --- a/db/migrate/20140304015034_create_game_attributes.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateGameAttributes < ActiveRecord::Migration - def change - create_table :game_attributes do |t| - t.references :game, index: true - t.text :key - t.integer :type - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015036_create_server_settings.rb b/db/migrate/20140304015036_create_server_settings.rb deleted file mode 100644 index dfdd91b..0000000 --- a/db/migrate/20140304015036_create_server_settings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateServerSettings < ActiveRecord::Migration - def change - create_table :server_settings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015042_create_tournament_options.rb b/db/migrate/20140304015042_create_tournament_options.rb deleted file mode 100644 index d2df22e..0000000 --- a/db/migrate/20140304015042_create_tournament_options.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateTournamentOptions < ActiveRecord::Migration - def change - create_table :tournament_options do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20140304015051_create_servers.rb b/db/migrate/20140304015051_create_servers.rb new file mode 100644 index 0000000..f33241a --- /dev/null +++ b/db/migrate/20140304015051_create_servers.rb @@ -0,0 +1,8 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015053_create_tournaments.rb b/db/migrate/20140304015053_create_tournaments.rb new file mode 100644 index 0000000..36fcf7e --- /dev/null +++ b/db/migrate/20140304015053_create_tournaments.rb @@ -0,0 +1,9 @@ +class CreateTournaments < ActiveRecord::Migration + def change + create_table :tournaments do |t| + t.references :game, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015055_create_matches.rb b/db/migrate/20140304015055_create_matches.rb new file mode 100644 index 0000000..6c0c157 --- /dev/null +++ b/db/migrate/20140304015055_create_matches.rb @@ -0,0 +1,9 @@ +class CreateMatches < ActiveRecord::Migration + def change + create_table :matches do |t| + t.references :tournament, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015057_create_teams.rb b/db/migrate/20140304015057_create_teams.rb new file mode 100644 index 0000000..dd8397d --- /dev/null +++ b/db/migrate/20140304015057_create_teams.rb @@ -0,0 +1,8 @@ +class CreateTeams < ActiveRecord::Migration + def change + create_table :teams do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015059_create_users.rb b/db/migrate/20140304015059_create_users.rb new file mode 100644 index 0000000..6a500e5 --- /dev/null +++ b/db/migrate/20140304015059_create_users.rb @@ -0,0 +1,11 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.text :name + t.text :pw_hash + t.integer :groups + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015102_create_user_team_pairs.rb b/db/migrate/20140304015102_create_user_team_pairs.rb new file mode 100644 index 0000000..2c492ac --- /dev/null +++ b/db/migrate/20140304015102_create_user_team_pairs.rb @@ -0,0 +1,10 @@ +class CreateUserTeamPairs < ActiveRecord::Migration + def change + create_table :user_team_pairs do |t| + t.references :user, index: true + t.references :team, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015104_create_team_match_pairs.rb b/db/migrate/20140304015104_create_team_match_pairs.rb new file mode 100644 index 0000000..8fac07e --- /dev/null +++ b/db/migrate/20140304015104_create_team_match_pairs.rb @@ -0,0 +1,10 @@ +class CreateTeamMatchPairs < ActiveRecord::Migration + def change + create_table :team_match_pairs do |t| + t.references :team, index: true + t.references :match, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015106_create_alerts.rb b/db/migrate/20140304015106_create_alerts.rb new file mode 100644 index 0000000..68a8e10 --- /dev/null +++ b/db/migrate/20140304015106_create_alerts.rb @@ -0,0 +1,10 @@ +class CreateAlerts < ActiveRecord::Migration + def change + create_table :alerts do |t| + t.references :author, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015108_create_pms.rb b/db/migrate/20140304015108_create_pms.rb new file mode 100644 index 0000000..93bb5c6 --- /dev/null +++ b/db/migrate/20140304015108_create_pms.rb @@ -0,0 +1,11 @@ +class CreatePms < ActiveRecord::Migration + def change + create_table :pms do |t| + t.references :author, index: true + t.references :recipient, index: true + t.text :message + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015110_create_games.rb b/db/migrate/20140304015110_create_games.rb new file mode 100644 index 0000000..fc54709 --- /dev/null +++ b/db/migrate/20140304015110_create_games.rb @@ -0,0 +1,9 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.text :name + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015112_create_game_attributes.rb b/db/migrate/20140304015112_create_game_attributes.rb new file mode 100644 index 0000000..b63f134 --- /dev/null +++ b/db/migrate/20140304015112_create_game_attributes.rb @@ -0,0 +1,11 @@ +class CreateGameAttributes < ActiveRecord::Migration + def change + create_table :game_attributes do |t| + t.references :game, index: true + t.text :key + t.integer :type + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015114_create_server_settings.rb b/db/migrate/20140304015114_create_server_settings.rb new file mode 100644 index 0000000..dfdd91b --- /dev/null +++ b/db/migrate/20140304015114_create_server_settings.rb @@ -0,0 +1,8 @@ +class CreateServerSettings < ActiveRecord::Migration + def change + create_table :server_settings do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140304015120_create_tournament_options.rb b/db/migrate/20140304015120_create_tournament_options.rb new file mode 100644 index 0000000..d2df22e --- /dev/null +++ b/db/migrate/20140304015120_create_tournament_options.rb @@ -0,0 +1,8 @@ +class CreateTournamentOptions < ActiveRecord::Migration + def change + create_table :tournament_options do |t| + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 86afd1b..7681cfc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140304015042) do +ActiveRecord::Schema.define(version: 20140304015120) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -88,10 +88,13 @@ ActiveRecord::Schema.define(version: 20140304015042) do end create_table "tournaments", force: true do |t| + t.integer "game_id" t.datetime "created_at" t.datetime "updated_at" end + add_index "tournaments", ["game_id"], name: "index_tournaments_on_game_id" + create_table "user_team_pairs", force: true do |t| t.integer "user_id" t.integer "team_id" diff --git a/generate.sh b/generate.sh index 7dbb444..b384813 100755 --- a/generate.sh +++ b/generate.sh @@ -10,7 +10,7 @@ set -x bundle exec rails generate scaffold server -bundle exec rails generate scaffold tournament +bundle exec rails generate scaffold tournament game:references bundle exec rails generate scaffold match tournament:references bundle exec rails generate scaffold team bundle exec rails generate scaffold user name:text pw_hash:text groups:integer diff --git a/test/controllers/tournaments_controller_test.rb b/test/controllers/tournaments_controller_test.rb index 9363bdf..bdbbfac 100644 --- a/test/controllers/tournaments_controller_test.rb +++ b/test/controllers/tournaments_controller_test.rb @@ -18,7 +18,7 @@ class TournamentsControllerTest < ActionController::TestCase test "should create tournament" do assert_difference('Tournament.count') do - post :create, tournament: { } + post :create, tournament: { game_id: @tournament.game_id } end assert_redirected_to tournament_path(assigns(:tournament)) @@ -35,7 +35,7 @@ class TournamentsControllerTest < ActionController::TestCase end test "should update tournament" do - patch :update, id: @tournament, tournament: { } + patch :update, id: @tournament, tournament: { game_id: @tournament.game_id } assert_redirected_to tournament_path(assigns(:tournament)) end diff --git a/test/fixtures/tournaments.yml b/test/fixtures/tournaments.yml index 937a0c0..4cba7ca 100644 --- a/test/fixtures/tournaments.yml +++ b/test/fixtures/tournaments.yml @@ -1,11 +1,7 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value +one: + game_id: + +two: + game_id: -- cgit v1.2.3-54-g00ecf
Game
<%= tournament.game %> <%= link_to 'Show', tournament %> <%= link_to 'Edit', edit_tournament_path(tournament) %> <%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' } %>