-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/assets/javascripts/admin_games.js.coffee b/app/assets/javascripts/admin_games.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/admin_games.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/code_compares.js.coffee b/app/assets/javascripts/code_compares.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/code_compares.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/codes.js.coffee b/app/assets/javascripts/codes.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/codes.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/game_codes.js.coffee b/app/assets/javascripts/game_codes.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/game_codes.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/game_hints.js.coffee b/app/assets/javascripts/game_hints.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/game_hints.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/games.js.coffee b/app/assets/javascripts/games.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/games.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/hints.js.coffee b/app/assets/javascripts/hints.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/hints.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/home.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/home.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/user_games.js.coffee b/app/assets/javascripts/user_games.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/user_games.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/admin_games.css.scss b/app/assets/stylesheets/admin_games.css.scss
deleted file mode 100644
index 03d3467..0000000
--- a/app/assets/stylesheets/admin_games.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the AdminGames controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/code_compares.css.scss b/app/assets/stylesheets/code_compares.css.scss
deleted file mode 100644
index 8888d08..0000000
--- a/app/assets/stylesheets/code_compares.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the code_compares controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/codes.css.scss b/app/assets/stylesheets/codes.css.scss
deleted file mode 100644
index 51f919d..0000000
--- a/app/assets/stylesheets/codes.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the codes controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/game_codes.css.scss b/app/assets/stylesheets/game_codes.css.scss
deleted file mode 100644
index 6497235..0000000
--- a/app/assets/stylesheets/game_codes.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the game_codes controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/game_hints.css.scss b/app/assets/stylesheets/game_hints.css.scss
deleted file mode 100644
index 4198b63..0000000
--- a/app/assets/stylesheets/game_hints.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the GameHints controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/games.css.scss b/app/assets/stylesheets/games.css.scss
deleted file mode 100644
index 3e6a7ec..0000000
--- a/app/assets/stylesheets/games.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the Games controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/hints.css.scss b/app/assets/stylesheets/hints.css.scss
deleted file mode 100644
index 7c9e053..0000000
--- a/app/assets/stylesheets/hints.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the Hints controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/user_games.css.scss b/app/assets/stylesheets/user_games.css.scss
deleted file mode 100644
index 55b461e..0000000
--- a/app/assets/stylesheets/user_games.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the UserGames controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/code_compares_controller.rb b/app/controllers/code_compares_controller.rb
index c85d6bc..61a7df9 100644
--- a/app/controllers/code_compares_controller.rb
+++ b/app/controllers/code_compares_controller.rb
@@ -1,18 +1,58 @@
class CodeComparesController < ApplicationController
before_action :set_code_compare, only: [:destroy]
skip_before_filter :authorize_admin
- def create
- @code_compare = CodeCompare.new(code_compare_params)
+ before_filter :check_code_compare_creation, only: [:create]
+ before_filter :authenticate_user!
- respond_to do |format|
- if @code_compare.save
- format.html { head :no_content }
- format.json { head :no_content }
- else
- format.html { head :no_content }
- format.json { head :no_content }
+ def create
+ #Не совсем понял как получить пароль конкретного юзера из девиза
+ @user_task = UserTask.where(user_id: current_user.id).last
+ @task_codes = TaskCode.where(task_id: @user_task.task_id)
+ notice = ""
+ @task_game = GameTask.where(task_id: @user_task.task_id).first
+ @task_codes.each do |task_code|
+ @code = Code.where(id: task_code.code_id, code_string: params[:try_text])
+ if @code.count > 0
+ new_code_compare = {user_id: current_user.id, code_id: @code.first.id}
+ @code_compare = CodeCompare.new(new_code_compare)
+ #respond_to do |format|
+ if @code_compare.save
+ notice = "Code was matched"
+ if (CodeCompare.where(user_id: current_user.id, code_id: task_code.code_id).count ==
+ @task_codes.count)
+ @user_hints = UserHint.where(user_id: current_user.id).count
+ @task = Task.find(task_code.task_id)
+ points_received = @task.points - @user_hints
+ @user_task.update(result: points_received)
+ @new_game_task = GameTask.where("`game_id` = ? AND `task_id` <> ?", @task_game.game_id, task_code.task_id)
+ if @new_game_task.count > 0
+ UserTask.create(user_id: current_user.id, task_id: @new_game_task.first.task_id)
+ notice = "Code was matched. New Task was started"
+ else
+ @user_tasks = UserTask.where(user_id: current_user.id)
+ points = 0
+ @user_tasks.each do |user_task|
+ points += user_task.result
+ end
+ @user_game = UserGame.where(user_id: current_user.id, game_id: @task_game.game_id).first
+ @user_game.update(result: points, state: -1)
+ notice = "Code was matched. Game was ended"
+ end
+ end
+ end
+ #end
+ break
end
end
+
+ if notice == ""
+ notice = "Code was not matched"
+ end
+
+ respond_to do |format|
+ format.html { redirect_to game_path(id: @task_game.game_id), notice: notice }
+ format.json { head :no_content }
+ end
end
def destroy
@@ -24,13 +64,22 @@ def destroy
end
private
- # Use callbacks to share common setup or constraints between actions.
- def set_code_compare
- @code_compare = CodeCompare.find(params[:id])
- end
+ # Use callbacks to share common setup or constraints between actions.
+ def set_code_compare
+ @code_compare = CodeCompare.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def code_compare_params
+ params.require(:code_compare).permit(:user_id, :code_id)
+ end
- # Never trust parameters from the scary internet, only allow the white list through.
- def code_compare_params
- params.require(:code_compare).permit(:user_id, :code_id)
+ protected
+ def check_code_compare_creation
+ unless params[:try_text] && params[:task]
+ @game_task = GameTask.where(task_id: params[:task]).first
+ redirect_to game_path(id: @game_task.game_id)
+ end
end
+
end
diff --git a/app/controllers/codes_controller.rb b/app/controllers/codes_controller.rb
index e7cd73b..345530a 100644
--- a/app/controllers/codes_controller.rb
+++ b/app/controllers/codes_controller.rb
@@ -1,7 +1,7 @@
class CodesController < ApplicationController
before_action :set_code, only: [:show, :edit, :update, :destroy]
- before_filter :check_game, only: [:new]
- before_filter :check_game_create, only: [:create]
+ before_filter :check_task, only: [:new]
+ before_filter :check_task_create, only: [:create]
before_filter :no_codes, except: [:new, :create]
# GET /codes
@@ -28,10 +28,10 @@ def edit
# POST /codes.json
def create
@code = Code.new(code_params)
- game = params.require(:code)[:game].to_i
+ task = params.require(:code)[:task].to_i
respond_to do |format|
if @code.save
- if GameCode.create(game_id: game, code_id: @code.id)
+ if TaskCode.create(task_id: task, code_id: @code.id)
format.html { redirect_to @code, notice: 'Code was successfully created.' }
format.json { render action: 'show', status: :created, location: @code }
end
@@ -79,14 +79,14 @@ def code_params
protected
- def check_game
- unless params.require(:game)
+ def check_task
+ unless params.require(:task)
redirect_to games_path
end
end
- def check_game_create
- unless params.require(:code)
+ def check_task_create
+ unless params.require(:code)[:task]
redirect_to games_path
end
end
diff --git a/app/controllers/game_codes_controller.rb b/app/controllers/game_tasks_controller.rb
similarity index 55%
rename from app/controllers/game_codes_controller.rb
rename to app/controllers/game_tasks_controller.rb
index cbc7999..54d489b 100644
--- a/app/controllers/game_codes_controller.rb
+++ b/app/controllers/game_tasks_controller.rb
@@ -1,13 +1,13 @@
-class GameCodesController < ApplicationController
- before_action :set_game_code, only: [:show, :edit, :update, :destroy]
+class GameTasksController < ApplicationController
+ before_action :set_game_task, only: [:show, :edit, :update, :destroy]
- # POST /game_codes
- # POST /game_codes.json
+ # POST /game_tasks
+ # POST /game_tasks.json
def create
- @game_code = GameCode.new(game_code_params)
+ @game_task = GameTask.new(game_task_params)
respond_to do |format|
- if @game_code.save
+ if @game_task.save
format.html { head :no_content }
format.json { head :no_content }
else
@@ -17,11 +17,10 @@ def create
end
end
-
- # DELETE /game_codes/1
- # DELETE /game_codes/1.json
+ # DELETE /game_tasks/1
+ # DELETE /game_tasks/1.json
def destroy
- @game_code.destroy
+ @game_task.destroy
respond_to do |format|
format.html { head :no_content }
format.json { head :no_content }
@@ -30,12 +29,12 @@ def destroy
private
# Use callbacks to share common setup or constraints between actions.
- def set_game_code
- @game_code = GameCode.find(params[:id])
+ def set_game_task
+ @game_task = GameTask.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
- def game_code_params
- params.require(:game_code).permit(:game_id, :code_id)
+ def game_task_params
+ params.require(:game_task).permit(:game_id, :task_id)
end
end
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index 8e553dd..48ad355 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -1,7 +1,7 @@
class GamesController < ApplicationController
- before_action :set_game, only: [:show, :edit, :update, :destroy]
+ before_action :set_game, only: [:show, :edit, :update, :destroy, :start_game, :check_game_status, :finish_game]
skip_before_filter :authorize_admin, only: [:index, :show]
-
+ before_filter :check_game_status, only: [:show]
# GET /games
# GET /games.json
def index
@@ -11,6 +11,17 @@ def index
# GET /games/1
# GET /games/1.json
def show
+ @status = ""
+ if @game.state == 0
+ @status = "Wait"
+ elsif @game.state > 0
+ @status = "Started"
+ @user_task = UserTask.where(user_id: current_user.id, game_id: @game.id).last
+ @task = Task.find(@user_task.task_id).first
+ @task_codes_count = TaskCode.where(task_id: @user_task.task_id).count
+ elsif @game.state < 0
+ @status = "Finished"
+ end
end
# GET /games/new
@@ -73,7 +84,42 @@ def set_game
end
# Never trust parameters from the scary internet, only allow the white list through.
- def game_params
- params.require(:game).permit(:title, :start_date, :duration)
+ def game_params
+ params.require(:game).permit(:title, :start_date)
+ end
+
+ public
+ #Заглушки для отложенных задач
+ def start_game
+ @game.update(state: 1)
+ @user_games = UserGame.where(game_id: @game.id)
+ @game_tasks = GameTask.where(game_id: @game.id).first
+ @user_games.each do |user_game|
+ UserTask.create(user_id: user_game.id, task_id: @game_tasks.task_id, result: 0)
+ user_game.update(state: 1)
+ end
+ redirect_to games_path
+ end
+
+ def finish_game
+ @game.update(state: -1)
+ @user_games = UserGame.where(game_id: @game.id)
+ @user_games.each do |user_game|
+ points = 0
+ UserTask.where(user_id: user_game.user_id).each do |user_task|
+ points += user_task.result
+ end
+ user_game.update(state: -1, result: points)
+ end
+ redirect_to games_path
+ end
+
+ protected
+
+ def check_game_status
+ if user_signed_in? && @game.status <= 0
+ redirect_to root_path
+ end
end
+
end
diff --git a/app/controllers/hints_controller.rb b/app/controllers/hints_controller.rb
index 5650bf3..f5bf62e 100644
--- a/app/controllers/hints_controller.rb
+++ b/app/controllers/hints_controller.rb
@@ -1,6 +1,6 @@
class HintsController < ApplicationController
- before_filter :check_game, only: [:new]
- before_filter :check_game_create, only: [:create]
+ before_filter :check_task, only: [:new]
+ before_filter :check_task_create, only: [:create]
before_filter :no_hints, except: [:new, :create]
before_action :set_hint, only: [:show, :edit, :update, :destroy]
skip_before_filter :authorize_admin, only: [:show]
@@ -18,8 +18,12 @@ def show
# GET /hints/new
def new
+ task = params[:task].to_i
+ @cant_add = false
+ if TaskHint.where(task_id: task).count == 2
+ @cant_add = true
+ end
@hint = Hint.new
- @game = params[:game]
end
# GET /hints/1/edit
@@ -29,11 +33,11 @@ def edit
# POST /hints
# POST /hints.json
def create
+ task = params.require(:hint)[:task].to_i
@hint = Hint.new(hint_params)
- game = params.require(:hint)[:game].to_i
respond_to do |format|
if @hint.save
- if GameHint.create(game_id: game, hint_id: @hint.id)
+ if TaskHint.create(task_id: task, hint_id: @hint.id)
format.html { redirect_to @hint, notice: 'Hint was successfully created.' }
format.json { render action: 'show', status: :created, location: @hint }
end
@@ -81,16 +85,24 @@ def hint_params
protected
- def check_game
- unless params.require(:game)
+ def check_task
+ unless params.require(:task)
redirect_to games_path
end
end
- def check_game_create
- unless params.require(:hint)
+ def check_task_create
+ unless params.require(:hint)[:task]
redirect_to games_path
end
+ task = params.require(:hint)[:task].to_i
+ @task_hints = TaskHint.where(task_id: task)
+ if @task_hints.count > 0
+ @hint = Hint.find(@task_hints.first.hint_id)
+ if @hint.queue_number == params.require(:hint)[:queue_number].to_i
+ redirect_to new_hint_path, notice: "Parameter queue_number must be equal to " + (3 - params.require(:hint)[:queue_number].to_i).to_s
+ end
+ end
end
def no_hints
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 7c3997a..7193e8f 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -3,23 +3,6 @@ class HomeController < ApplicationController
before_filter :authenticate_user!, only: [:game_code_compares, :create_code_compare]
def index
- @games = Game.all
+ @games = Game.where(state: 0)
end
-
- def game_code_compares
- @game = Game.find(params[:game].to_i)
- @game_codes = GameCode.where(game_id: @game.id)
- end
-
- def create_code_compare
- @code = Code.where(params[:try_text])
- if @code.count > 0
- code_compare_params = {}
- code_compare_params[:code_compare] = {user_id: current_user.id, game_id: params[:game].to_i}
- CodeCompare.create(code_compare_params)
- else
- redirect_to "home/game_code_compares", notice: "Code does not match"
- end
- end
-
end
diff --git a/app/controllers/task_codes_controller.rb b/app/controllers/task_codes_controller.rb
new file mode 100644
index 0000000..8360edd
--- /dev/null
+++ b/app/controllers/task_codes_controller.rb
@@ -0,0 +1,38 @@
+class TaskCodesController < ApplicationController
+ before_action :set_task_code, only: [:destroy]
+
+ def create
+ @task_code = TaskCode.new(task_code_params)
+
+ respond_to do |format|
+ if @task_code.save
+ format.html { head :no_content }
+ format.json { head :no_content }
+ else
+ format.html { head :no_content }
+ format.json { head :no_content }
+ end
+ end
+ end
+
+ # DELETE /task_codes/1
+ # DELETE /task_codes/1.json
+ def destroy
+ @task_code.destroy
+ respond_to do |format|
+ format.html { head :no_content }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_task_code
+ @task_code = TaskCode.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def task_code_params
+ params.require(:task_code).permit(:task_id, :code_id)
+ end
+end
diff --git a/app/controllers/game_hints_controller.rb b/app/controllers/task_hints_controller.rb
similarity index 58%
rename from app/controllers/game_hints_controller.rb
rename to app/controllers/task_hints_controller.rb
index e5722a8..00c7875 100644
--- a/app/controllers/game_hints_controller.rb
+++ b/app/controllers/task_hints_controller.rb
@@ -1,13 +1,11 @@
-class GameHintsController < ApplicationController
- before_action :set_game_hint, only: [:destroy]
+class TaskHintsController < ApplicationController
+ before_action :set_task_hint, only: [:destroy]
- # POST /game_hints
- # POST /game_hints.json
def create
- @game_hint = GameHint.new(game_hint_params)
+ @task_hint = TaskHint.new(task_hint_params)
respond_to do |format|
- if @game_hint.save
+ if @task_hint.save
format.html { head :no_content }
format.json { head :no_content }
else
@@ -17,8 +15,10 @@ def create
end
end
+ # DELETE /task_hints/1
+ # DELETE /task_hints/1.json
def destroy
- @game_hint.destroy
+ @task_hint.destroy
respond_to do |format|
format.html { head :no_content }
format.json { head :no_content }
@@ -27,12 +27,12 @@ def destroy
private
# Use callbacks to share common setup or constraints between actions.
- def set_game_hint
- @game_hint = GameHint.find(params[:id])
+ def set_task_hint
+ @task_hint = TaskHint.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
- def game_hint_params
- params.require(:game_hint).permit(:game_id, :hint_id)
+ def task_hint_params
+ params.require(:task_hint).permit(:task_id, :hint_id)
end
end
diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
new file mode 100644
index 0000000..b146676
--- /dev/null
+++ b/app/controllers/tasks_controller.rb
@@ -0,0 +1,121 @@
+class TasksController < ApplicationController
+ before_action :set_task, only: [:show, :edit, :update, :destroy, :raise_hint]
+ before_filter :check_game, only: [:new]
+ before_filter :check_game_create, only: [:create]
+ before_filter :no_tasks, except: [:new, :create]
+ # GET /tasks
+ # GET /tasks.json
+ def index
+ @tasks = Task.all
+ end
+
+ # GET /tasks/1
+ # GET /tasks/1.json
+ def show
+ end
+
+ # GET /tasks/new
+ def new
+ @task = Task.new
+ end
+
+ # GET /tasks/1/edit
+ def edit
+ end
+
+ # POST /tasks
+ # POST /tasks.json
+ def create
+ @task = Task.new(task_params)
+ game = params.require(:task)[:game].to_i
+ respond_to do |format|
+ if @task.save
+ if GameTask.create(game_id: game, task_id: @task.id)
+ format.html { redirect_to @task, notice: 'Task was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @code }
+ end
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @code.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /tasks/1
+ # PATCH/PUT /tasks/1.json
+ def update
+ respond_to do |format|
+ if @task.update(task_params)
+ format.html { redirect_to @task, notice: 'Task was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @task.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /tasks/1
+ # DELETE /tasks/1.json
+ def destroy
+ @task.destroy
+ respond_to do |format|
+ format.html { redirect_to tasks_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_task
+ @task = Task.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def task_params
+ params.require(:task).permit(:task_text, :points)
+ end
+
+ protected
+
+ def check_game
+ unless params.require(:game)
+ redirect_to games_path
+ end
+ end
+
+ def check_game_create
+ unless params.require(:task)[:game]
+ redirect_to games_path
+ end
+ end
+
+ def no_tasks
+ unless Task.all.count > 0
+ redirect_to games_path
+ end
+ end
+
+ public
+ #еще заглушка
+ def raise_hint
+ TaskHint.where(task_id: @task.id).each do |task_hint|
+ @hint = Hint.find(task_hint.hint_id)
+ if UserHint.where(hint_id: @hint.id).count > 0
+ next
+ else
+ @user_tasks = UserTask.where(task_id: task_hint.task_id)
+ @user_tasks.each do |user_task|
+ if user_task.result < 0
+ UserHint.create(user_id: user_task.user_id, hint_id: @hint.id)
+
+ end
+ end
+ break
+ end
+ end
+
+ redirect_to tasks_path
+ end
+
+end
diff --git a/app/controllers/user_games_controller.rb b/app/controllers/user_games_controller.rb
index 3c97edb..3a5a8e2 100644
--- a/app/controllers/user_games_controller.rb
+++ b/app/controllers/user_games_controller.rb
@@ -3,10 +3,12 @@ class UserGamesController < ApplicationController
skip_before_filter :authorize_admin
before_filter :authenticate_user!
before_filter :check_game_create, only: [:create]
+ before_filter :user_games_count, except: [:create]
# GET /user_games
# GET /user_games.json
def index
- @user_games = UserGame.where(user_id: current_user.id)
+ #@user_games = UserGame.where(""user_id: current_user.id, "`state` >= 0""")
+ @user_games = UserGame.where("`user_id` = ? AND `state` >= ?", current_user.id, 0)
@games = []
@user_games.each do |user_game|
@games << Game.find(user_game.game_id)
@@ -30,15 +32,14 @@ def edit
# POST /user_games
# POST /user_games.json
def create
- new_user_game = user_game_params
+ new_user_game = {}
+ new_user_game[:game_id] = params[:game_id].to_i
new_user_game[:user_id] = current_user.id
@user_game = UserGame.new(new_user_game)
- #@user_game = UserGame.new({game_id: params[:game].to_i, user_id: current_user.id})
-
respond_to do |format|
if @user_game.save
- format.html { redirect_to user_games_url, notice: 'User game was successfully created.' }
+ format.html { redirect_to user_games_url, notice: 'User game was join in game with success.' }
format.json { render action: 'index', status: :created, location: @user_game }
else
format.html { redirect_to root_path }
@@ -74,21 +75,28 @@ def destroy
end
private
- # Use callbacks to share common setup or constraints between actions.
- def set_user_game
- @user_game = UserGame.find(params[:id])
- end
+ # Use callbacks to share common setup or constraints between actions.
+ def set_user_game
+ @user_game = UserGame.find(params[:id])
+ end
- # Never trust parameters from the scary internet, only allow the white list through.
- def user_game_params
- params.require(:user_game).permit(:user_id, :game_id, :result)
- end
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def user_game_params
+ params.require(:user_game).permit(:user_id, :game_id, :result)
+ end
protected
def check_game_create
- unless params.require(:user_game)
+ unless params.require(:game_id)
redirect_to root_path
end
end
-end
+
+ def user_games_count
+ unless UserGame.count > 0
+ redirect_to root_path
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/user_hints_controller.rb b/app/controllers/user_hints_controller.rb
new file mode 100644
index 0000000..6e9a047
--- /dev/null
+++ b/app/controllers/user_hints_controller.rb
@@ -0,0 +1,42 @@
+class UserHintsController < ApplicationController
+ before_action :set_user_hint, only: [:destroy]
+ before_filter :authenticate_user!
+ skip_before_filter :authorize_admin
+
+ # POST /user_hints
+ # POST /user_hints.json
+ def create
+ @user_hint = UserHint.new(user_hint_params)
+
+ respond_to do |format|
+ if @user_hint.save
+ format.html { head :no_content }
+ format.json { head :no_content }
+ else
+ format.html { head :no_content }
+ format.json { head :no_content }
+ end
+ end
+ end
+
+ # DELETE /user_hints/1
+ # DELETE /user_hints/1.json
+ def destroy
+ @user_hint.destroy
+ respond_to do |format|
+ format.html { head :no_content }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_user_hint
+ @user_hint = UserHint.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def user_hint_params
+ params.require(:user_hint).permit(:user_id, :hint_id)
+ end
+end
diff --git a/app/controllers/user_tasks_controller.rb b/app/controllers/user_tasks_controller.rb
new file mode 100644
index 0000000..d85708d
--- /dev/null
+++ b/app/controllers/user_tasks_controller.rb
@@ -0,0 +1,40 @@
+class UserTasksController < ApplicationController
+ before_action :set_user_task, only: [:destroy]
+ skip_before_filter :authorize_admin
+ before_filter :authenticate_user!
+
+ def create
+ @user_task = UserTask.new(user_task_params)
+
+ respond_to do |format|
+ if @user_task.save
+ format.html { head :no_content }
+ format.json { head :no_content }
+ else
+ format.html { head :no_content }
+ format.json { head :no_content }
+ end
+ end
+ end
+
+ # DELETE /user_tasks/1
+ # DELETE /user_tasks/1.json
+ def destroy
+ @user_task.destroy
+ respond_to do |format|
+ format.html { head :no_content }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_user_task
+ @user_task = UserTask.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def user_task_params
+ params.require(:user_task).permit(:user_id, :task_id, :result)
+ end
+end
diff --git a/app/helpers/game_codes_helper.rb b/app/helpers/game_codes_helper.rb
deleted file mode 100644
index fa04e65..0000000
--- a/app/helpers/game_codes_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module GameCodesHelper
-end
diff --git a/app/helpers/game_hints_helper.rb b/app/helpers/game_hints_helper.rb
deleted file mode 100644
index 0779689..0000000
--- a/app/helpers/game_hints_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module GameHintsHelper
-end
diff --git a/app/helpers/game_tasks_helper.rb b/app/helpers/game_tasks_helper.rb
new file mode 100644
index 0000000..552b0a2
--- /dev/null
+++ b/app/helpers/game_tasks_helper.rb
@@ -0,0 +1,2 @@
+module GameTasksHelper
+end
diff --git a/app/helpers/task_codes_helper.rb b/app/helpers/task_codes_helper.rb
new file mode 100644
index 0000000..2c31b21
--- /dev/null
+++ b/app/helpers/task_codes_helper.rb
@@ -0,0 +1,2 @@
+module TaskCodesHelper
+end
diff --git a/app/helpers/task_hints_helper.rb b/app/helpers/task_hints_helper.rb
new file mode 100644
index 0000000..1f9d1f7
--- /dev/null
+++ b/app/helpers/task_hints_helper.rb
@@ -0,0 +1,2 @@
+module TaskHintsHelper
+end
diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb
new file mode 100644
index 0000000..ce894d0
--- /dev/null
+++ b/app/helpers/tasks_helper.rb
@@ -0,0 +1,2 @@
+module TasksHelper
+end
diff --git a/app/helpers/user_hints_helper.rb b/app/helpers/user_hints_helper.rb
new file mode 100644
index 0000000..2211fa8
--- /dev/null
+++ b/app/helpers/user_hints_helper.rb
@@ -0,0 +1,2 @@
+module UserHintsHelper
+end
diff --git a/app/helpers/user_tasks_helper.rb b/app/helpers/user_tasks_helper.rb
new file mode 100644
index 0000000..596de7c
--- /dev/null
+++ b/app/helpers/user_tasks_helper.rb
@@ -0,0 +1,2 @@
+module UserTasksHelper
+end
diff --git a/app/models/code.rb b/app/models/code.rb
index e834eeb..5ded048 100644
--- a/app/models/code.rb
+++ b/app/models/code.rb
@@ -1,4 +1,5 @@
class Code < ActiveRecord::Base
- has_one :game_code, dependent: :destroy
+ has_one :task_code, dependent: :destroy
+ has_many :code_compares, dependent: :destroy
validate :code_string, presence: true
end
diff --git a/app/models/code_compare.rb b/app/models/code_compare.rb
index e90aa48..30f4b70 100644
--- a/app/models/code_compare.rb
+++ b/app/models/code_compare.rb
@@ -1,2 +1,4 @@
class CodeCompare < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :code
end
diff --git a/app/models/game.rb b/app/models/game.rb
index 67065eb..07da62d 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -2,9 +2,8 @@ class Game < ActiveRecord::Base
has_one :admin_game, dependent: :destroy
has_many :user_games, dependent: :destroy
- has_many :game_hints, dependent: :destroy
- has_many :game_codes, dependent: :destroy
+ has_many :game_tasks, dependent: :destroy
- validate :title, :start_date, :duration, presence: true
+ validate :title, :start_date, presence: true
end
diff --git a/app/models/game_code.rb b/app/models/game_code.rb
deleted file mode 100644
index 589db33..0000000
--- a/app/models/game_code.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class GameCode < ActiveRecord::Base
- belongs_to :game
- belongs_to :code
-end
diff --git a/app/models/game_hint.rb b/app/models/game_hint.rb
deleted file mode 100644
index 4f4aea6..0000000
--- a/app/models/game_hint.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class GameHint < ActiveRecord::Base
- belongs_to :game
- belongs_to :hint
-end
diff --git a/app/models/game_task.rb b/app/models/game_task.rb
new file mode 100644
index 0000000..9c03994
--- /dev/null
+++ b/app/models/game_task.rb
@@ -0,0 +1,4 @@
+class GameTask < ActiveRecord::Base
+ belongs_to :game
+ belongs_to :task
+end
diff --git a/app/models/hint.rb b/app/models/hint.rb
index 6e77c9b..2e4b3bf 100644
--- a/app/models/hint.rb
+++ b/app/models/hint.rb
@@ -1,5 +1,5 @@
class Hint < ActiveRecord::Base
- has_one :game_hint, dependent: :destroy
-
+ has_one :task_hint, dependent: :destroy
+ has_many :user_hints, dependent: :destroy
validate :hint_text, :queue_number, presence: true
end
diff --git a/app/models/task.rb b/app/models/task.rb
new file mode 100644
index 0000000..0d689f1
--- /dev/null
+++ b/app/models/task.rb
@@ -0,0 +1,8 @@
+class Task < ActiveRecord::Base
+ has_many :task_hints, dependent: :destroy
+ has_many :task_codes, dependent: :destroy
+ has_many :user_tasks, dependent: :destroy
+ has_one :game_task, dependent: :destroy
+
+ validate :task_text, :points, presence: true
+end
diff --git a/app/models/task_code.rb b/app/models/task_code.rb
new file mode 100644
index 0000000..df6a839
--- /dev/null
+++ b/app/models/task_code.rb
@@ -0,0 +1,4 @@
+class TaskCode < ActiveRecord::Base
+ belongs_to :task
+ belongs_to :code
+end
diff --git a/app/models/task_hint.rb b/app/models/task_hint.rb
new file mode 100644
index 0000000..52e7c0d
--- /dev/null
+++ b/app/models/task_hint.rb
@@ -0,0 +1,5 @@
+class TaskHint < ActiveRecord::Base
+ belongs_to :task
+
+ belongs_to :hint
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 27a78a2..96d9699 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,6 +2,11 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :user_games, dependent: :destroy
+ has_many :code_compares, dependent: :destroy
+ has_many :code_compares, dependent: :destroy
+ has_one :user_task, dependent: :destroy
+ has_one :task, through: :user_task
+ has_many :user_hints, dependent: :destroy
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
diff --git a/app/models/user_game.rb b/app/models/user_game.rb
index 4ce4cda..4ff8f59 100644
--- a/app/models/user_game.rb
+++ b/app/models/user_game.rb
@@ -3,5 +3,4 @@ class UserGame < ActiveRecord::Base
belongs_to :game
validate :user_id, :game_id, :result, presence: true
-
end
diff --git a/app/models/user_hint.rb b/app/models/user_hint.rb
new file mode 100644
index 0000000..b304cc1
--- /dev/null
+++ b/app/models/user_hint.rb
@@ -0,0 +1,4 @@
+class UserHint < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :hint
+end
diff --git a/app/models/user_task.rb b/app/models/user_task.rb
new file mode 100644
index 0000000..6d45865
--- /dev/null
+++ b/app/models/user_task.rb
@@ -0,0 +1,4 @@
+class UserTask < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :task
+end
diff --git a/app/views/codes/_form.html.slim b/app/views/codes/_form.html.slim
index 8457f0a..8c849e5 100644
--- a/app/views/codes/_form.html.slim
+++ b/app/views/codes/_form.html.slim
@@ -4,7 +4,7 @@
.controls
= f.text_field :code_string, :class => 'text_field'
.controls
- = f.hidden_field :game, value: @game
+ = f.hidden_field :task, value: @game
.form-actions
= f.submit nil, :class => 'btn btn-primary'
'
diff --git a/app/views/home/_form.html.slim b/app/views/games/_code_compare_form.html.slim
similarity index 58%
rename from app/views/home/_form.html.slim
rename to app/views/games/_code_compare_form.html.slim
index 15ff142..01e0533 100644
--- a/app/views/home/_form.html.slim
+++ b/app/views/games/_code_compare_form.html.slim
@@ -1,7 +1,7 @@
-= form_tag "home/create_code_compare", method: "post" do |f|
+= form_tag "code_compares/create", method: "post" do |f|
.control-group
= f.label "try_text", :class => 'control-label'
.controls
= f.text_field "try_text", :class => 'text_field'
.controls
- = f.hidden_field_tag "game", :value => game.id
\ No newline at end of file
+ = f.hidden_field_tag "task", :value => task.id
\ No newline at end of file
diff --git a/app/views/games/_form.html.slim b/app/views/games/_form.html.slim
index aa73253..f2e8c72 100644
--- a/app/views/games/_form.html.slim
+++ b/app/views/games/_form.html.slim
@@ -7,10 +7,6 @@
= f.label :start_date, :class => 'control-label'
.controls
= f.text_field :start_date, :class => 'text_field'
- .control-group
- = f.label :duration, :class => 'control-label'
- .controls
- = f.text_field :duration, :class => 'text_field'
.form-actions
= f.submit nil, :class => 'btn btn-primary'
'
diff --git a/app/views/games/index.html.slim b/app/views/games/index.html.slim
index 036bb96..a7253b8 100644
--- a/app/views/games/index.html.slim
+++ b/app/views/games/index.html.slim
@@ -7,7 +7,6 @@ table class="table table-striped"
th= model_class.human_attribute_name(:id)
th= model_class.human_attribute_name(:title)
th= model_class.human_attribute_name(:start_date)
- th= model_class.human_attribute_name(:duration)
th= model_class.human_attribute_name(:created_at)
th=t '.actions', :default => t("helpers.actions")
tbody
@@ -16,8 +15,6 @@ table class="table table-striped"
td= link_to game.id, game_path(game)
td= game.title
td= game.start_date
- td= game.duration
- td=l game.created_at
td
= link_to t('.edit', :default => t("helpers.links.edit")), edit_game_path(game), :class => 'btn btn-mini'
'
diff --git a/app/views/games/show.html.slim b/app/views/games/show.html.slim
index f23d5e4..c362063 100644
--- a/app/views/games/show.html.slim
+++ b/app/views/games/show.html.slim
@@ -1,25 +1,27 @@
-- model_class = Game
div class="page-header"
- h1=t '.title', :default => model_class.model_name.human.titleize
+ h1=t '.title', :default => Game.model_name.human.titleize
-p
- strong= model_class.human_attribute_name(:title) + ':'
- br
- = @game.title
-p
- strong= model_class.human_attribute_name(:start_date) + ':'
- br
- = @game.start_date
-p
- strong= model_class.human_attribute_name(:duration) + ':'
- br
- = @game.duration
+ p
+ strong= Game.human_attribute_name(:title) + ':'
+ br
+ = @game.title
+-unless user_signed_in?
+ p
+ strong= Game.human_attribute_name(:start_date) + ':'
+ br
+ = @game.start_date
+ p
+ strong= Game.human_attribute_name(:start_date) + ':'
+ br
+ = @status
+ .form-actions
+ = link_to t('.back', :default => t("helpers.links.back")), games_path, :class => 'btn'
-.form-actions
- = link_to t('.back', :default => t("helpers.links.back")), games_path, :class => 'btn'
+ = link_to t('.back', :default => t("helpers.links.back")), new_hint_path(game: @game.id), :class => 'btn'
- = link_to t('.back', :default => t("helpers.links.back")), new_hint_path(game: @game.id), :class => 'btn'
-
- = link_to t('.edit', :default => t("helpers.links.edit")), edit_game_path(@game), :class => 'btn'
- '
- = link_to t('.destroy', :default => t("helpers.links.destroy")), game_path(@game), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_game_path(@game), :class => 'btn'
+ '
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), game_path(@game), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
+-else
+ -@task_codes_count.each do |num|
+ -render partial: code_compare_form
\ No newline at end of file
diff --git a/app/views/hints/_form.html.slim b/app/views/hints/_form.html.slim
index 3cc8f97..5ef2398 100644
--- a/app/views/hints/_form.html.slim
+++ b/app/views/hints/_form.html.slim
@@ -8,7 +8,7 @@
.controls
= f.text_field :queue_number, :class => 'text_field'
.controls
- = f.hidden_field :game, value: @game
+ = f.hidden_field :task, value: @game
.form-actions
= f.submit nil, :class => 'btn btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")), hints_path, :class => 'btn'
diff --git a/app/views/hints/new.html.slim b/app/views/hints/new.html.slim
index 8ac3066..e2f3e42 100644
--- a/app/views/hints/new.html.slim
+++ b/app/views/hints/new.html.slim
@@ -1,4 +1,10 @@
-- model_class = Hint
div class="page-header"
- h1=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize
-= render :partial => "form"
+-unless @cant_add
+ -if notice
+ h1 = notice
+ h1=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => Hint.model_name.human.titleize
+ = render :partial => "form"
+-else
+ h1 You can't add more hints for this task
+
+
diff --git a/app/views/home/game_code_compares.html.slim b/app/views/home/game_code_compares.html.slim
deleted file mode 100644
index fec76fd..0000000
--- a/app/views/home/game_code_compares.html.slim
+++ /dev/null
@@ -1,10 +0,0 @@
-- if @game.state >= 0
- table class="table table-striped"
- tbody
- - @game_codes.each do |game_code|
- tr
- td= render partial: form
-- else
- div id="main"
- p
- span class="redbox" Game was not started
\ No newline at end of file
diff --git a/app/views/home/index.html.slim b/app/views/home/index.html.slim
index 23a8d94..7edbf87 100644
--- a/app/views/home/index.html.slim
+++ b/app/views/home/index.html.slim
@@ -10,14 +10,12 @@
th=t '.actions', :default => t("helpers.actions")
tbody
- @games.each do |game|
- tr
- //td= link_to game.id, game_path(game)
- td= game.title
- td= game.start_date
- td= game.duration
- td=l game.created_at
- td
- = link_to "Subscribe", {controller: "user_games", action: "create", user_game: {game_id: game.id}}, :class => 'btn btn-mini'
+ - if game.state == 0
+ tr
+ td= game.title
+ td= game.start_date
+ td
+ = link_to "Join", {controller: "user_games", action: "create", user_game: {game_id: game.id}}, :class => 'btn btn-mini'
- else
div id="main"
diff --git a/app/views/tasks/_form.html.slim b/app/views/tasks/_form.html.slim
new file mode 100644
index 0000000..6af4282
--- /dev/null
+++ b/app/views/tasks/_form.html.slim
@@ -0,0 +1,13 @@
+= form_for @task, :html => { :class => "form-horizontal" } do |f|
+ .control-group
+ = f.label :task_text, :class => 'control-label'
+ .controls
+ = f.text_field :task_text, :class => 'text_field'
+ .control-group
+ = f.label :points, :class => 'control-label'
+ .controls
+ = f.text_field :points, :class => 'text_field'
+ .form-actions
+ = f.submit nil, :class => 'btn btn-primary'
+ '
+ = link_to t('.cancel', :default => t("helpers.links.cancel")), tasks_path, :class => 'btn'
diff --git a/app/views/tasks/edit.html.slim b/app/views/tasks/edit.html.slim
new file mode 100644
index 0000000..b186334
--- /dev/null
+++ b/app/views/tasks/edit.html.slim
@@ -0,0 +1,4 @@
+- model_class = Task
+div class="page-header"
+ h1=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize
+= render :partial => "form"
diff --git a/app/views/tasks/index.html.slim b/app/views/tasks/index.html.slim
new file mode 100644
index 0000000..399f488
--- /dev/null
+++ b/app/views/tasks/index.html.slim
@@ -0,0 +1,25 @@
+- model_class = Task
+div class="page-header"
+ h1=t '.title', :default => model_class.model_name.human.pluralize.titleize
+table class="table table-striped"
+ thead
+ tr
+ th= model_class.human_attribute_name(:id)
+ th= model_class.human_attribute_name(:task_text)
+ th= model_class.human_attribute_name(:points)
+ th= model_class.human_attribute_name(:created_at)
+ th=t '.actions', :default => t("helpers.actions")
+ tbody
+ - @tasks.each do |task|
+ tr
+ td= link_to task.id, task_path(task)
+ td= task.task_text
+ td= task.points
+ td=l task.created_at
+ td
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_task_path(task), :class => 'btn btn-mini'
+ '
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), task_path(task), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-mini btn-danger'
+
+= link_to t('.new', :default => t("helpers.links.new")), new_task_path, :class => 'btn btn-primary'
+
diff --git a/app/views/tasks/index.json.jbuilder b/app/views/tasks/index.json.jbuilder
new file mode 100644
index 0000000..5008e50
--- /dev/null
+++ b/app/views/tasks/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@tasks) do |task|
+ json.extract! task, :id
+ json.url task_url(task, format: :json)
+end
diff --git a/app/views/tasks/new.html.slim b/app/views/tasks/new.html.slim
new file mode 100644
index 0000000..0a0930b
--- /dev/null
+++ b/app/views/tasks/new.html.slim
@@ -0,0 +1,4 @@
+- model_class = Task
+div class="page-header"
+ h1=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize
+= render :partial => "form"
diff --git a/app/views/tasks/show.html.slim b/app/views/tasks/show.html.slim
new file mode 100644
index 0000000..a8e56d0
--- /dev/null
+++ b/app/views/tasks/show.html.slim
@@ -0,0 +1,19 @@
+- model_class = Task
+div class="page-header"
+ h1=t '.title', :default => model_class.model_name.human.titleize
+
+p
+ strong= model_class.human_attribute_name(:task_text) + ':'
+ br
+ = @task.task_text
+p
+ strong= model_class.human_attribute_name(:points) + ':'
+ br
+ = @task.points
+
+.form-actions
+ = link_to t('.back', :default => t("helpers.links.back")), tasks_path, :class => 'btn'
+ '
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_task_path(@task), :class => 'btn'
+ '
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), task_path(@task), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
diff --git a/app/views/tasks/show.json.jbuilder b/app/views/tasks/show.json.jbuilder
new file mode 100644
index 0000000..f03fde3
--- /dev/null
+++ b/app/views/tasks/show.json.jbuilder
@@ -0,0 +1 @@
+json.extract! @task, :id, :created_at, :updated_at
diff --git a/app/views/user_games/_form.html.slim b/app/views/user_games/_form.html.slim
index 6acd66a..3c49db0 100644
--- a/app/views/user_games/_form.html.slim
+++ b/app/views/user_games/_form.html.slim
@@ -14,4 +14,4 @@
.form-actions
= f.submit nil, :class => 'btn btn-primary'
'
- = link_to t('.cancel', :default => t("helpers.links.cancel")), user_games_path, :class => 'btn'
+ = link_to t('.cancel', :default => t("helpers.links.cancel")), user_games_path, :class => 'btn'
\ No newline at end of file
diff --git a/app/views/user_games/index.html.slim b/app/views/user_games/index.html.slim
index 87554e4..b3a2b72 100644
--- a/app/views/user_games/index.html.slim
+++ b/app/views/user_games/index.html.slim
@@ -13,9 +13,13 @@ table class="table table-striped"
tbody
- @games.each do |game|
tr
- td= game.title
+ -if game.state >0
+ td
+ = link_to game.title, game_path({id: game.id}), :method => :get, :class => 'btn btn-mini'
+ -else
+ td= game.title
td= game.start_date
- td= game.duration
- td=l game.created_at
//td
= link_to t('.destroy', :default => t("helpers.links.destroy")), user_game_path({id: game[:user_game]}), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-mini btn-danger'
+
+
diff --git a/app/views/user_games/show.html.slim b/app/views/user_games/show.html.slim
index c3932be..2b7b127 100644
--- a/app/views/user_games/show.html.slim
+++ b/app/views/user_games/show.html.slim
@@ -20,4 +20,4 @@ p
'
= link_to t('.edit', :default => t("helpers.links.edit")), edit_user_game_path(@user_game), :class => 'btn'
'
- = link_to t('.destroy', :default => t("helpers.links.destroy")), user_game_path(@user_game), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), user_game_path(@user_game), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
\ No newline at end of file
diff --git a/config/application.rb b/config/application.rb
index ece6266..a02bece 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -18,7 +18,7 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
+ config.i18n.default_locale = :ru
config.app_generators.scaffold_controller = :scaffold_controller
config.to_prepare do
Devise::SessionsController.skip_before_filter :authorize_admin
diff --git a/config/database.yml b/config/database.yml
deleted file mode 100644
index 6e75b8b..0000000
--- a/config/database.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-# MySQL. Versions 4.1 and 5.0 are recommended.
-#
-# Install the MYSQL driver
-# gem install mysql2
-#
-# Ensure the MySQL gem is defined in your Gemfile
-# gem 'mysql2'
-#
-# And be sure to use new-style password hashing:
-# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
-development:
- adapter: mysql2
- encoding: utf8
- database: nightzone_development
- pool: 5
- username: root
- password: 123456
- socket: /var/run/mysqld/mysqld.sock
-
-# Warning: The database defined as "test" will be erased and
-# re-generated from your development database when you run "rake".
-# Do not set this db to the same as development or production.
-test: &test
- adapter: mysql2
- encoding: utf8
- database: nightzone_test
- pool: 5
- username: root
- password: 123456
- socket: /var/run/mysqld/mysqld.sock
-
-production:
- adapter: mysql2
- encoding: utf8
- database: nightzone_production
- pool: 5
- username: root
- password:
- socket: /var/run/mysqld/mysqld.sock
-
-cucumber:
- <<: *test
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index a71daaa..de15f50 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,95 +1,76 @@
Nightzone::Application.routes.draw do
+ controller :user_hints do
+ post 'user_hints/', :to => 'user_hints#create'
+ delete 'user_hints/:id', :to => 'user_hints#destroy'
+ end
+
+ controller :game_tasks do
+ post 'game_tasks/', :to => 'game_tasks#create'
+ delete 'game_tasks/:id', :to => 'game_tasks#destroy'
+ end
+
controller :code_compares do
post 'code_compares/', :to => 'code_compares#create'
delete 'code_compares/:id', :to => 'code_compares#destroy'
end
- controller :game_codes do
- post 'game_codes/', :to => 'game_codes#create'
- delete 'game_codes/:id', :to => 'game_codes#destroy'
+ controller :user_tasks do
+ post 'user_tasks/', :to => 'user_tasks#create'
+ delete 'user_tasks/:id', :to => 'user_tasks#destroy'
end
- resources :codes
+ resources :user_games
- controller :game_hints do
- post 'game_hints/', :to => 'game_hints#create'
- delete 'game_hints/:id', :to => 'game_hints#destroy'
+ controller :task_hints do
+ post 'task_hints/', :to => 'task_hints#create'
+ delete 'task_hints/:id', :to => 'task_hints#destroy'
end
- resources :user_games
+ controller :task_codes do
+ post 'task_codes/', :to => 'task_codes#create'
+ delete 'task_codes/:id', :to => 'task_codes#destroy'
+ end
- resources :hints
+ resources :tasks
+
+ controller :code_compares do
+ post 'code_compares/', :to => 'code_compares#create'
+ delete 'code_compares/:id', :to => 'code_compares#destroy'
+ end
+
+ controller :game_codes do
+ post 'game_codes/', :to => 'game_codes#create'
+ delete 'game_codes/:id', :to => 'game_codes#destroy'
+ end
controller :admin_games do
post 'admin_games/', :to => 'admin_games#create'
delete 'admin_games/:id', :to => 'admin_games#destroy'
end
+ resources :codes
+
+ resources :hints
+
resources :games
devise_for :users
get "home/index"
- get "home/game_code_compares"
- post "home/create_code_compare"
+ controller :games do
+ get "start_game/:id" => "games#start_game"
+ get "finish_game/:id" => "games#finish_game"
+ end
+
+ controller :tasks do
+ get "raise_hint/:id" => "tasks#raise_hint"
+ end
+
+ #get "home/game_tasks_compares"
+ #post "home/create_code_compare"
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
- # The priority is based upon order of creation: first created -> highest priority.
- # See how all your routes lay out with "rake routes".
-
- # You can have the root of your site routed with "root"
- # root 'welcome#index'
-
- # Example of regular route:
- # get 'products/:id' => 'catalog#view'
-
- # Example of named route that can be invoked with purchase_url(id: product.id)
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
-
- # Example resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Example resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Example resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Example resource route with more complex sub-resources:
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', on: :collection
- # end
- # end
-
- # Example resource route with concerns:
- # concern :toggleable do
- # post 'toggle'
- # end
- # resources :posts, concerns: :toggleable
- # resources :photos, concerns: :toggleable
-
- # Example resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
root :to => "home#index"
end
diff --git a/db/migrate/20140112202751_create_games.rb b/db/migrate/20140112202751_create_games.rb
index 685e4e6..5d8ed96 100644
--- a/db/migrate/20140112202751_create_games.rb
+++ b/db/migrate/20140112202751_create_games.rb
@@ -3,7 +3,6 @@ def change
create_table :games do |t|
t.string :title
t.datetime :start_date
- t.integer :duration
t.timestamps
end
diff --git a/db/migrate/20140113070022_create_game_hints.rb b/db/migrate/20140113070022_create_game_hints.rb
deleted file mode 100644
index 7846c97..0000000
--- a/db/migrate/20140113070022_create_game_hints.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-class CreateGameHints < ActiveRecord::Migration
- def change
- create_table :game_hints do |t|
- t.integer :game_id
- t.integer :hint_id
-
- t.timestamps
- end
- end
-end
diff --git a/db/migrate/20140113101225_add_result_to_user_games.rb b/db/migrate/20140113101225_add_result_to_user_games.rb
deleted file mode 100644
index d8d39db..0000000
--- a/db/migrate/20140113101225_add_result_to_user_games.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class AddResultToUserGames < ActiveRecord::Migration
- def change
- add_column :user_games, :result, :integer, default: 0
- end
-end
diff --git a/db/migrate/20140113170656_create_game_codes.rb b/db/migrate/20140113170656_create_game_codes.rb
deleted file mode 100644
index ffd9e74..0000000
--- a/db/migrate/20140113170656_create_game_codes.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-class CreateGameCodes < ActiveRecord::Migration
- def change
- create_table :game_codes do |t|
- t.integer :game_id
- t.integer :code_id
-
- t.timestamps
- end
- end
-end
diff --git a/db/migrate/20140114114821_add_state_to_games.rb b/db/migrate/20140114114821_add_state_to_games.rb
index db5c972..fb6402c 100644
--- a/db/migrate/20140114114821_add_state_to_games.rb
+++ b/db/migrate/20140114114821_add_state_to_games.rb
@@ -1,5 +1,5 @@
class AddStateToGames < ActiveRecord::Migration
def change
- add_column :games, :state, :integer, default: -1
+ add_column :games, :state, :integer, default: 0
end
end
diff --git a/db/migrate/20140114124729_remove_result_from_code_compares.rb b/db/migrate/20140114124729_remove_result_from_code_compares.rb
deleted file mode 100644
index b9dd83c..0000000
--- a/db/migrate/20140114124729_remove_result_from_code_compares.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class RemoveResultFromCodeCompares < ActiveRecord::Migration
- def change
- remove_column :code_compares, :result
- end
-end
diff --git a/db/migrate/20140115081012_create_tasks.rb b/db/migrate/20140115081012_create_tasks.rb
new file mode 100644
index 0000000..e65b6c9
--- /dev/null
+++ b/db/migrate/20140115081012_create_tasks.rb
@@ -0,0 +1,10 @@
+class CreateTasks < ActiveRecord::Migration
+ def change
+ create_table :tasks do |t|
+ t.text :task_text
+ t.integer :points
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140115082513_create_task_codes.rb b/db/migrate/20140115082513_create_task_codes.rb
new file mode 100644
index 0000000..dcf4fbc
--- /dev/null
+++ b/db/migrate/20140115082513_create_task_codes.rb
@@ -0,0 +1,10 @@
+class CreateTaskCodes < ActiveRecord::Migration
+ def change
+ create_table :task_codes do |t|
+ t.integer :task_id
+ t.integer :code_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140115082554_create_task_hints.rb b/db/migrate/20140115082554_create_task_hints.rb
new file mode 100644
index 0000000..b479f37
--- /dev/null
+++ b/db/migrate/20140115082554_create_task_hints.rb
@@ -0,0 +1,10 @@
+class CreateTaskHints < ActiveRecord::Migration
+ def change
+ create_table :task_hints do |t|
+ t.integer :task_id
+ t.integer :hint_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140113061527_create_user_games.rb b/db/migrate/20140115090623_create_user_games.rb
similarity index 83%
rename from db/migrate/20140113061527_create_user_games.rb
rename to db/migrate/20140115090623_create_user_games.rb
index fdceae3..4a9413f 100644
--- a/db/migrate/20140113061527_create_user_games.rb
+++ b/db/migrate/20140115090623_create_user_games.rb
@@ -3,7 +3,7 @@ def change
create_table :user_games do |t|
t.integer :user_id
t.integer :game_id
-
+ t.integer :result, default: 0
t.timestamps
end
end
diff --git a/db/migrate/20140115090713_create_user_tasks.rb b/db/migrate/20140115090713_create_user_tasks.rb
new file mode 100644
index 0000000..381311a
--- /dev/null
+++ b/db/migrate/20140115090713_create_user_tasks.rb
@@ -0,0 +1,11 @@
+class CreateUserTasks < ActiveRecord::Migration
+ def change
+ create_table :user_tasks do |t|
+ t.integer :user_id
+ t.integer :task_id
+ t.integer :result, default: -1
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140112202805_create_admin_games.rb b/db/migrate/20140115091137_create_admin_games.rb
similarity index 100%
rename from db/migrate/20140112202805_create_admin_games.rb
rename to db/migrate/20140115091137_create_admin_games.rb
diff --git a/db/migrate/20140114083234_create_code_compares.rb b/db/migrate/20140115092553_create_code_compares.rb
similarity index 84%
rename from db/migrate/20140114083234_create_code_compares.rb
rename to db/migrate/20140115092553_create_code_compares.rb
index 316637d..3ab30d9 100644
--- a/db/migrate/20140114083234_create_code_compares.rb
+++ b/db/migrate/20140115092553_create_code_compares.rb
@@ -3,7 +3,6 @@ def change
create_table :code_compares do |t|
t.integer :user_id
t.integer :code_id
- t.integer :result, default: 0
t.timestamps
end
diff --git a/db/migrate/20140115100758_create_game_tasks.rb b/db/migrate/20140115100758_create_game_tasks.rb
new file mode 100644
index 0000000..3272884
--- /dev/null
+++ b/db/migrate/20140115100758_create_game_tasks.rb
@@ -0,0 +1,10 @@
+class CreateGameTasks < ActiveRecord::Migration
+ def change
+ create_table :game_tasks do |t|
+ t.integer :game_id
+ t.integer :task_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140115183545_create_user_hints.rb b/db/migrate/20140115183545_create_user_hints.rb
new file mode 100644
index 0000000..73a7385
--- /dev/null
+++ b/db/migrate/20140115183545_create_user_hints.rb
@@ -0,0 +1,10 @@
+class CreateUserHints < ActiveRecord::Migration
+ def change
+ create_table :user_hints do |t|
+ t.integer :user_id
+ t.integer :hint_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20140115190550_add_state_to_user_games.rb b/db/migrate/20140115190550_add_state_to_user_games.rb
new file mode 100644
index 0000000..354af4c
--- /dev/null
+++ b/db/migrate/20140115190550_add_state_to_user_games.rb
@@ -0,0 +1,5 @@
+class AddStateToUserGames < ActiveRecord::Migration
+ def change
+ add_column :user_games, :state, :integer, default: 0
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1e8943c..84ffca4 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: 20140114124729) do
+ActiveRecord::Schema.define(version: 20140115190550) do
create_table "active_admin_comments", force: true do |t|
t.string "namespace"
@@ -66,16 +66,9 @@
t.datetime "updated_at"
end
- create_table "game_codes", force: true do |t|
+ create_table "game_tasks", force: true do |t|
t.integer "game_id"
- t.integer "code_id"
- t.datetime "created_at"
- t.datetime "updated_at"
- end
-
- create_table "game_hints", force: true do |t|
- t.integer "game_id"
- t.integer "hint_id"
+ t.integer "task_id"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -83,10 +76,9 @@
create_table "games", force: true do |t|
t.string "title"
t.datetime "start_date"
- t.integer "duration"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "state", default: -1
+ t.integer "state", default: 0
end
create_table "hints", force: true do |t|
@@ -96,12 +88,49 @@
t.integer "queue_number"
end
+ create_table "task_codes", force: true do |t|
+ t.integer "task_id"
+ t.integer "code_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "task_hints", force: true do |t|
+ t.integer "task_id"
+ t.integer "hint_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "tasks", force: true do |t|
+ t.text "task_text"
+ t.integer "points"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "user_games", force: true do |t|
t.integer "user_id"
t.integer "game_id"
+ t.integer "result", default: 0
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "state", default: 0
+ end
+
+ create_table "user_hints", force: true do |t|
+ t.integer "user_id"
+ t.integer "hint_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "user_tasks", force: true do |t|
+ t.integer "user_id"
+ t.integer "task_id"
+ t.integer "result", default: -1
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "result", default: 0
end
create_table "users", force: true do |t|
diff --git a/spec/controllers/admin_games_controller_spec.rb b/spec/controllers/admin_games_controller_spec.rb
index 0a4e9e0..f72577c 100644
--- a/spec/controllers/admin_games_controller_spec.rb
+++ b/spec/controllers/admin_games_controller_spec.rb
@@ -1,33 +1,10 @@
require 'spec_helper'
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
describe AdminGamesController do
login_admin
- # This should return the minimal set of attributes required to create a valid
- # AdminGame. As you add validations to AdminGame, be sure to
- # adjust the attributes here as well.
+
let(:valid_attributes) { { "admin_id" => "1" } }
- # This should return the minimal set of values that should be in the session
- # in order to pass any filters (e.g. authentication) defined in
- # AdminGamesController. Be sure to keep this updated too.
let(:valid_session) { {} }
before do
diff --git a/spec/controllers/code_compares_controller_spec.rb b/spec/controllers/code_compares_controller_spec.rb
index c070fab..74d76d3 100644
--- a/spec/controllers/code_compares_controller_spec.rb
+++ b/spec/controllers/code_compares_controller_spec.rb
@@ -1,56 +1,61 @@
require 'spec_helper'
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
describe CodeComparesController do
login_user
- # This should return the minimal set of attributes required to create a valid
- # CodeCompare. As you add validations to CodeCompare, be sure to
- # adjust the attributes here as well.
+
let(:valid_attributes) { { "user_id" => "1" } }
- # This should return the minimal set of values that should be in the session
- # in order to pass any filters (e.g. authentication) defined in
- # CodeComparesController. Be sure to keep this updated too.
let(:valid_session) { {} }
- before do
- @code = FactoryGirl.create(:code)
- @code_compare = FactoryGirl.create(:code_compare, user_id: @user_id, code_id: @code.to_param)
- end
+ let(:task) { create :task }
+ let(:code) { create :code }
+
+ let(:game) { create :game }
+
+ let!(:task_code) { create :task_code, task: task, code: code }
+ let!(:user_task) { create :user_task, task: task, user: @user }
+ let!(:task_game) { create :game_task, game: game, task: task }
+ let!(:user_game) { create :user_game, game: game, user: @user}
describe "POST create" do
describe "with valid params" do
it "creates a new CodeCompare" do
expect {
- post :create, {:code_compare => @code_compare.attributes}, valid_session
+ post :create, {try_text: code.code_string, task: task}, valid_session
}.to change(CodeCompare, :count).by(1)
end
+
+ # I didn't understand what expected to occur here
+ # it "creates a new CodeCompare and change task" do
+ # new_task = create(:task, task_text: "sdgbhdrhndrbhzsgfr")
+ # new_code = create(:code, code_string: "dfbdfbndfgnhdfgdfh")
+ # # @new_user_task = FactoryGirl.build(:user_task, user_id: @user_id, task_id: @new_task.to_param)
+ # # @new_task_code = FactoryGirl.create(:task_code, task_id: @new_task.to_param, code_id: @new_code.to_param)
+ # # @new_task_game = FactoryGirl.create(:game_task, game_id: @game.to_param, task_id: @new_task.to_param)
+ # post :create, {:try_text => code.code_string, task: task}, valid_session
+ # expect(UserTask.last.task_id).to eq(new_task.id)
+ # end
+
+ it "creates a new CodeCompare and end the game of current user" do
+ post :create, {:try_text => code.code_string, task: task}, valid_session
+ expect(user_game.reload.state).to eq(-1)
+ end
+
+ it "creates a new CodeCompare with code mismatched result" do
+ post :create, {:try_text => code.code_string + "sefbgdfgbnfg", task: task}, valid_session
+ expect(response).to redirect_to(game_path(game))
+ end
+
end
end
describe "DELETE destroy" do
it "destroys the requested code_compare" do
+ @code_compare = FactoryGirl.create(:code_compare, user_id: @user_id, code_id: @code.to_param)
expect {
delete :destroy, {:id => @code_compare.to_param}, valid_session
}.to change(CodeCompare, :count).by(-1)
end
end
-end
+end
\ No newline at end of file
diff --git a/spec/controllers/codes_controller_spec.rb b/spec/controllers/codes_controller_spec.rb
index bc7731c..95e3eda 100644
--- a/spec/controllers/codes_controller_spec.rb
+++ b/spec/controllers/codes_controller_spec.rb
@@ -30,7 +30,7 @@
# CodesController. Be sure to keep this updated too.
let(:valid_session) { {} }
before do
- @game = FactoryGirl.create(:game)
+ @task = FactoryGirl.create(:task)
@code = FactoryGirl.create(:code)
@invalid_attributes = FactoryGirl.build(:code, code_string: "ывампывипа").attributes
end
@@ -51,7 +51,7 @@
describe "GET new" do
it "assigns a new code as @code" do
- get :new, {game: @game.to_param}, valid_session
+ get :new, {task: @task.to_param}, valid_session
expect(assigns(:code)).to be_a_new(Code)
end
end
@@ -64,21 +64,27 @@
end
describe "POST create" do
+ before(:each) do
+ @code_post = @code.attributes
+ @code_post[:task] = @task.to_param
+ @code_post_invalid = @invalid_attributes
+ @code_post_invalid[:task] = @task.to_param
+ end
describe "with valid params" do
it "creates a new Code" do
expect {
- post :create, {:code => @code.attributes}, valid_session
+ post :create, {:code => @code_post}, valid_session
}.to change(Code, :count).by(1)
end
it "assigns a newly created code as @code" do
- post :create, {:code => @code.attributes}, valid_session
+ post :create, {:code => @code_post}, valid_session
expect(assigns(:code)).to be_a(Code)
expect(assigns(:code)).to be_persisted
end
it "redirects to the created code" do
- post :create, {:code => @code.attributes}, valid_session
+ post :create, {:code => @code_post}, valid_session
expect(response).to redirect_to(Code.last)
end
end
@@ -86,15 +92,15 @@
describe "with invalid params" do
it "assigns a newly created but unsaved code as @code" do
# Trigger the behavior that occurs when invalid params are submitted
- Code.any_instance.stub(:save).and_return(false)
- post :create, {:code => @invalid_attributes}, valid_session
+ allow_any_instance_of(Code).to receive(:save).and_return(false)
+ post :create, {:code => @code_post_invalid}, valid_session
expect(assigns(:code)).to be_a_new(Code)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
- Code.any_instance.stub(:save).and_return(false)
- post :create, {:code => @invalid_attributes}, valid_session
+ allow_any_instance_of(Code).to receive(:save).and_return(false)
+ post :create, {:code => @code_post_invalid}, valid_session
expect(response).to render_template("new")
end
end
@@ -127,14 +133,14 @@
describe "with invalid params" do
it "assigns the code as @code" do
- Code.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Code).to receive(:save).and_return(false)
put :update, {:id => @code.to_param, :code => @invalid_attributes}, valid_session
expect(assigns(:code)).to eq(@code)
end
it "re-renders the 'edit' template" do
- Code.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Code).to receive(:save).and_return(false)
put :update, {:id => @code.to_param, :code => @invalid_attributes}, valid_session
expect(response).to render_template("edit")
end
diff --git a/spec/controllers/game_hints_controller_spec.rb b/spec/controllers/game_tasks_controller_spec.rb
similarity index 73%
rename from spec/controllers/game_hints_controller_spec.rb
rename to spec/controllers/game_tasks_controller_spec.rb
index 22e2b99..3f0c5c7 100644
--- a/spec/controllers/game_hints_controller_spec.rb
+++ b/spec/controllers/game_tasks_controller_spec.rb
@@ -18,39 +18,39 @@
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
-describe GameHintsController do
+describe GameTasksController do
login_admin
# This should return the minimal set of attributes required to create a valid
- # GameHint. As you add validations to GameHint, be sure to
+ # GameTask. As you add validations to GameTask, be sure to
# adjust the attributes here as well.
let(:valid_attributes) { { "game_id" => "1" } }
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
- # GameHintsController. Be sure to keep this updated too.
+ # GameTasksController. Be sure to keep this updated too.
let(:valid_session) { {} }
before do
@game = FactoryGirl.create(:game)
- @hint = FactoryGirl.create(:hint)
- @game_hint = FactoryGirl.create(:game_hint, game_id: @game.to_param, hint_id: @hint.to_param)
+ @task = FactoryGirl.create(:task)
+ @game_task = FactoryGirl.create(:game_task, game_id: @game.to_param, task_id: @task.to_param)
end
describe "POST create" do
describe "with valid params" do
- it "creates a new GameHint" do
+ it "creates a new GameTask" do
expect {
- post :create, {:game_hint => @game_hint.attributes}, valid_session
- }.to change(GameHint, :count).by(1)
+ post :create, {:game_task => @game_task.attributes}, valid_session
+ }.to change(GameTask, :count).by(1)
end
end
end
describe "DELETE destroy" do
- it "destroys the requested game_hint" do
+ it "destroys the requested game_task" do
expect {
- delete :destroy, {:id => @game_hint.to_param}, valid_session
- }.to change(GameHint, :count).by(-1)
+ delete :destroy, {:id => @game_task.to_param}, valid_session
+ }.to change(GameTask, :count).by(-1)
end
end
diff --git a/spec/controllers/games_controller_spec.rb b/spec/controllers/games_controller_spec.rb
index d5abbf8..fa5bc9b 100644
--- a/spec/controllers/games_controller_spec.rb
+++ b/spec/controllers/games_controller_spec.rb
@@ -32,10 +32,15 @@
before do
@game = FactoryGirl.create(:game)
- @invalid_attributes = FactoryGirl.build(:game, title: "впирапеи", start_date: "01.01.2014 00:00:00".to_datetime, duration: 11).attributes
+ @task = FactoryGirl.create(:task)
+ #@user = FactoryGirl.create(:user)
+ @game_task = FactoryGirl.create(:game_task, game_id: @game.to_param, task_id: @task.to_param)
+ @user_game = FactoryGirl.create(:user_game, user_id: @user_id, game_id: @game.to_param)
+ @invalid_attributes = FactoryGirl.build(:game, title: "впирапеи", start_date: "01.01.2014 00:00:00".to_datetime).attributes
end
describe "GET index" do
+ login_user
it "assigns all games as @games" do
get :index, {}, valid_session
expect(assigns(:games)).to eq([@game])
@@ -50,6 +55,7 @@
end
describe "GET new" do
+ login_user
it "assigns a new game as @game" do
get :new, {}, valid_session
expect(assigns(:game)).to be_a_new(Game)
@@ -86,14 +92,14 @@
describe "with invalid params" do
it "assigns a newly created but unsaved game as @game" do
# Trigger the behavior that occurs when invalid params are submitted
- Game.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Game).to receive(:save).and_return(false)
post :create, {:game => @invalid_attributes}, valid_session
expect(assigns(:game)).to be_a_new(Game)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
- Game.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Game).to receive(:save).and_return(false)
post :create, {:game => @invalid_attributes}, valid_session
expect(response).to render_template("new")
end
@@ -128,14 +134,14 @@
describe "with invalid params" do
it "assigns the game as @game" do
# Trigger the behavior that occurs when invalid params are submitted
- Game.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Game).to receive(:save).and_return(false)
put :update, {:id => @game.to_param, :game => @invalid_attributes}, valid_session
expect(assigns(:game)).to eq(@game)
end
it "re-renders the 'edit' template" do
# Trigger the behavior that occurs when invalid params are submitted
- Game.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Game).to receive(:save).and_return(false)
put :update, {:id => @game.to_param, :game => @invalid_attributes}, valid_session
expect(response).to render_template("edit")
end
@@ -155,4 +161,20 @@
end
end
+ describe "Start game" do
+ it "execute action " do
+ expect {
+ get "start_game", {id: @game.to_param}, valid_session
+ }.to change(UserTask, :count).by(1)
+ end
+ end
+
+ describe "Finish game" do
+ it "execute action " do
+ get "finish_game", {id: @game.to_param}, valid_session
+ expect(Game.find(@game.to_param.to_i).state).to eq(-1)
+ expect(UserGame.find(@user_game.to_param.to_i).state).to eq(-1)
+ end
+ end
+
end
diff --git a/spec/controllers/hints_controller_spec.rb b/spec/controllers/hints_controller_spec.rb
index f8b9d12..094450c 100644
--- a/spec/controllers/hints_controller_spec.rb
+++ b/spec/controllers/hints_controller_spec.rb
@@ -32,9 +32,11 @@
before do
queue_number = rand(1...2)
- @game = FactoryGirl.create(:game)
+ @task = FactoryGirl.create(:task)
@hint = FactoryGirl.create(:hint, queue_number: queue_number)
- @invalid_attributes = FactoryGirl.build(:hint, hint_text: "акпыук").attributes
+ @new_hint = FactoryGirl.build(:hint, queue_number: 3 - queue_number)
+ @task_hint = FactoryGirl.create(:task_hint, task_id: @task.to_param, hint_id: @hint.to_param)
+ @invalid_attributes = FactoryGirl.build(:hint, hint_text: "акпыук", queue_number: 3 - queue_number).attributes
end
describe "GET index" do
@@ -49,13 +51,22 @@
get :show, {:id => @hint.to_param}, valid_session
expect(assigns(:hint)).to eq(@hint)
end
+
end
describe "GET new" do
it "assigns a new hint as @hint" do
- get :new, {game: @game.to_param}, valid_session
+ get :new, {task: @task.to_param}, valid_session
expect(assigns(:hint)).to be_a_new(Hint)
end
+
+ it "check task hints count" do
+ @new_hint = FactoryGirl.create(:hint, hint_text: "gfbdfsbgsdfgbdfg")
+ @new_task_hint = FactoryGirl.create(:task_hint, task_id: @task.to_param, hint_id: @new_hint.to_param)
+ get :show, {:id => @hint.to_param}, valid_session
+ expect(assigns(:hint)).to eq(@hint)
+ end
+
end
describe "GET edit" do
@@ -66,21 +77,27 @@
end
describe "POST create" do
+ before(:each) do
+ @hint_post = @new_hint.attributes
+ @hint_post[:task] = @task.to_param
+ @hint_post_invalid = @invalid_attributes
+ @hint_post_invalid[:task] = @task.to_param
+ end
describe "with valid params" do
it "creates a new Hint" do
expect {
- post :create, {:hint => @hint.attributes}, valid_session
+ post :create, {:hint => @hint_post}, valid_session
}.to change(Hint, :count).by(1)
end
it "assigns a newly created hint as @hint" do
- post :create, {:hint => @hint.attributes}, valid_session
+ post :create, {:hint => @hint_post}, valid_session
expect(assigns(:hint)).to be_a(Hint)
expect(assigns(:hint)).to be_persisted
end
it "redirects to the created hint" do
- post :create, {:hint => @hint.attributes}, valid_session
+ post :create, {:hint => @hint_post}, valid_session
expect(response).to redirect_to(Hint.last)
end
end
@@ -88,15 +105,15 @@
describe "with invalid params" do
it "assigns a newly created but unsaved hint as @hint" do
# Trigger the behavior that occurs when invalid params are submitted
- Hint.any_instance.stub(:save).and_return(false)
- post :create, {:hint => @invalid_attributes}, valid_session
+ allow_any_instance_of(Hint).to receive(:save).and_return(false)
+ post :create, {:hint => @hint_post_invalid}, valid_session
expect(assigns(:hint)).to be_a_new(Hint)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
- Hint.any_instance.stub(:save).and_return(false)
- post :create, {:hint => @invalid_attributes}, valid_session
+ allow_any_instance_of(Hint).to receive(:save).and_return(false)
+ post :create, {:hint => @hint_post_invalid}, valid_session
expect(response).to render_template("new")
end
end
@@ -131,7 +148,7 @@
describe "with invalid params" do
it "assigns the hint as @hint" do
# Trigger the behavior that occurs when invalid params are submitted
- Hint.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Hint).to receive(:save).and_return(false)
put :update, {:id => @hint.to_param, :hint => @invalid_attributes}, valid_session
expect(assigns(:hint)).to eq(@hint)
end
@@ -139,7 +156,7 @@
it "re-renders the 'edit' template" do
hint = Hint.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
- Hint.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(Hint).to receive(:save).and_return(false)
put :update, {:id => @hint.to_param, :hint => @invalid_attributes}, valid_session
expect(response).to render_template("edit")
end
diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb
index 1b58657..2025240 100644
--- a/spec/controllers/home_controller_spec.rb
+++ b/spec/controllers/home_controller_spec.rb
@@ -8,6 +8,7 @@
before do
@game = FactoryGirl.create(:game)
@code = FactoryGirl.create(:code)
+ # @game_code = FactoryGirl.create(:game_code, game_id: @game.to_param, code_id: @code.to_param)
end
describe "GET 'index'" do
@@ -17,19 +18,4 @@
end
end
- describe "GET 'game_code_compares'" do
- it "returns http success" do
- get 'game_code_compares', {game: @game.to_param}, valid_session
- expect(response).to be_success
- end
- end
-
- describe "GET 'create_code_compare'" do
- it "returns http success" do
- expect {
- post "create_code_compare", {game: @game.to_param, try_text: @code.attributes[:code_text]}, valid_session
- }.to change(CodeCompare, :count).by(1)
- end
- end
-
end
diff --git a/spec/controllers/game_codes_controller_spec.rb b/spec/controllers/task_codes_controller_spec.rb
similarity index 69%
rename from spec/controllers/game_codes_controller_spec.rb
rename to spec/controllers/task_codes_controller_spec.rb
index fab2441..5108800 100644
--- a/spec/controllers/game_codes_controller_spec.rb
+++ b/spec/controllers/task_codes_controller_spec.rb
@@ -18,39 +18,40 @@
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
-describe GameCodesController do
+describe TaskCodesController do
login_admin
# This should return the minimal set of attributes required to create a valid
- # GameCode. As you add validations to GameCode, be sure to
+ # TaskCode. As you add validations to TaskCode, be sure to
# adjust the attributes here as well.
- let(:valid_attributes) { { "create" => "MyString" } }
+ let(:valid_attributes) { { "task_id" => "1" } }
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
- # GameCodesController. Be sure to keep this updated too.
+ # TaskCodesController. Be sure to keep this updated too.
let(:valid_session) { {} }
+
before do
- @game = FactoryGirl.create(:game)
- @code= FactoryGirl.create(:code)
- @game_code = FactoryGirl.create(:game_code, game_id: @game.to_param, code_id: @code.to_param)
+ @task = FactoryGirl.create(:task)
+ @code = FactoryGirl.create(:code)
+ @task_code = FactoryGirl.create(:task_code, task_id: @task.to_param, code_id: @code.to_param)
end
- describe "POST create" do
+ describe "POST create" do
describe "with valid params" do
- it "creates a new GameCode" do
+ it "creates a new TaskCode" do
expect {
- post :create, {:game_code => @game_code.attributes}, valid_session
- }.to change(GameCode, :count).by(1)
+ post :create, {:task_code => @task_code.attributes}, valid_session
+ }.to change(TaskCode, :count).by(1)
end
end
- end
+ end
describe "DELETE destroy" do
- it "destroys the requested game_code" do
+ it "destroys the requested task_code" do
expect {
- delete :destroy, {:id => @game_code.to_param}, valid_session
- }.to change(GameCode, :count).by(-1)
+ delete :destroy, {:id => @task_code.to_param}, valid_session
+ }.to change(TaskCode, :count).by(-1)
end
end
diff --git a/spec/controllers/task_hints_controller_spec.rb b/spec/controllers/task_hints_controller_spec.rb
new file mode 100644
index 0000000..b9aa971
--- /dev/null
+++ b/spec/controllers/task_hints_controller_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe TaskHintsController do
+ login_admin
+ # This should return the minimal set of attributes required to create a valid
+ # TaskHint. As you add validations to TaskHint, be sure to
+ # adjust the attributes here as well.
+ let(:valid_attributes) { { "task_id" => "1" } }
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # TaskHintsController. Be sure to keep this updated too.
+ let(:valid_session) { {} }
+
+ before do
+ @hint = FactoryGirl.create(:hint)
+ @task = FactoryGirl.create(:task)
+ @task_hint = FactoryGirl.create(:task_hint, task_id: @game.to_param, hint_id: @hint.to_param)
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new TaskHint" do
+ expect {
+ post :create, {:task_hint => @task.attributes}, valid_session
+ }.to change(TaskHint, :count).by(1)
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested task_hint" do
+ expect {
+ delete :destroy, {:id => @task_hint.to_param}, valid_session
+ }.to change(TaskHint, :count).by(-1)
+ end
+ end
+
+end
diff --git a/spec/controllers/tasks_controller_spec.rb b/spec/controllers/tasks_controller_spec.rb
new file mode 100644
index 0000000..f43b986
--- /dev/null
+++ b/spec/controllers/tasks_controller_spec.rb
@@ -0,0 +1,189 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe TasksController do
+ login_admin
+ # This should return the minimal set of attributes required to create a valid
+ # Task. As you add validations to Task, be sure to
+ # adjust the attributes here as well.
+ let(:valid_attributes) { { } }
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # TasksController. Be sure to keep this updated too.
+ let(:valid_session) { {} }
+
+ before do
+ @game = FactoryGirl.create(:game)
+ @task = FactoryGirl.create(:task)
+ @hint = FactoryGirl.create(:hint)
+ @user = FactoryGirl.create(:user)
+ @user_task = FactoryGirl.create(:user_task, user_id: @user.to_param, task_id: @task.to_param)
+ @task_hint = FactoryGirl.create(:task_hint, task_id: @task.to_param, hint_id: @hint.to_param)
+ @hint2 = FactoryGirl.create(:hint, hint_text: " wvgrawrfswf", queue_number: 2)
+ @task_hint2 = FactoryGirl.create(:task_hint, task_id: @task.to_param, hint_id: @hint2.to_param)
+ #puts Task.first.to_yaml
+ @invalid_attributes = FactoryGirl.build(:task, task_text: "впирапеи").attributes
+ end
+
+ describe "GET index" do
+ it "assigns all tasks as @tasks" do
+ get :index, {}, valid_session
+ expect(assigns(:tasks)).to eq([@task])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested task as @task" do
+ get :show, {:id => @task.to_param}, valid_session
+ expect(assigns(:task)).to eq(@task)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new task as @task" do
+ get :new, {game: @game.to_param}, valid_session
+ expect(assigns(:task)).to be_a_new(Task)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested task as @task" do
+ get :edit, {:id => @task.to_param}, valid_session
+ expect(assigns(:task)).to eq(@task)
+ end
+ end
+
+ describe "POST create" do
+ before(:each) do
+ @task_post = @task.attributes
+ @task_post[:game] = @game.to_param
+ @task_post_invalid = @invalid_attributes
+ @task_post_invalid[:game] = @game.to_param
+ end
+ describe "with valid params" do
+ it "creates a new Task" do
+ expect {
+ post :create, {:task => @task_post}, valid_session
+ }.to change(Task, :count).by(1)
+ end
+
+ it "assigns a newly created task as @task" do
+ post :create, {:task => @task_post}, valid_session
+ expect(assigns(:task)).to be_a(Task)
+ expect(assigns(:task)).to be_persisted
+ end
+
+ it "redirects to the created task" do
+ post :create, {:task =>@task_post}, valid_session
+ expect(response).to redirect_to(Task.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved task as @task" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ allow_any_instance_of(Task).to receive(:save).and_return(false)
+ post :create, {:task => @task_post_invalid}, valid_session
+ expect(assigns(:task)).to be_a_new(Task)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ allow_any_instance_of(Task).to receive(:save).and_return(false)
+ post :create, {:task => @task_post_invalid}, valid_session
+ expect(response).to render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ before (:each) do
+ @valid_attributes = FactoryGirl.build(:task, task_text: "asfvubasdfchnlasidfciojnk").attributes
+ end
+ it "updates the requested task" do
+ # Assuming there are no other tasks in the database, this
+ # specifies that the Task created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ expect_any_instance_of(Task).to receive(:update).with({ "task_text" => "arghbstghset" })
+ put :update, {:id => @task.to_param, :task => { "task_text" => "arghbstghset" }}, valid_session
+ end
+
+ it "assigns the requested task as @task" do
+ put :update, {:id => @task.to_param, :task => @valid_attributes}, valid_session
+ expect(assigns(:task)).to eq(@task)
+ end
+
+ it "redirects to the task" do
+ put :update, {:id => @task.to_param, :task => @valid_attributes}, valid_session
+ expect(response).to redirect_to(@task)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the task as @task" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ allow_any_instance_of(Task).to receive(:save).and_return(false)
+ put :update, {:id => @task.to_param, :task => @invalid_attributes}, valid_session
+ expect(assigns(:task)).to eq(@task)
+ end
+
+ it "re-renders the 'edit' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ allow_any_instance_of(Task).to receive(:save).and_return(false)
+ put :update, {:id => @task.to_param, :task => @invalid_attributes}, valid_session
+ expect(response).to render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested task" do
+ expect {
+ delete :destroy, {:id => @task.to_param}, valid_session
+ }.to change(Task, :count).by(-1)
+ end
+
+ it "redirects to the tasks list" do
+ delete :destroy, {:id => @task.to_param}, valid_session
+ expect(response).to redirect_to(tasks_url)
+ end
+ end
+
+ describe "Raise hint" do
+ it "execute action " do
+ expect {
+ get "raise_hint", {id: @task.to_param}, valid_session
+ }.to change(UserHint, :count).by(1)
+ end
+
+ it "insert second hint" do
+ @user_hint = FactoryGirl.create(:user_hint, user_id: @user.to_param, hint_id: @hint.to_param)
+ expect {
+ get "raise_hint", {id: @task.to_param}, valid_session
+ }.to change(UserHint, :count).by(1)
+ expect(UserHint.last.hint_id).to eq(@hint2.to_param.to_i)
+ end
+
+ end
+
+end
diff --git a/spec/controllers/user_games_controller_spec.rb b/spec/controllers/user_games_controller_spec.rb
index 4ab416b..64fa186 100644
--- a/spec/controllers/user_games_controller_spec.rb
+++ b/spec/controllers/user_games_controller_spec.rb
@@ -5,15 +5,15 @@
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
+# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
+# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
+# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
@@ -70,18 +70,18 @@
describe "with valid params" do
it "creates a new UserGame" do
expect {
- post :create, {:user_game => @user_game.attributes}, valid_session
+ post :create, {game_id: @user_game.attributes["game_id"]}, valid_session
}.to change(UserGame, :count).by(1)
end
it "assigns a newly created user_game as @user_game" do
- post :create, {:user_game => @user_game.attributes}, valid_session
+ post :create, {game_id: @user_game.attributes["game_id"]}, valid_session
expect(assigns(:user_game)).to be_a(UserGame)
expect(assigns(:user_game)).to be_persisted
end
it "redirects to the created users games list" do
- post :create, {:user_game => @user_game.attributes}, valid_session
+ post :create, {game_id: @user_game.attributes["game_id"]}, valid_session
expect(response).to redirect_to(user_games_url)
end
end
@@ -89,15 +89,15 @@
describe "with invalid params" do
it "assigns a newly created but unsaved user_game as @user_game" do
# Trigger the behavior that occurs when invalid params are submitted
- UserGame.any_instance.stub(:save).and_return(false)
- post :create, {:user_game => @invalid_attributes}, valid_session
+ allow_any_instance_of(UserGame).to receive(:save).and_return(false)
+ post :create, {game_id: "123"}, valid_session
expect(assigns(:user_game)).to be_a_new(UserGame)
end
it "redirect the root template" do
# Trigger the behavior that occurs when invalid params are submitted
- UserGame.any_instance.stub(:save).and_return(false)
- post :create, {:user_game => @invalid_attributes}, valid_session
+ allow_any_instance_of(UserGame).to receive(:save).and_return(false)
+ post :create, {game_id: "123"}, valid_session
expect(response).to redirect_to(root_path)
end
end
@@ -106,7 +106,7 @@
describe "PUT update" do
describe "with valid params" do
before (:each) do
- @valid_attributes = FactoryGirl.build(:user_game, user_id: @user_id).attributes
+ @valid_attributes = FactoryGirl.build(:user_game, user_id: @user_id.to_param).attributes
end
it "updates the requested user_game" do
# Assuming there are no other user_games in the database, this
@@ -131,14 +131,14 @@
describe "with invalid params" do
it "assigns the user_game as @user_game" do
# Trigger the behavior that occurs when invalid params are submitted
- UserGame.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(UserGame).to receive(:save).and_return(false)
put :update, {:id => @user_game.to_param, :user_game => @invalid_attributes}, valid_session
expect(assigns(:user_game)).to eq(@user_game)
end
it "re-renders the 'edit' template" do
# Trigger the behavior that occurs when invalid params are submitted
- UserGame.any_instance.stub(:save).and_return(false)
+ allow_any_instance_of(UserGame).to receive(:save).and_return(false)
put :update, {:id => @user_game.to_param, :user_game => @invalid_attributes}, valid_session
expect(response).to render_template("edit")
end
diff --git a/spec/controllers/user_hints_controller_spec.rb b/spec/controllers/user_hints_controller_spec.rb
new file mode 100644
index 0000000..ffc0bcf
--- /dev/null
+++ b/spec/controllers/user_hints_controller_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe UserHintsController do
+ login_user
+ # This should return the minimal set of attributes required to create a valid
+ # UserHint. As you add validations to UserHint, be sure to
+ # adjust the attributes here as well.
+ let(:valid_attributes) { { "user_id" => "1" } }
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # UserHintsController. Be sure to keep this updated too.
+ let(:valid_session) { {} }
+
+ before do
+ @hint = FactoryGirl.create(:hint)
+ @user_hint = FactoryGirl.create(:user_hint, user_id: @user_id, hint_id: @hint.to_param)
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new UserHint" do
+ expect {
+ post :create, {:user_hint => @user_hint.attributes}, valid_session
+ }.to change(UserHint, :count).by(1)
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested user_hint" do
+ expect {
+ delete :destroy, {:id => @user_hint.to_param}, valid_session
+ }.to change(UserHint, :count).by(-1)
+ end
+ end
+
+end
diff --git a/spec/controllers/user_tasks_controller_spec.rb b/spec/controllers/user_tasks_controller_spec.rb
new file mode 100644
index 0000000..cd32571
--- /dev/null
+++ b/spec/controllers/user_tasks_controller_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe UserTasksController do
+ login_user
+ # This should return the minimal set of attributes required to create a valid
+ # UserTask. As you add validations to UserTask, be sure to
+ # adjust the attributes here as well.
+ let(:valid_attributes) { { "user_id" => "1" } }
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # UserTasksController. Be sure to keep this updated too.
+ let(:valid_session) { {} }
+
+ before do
+ result = rand(-1..1)
+ @task = FactoryGirl.create(:task)
+ @user_task = FactoryGirl.create(:user_task, user_id: @user_id, task_id: @task.to_param, result: result)
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new UserTask" do
+ expect {
+ post :create, {:user_task => @user_task.attributes}, valid_session
+ }.to change(UserTask, :count).by(1)
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested user_task" do
+ expect {
+ delete :destroy, {:id => @user_task.to_param}, valid_session
+ }.to change(UserTask, :count).by(-1)
+ end
+ end
+
+end
diff --git a/spec/factories/game_codes.rb b/spec/factories/game_tasks.rb
similarity index 75%
rename from spec/factories/game_codes.rb
rename to spec/factories/game_tasks.rb
index 950cb13..82f7a8f 100644
--- a/spec/factories/game_codes.rb
+++ b/spec/factories/game_tasks.rb
@@ -1,8 +1,8 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
- factory :game_code do
+ factory :game_task do
game_id 1
- code_id 1
+ task_id 1
end
end
diff --git a/spec/factories/games.rb b/spec/factories/games.rb
index 2b60216..3771d14 100644
--- a/spec/factories/games.rb
+++ b/spec/factories/games.rb
@@ -4,6 +4,5 @@
factory :game do
title "new_game"
start_date "01.01.2014 00:00:00".to_datetime
- duration 30
end
end
diff --git a/spec/factories/task_codes.rb b/spec/factories/task_codes.rb
new file mode 100644
index 0000000..2a86be8
--- /dev/null
+++ b/spec/factories/task_codes.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :task_code do
+ task_id 1
+ code_id 1
+ end
+end
diff --git a/spec/factories/game_hints.rb b/spec/factories/task_hints.rb
similarity index 75%
rename from spec/factories/game_hints.rb
rename to spec/factories/task_hints.rb
index 0311333..eec1f39 100644
--- a/spec/factories/game_hints.rb
+++ b/spec/factories/task_hints.rb
@@ -1,8 +1,8 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
- factory :game_hint do
- game_id 1
+ factory :task_hint do
+ task_id 1
hint_id 1
end
end
diff --git a/spec/factories/tasks.rb b/spec/factories/tasks.rb
new file mode 100644
index 0000000..cb61a12
--- /dev/null
+++ b/spec/factories/tasks.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :task do
+ task_text "fgvjnsmgsjkanrfgasrfg"
+ points 10
+ end
+end
diff --git a/spec/factories/user_games.rb b/spec/factories/user_games.rb
index a5b9300..5f71020 100644
--- a/spec/factories/user_games.rb
+++ b/spec/factories/user_games.rb
@@ -4,6 +4,5 @@
factory :user_game do
user_id 1
game_id 1
- result 0
end
end
diff --git a/spec/factories/user_hints.rb b/spec/factories/user_hints.rb
new file mode 100644
index 0000000..d21cac1
--- /dev/null
+++ b/spec/factories/user_hints.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :user_hint do
+ user_id 1
+ hint_id 1
+ end
+end
diff --git a/spec/factories/user_tasks.rb b/spec/factories/user_tasks.rb
new file mode 100644
index 0000000..5788e18
--- /dev/null
+++ b/spec/factories/user_tasks.rb
@@ -0,0 +1,9 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :user_task do
+ user
+ task
+ result -1
+ end
+end
diff --git a/spec/factories/users.rb b/spec/factories/users.rb
index ed348b3..bb9111c 100644
--- a/spec/factories/users.rb
+++ b/spec/factories/users.rb
@@ -2,7 +2,7 @@
FactoryGirl.define do
factory :user do
- email "user@user.com"
+ sequence(:email) { |n| "user#{n}@user.com" }
password "1234567890"
password_confirmation "1234567890"
end
diff --git a/spec/helpers/admin_games_helper_spec.rb b/spec/helpers/admin_games_helper_spec.rb
deleted file mode 100644
index daca0c5..0000000
--- a/spec/helpers/admin_games_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the AdminGamesHelper. For example:
-#
-# describe AdminGamesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe AdminGamesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/code_compares_helper_spec.rb b/spec/helpers/code_compares_helper_spec.rb
deleted file mode 100644
index 7cfab59..0000000
--- a/spec/helpers/code_compares_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the CodeComparesHelper. For example:
-#
-# describe CodeComparesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe CodeComparesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/codes_helper_spec.rb b/spec/helpers/codes_helper_spec.rb
deleted file mode 100644
index d8f4f96..0000000
--- a/spec/helpers/codes_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the CodesHelper. For example:
-#
-# describe CodesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe CodesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/game_codes_helper_spec.rb b/spec/helpers/game_codes_helper_spec.rb
deleted file mode 100644
index f4cec26..0000000
--- a/spec/helpers/game_codes_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the GameCodesHelper. For example:
-#
-# describe GameCodesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe GameCodesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/game_hints_helper_spec.rb b/spec/helpers/game_hints_helper_spec.rb
deleted file mode 100644
index 43d31a3..0000000
--- a/spec/helpers/game_hints_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the GameHintsHelper. For example:
-#
-# describe GameHintsHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe GameHintsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/games_helper_spec.rb b/spec/helpers/games_helper_spec.rb
deleted file mode 100644
index 026e01b..0000000
--- a/spec/helpers/games_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the GamesHelper. For example:
-#
-# describe GamesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe GamesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/hints_helper_spec.rb b/spec/helpers/hints_helper_spec.rb
deleted file mode 100644
index 903f975..0000000
--- a/spec/helpers/hints_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the HintsHelper. For example:
-#
-# describe HintsHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe HintsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb
deleted file mode 100644
index f529425..0000000
--- a/spec/helpers/home_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the HomeHelper. For example:
-#
-# describe HomeHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe HomeHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/helpers/user_games_helper_spec.rb b/spec/helpers/user_games_helper_spec.rb
deleted file mode 100644
index 2069d0d..0000000
--- a/spec/helpers/user_games_helper_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the UserGamesHelper. For example:
-#
-# describe UserGamesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# expect(helper.concat_strings("this","that")).to eq("this that")
-# end
-# end
-# end
-describe UserGamesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/models/admin_game_spec.rb b/spec/models/admin_game_spec.rb
deleted file mode 100644
index 7869230..0000000
--- a/spec/models/admin_game_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe AdminGame do
-
-end
diff --git a/spec/models/admin_user_spec.rb b/spec/models/admin_user_spec.rb
deleted file mode 100644
index 3d15302..0000000
--- a/spec/models/admin_user_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe AdminUser do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/models/code_compare_spec.rb b/spec/models/code_compare_spec.rb
deleted file mode 100644
index 6621939..0000000
--- a/spec/models/code_compare_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe CodeCompare do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/models/game_code_spec.rb b/spec/models/game_code_spec.rb
deleted file mode 100644
index 21305ed..0000000
--- a/spec/models/game_code_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe GameCode do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/models/game_hint_spec.rb b/spec/models/game_hint_spec.rb
deleted file mode 100644
index 7d1e3a6..0000000
--- a/spec/models/game_hint_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe GameHint do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/models/user_game_spec.rb b/spec/models/user_game_spec.rb
deleted file mode 100644
index 444a62d..0000000
--- a/spec/models/user_game_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require 'spec_helper'
-
-describe UserGame do
- it "user games validation checking" do
- user_game_1 = FactoryGirl.create(:user_game)
-
- user_game_1.should be_valid
- end
-end
diff --git a/spec/routing/game_hints_routing_spec.rb b/spec/routing/game_hints_routing_spec.rb
deleted file mode 100644
index 2513cf0..0000000
--- a/spec/routing/game_hints_routing_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "spec_helper"
-
-describe GameHintsController do
-
- before do
- @game = FactoryGirl.create(:game)
- @hint = FactoryGirl.create(:hint)
- @game_hint = FactoryGirl.create(:game_hint, game_id: @game.to_param, hint_id: @hint.to_param)
- end
- describe "routing" do
-
- it "routes to #create" do
- expect(:post => "/game_hints").to route_to("game_hints#create")
- end
-
- it "routes to #destroy" do
- expect(:delete => "/game_hints/#{@game_hint.to_param}").to route_to("game_hints#destroy", :id => "#{@game_hint.to_param}")
- end
-
- end
-end
diff --git a/spec/routing/game_codes_routing_spec.rb b/spec/routing/game_tasks_routing_spec.rb
similarity index 50%
rename from spec/routing/game_codes_routing_spec.rb
rename to spec/routing/game_tasks_routing_spec.rb
index 15124ec..387e5e5 100644
--- a/spec/routing/game_codes_routing_spec.rb
+++ b/spec/routing/game_tasks_routing_spec.rb
@@ -1,14 +1,14 @@
require "spec_helper"
-describe GameCodesController do
+describe GameTasksController do
describe "routing" do
it "routes to #create" do
- expect(:post => "/game_codes").to route_to("game_codes#create")
+ expect(:post => "/game_tasks").to route_to("game_tasks#create")
end
it "routes to #destroy" do
- expect(:delete => "/game_codes/1").to route_to("game_codes#destroy", :id => "1")
+ expect(:delete => "/game_tasks/1").to route_to("game_tasks#destroy", :id => "1")
end
end
diff --git a/spec/routing/task_codes_routing_spec.rb b/spec/routing/task_codes_routing_spec.rb
new file mode 100644
index 0000000..2b7462b
--- /dev/null
+++ b/spec/routing/task_codes_routing_spec.rb
@@ -0,0 +1,15 @@
+require "spec_helper"
+
+describe TaskCodesController do
+ describe "routing" do
+
+ it "routes to #create" do
+ expect(:post => "/task_codes").to route_to("task_codes#create")
+ end
+
+ it "routes to #destroy" do
+ expect(:delete => "/task_codes/1").to route_to("task_codes#destroy", :id => "1")
+ end
+
+ end
+end
diff --git a/spec/routing/task_hints_routing_spec.rb b/spec/routing/task_hints_routing_spec.rb
new file mode 100644
index 0000000..2ed04ea
--- /dev/null
+++ b/spec/routing/task_hints_routing_spec.rb
@@ -0,0 +1,15 @@
+require "spec_helper"
+
+describe TaskHintsController do
+ describe "routing" do
+
+ it "routes to #create" do
+ expect(:post => "/task_hints").to route_to("task_hints#create")
+ end
+
+ it "routes to #destroy" do
+ expect(:delete => "/task_hints/1").to route_to("task_hints#destroy", :id => "1")
+ end
+
+ end
+end
diff --git a/spec/routing/tasks_routing_spec.rb b/spec/routing/tasks_routing_spec.rb
new file mode 100644
index 0000000..808d05c
--- /dev/null
+++ b/spec/routing/tasks_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe TasksController do
+ describe "routing" do
+
+ it "routes to #index" do
+ expect(:get => "/tasks").to route_to("tasks#index")
+ end
+
+ it "routes to #new" do
+ expect(:get => "/tasks/new").to route_to("tasks#new")
+ end
+
+ it "routes to #show" do
+ expect(:get => "/tasks/1").to route_to("tasks#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ expect(:get => "/tasks/1/edit").to route_to("tasks#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ expect(:post => "/tasks").to route_to("tasks#create")
+ end
+
+ it "routes to #update" do
+ expect(:put => "/tasks/1").to route_to("tasks#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ expect(:delete => "/tasks/1").to route_to("tasks#destroy", :id => "1")
+ end
+
+ end
+end
diff --git a/spec/routing/user_hints_routing_spec.rb b/spec/routing/user_hints_routing_spec.rb
new file mode 100644
index 0000000..f643ddc
--- /dev/null
+++ b/spec/routing/user_hints_routing_spec.rb
@@ -0,0 +1,15 @@
+require "spec_helper"
+
+describe UserHintsController do
+ describe "routing" do
+
+ it "routes to #create" do
+ expect(:post => "/user_hints").to route_to("user_hints#create")
+ end
+
+ it "routes to #destroy" do
+ expect(:delete => "/user_hints/1").to route_to("user_hints#destroy", :id => "1")
+ end
+
+ end
+end
diff --git a/spec/routing/user_tasks_routing_spec.rb b/spec/routing/user_tasks_routing_spec.rb
new file mode 100644
index 0000000..9e014e8
--- /dev/null
+++ b/spec/routing/user_tasks_routing_spec.rb
@@ -0,0 +1,15 @@
+require "spec_helper"
+
+describe UserTasksController do
+ describe "routing" do
+
+ it "routes to #create" do
+ expect(:post => "/user_tasks").to route_to("user_tasks#create")
+ end
+
+ it "routes to #destroy" do
+ expect(:delete => "/user_tasks/1").to route_to("user_tasks#destroy", :id => "1")
+ end
+
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index eda9a2d..896586a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -48,9 +48,12 @@
# --seed 1234
config.order = "random"
- config.include Devise::TestHelpers, :type => :controller
- config.extend ControllerMacros, :type => :controller
+ config.include Devise::TestHelpers, type: :controller
+ config.include Devise::TestHelpers, type: :view
+ config.extend ControllerMacros, type: :controller
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
+
+ config.include FactoryGirl::Syntax::Methods
end
diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb
index ff059c5..5592d13 100644
--- a/spec/support/controller_macros.rb
+++ b/spec/support/controller_macros.rb
@@ -11,15 +11,13 @@ def login_admin
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
- @user = FactoryGirl.create(:user)
+ @user = create :user
#@user.confirm!
sign_in @user
@user_id = @user.to_param
end
after(:each) do
User.find(@user_id).destroy
-
-
end
end
end
\ No newline at end of file
diff --git a/spec/views/home/index.html.slim_spec.rb b/spec/views/home/index.html.slim_spec.rb
deleted file mode 100644
index 6a21b7a..0000000
--- a/spec/views/home/index.html.slim_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe "home/index.html.slim" do
- pending "add some examples to (or delete) #{__FILE__}"
-end
diff --git a/spec/views/tasks/edit.html.slim_spec.rb b/spec/views/tasks/edit.html.slim_spec.rb
new file mode 100644
index 0000000..77d6935
--- /dev/null
+++ b/spec/views/tasks/edit.html.slim_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "tasks/edit" do
+ before(:each) do
+ @task = assign(:task, stub_model(Task))
+ end
+
+ it "renders the edit task form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form[action=?][method=?]", task_path(@task), "post" do
+ end
+ end
+end
diff --git a/spec/views/tasks/index.html.slim_spec.rb b/spec/views/tasks/index.html.slim_spec.rb
new file mode 100644
index 0000000..53e529a
--- /dev/null
+++ b/spec/views/tasks/index.html.slim_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe "tasks/index" do
+ before do
+ task1 = FactoryGirl.create(:task)
+ task2 = FactoryGirl.create(:task, :task_text => "fzvbsdfgvsdfgvsfd")
+ assign(:tasks, [
+ task1, task2
+ #stub_model Game, :id => game2.to_param
+ ])
+ end
+
+ it "renders a list of tasks" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ end
+end
diff --git a/spec/views/tasks/new.html.slim_spec.rb b/spec/views/tasks/new.html.slim_spec.rb
new file mode 100644
index 0000000..3b82589
--- /dev/null
+++ b/spec/views/tasks/new.html.slim_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "tasks/new" do
+ before(:each) do
+ assign(:task, stub_model(Task).as_new_record)
+ end
+
+ it "renders new task form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form[action=?][method=?]", tasks_path, "post" do
+ end
+ end
+end
diff --git a/spec/views/tasks/show.html.slim_spec.rb b/spec/views/tasks/show.html.slim_spec.rb
new file mode 100644
index 0000000..d55f204
--- /dev/null
+++ b/spec/views/tasks/show.html.slim_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe "tasks/show" do
+ before(:each) do
+ @task = assign(:task, stub_model(Task))
+ end
+
+ it "renders attributes in
" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ end
+end
diff --git a/spec/views/user_games/index.html.slim_spec.rb b/spec/views/user_games/index.html.slim_spec.rb
index ec6d6b2..c0da63d 100644
--- a/spec/views/user_games/index.html.slim_spec.rb
+++ b/spec/views/user_games/index.html.slim_spec.rb
@@ -5,7 +5,7 @@
game1 = FactoryGirl.create(:game)
game2 = FactoryGirl.create(:game, title: "dsgsdfgsdfgv")
assign(:games, [
- game1, game2
+ game1, game2
])
end
diff --git a/test/controllers/.keep b/test/controllers/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/fixtures/.keep b/test/fixtures/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/helpers/.keep b/test/helpers/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/integration/.keep b/test/integration/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/mailers/.keep b/test/mailers/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/models/.keep b/test/models/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/test_helper.rb b/test/test_helper.rb
deleted file mode 100644
index bc7e05d..0000000
--- a/test/test_helper.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-ENV["RAILS_ENV"] ||= "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- ActiveRecord::Migration.check_pending!
-
- # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
-end