summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--app/controllers/sessions_controller.rb72
-rw-r--r--app/models/session.rb3
-rw-r--r--app/views/sessions/_form.html.erb21
-rw-r--r--app/views/sessions/edit.html.erb6
-rw-r--r--app/views/sessions/index.html.erb27
-rw-r--r--app/views/sessions/index.json.jbuilder4
-rw-r--r--app/views/sessions/new.html.erb5
-rw-r--r--app/views/sessions/show.html.erb9
-rw-r--r--app/views/sessions/show.json.jbuilder1
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20140306014047_create_servers.rb (renamed from db/migrate/20140304043618_create_servers.rb)0
-rw-r--r--db/migrate/20140306014050_create_tournaments.rb (renamed from db/migrate/20140304043620_create_tournaments.rb)0
-rw-r--r--db/migrate/20140306014052_create_matches.rb (renamed from db/migrate/20140304043622_create_matches.rb)0
-rw-r--r--db/migrate/20140306014054_create_teams.rb (renamed from db/migrate/20140304043624_create_teams.rb)0
-rw-r--r--db/migrate/20140306014056_create_alerts.rb (renamed from db/migrate/20140304043626_create_alerts.rb)0
-rw-r--r--db/migrate/20140306014059_create_pms.rb (renamed from db/migrate/20140304043629_create_pms.rb)0
-rw-r--r--db/migrate/20140306014101_create_games.rb (renamed from db/migrate/20140304043631_create_games.rb)0
-rw-r--r--db/migrate/20140306014103_create_users.rb (renamed from db/migrate/20140304043633_create_users.rb)0
-rw-r--r--db/migrate/20140306014106_create_sessions.rb9
-rw-r--r--db/migrate/20140306014108_create_game_attributes.rb (renamed from db/migrate/20140304043635_create_game_attributes.rb)0
-rw-r--r--db/migrate/20140306014110_create_server_settings.rb (renamed from db/migrate/20140304043637_create_server_settings.rb)0
-rw-r--r--db/migrate/20140306014112_create_user_team_pairs.rb (renamed from db/migrate/20140304043639_create_user_team_pairs.rb)0
-rw-r--r--db/migrate/20140306014114_create_team_match_pairs.rb (renamed from db/migrate/20140304043642_create_team_match_pairs.rb)0
-rw-r--r--db/migrate/20140306014123_add_index_to_users_email.rb (renamed from db/migrate/20140304043652_add_index_to_users_email.rb)0
-rw-r--r--db/migrate/20140306014125_add_index_to_users_user_name.rb (renamed from db/migrate/20140304043654_add_index_to_users_user_name.rb)0
-rw-r--r--db/migrate/20140306014128_add_password_digest_to_users.rb (renamed from db/migrate/20140304043656_add_password_digest_to_users.rb)0
-rw-r--r--db/migrate/20140306014130_add_remember_token_to_users.rb (renamed from db/migrate/20140304043658_add_remember_token_to_users.rb)0
-rw-r--r--db/migrate/20140306014132_create_tournament_options.rb (renamed from db/migrate/20140304043700_create_tournament_options.rb)0
-rw-r--r--db/schema.rb10
-rwxr-xr-xgenerate.sh5
-rw-r--r--test/controllers/sessions_controller_test.rb48
-rw-r--r--test/fixtures/sessions.yml7
-rw-r--r--test/models/session_test.rb7
34 files changed, 233 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 9e29fc1..0e07518 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,7 +17,8 @@
# The above is from Rails. The following is from Luke.
/vendor/bundle
-# As noted aboce, you probably want to add the following to your global git config.
+nohup.out
+# As noted above, you probably want to add the following to your global git config.
.~lock.*
*~
*#
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 16d11b5..2f72bf7 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,2 +1,74 @@
class SessionsController < ApplicationController
+ before_action :set_session, only: [:show, :edit, :update, :destroy]
+
+ # GET /sessions
+ # GET /sessions.json
+ def index
+ @sessions = Session.all
+ end
+
+ # GET /sessions/1
+ # GET /sessions/1.json
+ def show
+ end
+
+ # GET /sessions/new
+ def new
+ @session = Session.new
+ end
+
+ # GET /sessions/1/edit
+ def edit
+ end
+
+ # POST /sessions
+ # POST /sessions.json
+ def create
+ @session = Session.new(session_params)
+
+ respond_to do |format|
+ if @session.save
+ format.html { redirect_to @session, notice: 'Session was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @session }
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @session.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /sessions/1
+ # PATCH/PUT /sessions/1.json
+ def update
+ respond_to do |format|
+ if @session.update(session_params)
+ format.html { redirect_to @session, notice: 'Session was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @session.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /sessions/1
+ # DELETE /sessions/1.json
+ def destroy
+ @session.destroy
+ respond_to do |format|
+ format.html { redirect_to sessions_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_session
+ @session = Session.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def session_params
+ params.require(:session).permit(:user_id)
+ end
end
diff --git a/app/models/session.rb b/app/models/session.rb
new file mode 100644
index 0000000..c66afec
--- /dev/null
+++ b/app/models/session.rb
@@ -0,0 +1,3 @@
+class Session < ActiveRecord::Base
+ belongs_to :user
+end
diff --git a/app/views/sessions/_form.html.erb b/app/views/sessions/_form.html.erb
new file mode 100644
index 0000000..1b94e77
--- /dev/null
+++ b/app/views/sessions/_form.html.erb
@@ -0,0 +1,21 @@
+<%= form_for(@session) do |f| %>
+ <% if @session.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@session.errors.count, "error") %> prohibited this session from being saved:</h2>
+
+ <ul>
+ <% @session.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :user_id %><br>
+ <%= f.text_field :user_id %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
diff --git a/app/views/sessions/edit.html.erb b/app/views/sessions/edit.html.erb
new file mode 100644
index 0000000..bbd8407
--- /dev/null
+++ b/app/views/sessions/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing session</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @session %> |
+<%= link_to 'Back', sessions_path %>
diff --git a/app/views/sessions/index.html.erb b/app/views/sessions/index.html.erb
new file mode 100644
index 0000000..707a47d
--- /dev/null
+++ b/app/views/sessions/index.html.erb
@@ -0,0 +1,27 @@
+<h1>Listing sessions</h1>
+
+<table>
+ <thead>
+ <tr>
+ <th>User</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @sessions.each do |session| %>
+ <tr>
+ <td><%= session.user %></td>
+ <td><%= link_to 'Show', session %></td>
+ <td><%= link_to 'Edit', edit_session_path(session) %></td>
+ <td><%= link_to 'Destroy', session, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Session', new_session_path %>
diff --git a/app/views/sessions/index.json.jbuilder b/app/views/sessions/index.json.jbuilder
new file mode 100644
index 0000000..18fd4fa
--- /dev/null
+++ b/app/views/sessions/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@sessions) do |session|
+ json.extract! session, :id, :user_id
+ json.url session_url(session, format: :json)
+end
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
new file mode 100644
index 0000000..55c9eca
--- /dev/null
+++ b/app/views/sessions/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New session</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', sessions_path %>
diff --git a/app/views/sessions/show.html.erb b/app/views/sessions/show.html.erb
new file mode 100644
index 0000000..5176869
--- /dev/null
+++ b/app/views/sessions/show.html.erb
@@ -0,0 +1,9 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>User:</strong>
+ <%= @session.user %>
+</p>
+
+<%= link_to 'Edit', edit_session_path(@session) %> |
+<%= link_to 'Back', sessions_path %>
diff --git a/app/views/sessions/show.json.jbuilder b/app/views/sessions/show.json.jbuilder
new file mode 100644
index 0000000..4ebf936
--- /dev/null
+++ b/app/views/sessions/show.json.jbuilder
@@ -0,0 +1 @@
+json.extract! @session, :id, :user_id, :created_at, :updated_at
diff --git a/config/routes.rb b/config/routes.rb
index 3bad42d..dac820b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,6 @@
Leaguer::Application.routes.draw do
+ resources :sessions
+
resources :users
resources :games
diff --git a/db/migrate/20140304043618_create_servers.rb b/db/migrate/20140306014047_create_servers.rb
index f33241a..f33241a 100644
--- a/db/migrate/20140304043618_create_servers.rb
+++ b/db/migrate/20140306014047_create_servers.rb
diff --git a/db/migrate/20140304043620_create_tournaments.rb b/db/migrate/20140306014050_create_tournaments.rb
index 36fcf7e..36fcf7e 100644
--- a/db/migrate/20140304043620_create_tournaments.rb
+++ b/db/migrate/20140306014050_create_tournaments.rb
diff --git a/db/migrate/20140304043622_create_matches.rb b/db/migrate/20140306014052_create_matches.rb
index 325863d..325863d 100644
--- a/db/migrate/20140304043622_create_matches.rb
+++ b/db/migrate/20140306014052_create_matches.rb
diff --git a/db/migrate/20140304043624_create_teams.rb b/db/migrate/20140306014054_create_teams.rb
index dd8397d..dd8397d 100644
--- a/db/migrate/20140304043624_create_teams.rb
+++ b/db/migrate/20140306014054_create_teams.rb
diff --git a/db/migrate/20140304043626_create_alerts.rb b/db/migrate/20140306014056_create_alerts.rb
index 68a8e10..68a8e10 100644
--- a/db/migrate/20140304043626_create_alerts.rb
+++ b/db/migrate/20140306014056_create_alerts.rb
diff --git a/db/migrate/20140304043629_create_pms.rb b/db/migrate/20140306014059_create_pms.rb
index 93bb5c6..93bb5c6 100644
--- a/db/migrate/20140304043629_create_pms.rb
+++ b/db/migrate/20140306014059_create_pms.rb
diff --git a/db/migrate/20140304043631_create_games.rb b/db/migrate/20140306014101_create_games.rb
index 59d4ef0..59d4ef0 100644
--- a/db/migrate/20140304043631_create_games.rb
+++ b/db/migrate/20140306014101_create_games.rb
diff --git a/db/migrate/20140304043633_create_users.rb b/db/migrate/20140306014103_create_users.rb
index f0986d4..f0986d4 100644
--- a/db/migrate/20140304043633_create_users.rb
+++ b/db/migrate/20140306014103_create_users.rb
diff --git a/db/migrate/20140306014106_create_sessions.rb b/db/migrate/20140306014106_create_sessions.rb
new file mode 100644
index 0000000..fe25bf2
--- /dev/null
+++ b/db/migrate/20140306014106_create_sessions.rb
@@ -0,0 +1,9 @@
+class CreateSessions < ActiveRecord::Migration
+ def change
+ create_table :sessions do |t|
+ t.references :user, index: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140304043635_create_game_attributes.rb b/db/migrate/20140306014108_create_game_attributes.rb
index b63f134..b63f134 100644
--- a/db/migrate/20140304043635_create_game_attributes.rb
+++ b/db/migrate/20140306014108_create_game_attributes.rb
diff --git a/db/migrate/20140304043637_create_server_settings.rb b/db/migrate/20140306014110_create_server_settings.rb
index dfdd91b..dfdd91b 100644
--- a/db/migrate/20140304043637_create_server_settings.rb
+++ b/db/migrate/20140306014110_create_server_settings.rb
diff --git a/db/migrate/20140304043639_create_user_team_pairs.rb b/db/migrate/20140306014112_create_user_team_pairs.rb
index 2c492ac..2c492ac 100644
--- a/db/migrate/20140304043639_create_user_team_pairs.rb
+++ b/db/migrate/20140306014112_create_user_team_pairs.rb
diff --git a/db/migrate/20140304043642_create_team_match_pairs.rb b/db/migrate/20140306014114_create_team_match_pairs.rb
index 8fac07e..8fac07e 100644
--- a/db/migrate/20140304043642_create_team_match_pairs.rb
+++ b/db/migrate/20140306014114_create_team_match_pairs.rb
diff --git a/db/migrate/20140304043652_add_index_to_users_email.rb b/db/migrate/20140306014123_add_index_to_users_email.rb
index b5f8a1a..b5f8a1a 100644
--- a/db/migrate/20140304043652_add_index_to_users_email.rb
+++ b/db/migrate/20140306014123_add_index_to_users_email.rb
diff --git a/db/migrate/20140304043654_add_index_to_users_user_name.rb b/db/migrate/20140306014125_add_index_to_users_user_name.rb
index 724cca5..724cca5 100644
--- a/db/migrate/20140304043654_add_index_to_users_user_name.rb
+++ b/db/migrate/20140306014125_add_index_to_users_user_name.rb
diff --git a/db/migrate/20140304043656_add_password_digest_to_users.rb b/db/migrate/20140306014128_add_password_digest_to_users.rb
index 0070da7..0070da7 100644
--- a/db/migrate/20140304043656_add_password_digest_to_users.rb
+++ b/db/migrate/20140306014128_add_password_digest_to_users.rb
diff --git a/db/migrate/20140304043658_add_remember_token_to_users.rb b/db/migrate/20140306014130_add_remember_token_to_users.rb
index 74c254f..74c254f 100644
--- a/db/migrate/20140304043658_add_remember_token_to_users.rb
+++ b/db/migrate/20140306014130_add_remember_token_to_users.rb
diff --git a/db/migrate/20140304043700_create_tournament_options.rb b/db/migrate/20140306014132_create_tournament_options.rb
index d2df22e..d2df22e 100644
--- a/db/migrate/20140304043700_create_tournament_options.rb
+++ b/db/migrate/20140306014132_create_tournament_options.rb
diff --git a/db/schema.rb b/db/schema.rb
index 1f844f5..e700a4a 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: 20140304043700) do
+ActiveRecord::Schema.define(version: 20140306014132) do
create_table "alerts", force: true do |t|
t.integer "author_id"
@@ -72,6 +72,14 @@ ActiveRecord::Schema.define(version: 20140304043700) do
t.datetime "updated_at"
end
+ create_table "sessions", force: true do |t|
+ t.integer "user_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "sessions", ["user_id"], name: "index_sessions_on_user_id"
+
create_table "team_match_pairs", force: true do |t|
t.integer "team_id"
t.integer "match_id"
diff --git a/generate.sh b/generate.sh
index f0db78e..0d07743 100755
--- a/generate.sh
+++ b/generate.sh
@@ -16,6 +16,7 @@ set -x
git rm -rf app test config/routes.rb db/migrate
git checkout clean-start -- app test config/routes.rb
+# The whole shebang, models, views, and controllers
bundle exec rails generate scaffold server --force $NOTEST
bundle exec rails generate scaffold tournament game:references $NOTEST
bundle exec rails generate scaffold match tournament:references name:string --force $NOTEST
@@ -24,16 +25,18 @@ bundle exec rails generate scaffold alert author:references message:text $NOTEST
bundle exec rails generate scaffold pm author:references recipient:references message:text $NOTEST
bundle exec rails generate scaffold game name:text players_per_team:integer teams_per_match:integer set_rounds:integer randomized_teams:integer --force $NOTEST
bundle exec rails generate scaffold user name:string email:string user_name:string $NOTEST
+bundle exec rails generate scaffold session user:references
+# Just models
bundle exec rails generate model game_attribute game:references key:text type:integer $NOTEST
bundle exec rails generate model server_settings $NOTEST
bundle exec rails generate model user_team_pair user:references team:references $NOTEST
bundle exec rails generate model team_match_pair team:references match:references $NOTEST
+# Just controllers
bundle exec rails generate controller search $NOTEST
bundle exec rails generate controller main $NOTEST
bundle exec rails generate controller static $NOTEST
-bundle exec rails generate controller sessions
#added some stuff to the database
diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb
index d30ebc3..a5cc8cb 100644
--- a/test/controllers/sessions_controller_test.rb
+++ b/test/controllers/sessions_controller_test.rb
@@ -1,7 +1,49 @@
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
+ setup do
+ @session = sessions(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:sessions)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create session" do
+ assert_difference('Session.count') do
+ post :create, session: { user_id: @session.user_id }
+ end
+
+ assert_redirected_to session_path(assigns(:session))
+ end
+
+ test "should show session" do
+ get :show, id: @session
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @session
+ assert_response :success
+ end
+
+ test "should update session" do
+ patch :update, id: @session, session: { user_id: @session.user_id }
+ assert_redirected_to session_path(assigns(:session))
+ end
+
+ test "should destroy session" do
+ assert_difference('Session.count', -1) do
+ delete :destroy, id: @session
+ end
+
+ assert_redirected_to sessions_path
+ end
end
diff --git a/test/fixtures/sessions.yml b/test/fixtures/sessions.yml
new file mode 100644
index 0000000..d9098d9
--- /dev/null
+++ b/test/fixtures/sessions.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ user_id:
+
+two:
+ user_id:
diff --git a/test/models/session_test.rb b/test/models/session_test.rb
new file mode 100644
index 0000000..2d1bc1b
--- /dev/null
+++ b/test/models/session_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SessionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end