Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_OPTIONS="--openssl-legacy-provider"
2 changes: 1 addition & 1 deletion app/views/admin/tournaments_players/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<tr>
<% board = @games[round - 1] %>
<% if round <= @games.size %>
<td><%= link_to board.round, round_admin_boards_path(@tournaments_player.tournament, board.round) %></td>
<td><%= link_to board.round, group_admin_boards_path(@tournaments_player.tournament, @tournaments_player.group, board.round) %></td>
<td <%= same_player?(@tournaments_player, board.white) ? raw('class="text-info"') : '' %>><%= board.white ? board.white.name : '<BYE>' %></td>
<td <%= same_player?(@tournaments_player, board.black) ? raw('class="text-info"') : '' %>><%= board.black ? board.black.name : '<BYE>' %></td>
<td style="text-align:center;"><%= chess_result(@tournaments_player.group, board) %> <% if board.walkover %><span class="badge bg-danger">WO</span> <% end %>
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
namespace :admin do
resources :standings do
collection do
get ':tournament_id/:round_id/show' => 'standings#index_by_round', as: "round"
#get ':tournament_id/:round_id/show' => 'standings#index_by_round', as: "round"
get ':tournament_id/:group_id/:round_id/show' => 'standings#index_by_group', as: "group"
end
end
Expand All @@ -69,7 +69,7 @@
namespace :admin do
resources :boards do
collection do
get ':tournament_id/:round_id/show' => 'boards#index_by_round', as: "round"
#get ':tournament_id/:round_id/show' => 'boards#index_by_round', as: "round"
delete ':tournament_id/:group_id/:round_id/delete' => 'boards#delete_by_round', as: "delete"
#delete ':tournament_id/:group_id/delete_by_group' => 'boards#delete_by_group', as: "delete_group"
get ':tournament_id/:group_id/:round_id/show' => 'boards#index_by_group', as: "group"
Expand Down
6 changes: 3 additions & 3 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
it { is_expected.to validate_presence_of(:password) }

context 'email uniqueness' do
let!(:existing_user) { create(:user, email: 'test@example.com') }
let!(:existing_user) { create(:user, email: 'existing@example.com') }

it 'validates uniqueness of email' do
new_user = build(:user, email: 'test@example.com')
new_user = build(:user, email: 'existing@example.com')
expect(new_user).not_to be_valid
expect(new_user.errors[:email]).to be_present
end
end
end

describe 'gravatar integration' do
let(:user) { create(:user, email: 'test@example.com') }
let(:user) { create(:user, email: 'gravatar@example.com') }

it 'includes Gravtastic module' do
expect(User.ancestors.map(&:to_s)).to include('Gravtastic::InstanceMethods')
Expand Down
17 changes: 16 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
Expand All @@ -39,8 +39,23 @@
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
# Use transactional fixtures for most tests except system specs
config.use_transactional_fixtures = true

# For system specs, we need different database cleaning
config.before(:each, type: :system) do
driven_by :rack_test
end

config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end

# Clean up after system tests
config.after(:each, type: :system) do
# Clear sessions and reset driver
end

# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

Expand Down
35 changes: 35 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'capybara/rspec'

# Configure Capybara to use Selenium with headless Chrome
Capybara.register_driver :selenium_chrome_headless do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--window-size=1400,1400')

Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

# Set default driver
Capybara.javascript_driver = :selenium_chrome_headless

# Configure Capybara settings
Capybara.configure do |config|
config.default_max_wait_time = 5
config.default_driver = :rack_test
config.app_host = 'http://localhost:3000'
end

RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end

config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end
end
1 change: 1 addition & 0 deletions spec/support/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::IntegrationHelpers, type: :feature
config.include Devise::Test::IntegrationHelpers, type: :request
config.include Devise::Test::IntegrationHelpers, type: :system
end
102 changes: 102 additions & 0 deletions spec/support/system_spec_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# frozen_string_literal: true

module SystemSpecHelpers
# Sign in helper for system tests
def sign_in(user)
visit new_user_session_path
fill_in 'user_username', with: user.username
fill_in 'user_password', with: user.password
click_button 'Sign in'
end

# Sign out helper
def sign_out
click_link 'Sign out'
end

# Wait for element to appear
def wait_for_element(selector, timeout: 5)
Timeout.timeout(timeout) do
sleep(0.1) until page.has_css?(selector)
end
end

# Wait for AJAX to complete
def wait_for_ajax(timeout: 5)
Timeout.timeout(timeout) do
loop until page.evaluate_script('jQuery.active').zero?
rescue StandardError
break
end
end

# Accept confirmation dialog
def accept_confirm
page.driver.browser.switch_to.alert.accept if Capybara.current_driver == :selenium_chrome_headless
yield if block_given?
end

# Dismiss confirmation dialog
def dismiss_confirm
page.driver.browser.switch_to.alert.dismiss if Capybara.current_driver == :selenium_chrome_headless
yield if block_given?
end

# Take screenshot for debugging
def take_debug_screenshot(name = 'debug')
timestamp = Time.now.strftime('%Y%m%d_%H%M%S')
filename = "#{name}_#{timestamp}.png"
save_screenshot(Rails.root.join('tmp', 'screenshots', filename))
end

# Fill in form with hash of attributes
def fill_form(attributes)
attributes.each do |field, value|
case value
when TrueClass
check field
when FalseClass
uncheck field
when Array
value.each { |v| check v }
else
fill_in field, with: value
end
end
end

# Create and sign in as admin user
def sign_in_as_admin
admin = create(:user, username: 'admin', email: 'admin@test.com', password: 'password123')
sign_in(admin)
admin
end

# Navigate to admin dashboard
def visit_admin_dashboard
visit admin_path
end

# Check for flash messages
def expect_flash_message(type, message)
within('.flash') do
expect(page).to have_content(message)
end
end

# Retry action on stale element
def retry_on_stale(retries: 3)
attempts = 0
begin
yield
rescue Selenium::WebDriver::Error::StaleElementReferenceError
attempts += 1
retry if attempts < retries
raise
end
end
end

RSpec.configure do |config|
config.include SystemSpecHelpers, type: :system
end
Loading
Loading