From efc1aad5bca65856889384cd3338b6fe9602d3d0 Mon Sep 17 00:00:00 2001 From: sorgal Date: Wed, 15 Jan 2014 18:01:07 +0400 Subject: [PATCH 1/8] tasks added --- .idea/workspace.xml | 388 ++++++++++-------- ...e_codes.js.coffee => game_tasks.js.coffee} | 0 ...e_hints.js.coffee => task_codes.js.coffee} | 0 app/assets/javascripts/task_hints.js.coffee | 3 + app/assets/javascripts/tasks.js.coffee | 3 + app/assets/javascripts/user_tasks.js.coffee | 3 + ...ame_codes.css.scss => game_tasks.css.scss} | 2 +- app/assets/stylesheets/task_codes.css.scss | 3 + app/assets/stylesheets/task_hints.css.scss | 3 + .../{game_hints.css.scss => tasks.css.scss} | 2 +- app/assets/stylesheets/user_games.css.scss | 2 +- app/assets/stylesheets/user_tasks.css.scss | 3 + app/controllers/code_compares_controller.rb | 18 +- app/controllers/codes_controller.rb | 16 +- ...controller.rb => game_tasks_controller.rb} | 27 +- app/controllers/games_controller.rb | 23 +- app/controllers/hints_controller.rb | 16 +- app/controllers/home_controller.rb | 21 +- app/controllers/task_codes_controller.rb | 38 ++ ...controller.rb => task_hints_controller.rb} | 22 +- app/controllers/tasks_controller.rb | 99 +++++ app/controllers/user_games_controller.rb | 18 +- app/controllers/user_tasks_controller.rb | 40 ++ app/helpers/game_codes_helper.rb | 2 - app/helpers/game_hints_helper.rb | 2 - app/helpers/game_tasks_helper.rb | 2 + app/helpers/task_codes_helper.rb | 2 + app/helpers/task_hints_helper.rb | 2 + app/helpers/tasks_helper.rb | 2 + app/helpers/user_tasks_helper.rb | 2 + app/models/code.rb | 3 +- app/models/code_compare.rb | 2 + app/models/game.rb | 2 - app/models/game_code.rb | 4 - app/models/game_hint.rb | 4 - app/models/game_task.rb | 4 + app/models/hint.rb | 2 +- app/models/task.rb | 7 + app/models/task_code.rb | 4 + app/models/task_hint.rb | 5 + app/models/user.rb | 3 + app/models/user_game.rb | 1 - app/models/user_task.rb | 4 + app/views/codes/_form.html.slim | 2 +- app/views/hints/_form.html.slim | 2 +- app/views/home/game_code_compares.html.slim | 10 - app/views/tasks/_form.html.slim | 13 + app/views/tasks/edit.html.slim | 4 + app/views/tasks/index.html.slim | 25 ++ app/views/tasks/index.json.jbuilder | 4 + app/views/tasks/new.html.slim | 4 + app/views/tasks/show.html.slim | 19 + app/views/tasks/show.json.jbuilder | 1 + app/views/user_games/_form.html.slim | 2 +- app/views/user_games/index.html.slim | 2 + app/views/user_games/show.html.slim | 2 +- config/routes.rb | 47 ++- .../20140113070022_create_game_hints.rb | 10 - ...20140113101225_add_result_to_user_games.rb | 5 - .../20140113170656_create_game_codes.rb | 10 - .../20140114114821_add_state_to_games.rb | 2 +- ...124729_remove_result_from_code_compares.rb | 5 - db/migrate/20140115081012_create_tasks.rb | 10 + .../20140115082513_create_task_codes.rb | 10 + .../20140115082554_create_task_hints.rb | 10 + ...rb => 20140115090623_create_user_games.rb} | 2 +- .../20140115090713_create_user_tasks.rb | 11 + ...b => 20140115091137_create_admin_games.rb} | 0 ...=> 20140115092553_create_code_compares.rb} | 1 - .../20140115100758_create_game_tasks.rb | 10 + db/schema.rb | 44 +- .../code_compares_controller_spec.rb | 32 +- spec/controllers/codes_controller_spec.rb | 20 +- ..._spec.rb => game_tasks_controller_spec.rb} | 22 +- spec/controllers/games_controller_spec.rb | 12 + spec/controllers/hints_controller_spec.rb | 20 +- spec/controllers/home_controller_spec.rb | 16 +- ..._spec.rb => task_codes_controller_spec.rb} | 31 +- .../controllers/task_hints_controller_spec.rb | 57 +++ spec/controllers/tasks_controller_spec.rb | 166 ++++++++ .../controllers/user_games_controller_spec.rb | 8 +- .../controllers/user_tasks_controller_spec.rb | 57 +++ .../{game_codes.rb => game_tasks.rb} | 4 +- spec/factories/task_codes.rb | 8 + .../{game_hints.rb => task_hints.rb} | 4 +- spec/factories/tasks.rb | 8 + spec/factories/user_games.rb | 1 - spec/factories/user_tasks.rb | 9 + ...lper_spec.rb => game_tasks_helper_spec.rb} | 6 +- ...lper_spec.rb => task_codes_helper_spec.rb} | 6 +- spec/helpers/task_hints_helper_spec.rb | 15 + spec/helpers/tasks_helper_spec.rb | 15 + spec/helpers/user_tasks_helper_spec.rb | 15 + .../{game_code_spec.rb => game_task_spec.rb} | 2 +- .../{game_hint_spec.rb => task_code_spec.rb} | 2 +- spec/models/task_hint_spec.rb | 5 + spec/models/task_spec.rb | 5 + spec/models/user_game_spec.rb | 6 +- spec/models/user_task_spec.rb | 5 + spec/routing/game_hints_routing_spec.rb | 21 - ...ing_spec.rb => game_tasks_routing_spec.rb} | 6 +- spec/routing/task_codes_routing_spec.rb | 15 + spec/routing/task_hints_routing_spec.rb | 15 + spec/routing/tasks_routing_spec.rb | 35 ++ spec/routing/user_tasks_routing_spec.rb | 15 + spec/support/controller_macros.rb | 2 - spec/views/tasks/edit.html.slim_spec.rb | 15 + spec/views/tasks/index.html.slim_spec.rb | 17 + spec/views/tasks/new.html.slim_spec.rb | 15 + spec/views/tasks/show.html.slim_spec.rb | 12 + spec/views/user_games/index.html.slim_spec.rb | 2 +- 111 files changed, 1340 insertions(+), 463 deletions(-) rename app/assets/javascripts/{game_codes.js.coffee => game_tasks.js.coffee} (100%) rename app/assets/javascripts/{game_hints.js.coffee => task_codes.js.coffee} (100%) create mode 100644 app/assets/javascripts/task_hints.js.coffee create mode 100644 app/assets/javascripts/tasks.js.coffee create mode 100644 app/assets/javascripts/user_tasks.js.coffee rename app/assets/stylesheets/{game_codes.css.scss => game_tasks.css.scss} (64%) create mode 100644 app/assets/stylesheets/task_codes.css.scss create mode 100644 app/assets/stylesheets/task_hints.css.scss rename app/assets/stylesheets/{game_hints.css.scss => tasks.css.scss} (63%) create mode 100644 app/assets/stylesheets/user_tasks.css.scss rename app/controllers/{game_codes_controller.rb => game_tasks_controller.rb} (55%) create mode 100644 app/controllers/task_codes_controller.rb rename app/controllers/{game_hints_controller.rb => task_hints_controller.rb} (58%) create mode 100644 app/controllers/tasks_controller.rb create mode 100644 app/controllers/user_tasks_controller.rb delete mode 100644 app/helpers/game_codes_helper.rb delete mode 100644 app/helpers/game_hints_helper.rb create mode 100644 app/helpers/game_tasks_helper.rb create mode 100644 app/helpers/task_codes_helper.rb create mode 100644 app/helpers/task_hints_helper.rb create mode 100644 app/helpers/tasks_helper.rb create mode 100644 app/helpers/user_tasks_helper.rb delete mode 100644 app/models/game_code.rb delete mode 100644 app/models/game_hint.rb create mode 100644 app/models/game_task.rb create mode 100644 app/models/task.rb create mode 100644 app/models/task_code.rb create mode 100644 app/models/task_hint.rb create mode 100644 app/models/user_task.rb delete mode 100644 app/views/home/game_code_compares.html.slim create mode 100644 app/views/tasks/_form.html.slim create mode 100644 app/views/tasks/edit.html.slim create mode 100644 app/views/tasks/index.html.slim create mode 100644 app/views/tasks/index.json.jbuilder create mode 100644 app/views/tasks/new.html.slim create mode 100644 app/views/tasks/show.html.slim create mode 100644 app/views/tasks/show.json.jbuilder delete mode 100644 db/migrate/20140113070022_create_game_hints.rb delete mode 100644 db/migrate/20140113101225_add_result_to_user_games.rb delete mode 100644 db/migrate/20140113170656_create_game_codes.rb delete mode 100644 db/migrate/20140114124729_remove_result_from_code_compares.rb create mode 100644 db/migrate/20140115081012_create_tasks.rb create mode 100644 db/migrate/20140115082513_create_task_codes.rb create mode 100644 db/migrate/20140115082554_create_task_hints.rb rename db/migrate/{20140113061527_create_user_games.rb => 20140115090623_create_user_games.rb} (83%) create mode 100644 db/migrate/20140115090713_create_user_tasks.rb rename db/migrate/{20140112202805_create_admin_games.rb => 20140115091137_create_admin_games.rb} (100%) rename db/migrate/{20140114083234_create_code_compares.rb => 20140115092553_create_code_compares.rb} (84%) create mode 100644 db/migrate/20140115100758_create_game_tasks.rb rename spec/controllers/{game_hints_controller_spec.rb => game_tasks_controller_spec.rb} (73%) rename spec/controllers/{game_codes_controller_spec.rb => task_codes_controller_spec.rb} (69%) create mode 100644 spec/controllers/task_hints_controller_spec.rb create mode 100644 spec/controllers/tasks_controller_spec.rb create mode 100644 spec/controllers/user_tasks_controller_spec.rb rename spec/factories/{game_codes.rb => game_tasks.rb} (75%) create mode 100644 spec/factories/task_codes.rb rename spec/factories/{game_hints.rb => task_hints.rb} (75%) create mode 100644 spec/factories/tasks.rb create mode 100644 spec/factories/user_tasks.rb rename spec/helpers/{game_codes_helper_spec.rb => game_tasks_helper_spec.rb} (77%) rename spec/helpers/{game_hints_helper_spec.rb => task_codes_helper_spec.rb} (77%) create mode 100644 spec/helpers/task_hints_helper_spec.rb create mode 100644 spec/helpers/tasks_helper_spec.rb create mode 100644 spec/helpers/user_tasks_helper_spec.rb rename spec/models/{game_code_spec.rb => game_task_spec.rb} (80%) rename spec/models/{game_hint_spec.rb => task_code_spec.rb} (80%) create mode 100644 spec/models/task_hint_spec.rb create mode 100644 spec/models/task_spec.rb create mode 100644 spec/models/user_task_spec.rb delete mode 100644 spec/routing/game_hints_routing_spec.rb rename spec/routing/{game_codes_routing_spec.rb => game_tasks_routing_spec.rb} (50%) create mode 100644 spec/routing/task_codes_routing_spec.rb create mode 100644 spec/routing/task_hints_routing_spec.rb create mode 100644 spec/routing/tasks_routing_spec.rb create mode 100644 spec/routing/user_tasks_routing_spec.rb create mode 100644 spec/views/tasks/edit.html.slim_spec.rb create mode 100644 spec/views/tasks/index.html.slim_spec.rb create mode 100644 spec/views/tasks/new.html.slim_spec.rb create mode 100644 spec/views/tasks/show.html.slim_spec.rb diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bcc6b51..15fdd9c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -23,46 +23,37 @@ - - + + - + - - + + - + - - + + - + - - + + - - - - - - - - - - + @@ -78,57 +69,57 @@ @@ -164,7 +155,6 @@ - @@ -198,6 +188,24 @@ + + @@ -488,6 +522,7 @@ + @@ -498,20 +533,19 @@ - - + - + @@ -522,8 +556,8 @@ - + @@ -544,359 +578,359 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/app/assets/javascripts/game_codes.js.coffee b/app/assets/javascripts/game_tasks.js.coffee similarity index 100% rename from app/assets/javascripts/game_codes.js.coffee rename to app/assets/javascripts/game_tasks.js.coffee diff --git a/app/assets/javascripts/game_hints.js.coffee b/app/assets/javascripts/task_codes.js.coffee similarity index 100% rename from app/assets/javascripts/game_hints.js.coffee rename to app/assets/javascripts/task_codes.js.coffee diff --git a/app/assets/javascripts/task_hints.js.coffee b/app/assets/javascripts/task_hints.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/task_hints.js.coffee @@ -0,0 +1,3 @@ +# 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/tasks.js.coffee b/app/assets/javascripts/tasks.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/tasks.js.coffee @@ -0,0 +1,3 @@ +# 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_tasks.js.coffee b/app/assets/javascripts/user_tasks.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/user_tasks.js.coffee @@ -0,0 +1,3 @@ +# 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/game_codes.css.scss b/app/assets/stylesheets/game_tasks.css.scss similarity index 64% rename from app/assets/stylesheets/game_codes.css.scss rename to app/assets/stylesheets/game_tasks.css.scss index 6497235..e37ba02 100644 --- a/app/assets/stylesheets/game_codes.css.scss +++ b/app/assets/stylesheets/game_tasks.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the game_codes controller here. +// Place all the styles related to the game_tasks 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/task_codes.css.scss b/app/assets/stylesheets/task_codes.css.scss new file mode 100644 index 0000000..4e74da2 --- /dev/null +++ b/app/assets/stylesheets/task_codes.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the task_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/task_hints.css.scss b/app/assets/stylesheets/task_hints.css.scss new file mode 100644 index 0000000..cc2a89d --- /dev/null +++ b/app/assets/stylesheets/task_hints.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the task_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/game_hints.css.scss b/app/assets/stylesheets/tasks.css.scss similarity index 63% rename from app/assets/stylesheets/game_hints.css.scss rename to app/assets/stylesheets/tasks.css.scss index 4198b63..b57862e 100644 --- a/app/assets/stylesheets/game_hints.css.scss +++ b/app/assets/stylesheets/tasks.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the GameHints controller here. +// Place all the styles related to the tasks 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 index 55b461e..20bb9f5 100644 --- a/app/assets/stylesheets/user_games.css.scss +++ b/app/assets/stylesheets/user_games.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the UserGames controller here. +// Place all the styles related to the user_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/user_tasks.css.scss b/app/assets/stylesheets/user_tasks.css.scss new file mode 100644 index 0000000..8d5d305 --- /dev/null +++ b/app/assets/stylesheets/user_tasks.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the user_tasks 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..1f00918 100644 --- a/app/controllers/code_compares_controller.rb +++ b/app/controllers/code_compares_controller.rb @@ -1,7 +1,7 @@ class CodeComparesController < ApplicationController before_action :set_code_compare, only: [:destroy] skip_before_filter :authorize_admin - def create + def create @code_compare = CodeCompare.new(code_compare_params) respond_to do |format| @@ -24,13 +24,13 @@ 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) + 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..c8d03bb 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -1,11 +1,11 @@ class GamesController < ApplicationController - before_action :set_game, only: [:show, :edit, :update, :destroy] + before_action :set_game, only: [:show, :edit, :update, :destroy, :start_game] skip_before_filter :authorize_admin, only: [:index, :show] # GET /games # GET /games.json def index - @games = Game.all + @games = Game.where(state: 0) end # GET /games/1 @@ -73,7 +73,20 @@ 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) - end + def game_params + params.require(:game).permit(:title, :start_date, :duration) + 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| + @user_tasks.create(user_id: @user_game.id, task_id: @game_tasks.first.task_id, result: 0) + end + redirect_to games_path + end + end diff --git a/app/controllers/hints_controller.rb b/app/controllers/hints_controller.rb index 5650bf3..928638b 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] @@ -30,10 +30,10 @@ def edit # POST /hints.json def create @hint = Hint.new(hint_params) - game = params.require(:hint)[:game].to_i + task = params.require(:hint)[:task].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,14 +81,14 @@ 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 end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 7c3997a..3ce1d6f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -6,20 +6,15 @@ def index @games = Game.all 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 + #@code = Code.where(params[:try_text]).joins() + #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..a5b7d9c --- /dev/null +++ b/app/controllers/tasks_controller.rb @@ -0,0 +1,99 @@ +class TasksController < ApplicationController + before_action :set_task, only: [:show, :edit, :update, :destroy] + 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 +end diff --git a/app/controllers/user_games_controller.rb b/app/controllers/user_games_controller.rb index 3c97edb..f23f252 100644 --- a/app/controllers/user_games_controller.rb +++ b/app/controllers/user_games_controller.rb @@ -74,15 +74,15 @@ 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 @@ -91,4 +91,4 @@ def check_game_create redirect_to root_path end end -end +end \ No newline at end of file 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_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..c1cc3c3 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -2,8 +2,6 @@ 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 validate :title, :start_date, :duration, presence: true 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..79bbf6f 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 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..fd7eddb --- /dev/null +++ b/app/models/task.rb @@ -0,0 +1,7 @@ +class Task < ActiveRecord::Base + has_many :task_hints, dependent: :destroy + has_many :task_codes, dependent: :destroy + has_many :user_tasks, 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..55da2f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,9 @@ 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_many :user_tasks, 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_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/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/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/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..bbf8251 100644 --- a/app/views/user_games/index.html.slim +++ b/app/views/user_games/index.html.slim @@ -19,3 +19,5 @@ table class="table table-striped" 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/routes.rb b/config/routes.rb index a71daaa..7645542 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,37 +1,62 @@ Nightzone::Application.routes.draw do + 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" + end + #get "home/game_tasks_compares" + #post "home/create_code_compare" devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self) 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..6ebdd23 --- /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: 0 + + 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/schema.rb b/db/schema.rb index 1e8943c..0e0336f 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: 20140115100758) 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 @@ -86,7 +79,7 @@ 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 +89,41 @@ 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" + end + + create_table "user_tasks", force: true do |t| + t.integer "user_id" + t.integer "task_id" t.integer "result", default: 0 + t.datetime "created_at" + t.datetime "updated_at" end create_table "users", force: true do |t| diff --git a/spec/controllers/code_compares_controller_spec.rb b/spec/controllers/code_compares_controller_spec.rb index c070fab..9999395 100644 --- a/spec/controllers/code_compares_controller_spec.rb +++ b/spec/controllers/code_compares_controller_spec.rb @@ -5,51 +5,51 @@ # 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. -describe CodeComparesController do - login_user +describe AdminGamesController do + login_admin # This should return the minimal set of attributes required to create a valid - # CodeCompare. As you add validations to CodeCompare, be sure to + # AdminGame. As you add validations to AdminGame, be sure to # adjust the attributes here as well. - let(:valid_attributes) { { "user_id" => "1" } } + 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 - # CodeComparesController. Be sure to keep this updated too. + # AdminGamesController. 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) + @game = FactoryGirl.create(:game) + @admin_game = FactoryGirl.create(:admin_game, admin_id: @admin_id, game_id: @game.to_param) end describe "POST create" do describe "with valid params" do - it "creates a new CodeCompare" do + it "creates a new AdminGame" do expect { - post :create, {:code_compare => @code_compare.attributes}, valid_session - }.to change(CodeCompare, :count).by(1) + post :create, {:admin_game => @admin_game.attributes}, valid_session + }.to change(AdminGame, :count).by(1) end end end describe "DELETE destroy" do - it "destroys the requested code_compare" do + it "destroys the requested admin_game" do expect { - delete :destroy, {:id => @code_compare.to_param}, valid_session - }.to change(CodeCompare, :count).by(-1) + delete :destroy, {:id => @admin_game.to_param}, valid_session + }.to change(AdminGame, :count).by(-1) end end diff --git a/spec/controllers/codes_controller_spec.rb b/spec/controllers/codes_controller_spec.rb index bc7731c..8321045 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 @@ -87,14 +93,14 @@ 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 + 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 + post :create, {:code => @code_post_invalid}, valid_session expect(response).to render_template("new") end 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..a3a5d87 100644 --- a/spec/controllers/games_controller_spec.rb +++ b/spec/controllers/games_controller_spec.rb @@ -32,6 +32,10 @@ before do @game = FactoryGirl.create(:game) + @task = FactoryGirl.create(:task) + @user = FactoryGirl.create(:user) + @game_task = FactoryGirl.create(:game_task) + @user_game = FactoryGirl.create(:user_game) @invalid_attributes = FactoryGirl.build(:game, title: "впирапеи", start_date: "01.01.2014 00:00:00".to_datetime, duration: 11).attributes end @@ -155,4 +159,12 @@ end end + describe "Start game" do + it "exuctes action " do + expect { + get "start_game", {id: @game.to_param}, valid_session + }.to change(UserTask, :count).by(1) + end + end + end diff --git a/spec/controllers/hints_controller_spec.rb b/spec/controllers/hints_controller_spec.rb index f8b9d12..c0b2e6a 100644 --- a/spec/controllers/hints_controller_spec.rb +++ b/spec/controllers/hints_controller_spec.rb @@ -32,7 +32,7 @@ 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 end @@ -53,7 +53,7 @@ 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 end @@ -66,21 +66,27 @@ end describe "POST create" do + before(:each) do + @hint_post = @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 @@ -89,14 +95,14 @@ 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 + 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 + post :create, {:hint => @hint_post_invalid}, valid_session expect(response).to render_template("new") end 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..18678c5 --- /dev/null +++ b/spec/controllers/tasks_controller_spec.rb @@ -0,0 +1,166 @@ +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) + #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 + Task.any_instance.stub(: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 + Task.any_instance.stub(: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 + Task.any_instance.stub(: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 + Task.any_instance.stub(: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 + +end diff --git a/spec/controllers/user_games_controller_spec.rb b/spec/controllers/user_games_controller_spec.rb index 4ab416b..5082e10 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. @@ -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 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/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_tasks.rb b/spec/factories/user_tasks.rb new file mode 100644 index 0000000..921b326 --- /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_id 1 + task_id 1 + result 1 + end +end diff --git a/spec/helpers/game_codes_helper_spec.rb b/spec/helpers/game_tasks_helper_spec.rb similarity index 77% rename from spec/helpers/game_codes_helper_spec.rb rename to spec/helpers/game_tasks_helper_spec.rb index f4cec26..b70a9c6 100644 --- a/spec/helpers/game_codes_helper_spec.rb +++ b/spec/helpers/game_tasks_helper_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' # Specs in this file have access to a helper object that includes -# the GameCodesHelper. For example: +# the GameTasksHelper. For example: # -# describe GameCodesHelper do +# describe GameTasksHelper 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 +describe GameTasksHelper do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/helpers/game_hints_helper_spec.rb b/spec/helpers/task_codes_helper_spec.rb similarity index 77% rename from spec/helpers/game_hints_helper_spec.rb rename to spec/helpers/task_codes_helper_spec.rb index 43d31a3..b5bd269 100644 --- a/spec/helpers/game_hints_helper_spec.rb +++ b/spec/helpers/task_codes_helper_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' # Specs in this file have access to a helper object that includes -# the GameHintsHelper. For example: +# the TaskCodesHelper. For example: # -# describe GameHintsHelper do +# describe TaskCodesHelper 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 +describe TaskCodesHelper do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/helpers/task_hints_helper_spec.rb b/spec/helpers/task_hints_helper_spec.rb new file mode 100644 index 0000000..73c21fc --- /dev/null +++ b/spec/helpers/task_hints_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TaskHintsHelper. For example: +# +# describe TaskHintsHelper 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 TaskHintsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/tasks_helper_spec.rb b/spec/helpers/tasks_helper_spec.rb new file mode 100644 index 0000000..c459188 --- /dev/null +++ b/spec/helpers/tasks_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TasksHelper. For example: +# +# describe TasksHelper 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 TasksHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/user_tasks_helper_spec.rb b/spec/helpers/user_tasks_helper_spec.rb new file mode 100644 index 0000000..50132d8 --- /dev/null +++ b/spec/helpers/user_tasks_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the UserTasksHelper. For example: +# +# describe UserTasksHelper 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 UserTasksHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/game_code_spec.rb b/spec/models/game_task_spec.rb similarity index 80% rename from spec/models/game_code_spec.rb rename to spec/models/game_task_spec.rb index 21305ed..ba06088 100644 --- a/spec/models/game_code_spec.rb +++ b/spec/models/game_task_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe GameCode do +describe GameTask do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/game_hint_spec.rb b/spec/models/task_code_spec.rb similarity index 80% rename from spec/models/game_hint_spec.rb rename to spec/models/task_code_spec.rb index 7d1e3a6..ef856c4 100644 --- a/spec/models/game_hint_spec.rb +++ b/spec/models/task_code_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe GameHint do +describe TaskCode do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/task_hint_spec.rb b/spec/models/task_hint_spec.rb new file mode 100644 index 0000000..9b09aa1 --- /dev/null +++ b/spec/models/task_hint_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe TaskHint do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/task_spec.rb b/spec/models/task_spec.rb new file mode 100644 index 0000000..296efd2 --- /dev/null +++ b/spec/models/task_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Task 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 index 444a62d..9e972c4 100644 --- a/spec/models/user_game_spec.rb +++ b/spec/models/user_game_spec.rb @@ -1,9 +1,5 @@ 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 + pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/user_task_spec.rb b/spec/models/user_task_spec.rb new file mode 100644 index 0000000..aed2c9c --- /dev/null +++ b/spec/models/user_task_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe UserTask do + pending "add some examples to (or delete) #{__FILE__}" +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_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/support/controller_macros.rb b/spec/support/controller_macros.rb index ff059c5..8ee25ca 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -18,8 +18,6 @@ def login_user end after(:each) do User.find(@user_id).destroy - - end end end \ No newline at end of file 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 From ad436b0b2412c266d14cbcf27ae266922cdf6ae4 Mon Sep 17 00:00:00 2001 From: sorgal Date: Thu, 16 Jan 2014 08:56:37 +0400 Subject: [PATCH 2/8] games functionality without time functions, normal views, integration tests and with two non-working tests --- .idea/.rakeTasks | 2 +- .idea/workspace.xml | 359 +++++++++--------- app/assets/javascripts/user_hints.js.coffee | 3 + app/assets/stylesheets/user_hints.css.scss | 3 + app/controllers/code_compares_controller.rb | 65 +++- app/controllers/games_controller.rb | 45 ++- app/controllers/hints_controller.rb | 16 +- app/controllers/home_controller.rb | 14 +- app/controllers/tasks_controller.rb | 26 +- app/controllers/user_games_controller.rb | 20 +- app/controllers/user_hints_controller.rb | 42 ++ app/helpers/user_hints_helper.rb | 2 + app/models/game.rb | 3 +- app/models/hint.rb | 2 +- app/models/task.rb | 1 + app/models/user.rb | 1 + app/models/user_hint.rb | 4 + .../_code_compare_form.html.slim} | 4 +- app/views/games/_form.html.slim | 4 - app/views/games/index.html.slim | 3 - app/views/games/show.html.slim | 44 ++- app/views/hints/new.html.slim | 13 +- app/views/home/index.html.slim | 14 +- app/views/user_games/index.html.slim | 8 +- config/routes.rb | 11 + db/migrate/20140112202751_create_games.rb | 1 - .../20140115090713_create_user_tasks.rb | 2 +- .../20140115183545_create_user_hints.rb | 10 + .../20140115190550_add_state_to_user_games.rb | 5 + db/schema.rb | 13 +- .../code_compares_controller_spec.rb | 54 ++- spec/controllers/games_controller_spec.rb | 20 +- spec/controllers/hints_controller_spec.rb | 15 +- spec/controllers/tasks_controller_spec.rb | 23 ++ .../controllers/user_games_controller_spec.rb | 10 +- .../controllers/user_hints_controller_spec.rb | 56 +++ spec/factories/games.rb | 1 - spec/factories/user_hints.rb | 8 + spec/factories/user_tasks.rb | 2 +- spec/helpers/user_hints_helper_spec.rb | 15 + spec/models/user_hint_spec.rb | 5 + spec/routing/user_hints_routing_spec.rb | 15 + 42 files changed, 661 insertions(+), 303 deletions(-) create mode 100644 app/assets/javascripts/user_hints.js.coffee create mode 100644 app/assets/stylesheets/user_hints.css.scss create mode 100644 app/controllers/user_hints_controller.rb create mode 100644 app/helpers/user_hints_helper.rb create mode 100644 app/models/user_hint.rb rename app/views/{home/_form.html.slim => games/_code_compare_form.html.slim} (58%) create mode 100644 db/migrate/20140115183545_create_user_hints.rb create mode 100644 db/migrate/20140115190550_add_state_to_user_games.rb create mode 100644 spec/controllers/user_hints_controller_spec.rb create mode 100644 spec/factories/user_hints.rb create mode 100644 spec/helpers/user_hints_helper_spec.rb create mode 100644 spec/models/user_hint_spec.rb create mode 100644 spec/routing/user_hints_routing_spec.rb diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks index 84c84c5..6047d4f 100644 --- a/.idea/.rakeTasks +++ b/.idea/.rakeTasks @@ -4,4 +4,4 @@ You are allowed to: 1. Remove rake task 2. Add existing rake tasks To add existing rake tasks automatically delete this file and reload the project. ---> +--> diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 15fdd9c..af93d95 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -26,34 +26,34 @@ - + - - + + - + - - + + - + - - + + - + @@ -69,31 +69,7 @@ @@ -202,7 +202,7 @@ + + + + + @@ -516,16 +519,15 @@ - + - - + @@ -534,6 +536,7 @@ + @@ -544,8 +547,8 @@ - + @@ -555,10 +558,10 @@ - + + - @@ -578,359 +581,339 @@ - + - + - + - + - + - + - + - - - + - + - + - + - + - + - - - + - + - + - + - - - + - + - + - + - + - + - + - + - - - + - + - + - + - - - + - + - - - + - + - - - + - + - - - + - + - - - + - + - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/app/assets/javascripts/user_hints.js.coffee b/app/assets/javascripts/user_hints.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/user_hints.js.coffee @@ -0,0 +1,3 @@ +# 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/user_hints.css.scss b/app/assets/stylesheets/user_hints.css.scss new file mode 100644 index 0000000..8f2be89 --- /dev/null +++ b/app/assets/stylesheets/user_hints.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the user_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/controllers/code_compares_controller.rb b/app/controllers/code_compares_controller.rb index 1f00918..86dc2bc 100644 --- a/app/controllers/code_compares_controller.rb +++ b/app/controllers/code_compares_controller.rb @@ -1,17 +1,57 @@ class CodeComparesController < ApplicationController before_action :set_code_compare, only: [:destroy] skip_before_filter :authorize_admin + before_filter :check_code_compare_creation, only: [:create] + before_filter :authenticate_user! + def create - @code_compare = CodeCompare.new(code_compare_params) + #Не совсем понял как получить пароль конкретного юзера из девиза + @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| - 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 } - end + format.html { redirect_to game_path(id: @task_game.game_id), notice: notice } + format.json { head :no_content } end end @@ -33,4 +73,13 @@ def set_code_compare def code_compare_params params.require(:code_compare).permit(:user_id, :code_id) end + + protected + def check_code_compare_creation + unless params[:try_text] && params[:task] + @game_task = GameTask.where(task_id: params[:task].to_i).first + redirect_to game_path(id: @game_task.game_id) + end + end + end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index c8d03bb..48ad355 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -1,16 +1,27 @@ class GamesController < ApplicationController - before_action :set_game, only: [:show, :edit, :update, :destroy, :start_game] + 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 - @games = Game.where(state: 0) + @games = Game.all end # 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 @@ -74,19 +85,41 @@ def set_game # Never trust parameters from the scary internet, only allow the white list through. def game_params - params.require(:game).permit(:title, :start_date, :duration) + 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| - @user_tasks.create(user_id: @user_game.id, task_id: @game_tasks.first.task_id, result: 0) + 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 928638b..f5bf62e 100644 --- a/app/controllers/hints_controller.rb +++ b/app/controllers/hints_controller.rb @@ -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,8 +33,8 @@ def edit # POST /hints # POST /hints.json def create - @hint = Hint.new(hint_params) task = params.require(:hint)[:task].to_i + @hint = Hint.new(hint_params) respond_to do |format| if @hint.save if TaskHint.create(task_id: task, hint_id: @hint.id) @@ -91,6 +95,14 @@ 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 3ce1d6f..7193e8f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,18 +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 create_code_compare - #@code = Code.where(params[:try_text]).joins() - #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/tasks_controller.rb b/app/controllers/tasks_controller.rb index a5b7d9c..b146676 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -1,9 +1,8 @@ class TasksController < ApplicationController - before_action :set_task, only: [:show, :edit, :update, :destroy] + 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 @@ -96,4 +95,27 @@ def no_tasks 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 f23f252..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 } @@ -87,8 +88,15 @@ def user_game_params protected def check_game_create - unless params.require(:user_game) + unless params.require(:game_id) + redirect_to root_path + 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/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/models/game.rb b/app/models/game.rb index c1cc3c3..07da62d 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -2,7 +2,8 @@ class Game < ActiveRecord::Base has_one :admin_game, dependent: :destroy has_many :user_games, 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/hint.rb b/app/models/hint.rb index 79bbf6f..2e4b3bf 100644 --- a/app/models/hint.rb +++ b/app/models/hint.rb @@ -1,5 +1,5 @@ class Hint < ActiveRecord::Base 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 index fd7eddb..0d689f1 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -2,6 +2,7 @@ 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/user.rb b/app/models/user.rb index 55da2f0..18b384d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,6 +5,7 @@ class User < ActiveRecord::Base has_many :code_compares, dependent: :destroy has_many :code_compares, dependent: :destroy has_many :user_tasks, dependent: :destroy + has_many :user_hints, dependent: :destroy devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable 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/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..3ee62a0 100644 --- a/app/views/games/show.html.slim +++ b/app/views/games/show.html.slim @@ -1,25 +1,29 @@ - model_class = Game -div class="page-header" - h1=t '.title', :default => model_class.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 + div class="page-header" + h1=t '.title', :default => model_class.model_name.human.titleize -.form-actions - = link_to t('.back', :default => t("helpers.links.back")), games_path, :class => 'btn' + p + strong= model_class.human_attribute_name(:title) + ':' + br + = @game.title + -unless current_user? + p + strong= model_class.human_attribute_name(:start_date) + ':' + br + = @game.start_date + p + strong= model_class.human_attribute_name(:start_date) + ':' + br + = @status + .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/new.html.slim b/app/views/hints/new.html.slim index 8ac3066..2926f4d 100644 --- a/app/views/hints/new.html.slim +++ b/app/views/hints/new.html.slim @@ -1,4 +1,11 @@ - 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" + div class="page-header" + -unless @cant_add + -if notice + h1 = notice + h1=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize + = render :partial => "form" + -else + h1 You can't add more hints for this task + + 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/user_games/index.html.slim b/app/views/user_games/index.html.slim index bbf8251..b3a2b72 100644 --- a/app/views/user_games/index.html.slim +++ b/app/views/user_games/index.html.slim @@ -13,10 +13,12 @@ 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/config/routes.rb b/config/routes.rb index 7645542..07660f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,10 @@ 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' @@ -54,7 +59,13 @@ get "home/index" 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 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/20140115090713_create_user_tasks.rb b/db/migrate/20140115090713_create_user_tasks.rb index 6ebdd23..381311a 100644 --- a/db/migrate/20140115090713_create_user_tasks.rb +++ b/db/migrate/20140115090713_create_user_tasks.rb @@ -3,7 +3,7 @@ def change create_table :user_tasks do |t| t.integer :user_id t.integer :task_id - t.integer :result, default: 0 + t.integer :result, default: -1 t.timestamps 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 0e0336f..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: 20140115100758) do +ActiveRecord::Schema.define(version: 20140115190550) do create_table "active_admin_comments", force: true do |t| t.string "namespace" @@ -76,7 +76,6 @@ 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: 0 @@ -116,12 +115,20 @@ 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: 0 + t.integer "result", default: -1 t.datetime "created_at" t.datetime "updated_at" end diff --git a/spec/controllers/code_compares_controller_spec.rb b/spec/controllers/code_compares_controller_spec.rb index 9999395..3ea9f88 100644 --- a/spec/controllers/code_compares_controller_spec.rb +++ b/spec/controllers/code_compares_controller_spec.rb @@ -18,39 +18,67 @@ # 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 +describe CodeComparesController do + login_user # This should return the minimal set of attributes required to create a valid - # AdminGame. As you add validations to AdminGame, be sure to + # CodeCompare. As you add validations to CodeCompare, be sure to # adjust the attributes here as well. - let(:valid_attributes) { { "admin_id" => "1" } } + 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 - # AdminGamesController. Be sure to keep this updated too. + # CodeComparesController. Be sure to keep this updated too. let(:valid_session) { {} } before do + @code = FactoryGirl.create(:code) + @task = FactoryGirl.create(:task) @game = FactoryGirl.create(:game) - @admin_game = FactoryGirl.create(:admin_game, admin_id: @admin_id, game_id: @game.to_param) + @user_task = FactoryGirl.create(:user_task, user_id: @user_id, task_id: @task.to_param) + @task_code = FactoryGirl.create(:task_code, task_id: @task.to_param, code_id: @code.to_param) + @task_game = 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) end describe "POST create" do describe "with valid params" do - it "creates a new AdminGame" do + it "creates a new CodeCompare" do expect { - post :create, {:admin_game => @admin_game.attributes}, valid_session - }.to change(AdminGame, :count).by(1) + post :create, {:try_text => @code.attributes["code_string"], task: @task.to_param}, valid_session + }.to change(CodeCompare, :count).by(1) end + + it "creates a new CodeCompare and change task" do + @new_task = FactoryGirl.create(:task, task_text: "sdgbhdrhndrbhzsgfr") + @new_code = FactoryGirl.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.attributes["code_string"], task: @task.to_param}, valid_session + #puts UserTask.count + expect(UserTask.last.task_id).to eq(@new_task.to_param.to_i) + end + + it "creates a new CodeCompare and end the game of current user" do + post :create, {:try_text => @code.attributes["code_string"], task: @task.to_param}, valid_session + expect(UserGame.find(@user_game.to_param.to_i).state).to eq(-1) + end + + it "creates a new CodeCompare with code mismatched result" do + post :create, {:try_text => @code.attributes["code_string"] + "sefbgdfgbnfg", task: @task.to_param}, valid_session + expect(response).to redirect_to(game_path(id: @game.to_param)) + end + end end describe "DELETE destroy" do - it "destroys the requested admin_game" 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 => @admin_game.to_param}, valid_session - }.to change(AdminGame, :count).by(-1) + 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/games_controller_spec.rb b/spec/controllers/games_controller_spec.rb index a3a5d87..e994b78 100644 --- a/spec/controllers/games_controller_spec.rb +++ b/spec/controllers/games_controller_spec.rb @@ -33,13 +33,14 @@ before do @game = FactoryGirl.create(:game) @task = FactoryGirl.create(:task) - @user = FactoryGirl.create(:user) - @game_task = FactoryGirl.create(:game_task) - @user_game = FactoryGirl.create(:user_game) - @invalid_attributes = FactoryGirl.build(:game, title: "впирапеи", start_date: "01.01.2014 00:00:00".to_datetime, duration: 11).attributes + #@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]) @@ -54,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) @@ -160,11 +162,19 @@ end describe "Start game" do - it "exuctes action " 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 c0b2e6a..1f87ba1 100644 --- a/spec/controllers/hints_controller_spec.rb +++ b/spec/controllers/hints_controller_spec.rb @@ -34,7 +34,9 @@ queue_number = rand(1...2) @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,6 +51,7 @@ get :show, {:id => @hint.to_param}, valid_session expect(assigns(:hint)).to eq(@hint) end + end describe "GET new" do @@ -56,6 +59,14 @@ 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 @@ -67,7 +78,7 @@ describe "POST create" do before(:each) do - @hint_post = @hint.attributes + @hint_post = @new_hint.attributes @hint_post[:task] = @task.to_param @hint_post_invalid = @invalid_attributes @hint_post_invalid[:task] = @task.to_param diff --git a/spec/controllers/tasks_controller_spec.rb b/spec/controllers/tasks_controller_spec.rb index 18678c5..e58fb9a 100644 --- a/spec/controllers/tasks_controller_spec.rb +++ b/spec/controllers/tasks_controller_spec.rb @@ -33,6 +33,12 @@ 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 @@ -163,4 +169,21 @@ 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 5082e10..c3c7008 100644 --- a/spec/controllers/user_games_controller_spec.rb +++ b/spec/controllers/user_games_controller_spec.rb @@ -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 @@ -90,14 +90,14 @@ 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 + 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 + post :create, {game_id: "123"}, valid_session expect(response).to redirect_to(root_path) end 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/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/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 index 921b326..86ddf0d 100644 --- a/spec/factories/user_tasks.rb +++ b/spec/factories/user_tasks.rb @@ -4,6 +4,6 @@ factory :user_task do user_id 1 task_id 1 - result 1 + result -1 end end diff --git a/spec/helpers/user_hints_helper_spec.rb b/spec/helpers/user_hints_helper_spec.rb new file mode 100644 index 0000000..87ba482 --- /dev/null +++ b/spec/helpers/user_hints_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the UserHintsHelper. For example: +# +# describe UserHintsHelper 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 UserHintsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_hint_spec.rb b/spec/models/user_hint_spec.rb new file mode 100644 index 0000000..64b6d6c --- /dev/null +++ b/spec/models/user_hint_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe UserHint do + pending "add some examples to (or delete) #{__FILE__}" +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 From dd2d10d612f838bad7f71852351189b807851eea Mon Sep 17 00:00:00 2001 From: Andrei Malyshev Date: Fri, 17 Jan 2014 00:54:33 +0400 Subject: [PATCH 3/8] Removed redmine settings --- .gitignore | 1 + .idea/.generators | 8 - .idea/.name | 1 - .idea/.rakeTasks | 7 - .idea/encodings.xml | 5 - .idea/misc.xml | 5 - .idea/modules.xml | 9 - .idea/nightzone.iml | 225 ----- .../Development__nightzone.xml | 28 - .../Production__nightzone.xml | 28 - .idea/runConfigurations/spec__nightzone.xml | 26 - .idea/runConfigurations/test__nightzone.xml | 28 - .idea/scopes/scope_settings.xml | 5 - .idea/vcs.xml | 7 - .idea/workspace.xml | 923 ------------------ 15 files changed, 1 insertion(+), 1305 deletions(-) delete mode 100644 .idea/.generators delete mode 100644 .idea/.name delete mode 100644 .idea/.rakeTasks delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/nightzone.iml delete mode 100644 .idea/runConfigurations/Development__nightzone.xml delete mode 100644 .idea/runConfigurations/Production__nightzone.xml delete mode 100644 .idea/runConfigurations/spec__nightzone.xml delete mode 100644 .idea/runConfigurations/test__nightzone.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 6a502e9..79b08de 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp +.idea diff --git a/.idea/.generators b/.idea/.generators deleted file mode 100644 index 2f879b8..0000000 --- a/.idea/.generators +++ /dev/null @@ -1,8 +0,0 @@ - - diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 8f00832..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -nightzone \ No newline at end of file diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks deleted file mode 100644 index 6047d4f..0000000 --- a/.idea/.rakeTasks +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index e206d70..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index f440fd1..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 113f7be..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/nightzone.iml b/.idea/nightzone.iml deleted file mode 100644 index 0255447..0000000 --- a/.idea/nightzone.iml +++ /dev/null @@ -1,225 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.idea/runConfigurations/Development__nightzone.xml b/.idea/runConfigurations/Development__nightzone.xml deleted file mode 100644 index 2d3d663..0000000 --- a/.idea/runConfigurations/Development__nightzone.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Production__nightzone.xml b/.idea/runConfigurations/Production__nightzone.xml deleted file mode 100644 index 7c2345b..0000000 --- a/.idea/runConfigurations/Production__nightzone.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/spec__nightzone.xml b/.idea/runConfigurations/spec__nightzone.xml deleted file mode 100644 index fa00905..0000000 --- a/.idea/runConfigurations/spec__nightzone.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/test__nightzone.xml b/.idea/runConfigurations/test__nightzone.xml deleted file mode 100644 index be02d57..0000000 --- a/.idea/runConfigurations/test__nightzone.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index def6a6a..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index af93d95..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,923 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1389592251443 - 1389592251443 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From bf00e84bd279cee3c7b10b6f3bde070dd6bcfef8 Mon Sep 17 00:00:00 2001 From: Andrei Malyshev Date: Fri, 17 Jan 2014 00:58:05 +0400 Subject: [PATCH 4/8] Removed empty assets --- app/assets/javascripts/admin_games.js.coffee | 3 --- app/assets/javascripts/code_compares.js.coffee | 3 --- app/assets/javascripts/codes.js.coffee | 3 --- app/assets/javascripts/game_tasks.js.coffee | 3 --- app/assets/javascripts/games.js.coffee | 3 --- app/assets/javascripts/hints.js.coffee | 3 --- app/assets/javascripts/home.js.coffee | 3 --- app/assets/javascripts/task_codes.js.coffee | 3 --- app/assets/javascripts/task_hints.js.coffee | 3 --- app/assets/javascripts/tasks.js.coffee | 3 --- app/assets/javascripts/user_games.js.coffee | 3 --- app/assets/javascripts/user_hints.js.coffee | 3 --- app/assets/javascripts/user_tasks.js.coffee | 3 --- app/assets/stylesheets/admin_games.css.scss | 3 --- app/assets/stylesheets/code_compares.css.scss | 3 --- app/assets/stylesheets/codes.css.scss | 3 --- app/assets/stylesheets/game_tasks.css.scss | 3 --- app/assets/stylesheets/games.css.scss | 3 --- app/assets/stylesheets/hints.css.scss | 3 --- app/assets/stylesheets/task_codes.css.scss | 3 --- app/assets/stylesheets/task_hints.css.scss | 3 --- app/assets/stylesheets/tasks.css.scss | 3 --- app/assets/stylesheets/user_games.css.scss | 3 --- app/assets/stylesheets/user_hints.css.scss | 3 --- app/assets/stylesheets/user_tasks.css.scss | 3 --- 25 files changed, 75 deletions(-) delete mode 100644 app/assets/javascripts/admin_games.js.coffee delete mode 100644 app/assets/javascripts/code_compares.js.coffee delete mode 100644 app/assets/javascripts/codes.js.coffee delete mode 100644 app/assets/javascripts/game_tasks.js.coffee delete mode 100644 app/assets/javascripts/games.js.coffee delete mode 100644 app/assets/javascripts/hints.js.coffee delete mode 100644 app/assets/javascripts/home.js.coffee delete mode 100644 app/assets/javascripts/task_codes.js.coffee delete mode 100644 app/assets/javascripts/task_hints.js.coffee delete mode 100644 app/assets/javascripts/tasks.js.coffee delete mode 100644 app/assets/javascripts/user_games.js.coffee delete mode 100644 app/assets/javascripts/user_hints.js.coffee delete mode 100644 app/assets/javascripts/user_tasks.js.coffee delete mode 100644 app/assets/stylesheets/admin_games.css.scss delete mode 100644 app/assets/stylesheets/code_compares.css.scss delete mode 100644 app/assets/stylesheets/codes.css.scss delete mode 100644 app/assets/stylesheets/game_tasks.css.scss delete mode 100644 app/assets/stylesheets/games.css.scss delete mode 100644 app/assets/stylesheets/hints.css.scss delete mode 100644 app/assets/stylesheets/task_codes.css.scss delete mode 100644 app/assets/stylesheets/task_hints.css.scss delete mode 100644 app/assets/stylesheets/tasks.css.scss delete mode 100644 app/assets/stylesheets/user_games.css.scss delete mode 100644 app/assets/stylesheets/user_hints.css.scss delete mode 100644 app/assets/stylesheets/user_tasks.css.scss 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_tasks.js.coffee b/app/assets/javascripts/game_tasks.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/game_tasks.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/task_codes.js.coffee b/app/assets/javascripts/task_codes.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/task_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/task_hints.js.coffee b/app/assets/javascripts/task_hints.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/task_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/tasks.js.coffee b/app/assets/javascripts/tasks.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/tasks.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/javascripts/user_hints.js.coffee b/app/assets/javascripts/user_hints.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/user_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/user_tasks.js.coffee b/app/assets/javascripts/user_tasks.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/user_tasks.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_tasks.css.scss b/app/assets/stylesheets/game_tasks.css.scss deleted file mode 100644 index e37ba02..0000000 --- a/app/assets/stylesheets/game_tasks.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the game_tasks 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/task_codes.css.scss b/app/assets/stylesheets/task_codes.css.scss deleted file mode 100644 index 4e74da2..0000000 --- a/app/assets/stylesheets/task_codes.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the task_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/task_hints.css.scss b/app/assets/stylesheets/task_hints.css.scss deleted file mode 100644 index cc2a89d..0000000 --- a/app/assets/stylesheets/task_hints.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the task_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/tasks.css.scss b/app/assets/stylesheets/tasks.css.scss deleted file mode 100644 index b57862e..0000000 --- a/app/assets/stylesheets/tasks.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the tasks 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 20bb9f5..0000000 --- a/app/assets/stylesheets/user_games.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the user_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/user_hints.css.scss b/app/assets/stylesheets/user_hints.css.scss deleted file mode 100644 index 8f2be89..0000000 --- a/app/assets/stylesheets/user_hints.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the user_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_tasks.css.scss b/app/assets/stylesheets/user_tasks.css.scss deleted file mode 100644 index 8d5d305..0000000 --- a/app/assets/stylesheets/user_tasks.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the user_tasks controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ From 486daffbcde591ff8cd752a092e22b6931b18307 Mon Sep 17 00:00:00 2001 From: Andrei Malyshev Date: Fri, 17 Jan 2014 00:58:44 +0400 Subject: [PATCH 5/8] Removed tests unused --- test/controllers/.keep | 0 test/fixtures/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/test_helper.rb | 15 --------------- 7 files changed, 15 deletions(-) delete mode 100644 test/controllers/.keep delete mode 100644 test/fixtures/.keep delete mode 100644 test/helpers/.keep delete mode 100644 test/integration/.keep delete mode 100644 test/mailers/.keep delete mode 100644 test/models/.keep delete mode 100644 test/test_helper.rb 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 From 925c3ccbbf0db1b98407a3be35b7555c3fef51bb Mon Sep 17 00:00:00 2001 From: Andrei Malyshev Date: Fri, 17 Jan 2014 00:59:43 +0400 Subject: [PATCH 6/8] Removed database.yml from VCS --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 79b08de..149667f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /log/*.log /tmp .idea +config/database.yml From 555f682b9533229306810c62b527ee4b7adccc2e Mon Sep 17 00:00:00 2001 From: Andrei Malyshev Date: Fri, 17 Jan 2014 01:07:11 +0400 Subject: [PATCH 7/8] Removed database.yml from VCS and fixed specs --- app/views/games/show.html.slim | 50 +++++++++---------- app/views/hints/new.html.slim | 17 +++---- config/database.yml | 42 ---------------- .../admin_games_controller_spec.rb | 25 +--------- .../code_compares_controller_spec.rb | 25 ---------- spec/spec_helper.rb | 5 +- 6 files changed, 36 insertions(+), 128 deletions(-) delete mode 100644 config/database.yml diff --git a/app/views/games/show.html.slim b/app/views/games/show.html.slim index 3ee62a0..c362063 100644 --- a/app/views/games/show.html.slim +++ b/app/views/games/show.html.slim @@ -1,29 +1,27 @@ -- model_class = Game +div class="page-header" + h1=t '.title', :default => Game.model_name.human.titleize - div class="page-header" - h1=t '.title', :default => model_class.model_name.human.titleize + 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' - p - strong= model_class.human_attribute_name(:title) + ':' - br - = @game.title - -unless current_user? - p - strong= model_class.human_attribute_name(:start_date) + ':' - br - = @game.start_date - p - strong= model_class.human_attribute_name(:start_date) + ':' - br - = @status - .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' - -else - -@task_codes_count.each do |num| - -render partial: code_compare_form \ No newline at end of file + = 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/new.html.slim b/app/views/hints/new.html.slim index 2926f4d..e2f3e42 100644 --- a/app/views/hints/new.html.slim +++ b/app/views/hints/new.html.slim @@ -1,11 +1,10 @@ -- model_class = Hint - div class="page-header" - -unless @cant_add - -if notice - h1 = notice - h1=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize - = render :partial => "form" - -else - h1 You can't add more hints for this task +div class="page-header" +-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/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/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 3ea9f88..5228faa 100644 --- a/spec/controllers/code_compares_controller_spec.rb +++ b/spec/controllers/code_compares_controller_spec.rb @@ -1,33 +1,9 @@ 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 @@ -55,7 +31,6 @@ @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.attributes["code_string"], task: @task.to_param}, valid_session - #puts UserTask.count expect(UserTask.last.task_id).to eq(@new_task.to_param.to_i) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eda9a2d..a71b361 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -48,8 +48,9 @@ # --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) From c6ddfc5cdf7769ade749fe2a558dc0957230d361 Mon Sep 17 00:00:00 2001 From: Andrei Malyshev Date: Fri, 17 Jan 2014 01:45:25 +0400 Subject: [PATCH 8/8] Removed specs unused and refactored specs a bit --- app/controllers/code_compares_controller.rb | 2 +- app/models/user.rb | 3 +- config/application.rb | 2 +- config/routes.rb | 55 ------------------- .../code_compares_controller_spec.rb | 48 ++++++++-------- spec/controllers/codes_controller_spec.rb | 8 +-- spec/controllers/games_controller_spec.rb | 8 +-- spec/controllers/hints_controller_spec.rb | 8 +-- spec/controllers/tasks_controller_spec.rb | 8 +-- .../controllers/user_games_controller_spec.rb | 8 +-- spec/factories/user_tasks.rb | 4 +- spec/factories/users.rb | 2 +- spec/helpers/admin_games_helper_spec.rb | 15 ----- spec/helpers/code_compares_helper_spec.rb | 15 ----- spec/helpers/codes_helper_spec.rb | 15 ----- spec/helpers/game_tasks_helper_spec.rb | 15 ----- spec/helpers/games_helper_spec.rb | 15 ----- spec/helpers/hints_helper_spec.rb | 15 ----- spec/helpers/home_helper_spec.rb | 15 ----- spec/helpers/task_codes_helper_spec.rb | 15 ----- spec/helpers/task_hints_helper_spec.rb | 15 ----- spec/helpers/tasks_helper_spec.rb | 15 ----- spec/helpers/user_games_helper_spec.rb | 15 ----- spec/helpers/user_hints_helper_spec.rb | 15 ----- spec/helpers/user_tasks_helper_spec.rb | 15 ----- spec/models/admin_game_spec.rb | 5 -- spec/models/admin_user_spec.rb | 5 -- spec/models/code_compare_spec.rb | 5 -- spec/models/game_task_spec.rb | 5 -- spec/models/task_code_spec.rb | 5 -- spec/models/task_hint_spec.rb | 5 -- spec/models/task_spec.rb | 5 -- spec/models/user_game_spec.rb | 5 -- spec/models/user_hint_spec.rb | 5 -- spec/models/user_task_spec.rb | 5 -- spec/spec_helper.rb | 2 + spec/support/controller_macros.rb | 2 +- spec/views/home/index.html.slim_spec.rb | 5 -- 38 files changed, 55 insertions(+), 355 deletions(-) delete mode 100644 spec/helpers/admin_games_helper_spec.rb delete mode 100644 spec/helpers/code_compares_helper_spec.rb delete mode 100644 spec/helpers/codes_helper_spec.rb delete mode 100644 spec/helpers/game_tasks_helper_spec.rb delete mode 100644 spec/helpers/games_helper_spec.rb delete mode 100644 spec/helpers/hints_helper_spec.rb delete mode 100644 spec/helpers/home_helper_spec.rb delete mode 100644 spec/helpers/task_codes_helper_spec.rb delete mode 100644 spec/helpers/task_hints_helper_spec.rb delete mode 100644 spec/helpers/tasks_helper_spec.rb delete mode 100644 spec/helpers/user_games_helper_spec.rb delete mode 100644 spec/helpers/user_hints_helper_spec.rb delete mode 100644 spec/helpers/user_tasks_helper_spec.rb delete mode 100644 spec/models/admin_game_spec.rb delete mode 100644 spec/models/admin_user_spec.rb delete mode 100644 spec/models/code_compare_spec.rb delete mode 100644 spec/models/game_task_spec.rb delete mode 100644 spec/models/task_code_spec.rb delete mode 100644 spec/models/task_hint_spec.rb delete mode 100644 spec/models/task_spec.rb delete mode 100644 spec/models/user_game_spec.rb delete mode 100644 spec/models/user_hint_spec.rb delete mode 100644 spec/models/user_task_spec.rb delete mode 100644 spec/views/home/index.html.slim_spec.rb diff --git a/app/controllers/code_compares_controller.rb b/app/controllers/code_compares_controller.rb index 86dc2bc..61a7df9 100644 --- a/app/controllers/code_compares_controller.rb +++ b/app/controllers/code_compares_controller.rb @@ -77,7 +77,7 @@ def code_compare_params protected def check_code_compare_creation unless params[:try_text] && params[:task] - @game_task = GameTask.where(task_id: params[:task].to_i).first + @game_task = GameTask.where(task_id: params[:task]).first redirect_to game_path(id: @game_task.game_id) end end diff --git a/app/models/user.rb b/app/models/user.rb index 18b384d..96d9699 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,8 @@ class User < ActiveRecord::Base has_many :user_games, dependent: :destroy has_many :code_compares, dependent: :destroy has_many :code_compares, dependent: :destroy - has_many :user_tasks, 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 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/routes.rb b/config/routes.rb index 07660f3..de15f50 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,61 +71,6 @@ 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/spec/controllers/code_compares_controller_spec.rb b/spec/controllers/code_compares_controller_spec.rb index 5228faa..74d76d3 100644 --- a/spec/controllers/code_compares_controller_spec.rb +++ b/spec/controllers/code_compares_controller_spec.rb @@ -2,46 +2,48 @@ describe CodeComparesController do login_user + let(:valid_attributes) { { "user_id" => "1" } } let(:valid_session) { {} } - before do - @code = FactoryGirl.create(:code) - @task = FactoryGirl.create(:task) - @game = FactoryGirl.create(:game) - @user_task = FactoryGirl.create(:user_task, user_id: @user_id, task_id: @task.to_param) - @task_code = FactoryGirl.create(:task_code, task_id: @task.to_param, code_id: @code.to_param) - @task_game = 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) - 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, {:try_text => @code.attributes["code_string"], task: @task.to_param}, valid_session + post :create, {try_text: code.code_string, task: task}, valid_session }.to change(CodeCompare, :count).by(1) end - it "creates a new CodeCompare and change task" do - @new_task = FactoryGirl.create(:task, task_text: "sdgbhdrhndrbhzsgfr") - @new_code = FactoryGirl.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.attributes["code_string"], task: @task.to_param}, valid_session - expect(UserTask.last.task_id).to eq(@new_task.to_param.to_i) - 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.attributes["code_string"], task: @task.to_param}, valid_session - expect(UserGame.find(@user_game.to_param.to_i).state).to eq(-1) + 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.attributes["code_string"] + "sefbgdfgbnfg", task: @task.to_param}, valid_session - expect(response).to redirect_to(game_path(id: @game.to_param)) + post :create, {:try_text => code.code_string + "sefbgdfgbnfg", task: task}, valid_session + expect(response).to redirect_to(game_path(game)) end end diff --git a/spec/controllers/codes_controller_spec.rb b/spec/controllers/codes_controller_spec.rb index 8321045..95e3eda 100644 --- a/spec/controllers/codes_controller_spec.rb +++ b/spec/controllers/codes_controller_spec.rb @@ -92,14 +92,14 @@ 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) + 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) + 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 @@ -133,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/games_controller_spec.rb b/spec/controllers/games_controller_spec.rb index e994b78..fa5bc9b 100644 --- a/spec/controllers/games_controller_spec.rb +++ b/spec/controllers/games_controller_spec.rb @@ -92,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 @@ -134,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 diff --git a/spec/controllers/hints_controller_spec.rb b/spec/controllers/hints_controller_spec.rb index 1f87ba1..094450c 100644 --- a/spec/controllers/hints_controller_spec.rb +++ b/spec/controllers/hints_controller_spec.rb @@ -105,14 +105,14 @@ 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) + 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) + 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 @@ -148,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 @@ -156,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/tasks_controller_spec.rb b/spec/controllers/tasks_controller_spec.rb index e58fb9a..f43b986 100644 --- a/spec/controllers/tasks_controller_spec.rb +++ b/spec/controllers/tasks_controller_spec.rb @@ -100,14 +100,14 @@ 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 - Task.any_instance.stub(:save).and_return(false) + 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 - Task.any_instance.stub(:save).and_return(false) + 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 @@ -142,14 +142,14 @@ describe "with invalid params" do it "assigns the task as @task" do # Trigger the behavior that occurs when invalid params are submitted - Task.any_instance.stub(:save).and_return(false) + 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 - Task.any_instance.stub(:save).and_return(false) + 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 diff --git a/spec/controllers/user_games_controller_spec.rb b/spec/controllers/user_games_controller_spec.rb index c3c7008..64fa186 100644 --- a/spec/controllers/user_games_controller_spec.rb +++ b/spec/controllers/user_games_controller_spec.rb @@ -89,14 +89,14 @@ 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) + 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) + 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 @@ -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/factories/user_tasks.rb b/spec/factories/user_tasks.rb index 86ddf0d..5788e18 100644 --- a/spec/factories/user_tasks.rb +++ b/spec/factories/user_tasks.rb @@ -2,8 +2,8 @@ FactoryGirl.define do factory :user_task do - user_id 1 - task_id 1 + 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_tasks_helper_spec.rb b/spec/helpers/game_tasks_helper_spec.rb deleted file mode 100644 index b70a9c6..0000000 --- a/spec/helpers/game_tasks_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 GameTasksHelper. For example: -# -# describe GameTasksHelper 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 GameTasksHelper 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/task_codes_helper_spec.rb b/spec/helpers/task_codes_helper_spec.rb deleted file mode 100644 index b5bd269..0000000 --- a/spec/helpers/task_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 TaskCodesHelper. For example: -# -# describe TaskCodesHelper 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 TaskCodesHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/task_hints_helper_spec.rb b/spec/helpers/task_hints_helper_spec.rb deleted file mode 100644 index 73c21fc..0000000 --- a/spec/helpers/task_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 TaskHintsHelper. For example: -# -# describe TaskHintsHelper 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 TaskHintsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/tasks_helper_spec.rb b/spec/helpers/tasks_helper_spec.rb deleted file mode 100644 index c459188..0000000 --- a/spec/helpers/tasks_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 TasksHelper. For example: -# -# describe TasksHelper 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 TasksHelper 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/helpers/user_hints_helper_spec.rb b/spec/helpers/user_hints_helper_spec.rb deleted file mode 100644 index 87ba482..0000000 --- a/spec/helpers/user_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 UserHintsHelper. For example: -# -# describe UserHintsHelper 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 UserHintsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/user_tasks_helper_spec.rb b/spec/helpers/user_tasks_helper_spec.rb deleted file mode 100644 index 50132d8..0000000 --- a/spec/helpers/user_tasks_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 UserTasksHelper. For example: -# -# describe UserTasksHelper 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 UserTasksHelper 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_task_spec.rb b/spec/models/game_task_spec.rb deleted file mode 100644 index ba06088..0000000 --- a/spec/models/game_task_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe GameTask do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/task_code_spec.rb b/spec/models/task_code_spec.rb deleted file mode 100644 index ef856c4..0000000 --- a/spec/models/task_code_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe TaskCode do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/task_hint_spec.rb b/spec/models/task_hint_spec.rb deleted file mode 100644 index 9b09aa1..0000000 --- a/spec/models/task_hint_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe TaskHint do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/task_spec.rb b/spec/models/task_spec.rb deleted file mode 100644 index 296efd2..0000000 --- a/spec/models/task_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Task 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 9e972c4..0000000 --- a/spec/models/user_game_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe UserGame do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/user_hint_spec.rb b/spec/models/user_hint_spec.rb deleted file mode 100644 index 64b6d6c..0000000 --- a/spec/models/user_hint_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe UserHint do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/user_task_spec.rb b/spec/models/user_task_spec.rb deleted file mode 100644 index aed2c9c..0000000 --- a/spec/models/user_task_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe UserTask do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a71b361..896586a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -54,4 +54,6 @@ 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 8ee25ca..5592d13 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -11,7 +11,7 @@ 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 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