From c82d6d727b21e55951e1e1761116c15a5630f80f Mon Sep 17 00:00:00 2001 From: jcwimer Date: Wed, 30 Dec 2015 18:48:49 +0000 Subject: [PATCH] Added date to tournament --- app/controllers/static_pages_controller.rb | 2 +- app/controllers/tournaments_controller.rb | 4 ++-- app/models/tournament.rb | 10 +++++++++- app/views/static_pages/my_tournaments.html.erb | 12 +++++++----- app/views/tournaments/_form.html.erb | 4 ++++ app/views/tournaments/index.html.erb | 12 +++++++----- db/migrate/20151230164000_tournament_date.rb | 5 +++++ db/schema.rb | 3 ++- db/seeds.rb | 2 +- test/fixtures/tournaments.yml | 2 ++ test/integration/poolbracket_matchups_test.rb | 3 ++- test/models/tournament_test.rb | 6 ++++++ 12 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20151230164000_tournament_date.rb diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 0d085c4..6bf1c9e 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,7 +1,7 @@ class StaticPagesController < ApplicationController def my_tournaments - @tournaments = current_user.tournaments.order('updated_at desc') + @tournaments = current_user.tournaments.sort_by{|t| t.daysUntil} end def not_allowed diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 8694cad..b96e8b4 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -71,7 +71,7 @@ class TournamentsController < ApplicationController end def index - @tournaments = Tournament.all.limit(50).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).order('updated_at desc') + @tournaments = Tournament.all.sort_by{|t| t.daysUntil} end def show @@ -132,7 +132,7 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id) + params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id, :date) end #Check for tournament owner diff --git a/app/models/tournament.rb b/app/models/tournament.rb index dd741f2..c11eee3 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -9,7 +9,15 @@ class Tournament < ActiveRecord::Base has_many :wrestlers, through: :weights has_many :matches, dependent: :destroy - + validates :date, presence: true + + def daysUntil + time = (Date.today - self.date).to_i + if time < 0 + time = time * -1 + end + time + end def resetSchoolScores schools.update_all("score = 0.0") diff --git a/app/views/static_pages/my_tournaments.html.erb b/app/views/static_pages/my_tournaments.html.erb index ad689d1..eccbf20 100644 --- a/app/views/static_pages/my_tournaments.html.erb +++ b/app/views/static_pages/my_tournaments.html.erb @@ -1,19 +1,20 @@

My Tournaments

<% if user_signed_in? %> <%= link_to 'New Tournament', new_tournament_path, :class=>"btn btn-success" %> <% end %>

- +
+ @@ -22,6 +23,7 @@ <% @tournaments.each do |tournament| %> +
NameDate
<%= tournament.name %><%= tournament.date %> <%= link_to 'Show', tournament, :class=>"btn btn-default" %> <% if tournament_permissions(tournament) %> <%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %> diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 4d1e8ff..3b0eecc 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -27,6 +27,10 @@ <%= f.label :director_email %>
<%= f.text_field :director_email %> +
+ <%= f.label :date %>
+ <%= f.date_field :date %> +
<%= f.label :tournament_type %>
<%= f.select :tournament_type, @tournament.tournament_types %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 2b0e5c2..d361cea 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -1,19 +1,20 @@

Pick A Tournament

<% if user_signed_in? %> <%= link_to 'New Tournament', new_tournament_path, :class=>"btn btn-success" %> <% end %>

- +
+ @@ -22,6 +23,7 @@ <% @tournaments.each do |tournament| %> +
NameDate
<%= tournament.name %><%= tournament.date %> <%= link_to 'Show', tournament, :class=>"btn btn-default" %> <% if tournament_permissions(tournament) %> <%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %> diff --git a/db/migrate/20151230164000_tournament_date.rb b/db/migrate/20151230164000_tournament_date.rb new file mode 100644 index 0000000..4824a3d --- /dev/null +++ b/db/migrate/20151230164000_tournament_date.rb @@ -0,0 +1,5 @@ +class TournamentDate < ActiveRecord::Migration + def change + add_column :tournaments, :date, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d0b074..4b815fa 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: 20151230163202) do +ActiveRecord::Schema.define(version: 20151230164000) do create_table "delayed_jobs", force: :cascade do |t| t.integer "priority", default: 0, null: false @@ -94,6 +94,7 @@ ActiveRecord::Schema.define(version: 20151230163202) do t.text "weigh_in_ref" t.integer "user_id" t.integer "curently_generating_matches" + t.date "date" end add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id" diff --git a/db/seeds.rb b/db/seeds.rb index ce18142..546247e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,7 +7,7 @@ # Mayor.create(name: 'Emanuel', city: cities.first) if Rails.env.development? User.create(id: 1, email: 'test@test.com', password: 'password', password_confirmation: 'password') - Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com', tournament_type: 'Pool to bracket', user_id: 1) + Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com', tournament_type: 'Pool to bracket', user_id: 1, date: Date.today) School.create(id: 200, name: 'Central Crossing', tournament_id: 200) School.create(id: 201, name: 'Turd Town', tournament_id: 200) School.create(id: 202, name: 'Shit Show', tournament_id: 200) diff --git a/test/fixtures/tournaments.yml b/test/fixtures/tournaments.yml index b573534..f2f3b1d 100644 --- a/test/fixtures/tournaments.yml +++ b/test/fixtures/tournaments.yml @@ -8,6 +8,7 @@ one: director_email: jacob.wimer@gmail.com tournament_type: Pool to bracket user_id: 1 + date: 2015-12-30 two: id: 2 @@ -17,5 +18,6 @@ two: director_email: jacob.wimer@gmail.com tournament_type: Pool to bracket user_id: 1 + date: 2015-12-30 diff --git a/test/integration/poolbracket_matchups_test.rb b/test/integration/poolbracket_matchups_test.rb index cc216ef..0279a91 100644 --- a/test/integration/poolbracket_matchups_test.rb +++ b/test/integration/poolbracket_matchups_test.rb @@ -23,7 +23,8 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest name: "Something", address: "Some Place", director: "Some Guy", - director_email: "test@test.com" + director_email: "test@test.com", + date: Date.today ) tournament.save tournament diff --git a/test/models/tournament_test.rb b/test/models/tournament_test.rb index 66544d8..21ed0cc 100644 --- a/test/models/tournament_test.rb +++ b/test/models/tournament_test.rb @@ -4,4 +4,10 @@ class TournamentTest < ActiveSupport::TestCase test "the truth" do assert true end + + test "Tournament needs a date" do + tourney = Tournament.new + assert_not tourney.valid? + assert_equal [:date], tourney.errors.keys + end end