From 9d956c2ae693a4fd21f90c247368b4a72ca86dd2 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 11:35:03 +1000 Subject: [PATCH 01/12] Add last_judgement_at to API --- app/serializers/prediction_serializer.rb | 5 +++++ spec/requests/api/my_predictions_controller_spec.rb | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/app/serializers/prediction_serializer.rb b/app/serializers/prediction_serializer.rb index 6af6142a..b046048d 100644 --- a/app/serializers/prediction_serializer.rb +++ b/app/serializers/prediction_serializer.rb @@ -12,6 +12,7 @@ class PredictionSerializer < ActiveModel::Serializer :mean_confidence, :outcome, :prediction_group_id, + :last_judgement_at, :updated_at, :uuid, :version, @@ -23,4 +24,8 @@ class PredictionSerializer < ActiveModel::Serializer def creator_label object.creator.to_s end + + def last_judgement_at + object.judged_at + end end diff --git a/spec/requests/api/my_predictions_controller_spec.rb b/spec/requests/api/my_predictions_controller_spec.rb index 442133ed..50d46710 100644 --- a/spec/requests/api/my_predictions_controller_spec.rb +++ b/spec/requests/api/my_predictions_controller_spec.rb @@ -60,12 +60,16 @@ predictions = json_hash['predictions'] expect(predictions.length).to eq 2 + before_judgment_timestamp = Time.now + another_prediction.judgements.create!(outcome: true) + get url, params: params.merge(page_size: 1, page: 1) json_hash = JSON.parse(response.body) predictions = json_hash['predictions'] actor = json_hash['user'] expect(predictions.length).to eq 1 expect(predictions.first['description']).to eq another_prediction.description + expect(predictions.first['last_judgement_at'] > before_judgment_timestamp).to be true expect(actor['email']).to eq user.email get url, params: params.merge(page_size: 1, page: 2) From eda969c2a044eafffac4b5ef1a5c09229edc6679 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:03:28 +1000 Subject: [PATCH 02/12] Add chromium and chromedriver to the list of dependencies --- flake.lock | 12 ++++++------ flake.nix | 3 ++- spec/requests/api/my_predictions_controller_spec.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 576f70d3..f7e91cbd 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1687709756, - "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", "owner": "numtide", "repo": "flake-utils", - "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1687861235, - "narHash": "sha256-svC9lDtEft6hPopvs85z6AN1RDSI+UAZAISXHuRNvqg=", + "lastModified": 1690780834, + "narHash": "sha256-xt/0Tv1d2DdKrCqzWU4RikIn+pUoZDU2MKtsWf8Bb60=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4fec046839e4c2f58a930d358d0e9f893ece59f5", + "rev": "b4ddd645e94706759d443755dbec35901553f35d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 78a6850f..4c05c9b1 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,8 @@ bundler = pkgs.bundler.override { inherit ruby; }; developmentInputs = with pkgs; [ bundler + chromedriver + chromium libnotify pkg-config postgresql_12 @@ -36,4 +38,3 @@ }; }); } - diff --git a/spec/requests/api/my_predictions_controller_spec.rb b/spec/requests/api/my_predictions_controller_spec.rb index 50d46710..f44f4334 100644 --- a/spec/requests/api/my_predictions_controller_spec.rb +++ b/spec/requests/api/my_predictions_controller_spec.rb @@ -69,7 +69,7 @@ actor = json_hash['user'] expect(predictions.length).to eq 1 expect(predictions.first['description']).to eq another_prediction.description - expect(predictions.first['last_judgement_at'] > before_judgment_timestamp).to be true + expect(predictions.first['last_judgement_at'] >= before_judgment_timestamp).to be true expect(actor['email']).to eq user.email get url, params: params.merge(page_size: 1, page: 2) From b6d820848521c18f18b3d0e251cce9b2560fb296 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:19:29 +1000 Subject: [PATCH 03/12] Add libffi --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 4c05c9b1..d53da6c8 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,7 @@ bundler chromedriver chromium + libffi libnotify pkg-config postgresql_12 From e04ce5525c7a7d5a3977f7b28ff1d280cf4fa0b0 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:24:39 +1000 Subject: [PATCH 04/12] Fix type mismatch --- spec/requests/api/my_predictions_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/api/my_predictions_controller_spec.rb b/spec/requests/api/my_predictions_controller_spec.rb index f44f4334..a1e96fb6 100644 --- a/spec/requests/api/my_predictions_controller_spec.rb +++ b/spec/requests/api/my_predictions_controller_spec.rb @@ -69,7 +69,7 @@ actor = json_hash['user'] expect(predictions.length).to eq 1 expect(predictions.first['description']).to eq another_prediction.description - expect(predictions.first['last_judgement_at'] >= before_judgment_timestamp).to be true + expect(Time.parse(predictions.first['last_judgement_at']) >= before_judgment_timestamp).to be true expect(actor['email']).to eq user.email get url, params: params.merge(page_size: 1, page: 2) From 96c3ec6005fe99f8ca0f1582186376484ef3eee1 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:30:13 +1000 Subject: [PATCH 05/12] Fix timestamp clash --- spec/requests/api/my_predictions_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/api/my_predictions_controller_spec.rb b/spec/requests/api/my_predictions_controller_spec.rb index a1e96fb6..96780130 100644 --- a/spec/requests/api/my_predictions_controller_spec.rb +++ b/spec/requests/api/my_predictions_controller_spec.rb @@ -60,7 +60,7 @@ predictions = json_hash['predictions'] expect(predictions.length).to eq 2 - before_judgment_timestamp = Time.now + before_judgment_timestamp = Time.now - 1.second another_prediction.judgements.create!(outcome: true) get url, params: params.merge(page_size: 1, page: 1) From a79fa7825680c953ef124fdaaff223f20387712b Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:45:54 +1000 Subject: [PATCH 06/12] Got tests running locally --- Gemfile | 2 +- Gemfile.lock | 6 +----- spec/support/feature_spec_dependencies.rb | 7 +++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 825f5223..d56e9e00 100644 --- a/Gemfile +++ b/Gemfile @@ -80,8 +80,8 @@ group :test do gem 'guard-rspec' gem 'launchy' gem 'rails-controller-testing' + gem 'selenium-webdriver', require: false gem 'shoulda-matchers' - gem 'webdrivers' end group :linux, :production do diff --git a/Gemfile.lock b/Gemfile.lock index fdd3ad3c..19cc69ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -414,10 +414,6 @@ GEM uuidtools (2.2.0) warden (1.2.9) rack (>= 2.0.9) - webdrivers (5.2.0) - nokogiri (~> 1.6) - rubyzip (>= 1.3.0) - selenium-webdriver (~> 4.0) websocket (1.2.9) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) @@ -487,6 +483,7 @@ DEPENDENCIES rspec-activemodel-mocks rspec-rails sass-rails + selenium-webdriver sentry-rails (>= 4.0) sentry-ruby (>= 4.0) shoulda-matchers @@ -495,7 +492,6 @@ DEPENDENCIES timecop uglifier uuidtools - webdrivers whenever wirble zeitwerk (< 2.6.4) diff --git a/spec/support/feature_spec_dependencies.rb b/spec/support/feature_spec_dependencies.rb index d036202c..9a9830e6 100644 --- a/spec/support/feature_spec_dependencies.rb +++ b/spec/support/feature_spec_dependencies.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'selenium/webdriver' + Capybara.register_driver :chrome_headless do |app| options = Selenium::WebDriver::Chrome::Options.new options.add_argument('disable-dev-shm-usage') @@ -11,7 +13,7 @@ options.binary = `which chromium`.chomp || `which google-chrome-stable`.chomp end - capabilities = Selenium::WebDriver::Remote::Capabilities.chrome + capabilities = Selenium:q:WebDriver::Remote::Capabilities.chrome Capybara::Selenium::Driver.new( app, browser: :chrome, capabilities: [options, capabilities] @@ -19,6 +21,3 @@ end Capybara.javascript_driver = :chrome_headless -Capybara.run_server = true -Capybara.server_port = 30_000 -Capybara.default_max_wait_time = 10 From fa5a56dc5629d5e28f795a7b62399674c190fefd Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:47:00 +1000 Subject: [PATCH 07/12] Fix typo --- spec/support/feature_spec_dependencies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/feature_spec_dependencies.rb b/spec/support/feature_spec_dependencies.rb index 9a9830e6..91747662 100644 --- a/spec/support/feature_spec_dependencies.rb +++ b/spec/support/feature_spec_dependencies.rb @@ -13,7 +13,7 @@ options.binary = `which chromium`.chomp || `which google-chrome-stable`.chomp end - capabilities = Selenium:q:WebDriver::Remote::Capabilities.chrome + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome Capybara::Selenium::Driver.new( app, browser: :chrome, capabilities: [options, capabilities] From f700b78055573b0eb710a82ded6557b90ff33734 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:54:03 +1000 Subject: [PATCH 08/12] Remove libffi --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index d53da6c8..4c05c9b1 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,6 @@ bundler chromedriver chromium - libffi libnotify pkg-config postgresql_12 From 690560f3dbc292a315c7933f7996db3629b702da Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 12:59:42 +1000 Subject: [PATCH 09/12] Add gnumake --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 4c05c9b1..0b287e67 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,7 @@ bundler chromedriver chromium + gnumake libnotify pkg-config postgresql_12 From f952304e3c0c2858973346179a987f520ba4bc20 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 13:02:24 +1000 Subject: [PATCH 10/12] Remove all flake modifications --- flake.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/flake.nix b/flake.nix index 0b287e67..7d83c68e 100644 --- a/flake.nix +++ b/flake.nix @@ -15,9 +15,6 @@ bundler = pkgs.bundler.override { inherit ruby; }; developmentInputs = with pkgs; [ bundler - chromedriver - chromium - gnumake libnotify pkg-config postgresql_12 From 97d55882c223afbe1022c63cc6474ce0406db691 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 13:04:54 +1000 Subject: [PATCH 11/12] Revert flake.lock change --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index f7e91cbd..576f70d3 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", "owner": "numtide", "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1690780834, - "narHash": "sha256-xt/0Tv1d2DdKrCqzWU4RikIn+pUoZDU2MKtsWf8Bb60=", + "lastModified": 1687861235, + "narHash": "sha256-svC9lDtEft6hPopvs85z6AN1RDSI+UAZAISXHuRNvqg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b4ddd645e94706759d443755dbec35901553f35d", + "rev": "4fec046839e4c2f58a930d358d0e9f893ece59f5", "type": "github" }, "original": { From b93950c4b7de1b8a646a2e4dea785c7d6df4d52f Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 13:12:27 +1000 Subject: [PATCH 12/12] Remove things we do not care about any more --- Gemfile | 1 - Gemfile.lock | 8 --- spec/features/prediction_groups_spec.rb | 81 ----------------------- spec/support/feature_spec_dependencies.rb | 23 ------- 4 files changed, 113 deletions(-) delete mode 100644 spec/features/prediction_groups_spec.rb delete mode 100644 spec/support/feature_spec_dependencies.rb diff --git a/Gemfile b/Gemfile index d56e9e00..faf2a363 100644 --- a/Gemfile +++ b/Gemfile @@ -80,7 +80,6 @@ group :test do gem 'guard-rspec' gem 'launchy' gem 'rails-controller-testing' - gem 'selenium-webdriver', require: false gem 'shoulda-matchers' end diff --git a/Gemfile.lock b/Gemfile.lock index 19cc69ef..016ef38c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -331,7 +331,6 @@ GEM responders (3.1.0) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.2.5) rouge (4.1.2) rspec (3.12.0) rspec-core (~> 3.12.0) @@ -358,7 +357,6 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -369,10 +367,6 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (4.10.0) - rexml (~> 3.2, >= 3.2.5) - rubyzip (>= 1.2.2, < 3.0) - websocket (~> 1.0) sentry-rails (5.9.0) railties (>= 5.0) sentry-ruby (~> 5.9.0) @@ -414,7 +408,6 @@ GEM uuidtools (2.2.0) warden (1.2.9) rack (>= 2.0.9) - websocket (1.2.9) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -483,7 +476,6 @@ DEPENDENCIES rspec-activemodel-mocks rspec-rails sass-rails - selenium-webdriver sentry-rails (>= 4.0) sentry-ruby (>= 4.0) shoulda-matchers diff --git a/spec/features/prediction_groups_spec.rb b/spec/features/prediction_groups_spec.rb deleted file mode 100644 index 59c94eba..00000000 --- a/spec/features/prediction_groups_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'creating and modifying prediction groups', js: true do - let(:user) { FactoryBot.create(:user) } - - before { login_as user } - - it 'making a new prediction group' do - visit new_prediction_group_path - fill_in 'prediction_group[description]', with: 'I will do a thing in' - fill_in 'prediction_group[prediction_0_description]', with: 'Less than a day' - fill_in 'prediction_group[prediction_0_initial_confidence]', with: '1' - click_button 'Add another prediction' - fill_in 'prediction_group[prediction_1_description]', with: 'Less than a week' - fill_in 'prediction_group[prediction_1_initial_confidence]', with: '10' - click_button 'Add another prediction' - fill_in 'prediction_group[prediction_2_description]', with: 'Less than a month' - fill_in 'prediction_group[prediction_2_initial_confidence]', with: '40' - click_button 'Add another prediction' - fill_in 'prediction_group[prediction_3_description]', with: 'Less than a year' - fill_in 'prediction_group[prediction_3_initial_confidence]', with: '95' - fill_in 'prediction_group[deadline_text]', with: '1 year from now' - click_button 'Lock in your predictions!' - - expect(page).to have_content "known on #{1.year.from_now.strftime('%Y')}" - - expect(page).to have_content '[I will do a thing in] Less than a day' - expect(page).to have_content '( 1% confidence )' - expect(page).to have_content '[I will do a thing in] Less than a week' - expect(page).to have_content '( 10% confidence )' - expect(page).to have_content '[I will do a thing in] Less than a month' - expect(page).to have_content '( 40% confidence )' - expect(page).to have_content '[I will do a thing in] Less than a year' - expect(page).to have_content '( 95% confidence )' - end - - it 'editing a prediction' do - prediction_group = FactoryBot.create(:prediction_group, creator: user, predictions: 5) - visit edit_prediction_group_path(prediction_group) - - fill_in 'prediction_group_description', with: 'A new prediction' - fill_in 'prediction_group[prediction_0_description]', with: 'Your calibration is going to suck' - click_button 'Lock in your predictions!' - - expect(page).to have_content 'A new prediction' - expect(page).to have_content 'Your calibration is going to suck' - prediction_group.reload - expect(prediction_group.predictions.length).to eq 5 - prediction_group.predictions.each do |prediction| - expect(page).to have_content prediction.description_with_group - end - expect(current_path).to eq prediction_group_path(prediction_group) - end - - it 'when user has set a visibility default' do - user.update(visibility_default: 'visible_to_creator') - - visit new_prediction_group_path - fill_in 'prediction_group_description', with: 'Tomorrow' - fill_in 'prediction_group[prediction_0_description]', with: 'You will explode' - fill_in 'prediction_group[prediction_0_initial_confidence]', with: '55' - fill_in 'prediction_group_deadline_text', with: '1 day from now' - click_button 'Lock in your predictions!' - - expect(page).to have_content '[private]' - - visit predictions_path - - expect(page).not_to have_content '[Tomorrow] You will explode' - expect(page).not_to have_content 'known in 1 day' - expect(page).not_to have_content 'estimated 55%' - - visit user_path(user) - - expect(page).to have_content '[Tomorrow] You will explode' - expect(page).to have_content 'known in 1 day' - expect(page).to have_content '55% confidence' - end -end diff --git a/spec/support/feature_spec_dependencies.rb b/spec/support/feature_spec_dependencies.rb deleted file mode 100644 index 91747662..00000000 --- a/spec/support/feature_spec_dependencies.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'selenium/webdriver' - -Capybara.register_driver :chrome_headless do |app| - options = Selenium::WebDriver::Chrome::Options.new - options.add_argument('disable-dev-shm-usage') - options.add_argument('no-sandbox') - options.add_argument('headless') unless ENV['SHOW_CHROME'] - options.add_argument('disable-gpu') - options.add_argument('window-size=1200,960') - if RUBY_PLATFORM.include?('linux') - options.binary = `which chromium`.chomp || `which google-chrome-stable`.chomp - end - - capabilities = Selenium::WebDriver::Remote::Capabilities.chrome - - Capybara::Selenium::Driver.new( - app, browser: :chrome, capabilities: [options, capabilities] - ) -end - -Capybara.javascript_driver = :chrome_headless