diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml new file mode 100644 index 00000000..0365e34a --- /dev/null +++ b/.github/workflows/rubyonrails.yml @@ -0,0 +1,72 @@ +# This workflow uses actions that are not certified by GitHub. They are +# provided by a third-party and are governed by separate terms of service, +# privacy policy, and support documentation. +# +# This workflow will install a prebuilt Ruby version, install dependencies, and +# run tests and linters. +name: "Ruby on Rails CI" +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + test: + runs-on: ubuntu-18.04 + services: + redis: + image: redis:3 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + postgres: + image: postgres:11 + ports: + - "5432:5432" + env: + POSTGRES_DB: nztrain_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + DATABASE_URL: "postgres://rails:password@127.0.0.1:5432/nztrain_test" + NZIC_DATABASE_URL: "postgres://rails:password@127.0.0.1:5432/nzic_test" + REDIS_HOST: redis + PGGSSENCMODE: "disable" # Workaround for https://www.postgresql.org/message-id/93f7379b-2e2f-db0c-980e-07ebd5de92ff%40crunchydata.com, remove after upgrading pg > 1.0 + steps: + - name: Install libmaxmind + run: | + sudo add-apt-repository ppa:maxmind/ppa + sudo apt-get update + sudo apt-get install -y libmaxminddb0 libmaxminddb-dev mmdb-bin + - name: Checkout code + uses: actions/checkout@v3 + # Add or replace dependency steps here + - name: Install Ruby and gems + uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0 + with: + bundler-cache: true + - name: Setup database schema + run: bundle exec rake db:schema:load + # Add or replace test runners here + - name: Run tests + run: bundle exec rspec + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install Ruby and gems + uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0 + with: + bundler-cache: true + # Add or replace any other lints here + # - name: Security audit dependencies + # run: bin/bundler-audit --update + # - name: Security audit application code + # run: bin/brakeman -q -w2 + # - name: Lint Ruby files + # run: bin/rubocop --parallel diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 00000000..461ab3c0 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 2.4.10 diff --git a/Gemfile b/Gemfile index be67045e..56c65dac 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'rails', '~> 4.0.0' -gem 'nzic_models', github: 'NZOI/nzic_models' -#gem 'nzic_models', path: '../../nzic/nzic_models' - gem 'devise', '~> 3.2.2' gem 'psych', '~> 2.0.2' # part of stdlib, need newer version for safe_load @@ -19,9 +16,6 @@ gem 'jquery-ui-rails', '4.0.5' gem 'jquery-historyjs', '0.2.3' gem 'superfish-rails', '~> 1.6.0' -gem 'forem', github: 'radar/forem', branch: 'rails4' -gem 'forem-redcarpet', github: 'NZOI/forem-redcarpet' - gem "nokogiri", '~> 1.10.8' gem 'redcarpet' #gem 'rmagick', '2.13.2' @@ -40,7 +34,6 @@ gem 'simple_form', '3.0.1' gem 'facebox-rails' gem 'strong_presenter', '~> 0.2.2' gem 'render_anywhere' -gem 'pygments.rb', '0.5.4' gem 'ranked-model', :github => 'mixonic/ranked-model' gem 'pdf-reader' gem 'mechanize' @@ -56,7 +49,7 @@ gem 'world-flags' gem 'jquery-final_countdown-rails' gem 'ruby-duration' -gem 'pg' +gem 'pg', '<1.0' gem 'backup' # Redis and Background Processing @@ -89,10 +82,9 @@ group :development, :test do gem 'capybara' gem 'capybara-email' - gem 'factory_girl_rails' + gem 'factory_bot_rails' gem 'byebug' - gem 'factory_girl'#, '~> 4.0' gem 'ruby_parser' # for declarative_authorization end diff --git a/Gemfile.lock b/Gemfile.lock index fa379b53..c680d1d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,21 +1,3 @@ -GIT - remote: https://github.com/NZOI/forem-redcarpet.git - revision: b9908439463723071d9f2f50290af84ca37042a4 - specs: - forem-redcarpet (1.0.2) - nokogiri - pygments.rb (= 0.5.4) - redcarpet (~> 3.2.2) - -GIT - remote: https://github.com/NZOI/nzic_models.git - revision: 0afa31e8bb8b045d12951a36032b15a768a3c868 - specs: - nzic_models (0.0.2) - loofah - rails (~> 4.0) - redcarpet - GIT remote: https://github.com/mixonic/ranked-model.git revision: 5fd725bb07a331e0fb10ba3f1b0bee15dad8a47f @@ -23,22 +5,6 @@ GIT ranked-model (0.4.0) activerecord (>= 3.1.12) -GIT - remote: https://github.com/radar/forem.git - revision: fb37858a51cfc8fe2ccd113e61af42546091fd27 - branch: rails4 - specs: - forem (1.0.0.beta1) - cancancan (~> 1.7) - decorators (~> 1.0.2) - friendly_id (~> 5.0.0) - gemoji (= 2.1.0) - rails (~> 4.0, != 4.2.3, != 4.2.2, != 4.2.1, != 4.2.0) - sanitize (= 2.0.6) - select2-rails (~> 3.5.4) - simple_form (~> 3.0) - workflow (= 1.0.0) - GEM remote: https://rubygems.org/ specs: @@ -92,7 +58,6 @@ GEM debug_inspector (>= 0.0.1) builder (3.1.4) byebug (9.1.0) - cancancan (1.17.0) capybara (2.17.0) addressable mini_mime (>= 0.1.3) @@ -136,8 +101,6 @@ GEM crass (1.0.5) daemons (1.3.1) debug_inspector (0.0.3) - decorators (1.0.5) - railties (>= 3.0.19) devise (3.2.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -155,19 +118,16 @@ GEM facebox-rails (0.2.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - factory_girl (4.9.0) + factory_bot (4.11.1) activesupport (>= 3.0.0) - factory_girl_rails (4.9.0) - factory_girl (~> 4.9.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) railties (>= 3.0.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) ffi (1.12.2) foreman (0.84.0) thor (~> 0.19.1) - friendly_id (5.0.5) - activerecord (>= 4.0.0) - gemoji (2.1.0) geocoder (1.4.5) has_scope (0.6.0) actionpack (>= 3.2, < 5) @@ -240,9 +200,9 @@ GEM ttfunk pdfkit (0.8.2) pg (0.21.0) + pkg-config (1.5.1) polyamorous (1.1.0) activerecord (>= 3.0) - posix-spawn (0.3.13) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -250,9 +210,6 @@ GEM public_suffix (3.0.1) pundit (0.2.1) activesupport (>= 3.0.0) - pygments.rb (0.5.4) - posix-spawn (~> 0.3.6) - yajl-ruby (~> 1.1.0) qless (0.12.0) metriks (~> 0.9) redis (>= 2.2, < 4.0.0.rc1) @@ -293,7 +250,8 @@ GEM render_anywhere (0.0.12) rails (>= 3.0.7) request_store (1.0.8) - rmagick (2.16.0) + rmagick (5.1.0) + pkg-config (~> 1.4) rqrcode (0.10.1) chunky_png (~> 1.0) rspec-collection_matchers (1.1.3) @@ -320,8 +278,6 @@ GEM sexp_processor (~> 4.9) rubyzip (1.3.0) rusage (0.2.0) - sanitize (2.0.6) - nokogiri (>= 1.4.4) sass (3.5.5) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -333,8 +289,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - select2-rails (3.5.10) - thor (~> 0.14) sentry-raven (0.15.6) faraday (>= 0.7.6) sexp_processor (4.10.0) @@ -406,13 +360,11 @@ GEM whenever (0.10.0) chronic (>= 0.6.3) will_paginate (3.1.6) - workflow (1.0.0) world-flags (0.6.5) hashie (>= 1.2) i18n (>= 0.6) xpath (2.1.0) nokogiri (~> 1.3) - yajl-ruby (1.1.0) yui-compressor (0.12.0) PLATFORMS @@ -434,10 +386,7 @@ DEPENDENCIES coveralls devise (~> 3.2.2) facebox-rails - factory_girl - factory_girl_rails - forem! - forem-redcarpet! + factory_bot_rails foreman geocoder has_scope @@ -451,14 +400,12 @@ DEPENDENCIES mechanize newrelic_rpm nokogiri (~> 1.10.8) - nzic_models! pdf-reader pdfkit - pg + pg (< 1.0) prawn psych (~> 2.0.2) pundit (= 0.2.1) - pygments.rb (= 0.5.4) qless rails (~> 4.0.0) rake (< 11.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index accdf347..16ce7f5d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,7 +11,6 @@ //= require history //= require jquery.facebox //= require jquery.facebox.adapter -//= require forem //= require_self diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 29621572..c5efe221 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -2,7 +2,6 @@ *= require jquery.ui.datepicker *= require jquery.ui.slider *= require scaffold -*= require pygments *= require code *= require sample *= require jquery.facebox @@ -15,7 +14,6 @@ *= require messagebox *= require message *= require fontello -*= require forem/base *= require forum *= require flags/basic *= require flags/flags24 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 70120ad4..cb9b146e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,12 +1,7 @@ class ApplicationController < ActionController::Base - - def forem_user - current_user - end - helper_method :forem_user - include ApplicationHelper include Pundit + layout "scaffold" before_filter :update_last_seen_at @@ -15,6 +10,7 @@ def forem_user before_filter :check_su_loss before_filter :wrong_site before_filter :configure_permitted_parameters, if: :devise_controller? + protect_from_forgery #helper ApplicationHelper diff --git a/app/controllers/nzic/info_controller.rb b/app/controllers/nzic/info_controller.rb deleted file mode 100644 index c8c75823..00000000 --- a/app/controllers/nzic/info_controller.rb +++ /dev/null @@ -1,64 +0,0 @@ -class NZIC::InfoController < ApplicationController - helper NZIC::InfoHelper - #helper 'nzic/info' - - def permitted_params - params.require(:nzic_info).permit(:name, :title, :text) - end - - def index - authorize NZIC::Info, :index? - @infos = policy_scope(NZIC::Info).order(:name) - end - - def show - @info = NZIC::Info.find(params[:name]) - authorize @info, :show? - end - - def new - @info = NZIC::Info.new - authorize @info, :new? - end - - def create - @info = NZIC::Info.new(permitted_params) - authorize @info, :create? - - respond_to do |format| - if @info.save - format.html { redirect_to @info, notice: "Info page created." } - else - format.html { render action: "new" } - end - end - end - - def edit - @info = NZIC::Info.find(params[:name]) - authorize @info, :edit? - end - - def update - @info = NZIC::Info.find(params[:name]) - authorize @info, :update? - - respond_to do |format| - if @info.update_attributes(permitted_params) - format.html { redirect_to @info, notice: "Info page updated." } - else - format.html { render action: "edit" } - end - end - end - - def destroy - @info = NZIC::Info.find(params[:name]) - authorize @info, :destroy? - @info.destroy - - respond_to do |format| - format.html { redirect_to nzic_info_path, notice: "NZIC info page destroyed." } - end - end -end diff --git a/app/controllers/nzic/menu_items_controller.rb b/app/controllers/nzic/menu_items_controller.rb deleted file mode 100644 index 5df20d0f..00000000 --- a/app/controllers/nzic/menu_items_controller.rb +++ /dev/null @@ -1,62 +0,0 @@ -class NZIC::MenuItemsController < ApplicationController - - def permitted_params - params.require(:nzic_menu_item).permit(:name, :link) - end - - def index - authorize NZIC::MenuItem, :index? - @menu_items = policy_scope(NZIC::MenuItem).order(:id) - end - - def show - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :show? - end - - def new - @menu_item = NZIC::MenuItem.new - authorize @menu_item, :new? - end - - def create - @menu_item = NZIC::MenuItem.new(permitted_params) - authorize @menu_item, :create? - - respond_to do |format| - if @menu_item.save - format.html { redirect_to @menu_item, notice: "Menu item created." } - else - format.html { render action: "new" } - end - end - end - - def edit - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :edit? - end - - def update - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :update? - - respond_to do |format| - if @menu_item.update_attributes(permitted_params) - format.html { redirect_to @menu_item, notice: "Menu item updated." } - else - format.html { render action: "edit" } - end - end - end - - def destroy - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :destroy? - @menu_item.destroy - - respond_to do |format| - format.html { redirect_to nzic_menu_item_path, notice: "Menu item destroyed." } - end - end -end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 00000000..1807a2ff --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,4 @@ +class PagesController < ApplicationController + def forum + end +end diff --git a/app/models/user.rb b/app/models/user.rb index c50b77c0..cbc169f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,50 +52,6 @@ def self.find_for_authentication(conditions={}) self.where("email = ?", conditions[:email]).limit(1).first end - def forem_name - username - end - - def forem_admin? - is_admin? || self.has_role?(:forum_admin) - end - - def forem_avatar - avatar.small.url - end - - def can_read_forem_category?(category) - true - end - - def can_read_forem_forums? - true - end - - def can_read_forem_forum?(forum) - true - end - - def can_create_forem_topics?(forum) - if forum.category.name == "Announcements" - forem_admin? - else - persisted? - end - end - - def can_reply_to_forem_topic?(topic) - persisted? - end - - def can_edit_forem_posts?(forum) - persisted? - end - - def can_destroy_forem_posts?(forum) - persisted? - end - def get_solved solved = [] @solved_problems = Problem.select("problems.*, (SELECT MAX(score) FROM submissions WHERE problem_id = problems.id AND user_id = #{self.id}) as score") diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 80be8e43..1db12a95 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -123,20 +123,11 @@ <% if policy(User.new).inspect? %>
| Name | -URL | -Summary | -- | - - - <% @infos.each do |info| %> - |
|---|---|---|---|---|
| <%= link_to info.name, info %> | -<%= "/info/#{info.name}" %> | -
- <%= info.title %> - <%= Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC.new(no_links: true, space_after_headers: true, escape_html: true, nesting_level: 2)).render(info.text).to_s.html_safe %><%#TODO: move to nzic_models helper %> - |
- <%= link_to "Edit", edit_nzic_info_path(info) %> | -<%= "Destroy" %> | -
| ID | -Name | -Link | -- | - - - <% @menu_items.each do |menu| %> - |
|---|---|---|---|---|
| <%= menu.id %> | -<%= link_to menu.name, menu %> | -<%= menu.link %> | -<%= link_to "Edit", edit_nzic_menu_item_path(menu) %> | -<%= "Destroy" %> | -
Name: <%= @menu_item.name %>
-Link: <%= @menu_item.link %>
- diff --git a/app/views/pages/forum.html.erb b/app/views/pages/forum.html.erb new file mode 100644 index 00000000..4f6b6da5 --- /dev/null +++ b/app/views/pages/forum.html.erb @@ -0,0 +1,3 @@ +We've discontinued the forums.
diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 00000000..41844acb --- /dev/null +++ b/config/database.yml @@ -0,0 +1,17 @@ +# SQLite version 3.x +# gem install sqlite3 +# 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. +default: &default + adapter: postgresql + pool: 5 + timeout: 5000 + +test: + <<: *default + url: <%= ENV["DATABASE_URL"] %> + +nzic_test: + <<: *default + url: <%= ENV["NZIC_DATABASE_URL"] %> diff --git a/config/database.yml.template b/config/database.yml.template index 880ddb17..252b43f7 100644 --- a/config/database.yml.template +++ b/config/database.yml.template @@ -26,26 +26,3 @@ production: username: ${DATABASE_USERNAME} password: -nzic_development: - adapter: postgresql - encoding: unicode - database: nzic - pool: 5 - username: ${DATABASE_USERNAME} - password: - -nzic_test: - adapter: postgresql - encoding: unicode - database: ${TEST_DATABASE} - pool: 5 - username: ${DATABASE_USERNAME} - -nzic_production: - adapter: postgresql - encoding: unicode - database: nzic - pool: 5 - username: ${DATABASE_USERNAME} - password: - diff --git a/config/environment.rb b/config/environment.rb index 906a4f55..33bf8edd 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -12,5 +12,15 @@ #ActiveRecord::Base.pluralize_table_names = false +require 'active_record/connection_adapters/postgresql_adapter' + +class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + def set_standard_conforming_strings + old, self.client_min_messages = client_min_messages, 'warning' + execute('SET standard_conforming_strings = on', 'SCHEMA') rescue nil + ensure + self.client_min_messages = old + end +end #Initialize the rails application NZTrain::Application.initialize! diff --git a/config/initializers/forem.rb b/config/initializers/forem.rb deleted file mode 100644 index 968ebc7a..00000000 --- a/config/initializers/forem.rb +++ /dev/null @@ -1,16 +0,0 @@ -Forem.user_class = "User" -Forem.email_from_address = "nztrain@gmail.com" -# If you do not want to use gravatar for avatars then specify the method to use here: -Forem.avatar_user_method = :forem_avatar -Forem.per_page = 20 - - -Rails.application.config.to_prepare do -# If you want to change the layout that Forem uses, uncomment and customize the next line: - Forem.layout = "scaffold" -# -# If you want to add your own cancan Abilities to Forem, uncomment and customize the next line: -# Forem::Ability.register_ability(Ability) -end -# -# By default, these lines will use the layout located at app/views/layouts/forem.html.erb in your application. diff --git a/config/initializers/nzic.rb b/config/initializers/nzic.rb deleted file mode 100644 index feb1a681..00000000 --- a/config/initializers/nzic.rb +++ /dev/null @@ -1,7 +0,0 @@ - -Rails.configuration.to_prepare do - NZIC::Base.class_eval do - establish_connection "nzic_#{Rails.env}" - end -end - diff --git a/config/redis.yml b/config/redis.yml new file mode 100644 index 00000000..5dfb0b74 --- /dev/null +++ b/config/redis.yml @@ -0,0 +1,11 @@ +default: + host: localhost + port: 6379 + password: "" +production: + db: 0 +development: + db: 1 +test: + db: 2 + diff --git a/config/routes.rb b/config/routes.rb index d2d886b7..bea23c67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,4 @@ NZTrain::Application.routes.draw do - - # This line mounts Forem's routes at /forums by default. - # This means, any requests to the /forums URL of your application will go to Forem::ForumsController#index. - # If you would like to change where this extension is mounted, simply change the :at option to something different. - # - # We ask that you don't use the :as option here, as Forem relies on it being the default of "forem" - mount Forem::Engine, :at => '/forum' - concern :file_root do |options| options ||= {} resources :files, options.merge(:except => [:new, :edit]) do @@ -256,16 +248,6 @@ end end - get 'nzic/info/*name/edit', to: 'nzic/info#edit', as: :edit_nzic_info - namespace :nzic do - resources :infos, controller: :info, param: :name, only: [:index, :new, :create] - get 'info/*name', to: 'info#show', as: :info - patch 'info/*name', to: 'info#update' - delete 'info/*name', to: 'info#destroy' - - resources :menu_items - end - # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products @@ -308,4 +290,6 @@ # See how all your routes lay out with "rake routes" + # Legacy routes maintained to avoid routes breaking + get "/forum/*anything" => "pages#forum" end diff --git a/spec/controllers/accounts/passwords_controller_spec.rb b/spec/controllers/accounts/passwords_controller_spec.rb index e71e846f..c972e100 100644 --- a/spec/controllers/accounts/passwords_controller_spec.rb +++ b/spec/controllers/accounts/passwords_controller_spec.rb @@ -21,7 +21,7 @@ context "using password reset token" do before(:all) do - @resetuser = FactoryGirl.create(:user) + @resetuser = FactoryBot.create(:user) end after(:all) do @resetuser.destroy diff --git a/spec/controllers/accounts/registrations_controller_spec.rb b/spec/controllers/accounts/registrations_controller_spec.rb index fb0f4ce5..2befdb69 100644 --- a/spec/controllers/accounts/registrations_controller_spec.rb +++ b/spec/controllers/accounts/registrations_controller_spec.rb @@ -24,7 +24,7 @@ context 'when signed in' do before(:all) do - @user = FactoryGirl.create(:user, :password => "registration password") + @user = FactoryBot.create(:user, :password => "registration password") end after(:all) do @user.destroy @@ -46,7 +46,7 @@ context 'when signed in' do before(:each) do - @user = FactoryGirl.create(:user, :password => "registration password") + @user = FactoryBot.create(:user, :password => "registration password") sign_in @user end after(:each) do diff --git a/spec/controllers/contests_controller_spec.rb b/spec/controllers/contests_controller_spec.rb index 571a2c8a..585792fe 100644 --- a/spec/controllers/contests_controller_spec.rb +++ b/spec/controllers/contests_controller_spec.rb @@ -2,8 +2,8 @@ describe ContestsController do before(:all) do - @problem_set = FactoryGirl.create(:problem_set) - @contest = FactoryGirl.create(:contest, :problem_set => @problem_set) + @problem_set = FactoryBot.create(:problem_set) + @contest = FactoryBot.create(:contest, :problem_set => @problem_set) end after(:all) do @contest.destroy diff --git a/spec/controllers/evaluators_controller_spec.rb b/spec/controllers/evaluators_controller_spec.rb index d3e12a62..ef0ed3d2 100644 --- a/spec/controllers/evaluators_controller_spec.rb +++ b/spec/controllers/evaluators_controller_spec.rb @@ -2,7 +2,7 @@ describe EvaluatorsController do before(:all) do - @evaluator = FactoryGirl.create(:evaluator) + @evaluator = FactoryBot.create(:evaluator) end after(:all) do @evaluator.destroy diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 0cb3e503..c275c083 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -2,7 +2,7 @@ describe GroupsController do before(:all) do - @group = FactoryGirl.create(:group) + @group = FactoryBot.create(:group) end after(:all) do @group.destroy diff --git a/spec/controllers/problem_sets_controller_spec.rb b/spec/controllers/problem_sets_controller_spec.rb index 9868979b..033752ec 100644 --- a/spec/controllers/problem_sets_controller_spec.rb +++ b/spec/controllers/problem_sets_controller_spec.rb @@ -2,7 +2,7 @@ describe ProblemSetsController do before(:all) do - @problem_set = FactoryGirl.create(:problem_set) + @problem_set = FactoryBot.create(:problem_set) end after(:all) do @problem_set.destroy diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index 6f3d86b1..02c4aa47 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -2,9 +2,9 @@ describe ProblemsController do before(:all) do - @group = FactoryGirl.create(:group, :name => "Special Group", :members => [users(:admin),users(:user)]) - @group_set = FactoryGirl.create(:problem_set, :name => "Set in Group", :groups => [@group]) - @group_problem = FactoryGirl.create(:adding_problem, :problem_sets => [@group_set]) + @group = FactoryBot.create(:group, :name => "Special Group", :members => [users(:admin),users(:user)]) + @group_set = FactoryBot.create(:problem_set, :name => "Set in Group", :groups => [@group]) + @group_problem = FactoryBot.create(:adding_problem, :problem_sets => [@group_set]) end after(:all) do [@group, @group_set, @group_problem].reverse_each { |object| object.destroy } @@ -17,8 +17,8 @@ context "as admin" do before(:all) do - @owned_problem = FactoryGirl.create(:problem, :owner => users(:admin)) - @unowned_problem = FactoryGirl.create(:problem) + @owned_problem = FactoryBot.create(:problem, :owner => users(:admin)) + @unowned_problem = FactoryBot.create(:problem) end after(:all) do @unowned_problem.destroy @@ -33,8 +33,8 @@ context "as a normal user" do before(:all) do - @owned_problem = FactoryGirl.create(:problem, :owner => users(:user)) - @unowned_problem = FactoryGirl.create(:problem) + @owned_problem = FactoryBot.create(:problem, :owner => users(:user)) + @unowned_problem = FactoryBot.create(:problem) end after(:all) do @unowned_problem.destroy diff --git a/spec/controllers/roles_controller_spec.rb b/spec/controllers/roles_controller_spec.rb index d488b548..8094af3d 100644 --- a/spec/controllers/roles_controller_spec.rb +++ b/spec/controllers/roles_controller_spec.rb @@ -2,7 +2,7 @@ describe RolesController do before(:all) do - @role = FactoryGirl.create(:role) + @role = FactoryBot.create(:role) end after(:all) do @role.destroy diff --git a/spec/controllers/settings_controller_spec.rb b/spec/controllers/settings_controller_spec.rb index 0b05ce2f..b1541e5e 100644 --- a/spec/controllers/settings_controller_spec.rb +++ b/spec/controllers/settings_controller_spec.rb @@ -2,7 +2,7 @@ describe SettingsController do before(:all) do - @setting = FactoryGirl.create(:setting) + @setting = FactoryBot.create(:setting) end after(:all) do @setting.destroy diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb index e638cd75..1fd481db 100644 --- a/spec/controllers/submissions_controller_spec.rb +++ b/spec/controllers/submissions_controller_spec.rb @@ -2,7 +2,7 @@ describe SubmissionsController do before(:all) do - @submission = FactoryGirl.create(:submission, :problem => problems(:problem), :user => users(:superadmin)) + @submission = FactoryBot.create(:submission, :problem => problems(:problem), :user => users(:superadmin)) end after(:all) do @submission.destroy diff --git a/spec/controllers/test_cases_controller_spec.rb b/spec/controllers/test_cases_controller_spec.rb index e162523a..e5536245 100644 --- a/spec/controllers/test_cases_controller_spec.rb +++ b/spec/controllers/test_cases_controller_spec.rb @@ -3,7 +3,7 @@ describe TestCasesController do before { pending } before(:all) do - @test_case = FactoryGirl.create(:test_case, :problem_id => test_sets(:test_set).problem_id) + @test_case = FactoryBot.create(:test_case, :problem_id => test_sets(:test_set).problem_id) TestCaseRelation.create(:test_set => test_sets(:test_set), :test_case => @test_case) end after(:all) do diff --git a/spec/controllers/test_sets_controller_spec.rb b/spec/controllers/test_sets_controller_spec.rb index c6b3dfb9..18c60bc6 100644 --- a/spec/controllers/test_sets_controller_spec.rb +++ b/spec/controllers/test_sets_controller_spec.rb @@ -2,7 +2,7 @@ describe TestSetsController do before(:all) do - @test_set = FactoryGirl.create(:test_set, :problem => problems(:problem)) + @test_set = FactoryBot.create(:test_set, :problem => problems(:problem)) end after(:all) do @test_set.destroy diff --git a/spec/factories/ai_contest_games.rb b/spec/factories/ai_contest_games.rb index fb77377d..dc854f14 100644 --- a/spec/factories/ai_contest_games.rb +++ b/spec/factories/ai_contest_games.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :ai_contest_games do ai_contest_id 1 ai_submission_2_id 1 diff --git a/spec/factories/ai_contests.rb b/spec/factories/ai_contests.rb index 391949e1..5a3ec77c 100644 --- a/spec/factories/ai_contests.rb +++ b/spec/factories/ai_contests.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :ai_contest do name "MyString" start_time "2013-01-07 14:51:43" diff --git a/spec/factories/ai_submissions.rb b/spec/factories/ai_submissions.rb index 68d5a690..08855ca1 100644 --- a/spec/factories/ai_submissions.rb +++ b/spec/factories/ai_submissions.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :ai_submission do source "MyText" language "MyString" diff --git a/spec/factories/contest_relations.rb b/spec/factories/contest_relations.rb index ee3d5b94..4210b567 100644 --- a/spec/factories/contest_relations.rb +++ b/spec/factories/contest_relations.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :contest_relation do user_id 0 contest_id 0 diff --git a/spec/factories/contest_scores.rb b/spec/factories/contest_scores.rb index 1f6ec246..7b22d520 100644 --- a/spec/factories/contest_scores.rb +++ b/spec/factories/contest_scores.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :contest_score do user_id 0 contest_relation_id 0 diff --git a/spec/factories/contest_supervisors.rb b/spec/factories/contest_supervisors.rb index bfd089b6..0b06c386 100644 --- a/spec/factories/contest_supervisors.rb +++ b/spec/factories/contest_supervisors.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :contest_supervisor, :class => 'ContestSupervisors' do contest_id 1 user_id 1 diff --git a/spec/factories/contests.rb b/spec/factories/contests.rb index f103aa60..b7a922c7 100644 --- a/spec/factories/contests.rb +++ b/spec/factories/contests.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :contest do sequence(:name) {|n| "Contest #{n}" } start_time "2012-01-01 08:00:00" diff --git a/spec/factories/evaluators.rb b/spec/factories/evaluators.rb index cc5c063e..a711aff0 100644 --- a/spec/factories/evaluators.rb +++ b/spec/factories/evaluators.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :evaluator do sequence(:name) {|n| "Evaluator #{n}" } description "Evaluator description" diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index 8c30136f..c0beaf0d 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :group do sequence(:name) {|n| "Group #{n}" } owner_id 0 diff --git a/spec/factories/languages.rb b/spec/factories/languages.rb index efe99347..ad2b3858 100644 --- a/spec/factories/languages.rb +++ b/spec/factories/languages.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :language do name "MyString" compiler "MyString" diff --git a/spec/factories/problem_sets.rb b/spec/factories/problem_sets.rb index 539d53c2..c22df2aa 100644 --- a/spec/factories/problem_sets.rb +++ b/spec/factories/problem_sets.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :problem_set do sequence(:name) {|n| "Problem Set #{n}" } owner_id 0 diff --git a/spec/factories/problems.rb b/spec/factories/problems.rb index 9ae24a77..cff9c655 100644 --- a/spec/factories/problems.rb +++ b/spec/factories/problems.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :problem do sequence(:name) {|n| "Problem #{n}" } statement "Do nothing" @@ -16,15 +16,15 @@ output "add.out" memory_limit 30 time_limit 1 - test_cases { [FactoryGirl.create(:test_case, :input => "5 9", :output => "14"), - FactoryGirl.create(:test_case, :input => "100 -50", :output => "50"), - FactoryGirl.create(:test_case, :input => "1235 942", :output => "2177"), - FactoryGirl.create(:test_case, :input => "-4000 123", :output => "-3877")] } - test_sets { (0...4).map{FactoryGirl.create(:test_set)} } + test_cases { [FactoryBot.create(:test_case, :input => "5 9", :output => "14"), + FactoryBot.create(:test_case, :input => "100 -50", :output => "50"), + FactoryBot.create(:test_case, :input => "1235 942", :output => "2177"), + FactoryBot.create(:test_case, :input => "-4000 123", :output => "-3877")] } + test_sets { (0...4).map{FactoryBot.create(:test_set)} } after(:create) do |problem| (0...4).each do |i| - FactoryGirl.create(:test_case_relation, :test_case => problem.test_cases[i], :test_set => problem.test_sets[i]) + FactoryBot.create(:test_case_relation, :test_case => problem.test_cases[i], :test_set => problem.test_sets[i]) end end diff --git a/spec/factories/roles.rb b/spec/factories/roles.rb index ee31177a..47decf4b 100644 --- a/spec/factories/roles.rb +++ b/spec/factories/roles.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :role do sequence(:name) {|n| "Role #{n}" } end diff --git a/spec/factories/settings.rb b/spec/factories/settings.rb index f68cd479..b4e700d6 100644 --- a/spec/factories/settings.rb +++ b/spec/factories/settings.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :setting do sequence(:key) {|n| "Setting #{n}" } value "value" diff --git a/spec/factories/submissions.rb b/spec/factories/submissions.rb index 8c35722e..80de2cc5 100644 --- a/spec/factories/submissions.rb +++ b/spec/factories/submissions.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :submission do source "sauce" language { LanguageGroup.find_by_identifier("c++").current_language } diff --git a/spec/factories/test_case_relations.rb b/spec/factories/test_case_relations.rb index d6497d29..1749c772 100644 --- a/spec/factories/test_case_relations.rb +++ b/spec/factories/test_case_relations.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :test_case_relation do end end diff --git a/spec/factories/test_cases.rb b/spec/factories/test_cases.rb index 72c30900..81897df7 100644 --- a/spec/factories/test_cases.rb +++ b/spec/factories/test_cases.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :test_case do sequence(:name) {|n| "Test Case #{n}" } input "Input" diff --git a/spec/factories/test_sets.rb b/spec/factories/test_sets.rb index 46f41851..f9240912 100644 --- a/spec/factories/test_sets.rb +++ b/spec/factories/test_sets.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :test_set do sequence(:name) {|n| "Test Set #{n}" } points 1 diff --git a/spec/factories/users.rb b/spec/factories/users.rb index acf3b560..e13166a9 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,6 +1,6 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl +# Read about factories at https://github.com/thoughtbot/factory_bot -FactoryGirl.define do +FactoryBot.define do factory :user, :aliases => [:owner] do name "Name of User" sequence(:username) {|n| "user#{n}" } diff --git a/spec/features/invitation_and_join_request_spec.rb b/spec/features/invitation_and_join_request_spec.rb index 0bfbca99..3a45604a 100644 --- a/spec/features/invitation_and_join_request_spec.rb +++ b/spec/features/invitation_and_join_request_spec.rb @@ -2,7 +2,7 @@ feature 'invitation and join request' do scenario 'group owner invites a user, and user accepts invitation to group' do - @group = FactoryGirl.create(:group, :owner => users(:organiser), :visibility => Group::VISIBILITY[:private], :membership => Group::MEMBERSHIP[:private]) + @group = FactoryBot.create(:group, :owner => users(:organiser), :visibility => Group::VISIBILITY[:private], :membership => Group::MEMBERSHIP[:private]) login_as users(:organiser), :scope => :user visit invites_members_group_path(@group) @@ -30,7 +30,7 @@ end scenario 'group member invites a user and cancels the invitation' do - @group = FactoryGirl.create(:group, :members => [users(:user)], :visibility => Group::VISIBILITY[:private], :membership => Group::MEMBERSHIP[:invitation]) + @group = FactoryBot.create(:group, :members => [users(:user)], :visibility => Group::VISIBILITY[:private], :membership => Group::MEMBERSHIP[:invitation]) login_as users(:user), :scope => :user visit invites_members_group_path(@group) @@ -50,7 +50,7 @@ end scenario 'user applies to join group, and group member accepts join request' do - @group = FactoryGirl.create(:group, :owner => users(:organiser), :visibility => Group::VISIBILITY[:unlisted], :membership => Group::MEMBERSHIP[:invitation]) + @group = FactoryBot.create(:group, :owner => users(:organiser), :visibility => Group::VISIBILITY[:unlisted], :membership => Group::MEMBERSHIP[:invitation]) login_as users(:user), :scope => :user visit group_path(@group) @@ -70,7 +70,7 @@ end scenario 'user applies to join group, and group owner rejects join request' do - @group = FactoryGirl.create(:group, :owner => users(:organiser), :visibility => Group::VISIBILITY[:public], :membership => Group::MEMBERSHIP[:application]) + @group = FactoryBot.create(:group, :owner => users(:organiser), :visibility => Group::VISIBILITY[:public], :membership => Group::MEMBERSHIP[:application]) login_as users(:user), :scope => :user visit group_path(@group) diff --git a/spec/features/submissions_spec.rb b/spec/features/submissions_spec.rb index 2ba7a4f3..534bcd53 100644 --- a/spec/features/submissions_spec.rb +++ b/spec/features/submissions_spec.rb @@ -2,8 +2,8 @@ feature 'submission' do scenario 'submit code for a problem' do - @problem = FactoryGirl.create(:adding_problem) - @problem_set = FactoryGirl.create(:problem_set, :problems => [@problem], :group_ids => [0]) + @problem = FactoryBot.create(:adding_problem) + @problem_set = FactoryBot.create(:problem_set, :problems => [@problem], :group_ids => [0]) login_as users(:user), :scope => :user visit submit_problem_path(@problem) diff --git a/spec/models/contest_relation_spec.rb b/spec/models/contest_relation_spec.rb index eff5bec3..6cffe302 100644 --- a/spec/models/contest_relation_spec.rb +++ b/spec/models/contest_relation_spec.rb @@ -20,8 +20,8 @@ def expected_time(relation) end end before(:all) do - @contest = FactoryGirl.create(:contest) - @relation = FactoryGirl.create(:contest_relation, :contest => @contest, :user => users(:user)) + @contest = FactoryBot.create(:contest) + @relation = FactoryBot.create(:contest_relation, :contest => @contest, :user => users(:user)) end after(:all) do @relation.destroy @@ -33,7 +33,7 @@ def expected_time(relation) @relation.should finish_at_correct_time end it "updates finish_at when contest changes" do - @anothercontest = FactoryGirl.build(:contest, :start_time => @relation.started_at.advance(:hours => -1), :end_time => @relation.started_at.advance(:hours => 1)) + @anothercontest = FactoryBot.build(:contest, :start_time => @relation.started_at.advance(:hours => -1), :end_time => @relation.started_at.advance(:hours => 1)) @relation.contest = @anothercontest @relation.should finish_at_correct_time @relation.contest_id = @contest.id diff --git a/spec/models/contest_score_spec.rb b/spec/models/contest_score_spec.rb index 93c05473..f0e55fef 100644 --- a/spec/models/contest_score_spec.rb +++ b/spec/models/contest_score_spec.rb @@ -2,15 +2,15 @@ describe ContestRelation do before(:all) do - @problem_set = FactoryGirl.build(:problem_set) - @contest = FactoryGirl.build(:contest, :duration => 5.0, :start_time => "01/01/2012 9:00:00", :end_time => "01/01/2012 18:00:00", :problem_set => @problem_set, :finalized_at => nil) - @user = FactoryGirl.create(:user, :username => "contest_score_spec.model.user") - @relation = FactoryGirl.create(:contest_relation, :contest => @contest, :user => @user, :started_at => @contest.start_time.advance(:hours => 2)) - @problem_stub = FactoryGirl.create(:problem, :problem_sets => [@problem_set]) - @submission_stub = FactoryGirl.create(:submission, :user => @user, :problem => @problem_stub, :maximum_points => 100, :points => 14, :created_at => @relation.started_at.advance(:hours => 1)) - @adding_problem = FactoryGirl.create(:adding_problem, :problem_sets => [@problem_set]) - @adding_submission = FactoryGirl.create(:adding_submission, :user => @user, :problem => @adding_problem, :created_at => @relation.started_at.advance(:hours => 1), :maximum_points => 100) - #@contestscore = FactoryGirl.create(:contest_score + @problem_set = FactoryBot.build(:problem_set) + @contest = FactoryBot.build(:contest, :duration => 5.0, :start_time => "01/01/2012 9:00:00", :end_time => "01/01/2012 18:00:00", :problem_set => @problem_set, :finalized_at => nil) + @user = FactoryBot.create(:user, :username => "contest_score_spec.model.user") + @relation = FactoryBot.create(:contest_relation, :contest => @contest, :user => @user, :started_at => @contest.start_time.advance(:hours => 2)) + @problem_stub = FactoryBot.create(:problem, :problem_sets => [@problem_set]) + @submission_stub = FactoryBot.create(:submission, :user => @user, :problem => @problem_stub, :maximum_points => 100, :points => 14, :created_at => @relation.started_at.advance(:hours => 1)) + @adding_problem = FactoryBot.create(:adding_problem, :problem_sets => [@problem_set]) + @adding_submission = FactoryBot.create(:adding_submission, :user => @user, :problem => @adding_problem, :created_at => @relation.started_at.advance(:hours => 1), :maximum_points => 100) + #@contestscore = FactoryBot.create(:contest_score end after(:all) do @adding_submission.destroy @@ -34,15 +34,15 @@ ContestScore.where(:submission_id => @submission_stub.id).count.should == 0 end it "finds submission with maximum score" do - FactoryGirl.create(:submission, :user => @user, :problem => @problem_stub, :maximum_points => 100, :points => 13, :created_at => @relation.started_at.advance(:hours => 2)) + FactoryBot.create(:submission, :user => @user, :problem => @problem_stub, :maximum_points => 100, :points => 13, :created_at => @relation.started_at.advance(:hours => 2)) ContestScore.where(:contest_relation_id => @relation.id, :problem_id => @problem_stub.id).first.try(:score).should == 14 - FactoryGirl.create(:submission, :user => @user, :problem => @problem_stub, :points => 28, :maximum_points => 50, :created_at => @relation.started_at.advance(:hours => 1.5)) + FactoryBot.create(:submission, :user => @user, :problem => @problem_stub, :points => 28, :maximum_points => 50, :created_at => @relation.started_at.advance(:hours => 1.5)) ContestScore.where(:contest_relation_id => @relation.id, :problem_id => @problem_stub.id).first.try(:score).should == 56 end it "only considers submissions during time when contest_relation is valid" do - FactoryGirl.create(:submission, :user => @user, :problem => @problem_stub, :points => 100, :maximum_points => 100, :created_at => @relation.started_at.advance(:hours => -0.5)) + FactoryBot.create(:submission, :user => @user, :problem => @problem_stub, :points => 100, :maximum_points => 100, :created_at => @relation.started_at.advance(:hours => -0.5)) ContestScore.where(:contest_relation_id => @relation.id, :problem_id => @problem_stub.id).first.try(:score).should == 14 - FactoryGirl.create(:submission, :user => @user, :problem => @problem_stub, :points => 56, :maximum_points => 100, :created_at => @relation.finish_at.advance(:hours => 0.5)) + FactoryBot.create(:submission, :user => @user, :problem => @problem_stub, :points => 56, :maximum_points => 100, :created_at => @relation.finish_at.advance(:hours => 0.5)) ContestScore.where(:contest_relation_id => @relation.id, :problem_id => @problem_stub.id).first.try(:score).should == 14 end it "has automatically updates contest_relation score and time_taken" do diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb index b4a0094f..56ef3e9d 100644 --- a/spec/models/submission_spec.rb +++ b/spec/models/submission_spec.rb @@ -4,11 +4,11 @@ #pending "add some examples to (or delete) #{__FILE__}" context 'on "adding" problem' do before(:all) do - @user = FactoryGirl.create(:user) - @problem = FactoryGirl.create(:adding_problem) - @submission = FactoryGirl.create(:adding_submission, :problem => @problem, :user => @user) - @char_submission = FactoryGirl.create(:adding_char_submission, :problem => @problem, :user => @user) - @unsigned_submission = FactoryGirl.create(:adding_unsigned_submission, :problem => @problem, :user => @user) + @user = FactoryBot.create(:user) + @problem = FactoryBot.create(:adding_problem) + @submission = FactoryBot.create(:adding_submission, :problem => @problem, :user => @user) + @char_submission = FactoryBot.create(:adding_char_submission, :problem => @problem, :user => @user) + @unsigned_submission = FactoryBot.create(:adding_unsigned_submission, :problem => @problem, :user => @user) end after(:all) do [@user, @problem, @submission, @char_submission, @unsigned_submission].reverse_each { |object| object.destroy } @@ -20,8 +20,8 @@ @submission.evaluation.should == 1 end it 'judges submission on stdio problem' do - problem = FactoryGirl.create(:adding_problem_stdio) - submission = FactoryGirl.create(:adding_submission_stdio, :problem => problem, :user => @user) + problem = FactoryBot.create(:adding_problem_stdio) + submission = FactoryBot.create(:adding_submission_stdio, :problem => problem, :user => @user) submission.evaluation.should be_nil submission.judge submission.reload diff --git a/spec/policies/authorization_spec.rb b/spec/policies/authorization_spec.rb index 5f13c545..b6dc0a3e 100644 --- a/spec/policies/authorization_spec.rb +++ b/spec/policies/authorization_spec.rb @@ -8,24 +8,24 @@ @organiser = users(:organiser) @user = users(:user) # various objects to test ability on - @member = FactoryGirl.create(:user) - @group = FactoryGirl.create(:group, :members => [users(:user), users(:admin), users(:superadmin), @member]) - @organiser_group = FactoryGirl.create(:group, :owner => users(:organiser), :members => [@member]) - @private_problem = FactoryGirl.create(:problem) - @group_set = FactoryGirl.create(:problem_set, :groups => [@group]) - @everyone_set = FactoryGirl.create(:problem_set, :group_ids => [0]) - @group_problem = FactoryGirl.create(:problem, :problem_sets => [@group_set]) - @user_problem = FactoryGirl.create(:problem, :owner => users(:user)) - @admin_problem = FactoryGirl.create(:problem, :owner => users(:admin)) - @everyone_problem = FactoryGirl.create(:problem, :problem_sets => [@everyone_set]) - @contest_set = FactoryGirl.create(:problem_set) - @contest = FactoryGirl.create(:contest, :name => "Contest", :groups => [@group], :problem_set => @contest_set, :duration => 100, :start_time => DateTime.now.advance(:hours => -100), :end_time => DateTime.now.advance(:hours => 100)) - @contest_problem = FactoryGirl.create(:problem, :problem_sets => [@contest_set]) - @private_set = FactoryGirl.create(:problem_set) - @private_contest = FactoryGirl.create(:contest, :problem_set => @contest_set) - @past_contest = FactoryGirl.create(:contest, :groups => [@group], :problem_set => @contest_set, :start_time => DateTime.now.advance(:hours => -100), :end_time => DateTime.now.advance(:hours => -50)) - @future_contest = FactoryGirl.create(:contest, :groups => [@group], :problem_set => @contest_set, :start_time => DateTime.now.advance(:hours => 100), :end_time => DateTime.now.advance(:hours => 200)) - @everyone_contest = FactoryGirl.create(:contest, :group_ids => [0], :problem_set => @contest_set, :start_time => DateTime.now.advance(:hours => -100), :end_time => DateTime.now.advance(:hours => 100)) + @member = FactoryBot.create(:user) + @group = FactoryBot.create(:group, :members => [users(:user), users(:admin), users(:superadmin), @member]) + @organiser_group = FactoryBot.create(:group, :owner => users(:organiser), :members => [@member]) + @private_problem = FactoryBot.create(:problem) + @group_set = FactoryBot.create(:problem_set, :groups => [@group]) + @everyone_set = FactoryBot.create(:problem_set, :group_ids => [0]) + @group_problem = FactoryBot.create(:problem, :problem_sets => [@group_set]) + @user_problem = FactoryBot.create(:problem, :owner => users(:user)) + @admin_problem = FactoryBot.create(:problem, :owner => users(:admin)) + @everyone_problem = FactoryBot.create(:problem, :problem_sets => [@everyone_set]) + @contest_set = FactoryBot.create(:problem_set) + @contest = FactoryBot.create(:contest, :name => "Contest", :groups => [@group], :problem_set => @contest_set, :duration => 100, :start_time => DateTime.now.advance(:hours => -100), :end_time => DateTime.now.advance(:hours => 100)) + @contest_problem = FactoryBot.create(:problem, :problem_sets => [@contest_set]) + @private_set = FactoryBot.create(:problem_set) + @private_contest = FactoryBot.create(:contest, :problem_set => @contest_set) + @past_contest = FactoryBot.create(:contest, :groups => [@group], :problem_set => @contest_set, :start_time => DateTime.now.advance(:hours => -100), :end_time => DateTime.now.advance(:hours => -50)) + @future_contest = FactoryBot.create(:contest, :groups => [@group], :problem_set => @contest_set, :start_time => DateTime.now.advance(:hours => 100), :end_time => DateTime.now.advance(:hours => 200)) + @everyone_contest = FactoryBot.create(:contest, :group_ids => [0], :problem_set => @contest_set, :start_time => DateTime.now.advance(:hours => -100), :end_time => DateTime.now.advance(:hours => 100)) end after(:all) do [@member, @group, @organiser_group, @private_problem, @group_set, @everyone_set, @group_problem, @user_problem, @admin_problem, @everyone_problem, @contest_set, @contest, @contest_problem, @private_set, @private_contest, @past_contest, @future_contest, @everyone_contest].reverse_each { |obj| obj.destroy } @@ -63,7 +63,7 @@ end context 'user in contest' do before(:all) do - @relation = FactoryGirl.create(:contest_relation, :user_id => users(:user).id, :contest_id => @contest.id, :started_at => DateTime.now.advance(:hours => -1)) + @relation = FactoryBot.create(:contest_relation, :user_id => users(:user).id, :contest_id => @contest.id, :started_at => DateTime.now.advance(:hours => -1)) @contest_problem.reload @contest_user = users(:user).reload end @@ -93,7 +93,7 @@ end context 'user in contest' do before(:all) do - @relation = FactoryGirl.create(:contest_relation, :user_id => users(:user).id, :contest_id => @contest.id, :started_at => DateTime.now.advance(:hours => -1)) + @relation = FactoryBot.create(:contest_relation, :user_id => users(:user).id, :contest_id => @contest.id, :started_at => DateTime.now.advance(:hours => -1)) @contest_user = users(:user).reload # refresh .competing? end after(:all) do diff --git a/spec/support/fixtures_spec_helper.rb b/spec/support/fixtures_spec_helper.rb index 2226c933..664ed482 100644 --- a/spec/support/fixtures_spec_helper.rb +++ b/spec/support/fixtures_spec_helper.rb @@ -3,13 +3,13 @@ module FixturesSpecHelper def self.initialize @@users = { - :user => FactoryGirl.create(:user), - :organiser => FactoryGirl.create(:organiser), - :admin => FactoryGirl.create(:admin), - :superadmin => FactoryGirl.create(:superadmin) + :user => FactoryBot.create(:user), + :organiser => FactoryBot.create(:organiser), + :admin => FactoryBot.create(:admin), + :superadmin => FactoryBot.create(:superadmin) } - @@problems = { :problem => FactoryGirl.create(:problem) } - @@test_sets = { :test_set => FactoryGirl.create(:test_set, :problem => @@problems[:problem]) } + @@problems = { :problem => FactoryBot.create(:problem) } + @@test_sets = { :test_set => FactoryBot.create(:test_set, :problem => @@problems[:problem]) } end def self.destroy