diff --git a/.gitignore b/.gitignore index 8b6c431..d307a05 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ .ruby-version .ruby-gemset .DS_Store +.byebug_history /public/sitemap.xml.gz diff --git a/Gemfile b/Gemfile index eecd15c..9b6f85c 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' gem 'rails', '5.1.0' gem 'pg' +gem 'puma', '~> 3.7' gem 'sass-rails' gem 'sprockets', '3.6.3' # remove when fixed: DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. gem 'coffee-rails' @@ -35,7 +36,9 @@ gem 'capistrano-passenger' group :test, :development do gem 'listen' gem 'minitest-spec-rails' - gem 'capybara_minitest_spec' + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'capybara', '~> 2.13.0' + gem 'selenium-webdriver' gem 'factory_girl_rails', '~> 4.0' end gem 'spring', group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 65ec3a2..cee2480 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,11 +43,13 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.4.0) + addressable (2.5.1) + public_suffix (~> 2.0, >= 2.0.2) airbrussh (1.1.1) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) builder (3.2.3) + byebug (9.0.6) capistrano (3.6.1) airbrussh (>= 1.0.0) capistrano-harrow @@ -63,16 +65,15 @@ GEM capistrano-rails (1.1.8) capistrano (~> 3.1) capistrano-bundler (~> 1.1) - capybara (2.10.1) + capybara (2.13.0) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - capybara_minitest_spec (1.0.5) - capybara (>= 2) - minitest (>= 4) + childprocess (0.7.0) + ffi (~> 1.0, >= 1.0.11) chronic (0.10.2) coffee-rails (4.2.1) coffee-script (>= 2.2.0) @@ -175,6 +176,8 @@ GEM oauth2 (~> 1.0) omniauth (~> 1.2) pg (0.19.0) + public_suffix (2.0.5) + puma (3.8.2) rack (2.0.1) rack-test (0.6.3) rack (>= 1.0) @@ -210,6 +213,7 @@ GEM record_tag_helper (1.0.0) actionview (~> 5.x) ref (2.0.0) + rubyzip (1.2.1) sass (3.4.22) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -220,6 +224,10 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + selenium-webdriver (3.4.0) + childprocess (~> 0.5) + rubyzip (~> 1.0) + websocket (~> 1.0) sitemap_generator (5.2.0) builder (~> 3.0) spring (2.0.0) @@ -247,6 +255,7 @@ GEM thread_safe (~> 0.1) uglifier (3.0.2) execjs (>= 0.3.0, < 3) + websocket (1.2.4) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) @@ -260,11 +269,12 @@ PLATFORMS DEPENDENCIES active_model_serializers + byebug capistrano (~> 3.6.1) capistrano-bundler capistrano-passenger capistrano-rails - capybara_minitest_spec + capybara (~> 2.13.0) coffee-rails dalli exception_notification (~> 4.0.0.rc1) @@ -282,10 +292,12 @@ DEPENDENCIES omniauth omniauth-google-oauth2 pg + puma (~> 3.7) rails (= 5.1.0) record_tag_helper sass-rails sdoc (~> 0.4.0) + selenium-webdriver sitemap_generator spring sprockets (= 3.6.3) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000..5d6c9f0 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,14 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + + def login_service + service = create(:service) + OmniAuth.config.add_mock("developer", "uid" => service.uid, "info" => {"name" => service.name, "email" => service.email}) + visit session_path + click_link "Developer" + assert_text I18n.t('sessions.create.success', :provider => 'Developer') + service + end +end diff --git a/test/integration/challenges_integration_test.rb b/test/system/challenges_test.rb similarity index 78% rename from test/integration/challenges_integration_test.rb rename to test/system/challenges_test.rb index 632b011..58093ef 100644 --- a/test/integration/challenges_integration_test.rb +++ b/test/system/challenges_test.rb @@ -1,6 +1,6 @@ -require "test_helper" +require "application_system_test_case" -class ChallengesIntegrationTest < ActionDispatch::IntegrationTest +class ChallengesTest < ApplicationSystemTestCase before do @service = login_service @tournament = create(:started_tournament) @@ -17,17 +17,17 @@ class ChallengesIntegrationTest < ActionDispatch::IntegrationTest visit tournament_path @tournament all('a', :text => I18n.t('tournaments.show.challenge')).last.click click_button I18n.t('helpers.submit.create') - must_have_content @rating1.user.name - must_have_content @rating2.user.name + assert_text @rating1.user.name + assert_text @rating2.user.name end it "must send challenge email" do visit tournament_path @tournament all('a', :text => I18n.t('tournaments.show.challenge')).last.click click_button I18n.t('helpers.submit.create') - ActionMailer::Base.deliveries.length.must_equal 1 + assert_equal 1, ActionMailer::Base.deliveries.length email = ActionMailer::Base.deliveries.first - email.to.must_equal [@user2.email] + assert_equal [@user2.email], email.to end end diff --git a/test/integration/games_integration_test.rb b/test/system/games_test.rb similarity index 77% rename from test/integration/games_integration_test.rb rename to test/system/games_test.rb index 18aecfd..8504171 100644 --- a/test/integration/games_integration_test.rb +++ b/test/system/games_test.rb @@ -1,6 +1,6 @@ -require "test_helper" +require "application_system_test_case" -class GamesIntegrationTest < ActionDispatch::IntegrationTest +class GamesTest < ApplicationSystemTestCase before do @service = login_service @tournament = create(:started_tournament) @@ -14,15 +14,17 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest describe "creation" do it "must be created" do visit tournament_path @tournament + find('a.dropdown-toggle span.caret').click click_link I18n.t('tournaments.show.log_a_game') click_button I18n.t('helpers.submit.create') - must_have_content @rating1.user.name - must_have_content @rating2.user.name - must_have_content I18n.t('games.game_rank.unconfirmed') + assert_text @rating1.user.name + assert_text @rating2.user.name + assert_text I18n.t('games.game_rank.unconfirmed') end it "must send confirmation email" do visit tournament_path @tournament + find('a.dropdown-toggle span.caret').click click_link I18n.t('tournaments.show.log_a_game') click_button I18n.t('helpers.submit.create') ActionMailer::Base.deliveries.length.must_equal 1 @@ -41,7 +43,7 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest it "must be confirmed" do visit game_path @game click_button I18n.t('games.show.confirm') - must_have_content I18n.t('games.game_rank.confirmed', :time => 'less than a minute') + assert_text I18n.t('games.game_rank.confirmed', :time => 'less than a minute') end describe "on final confirmation" do @@ -78,13 +80,10 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest end it "must respond" do - must_have_content I18n.t('games.game_rank.confirmed', :time => 'less than a minute') - end - - it "must send confirmation email" do - ActionMailer::Base.deliveries.length.must_equal 1 + assert_text I18n.t('games.game_rank.confirmed', :time => 'less than a minute') + assert_equal 1, ActionMailer::Base.deliveries.length email = ActionMailer::Base.deliveries.first - email.to.must_equal [@player2.user.email] + assert_equal [@player2.user.email], email.to end end @@ -96,13 +95,10 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest end it "must respond" do - must_have_content I18n.t('games.game_rank.confirmed', :time => 'less than a minute') - end - - it "must send confirmation email" do - ActionMailer::Base.deliveries.length.must_equal 1 + assert_text I18n.t('games.game_rank.confirmed', :time => 'less than a minute') + assert_equal 1, ActionMailer::Base.deliveries.length email = ActionMailer::Base.deliveries.first - email.to.must_equal [@player2.user.email] + assert_equal [@player2.user.email], email.to end end end diff --git a/test/integration/invites_integration_test.rb b/test/system/invites_test.rb similarity index 76% rename from test/integration/invites_integration_test.rb rename to test/system/invites_test.rb index 44c372e..6a5dd5d 100644 --- a/test/integration/invites_integration_test.rb +++ b/test/system/invites_test.rb @@ -1,6 +1,6 @@ -require "test_helper" +require "application_system_test_case" -class InvitesIntegrationTest < ActionDispatch::IntegrationTest +class InvitesTest < ApplicationSystemTestCase before do @service = login_service @tournament = create(:started_tournament) @@ -17,7 +17,7 @@ class InvitesIntegrationTest < ActionDispatch::IntegrationTest visit new_tournament_invite_path @tournament fill_in Invite.human_attribute_name("email"), :with => "user@example.com" click_button Invite.model_name.human - must_have_content @tournament.name + assert_text @tournament.name Invite.last.email.must_equal "user@example.com" end @@ -25,7 +25,7 @@ class InvitesIntegrationTest < ActionDispatch::IntegrationTest visit new_tournament_invite_path @tournament fill_in Invite.human_attribute_name("email"), :with => "user@example.com" click_button Invite.model_name.human - must_have_content @tournament.name + assert_text @tournament.name ActionMailer::Base.deliveries.length.must_equal 1 email = ActionMailer::Base.deliveries.first email.to.must_equal ["user@example.com"] @@ -39,16 +39,16 @@ class InvitesIntegrationTest < ActionDispatch::IntegrationTest it "must show invite page" do visit tournament_invite_path @tournament, @invite - must_have_content @tournament.name - must_have_button I18n.t("helpers.submit.invite.update") - must_have_link I18n.t("helpers.cancel_link") + assert_text @tournament.name + assert_button I18n.t("helpers.submit.invite.update") + assert_link I18n.t("helpers.cancel_link") end it "must join player" do visit tournament_invite_path @tournament, @invite click_button I18n.t("helpers.submit.invite.update") - must_have_content @tournament.name - must_have_content @user.name + assert_text @tournament.name + assert_text @user.name end end diff --git a/test/integration/sessions_integration_test.rb b/test/system/sessions_test.rb similarity index 63% rename from test/integration/sessions_integration_test.rb rename to test/system/sessions_test.rb index 51f3d97..9874916 100644 --- a/test/integration/sessions_integration_test.rb +++ b/test/system/sessions_test.rb @@ -1,6 +1,6 @@ -require "test_helper" +require "application_system_test_case" -class SessionsIntegrationTest < ActionDispatch::IntegrationTest +class SessionsTest < ApplicationSystemTestCase before do @omniauth = OmniAuth.config.add_mock('developer', "info" => {"name" => "Bob Bobson", "email" => "bob@bob.com"}) end @@ -14,20 +14,20 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest it "must authenticate" do visit session_path click_link "Developer" - must_have_content I18n.translate('sessions.create.success', :provider => 'Developer') + assert_text I18n.translate('sessions.create.success', :provider => 'Developer') end it "must redirect back after authentication" do visit games_path click_link "Developer" - must_have_content Game.model_name.human.pluralize + assert_text Game.model_name.human.pluralize end it "must update info after authentication" do @omniauth['info']['image'] = 'http://localhost:3000' visit session_path click_link "Developer" - must_have_content I18n.translate('sessions.create.success', :provider => 'Developer') + assert_text I18n.translate('sessions.create.success', :provider => 'Developer') @service.reload.image_url.must_equal 'http://localhost:3000' end end @@ -36,26 +36,24 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest it "must show new account creation" do visit session_path click_link "Developer" - must_have_content @omniauth["provider"].humanize - must_have_content @omniauth["uid"] - must_have_content @omniauth["info"]["name"] - must_have_content @omniauth["info"]["email"] - must_have_button I18n.translate('sessions.new.confirm') - must_have_button I18n.translate('helpers.cancel_link') + assert_text @omniauth["provider"].humanize + assert_text @omniauth["uid"] + assert_text @omniauth["info"]["name"] + assert_text @omniauth["info"]["email"] end it "must authenticate" do visit session_path click_link "Developer" click_button I18n.translate('sessions.new.confirm') - must_have_content I18n.translate('sessions.create.success', :provider => 'Developer') + assert_text I18n.translate('sessions.create.success', :provider => 'Developer') end it "must redirect on cancel" do visit session_path click_link "Developer" click_button I18n.translate('helpers.cancel_link') - must_have_content I18n.translate('sessions.create.canceled', :provider => 'Developer') + assert_text I18n.translate('sessions.create.canceled', :provider => 'Developer') end end @@ -64,21 +62,21 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest OmniAuth.config.mock_auth[:developer] = :invalid_credentials visit session_path click_link "Developer" - must_have_content I18n.translate('sessions.failure.invalid') + assert_text I18n.translate('sessions.failure.invalid') end it "must display time out" do OmniAuth.config.mock_auth[:developer] = :timeout visit session_path click_link "Developer" - must_have_content I18n.translate('sessions.failure.timed_out') + assert_text I18n.translate('sessions.failure.timed_out') end it "must display unknown error" do OmniAuth.config.mock_auth[:developer] = :something_else visit session_path click_link "Developer" - must_have_content I18n.translate('sessions.failure.unknown') + assert_text I18n.translate('sessions.failure.unknown') end end @@ -88,7 +86,7 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest click_link "Developer" click_button I18n.translate('sessions.new.confirm') visit logout_path - must_have_content I18n.translate('sessions.destroy.success') + assert_text I18n.translate('sessions.destroy.success') end end end diff --git a/test/integration/tournaments_integration_test.rb b/test/system/tournaments_test.rb similarity index 77% rename from test/integration/tournaments_integration_test.rb rename to test/system/tournaments_test.rb index 78cf9c6..2f8b420 100644 --- a/test/integration/tournaments_integration_test.rb +++ b/test/system/tournaments_test.rb @@ -1,6 +1,6 @@ -require File.expand_path("../test_helper", File.dirname(__FILE__)) +require "application_system_test_case" -class TournamentsIntegrationTest < ActionDispatch::IntegrationTest +class TournamentsTest < ApplicationSystemTestCase before do @service = login_service end @@ -12,37 +12,41 @@ class TournamentsIntegrationTest < ActionDispatch::IntegrationTest it "must show tournaments" do visit tournaments_path + click_link I18n.t('tournaments.index.title') @tournaments.each do |tournament| - must_have_link tournament.name + assert_link tournament.name end - must_have_link I18n.t('tournaments.index.start') + assert_link I18n.t('tournaments.index.start') end end describe "creation" do it "must be created" do visit tournaments_path + click_link I18n.t('tournaments.index.title') click_link I18n.t('tournaments.index.start') fill_in 'Name', :with => 'Test Tournament' select "Glicko2", from: "tournament_ranking_type" click_button I18n.t('helpers.submit.tournament.create') - must_have_content 'Test Tournament' + assert_text 'Test Tournament' end it "must fail with empty name" do visit tournaments_path + click_link I18n.t('tournaments.index.title') click_link I18n.t('tournaments.index.start') click_button I18n.t('helpers.submit.tournament.create') - must_have_content I18n.t('tournaments.new.title') + assert_text I18n.t('tournaments.new.title') end it "must be created" do visit tournaments_path + click_link I18n.t('tournaments.index.title') click_link I18n.t('tournaments.index.start') fill_in 'Name', :with => 'Test Tournament' select "King of the hill", from: "tournament_ranking_type" click_button I18n.t('helpers.submit.tournament.create') - must_have_content 'Test Tournament' + assert_text 'Test Tournament' end end @@ -54,7 +58,7 @@ class TournamentsIntegrationTest < ActionDispatch::IntegrationTest it "must let owner join" do visit tournament_path(@tournament) click_link I18n.t('layouts.tournament_title.join.link') - wont_have_link I18n.t('layouts.tournaments_title.join.link') + refute_link I18n.t('layouts.tournaments_title.join.link') end end @@ -74,13 +78,13 @@ class TournamentsIntegrationTest < ActionDispatch::IntegrationTest click_link I18n.t('tournaments.admin.title') fill_in 'Name', :with => 'New Name' click_button I18n.t('helpers.submit.update') - must_have_content 'New Name' + assert_text 'New Name' end it "wont let others update" do @tournament.update_attributes :owner => @other_user visit tournament_path(@tournament) - wont_have_link I18n.t('tournaments.admin.title') + refute_link I18n.t('tournaments.admin.title') end it "transfers ownership to others via update" do @@ -90,7 +94,7 @@ class TournamentsIntegrationTest < ActionDispatch::IntegrationTest click_link I18n.t('tournaments.admin.title') select @other_user.name, from: "tournament_owner_id" click_button I18n.t('helpers.submit.update') - must_have_content 'Ownership of the tournament has been transferred. You are no longer the owner of the tournament.' + assert_text 'Ownership of the tournament has been transferred. You are no longer the owner of the tournament.' end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 6aebda2..fcc4747 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,5 @@ -ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' -require 'capybara/rails' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. @@ -14,17 +12,3 @@ class ActiveSupport::TestCase ActionMailer::Base.deliveries.clear end end - -class ActionDispatch::IntegrationTest - include Rails.application.routes.url_helpers - include Capybara::DSL - - def login_service - service = create(:service) - OmniAuth.config.add_mock("developer", "uid" => service.uid, "info" => {"name" => service.name, "email" => service.email}) - visit session_path - click_link "Developer" - assert_page_has_content I18n.t('sessions.create.success', :provider => 'Developer') - service - end -end