From 683d99ab126d1d79572319b3945a99e1485f6c5d Mon Sep 17 00:00:00 2001 From: sto Date: Fri, 12 Dec 2025 10:31:03 +0100 Subject: [PATCH] System test for CSV export https://gitea.puzzle-scoreboard.org/sto/puzzle-scoreboard/issues/5 --- Gemfile | 1 + Gemfile.lock | 3 +++ spec/factories/contestant.rb | 29 ++++++++++++++++++++++++++ spec/models/category_spec.rb | 23 -------------------- spec/models/csv_import_spec.rb | 15 -------------- spec/models/message_spec.rb | 26 ----------------------- spec/models/offline_spec.rb | 35 ------------------------------- spec/rails_helper.rb | 2 ++ spec/system/export_spec.rb | 38 ++++++++++++++++++++++++++++++++++ 9 files changed, 73 insertions(+), 99 deletions(-) create mode 100644 spec/factories/contestant.rb delete mode 100644 spec/models/category_spec.rb delete mode 100644 spec/models/csv_import_spec.rb delete mode 100644 spec/models/message_spec.rb delete mode 100644 spec/models/offline_spec.rb create mode 100644 spec/system/export_spec.rb diff --git a/Gemfile b/Gemfile index e909d95..4e0956f 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 286feb6..d9e0981 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/spec/factories/contestant.rb b/spec/factories/contestant.rb new file mode 100644 index 0000000..025eea1 --- /dev/null +++ b/spec/factories/contestant.rb @@ -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 diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb deleted file mode 100644 index 86c8383..0000000 --- a/spec/models/category_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/csv_import_spec.rb b/spec/models/csv_import_spec.rb deleted file mode 100644 index 08a622a..0000000 --- a/spec/models/csv_import_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb deleted file mode 100644 index cdabb8f..0000000 --- a/spec/models/message_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/offline_spec.rb b/spec/models/offline_spec.rb deleted file mode 100644 index 62cdfa3..0000000 --- a/spec/models/offline_spec.rb +++ /dev/null @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6221e85..769b16c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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 diff --git a/spec/system/export_spec.rb b/spec/system/export_spec.rb new file mode 100644 index 0000000..3571da0 --- /dev/null +++ b/spec/system/export_spec.rb @@ -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