System test for CSV export
Some checks failed
CI / scan_ruby (push) Successful in 15s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Failing after 1m28s

#5
This commit is contained in:
sto
2025-12-12 10:31:03 +01:00
parent 76553d4cbc
commit 683d99ab12
9 changed files with 73 additions and 99 deletions

View File

@@ -74,6 +74,7 @@ group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "so_many_devices"
end
gem "pundit", "~> 2.5"

View File

@@ -365,6 +365,8 @@ GEM
slim (5.2.1)
temple (~> 0.10.0)
tilt (>= 2.1.0)
so_many_devices (1.0.0)
capybara (>= 3.0)
solid_cable (3.0.12)
actioncable (>= 7.2)
activejob (>= 7.2)
@@ -465,6 +467,7 @@ DEPENDENCIES
rubocop-rails-omakase
selenium-webdriver
slim
so_many_devices
solid_cable
solid_cache
solid_queue

View File

@@ -0,0 +1,29 @@
# == Schema Information
#
# Table name: contestants
#
# id :integer not null, primary key
# display_time :string
# email :string
# name :string
# projected_time :string
# qrcode :string
# time_seconds :integer
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_contestants_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
FactoryBot.define do
factory :contestant do
name { Faker::Name.name }
email { Faker::Internet.unique.email }
end
end

View File

@@ -1,23 +0,0 @@
# == Schema Information
#
# Table name: categories
#
# id :integer not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_categories_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
require 'rails_helper'
RSpec.describe Category, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -1,15 +0,0 @@
# == Schema Information
#
# Table name: csv_imports
#
# id :integer not null, primary key
# content :string not null
# separator :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
require 'rails_helper'
RSpec.describe CsvImport, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -1,26 +0,0 @@
# == Schema Information
#
# Table name: messages
#
# id :integer not null, primary key
# author :string
# display_time :string
# text :string not null
# time_seconds :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_messages_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
require 'rails_helper'
RSpec.describe Message, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -1,35 +0,0 @@
# == Schema Information
#
# Table name: offlines
#
# id :integer not null, primary key
# completed :boolean
# end_time :datetime
# missing_pieces :integer
# name :string not null
# remaining_pieces :integer
# start_time :datetime not null
# submitted :boolean
# created_at :datetime not null
# updated_at :datetime not null
# completion_id :integer
# contest_id :integer not null
# contestant_id :integer
#
# Indexes
#
# index_offlines_on_completion_id (completion_id)
# index_offlines_on_contest_id (contest_id)
# index_offlines_on_contestant_id (contestant_id)
#
# Foreign Keys
#
# completion_id (completion_id => completions.id)
# contest_id (contest_id => contests.id)
# contestant_id (contestant_id => contestants.id)
#
require 'rails_helper'
RSpec.describe Offline, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -67,4 +67,6 @@ RSpec.configure do |config|
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
config.include SoManyDevices::DownloadsHelper, type: :system
end

View File

@@ -0,0 +1,38 @@
require 'rails_helper'
RSpec.describe "Exports", type: :system do
let!(:user) { create(:user) }
before do
driven_by :selenium_chrome_with_download_headless
end
after do
clear_downloads
end
context "when in a contest with at least one contestant" do
let!(:contest) { create(:contest, user: user) }
let!(:first_contestant) { create(:contestant, contest: contest) }
let!(:second_contestant) { create(:contestant, contest: contest) }
it "should be possible to export the list of contestants", :with_downloads do
login(user)
sleep 0.5
visit contest_contestants_path(contest)
click_link I18n.t("helpers.buttons.export")
wait_for_download
expect(downloads.length).to eq(1)
expect(last_download).to include("#{contest.friendly_id}_results.csv")
results_csv = File.read(last_download)
expect(results_csv).to include(first_contestant.name)
expect(results_csv).to include(second_contestant.name)
end
end
end