From 448775a5e942f5d55b25493777a4b0174d7c6cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 24 Apr 2024 02:26:03 +0200 Subject: [PATCH] Remove unused Campaign model The only way to use campaigns is to manually insert them in the database, which IMHO isn't very practical. We're going to change every piece of code that generates an Ahoy event and, in this case, the easiest way to change the Campaing model so it doesn't use Ahoy events is to simply remove it. Note we're keeping the database tables until we release a new version, just in case some Consul Democracy installations are using them. We'll inform in the release notes that we'll remove the campaigns table after the release, so existing installations using the `campaigns` table can move the data somewhere else before we remove the table. --- app/controllers/application_controller.rb | 8 ----- app/models/campaign.rb | 2 -- spec/factories/analytics.rb | 5 --- spec/system/admin/stats_spec.rb | 14 +++++---- spec/system/campaigns_spec.rb | 37 ----------------------- 5 files changed, 8 insertions(+), 58 deletions(-) delete mode 100644 app/models/campaign.rb delete mode 100644 spec/system/campaigns_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 76092d526..082c74754 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,7 +11,6 @@ class ApplicationController < ActionController::Base before_action :ensure_signup_complete around_action :switch_locale - before_action :track_email_campaign before_action :set_return_url check_authorization unless: :devise_controller? @@ -91,13 +90,6 @@ class ApplicationController < ActionController::Base end end - def track_email_campaign - if params[:track_id] - campaign = Campaign.find_by(track_id: params[:track_id]) - ahoy.track campaign.name if campaign.present? - end - end - def set_return_url if request.get? && !devise_controller? && is_navigational_format? store_location_for(:user, request.fullpath) diff --git a/app/models/campaign.rb b/app/models/campaign.rb deleted file mode 100644 index 69ab7c811..000000000 --- a/app/models/campaign.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Campaign < ApplicationRecord -end diff --git a/spec/factories/analytics.rb b/spec/factories/analytics.rb index bc7fa2654..0d564336e 100644 --- a/spec/factories/analytics.rb +++ b/spec/factories/analytics.rb @@ -9,9 +9,4 @@ FactoryBot.define do id { SecureRandom.uuid } started_at { DateTime.current } end - - factory :campaign do - sequence(:name) { |n| "Campaign #{n}" } - sequence(:track_id, &:to_s) - end end diff --git a/spec/system/admin/stats_spec.rb b/spec/system/admin/stats_spec.rb index 9ac12611c..86a7a8afa 100644 --- a/spec/system/admin/stats_spec.rb +++ b/spec/system/admin/stats_spec.rb @@ -152,19 +152,21 @@ describe "Stats", :admin do context "graphs" do scenario "event graphs", :with_frozen_time do - campaign = create(:campaign) + visit new_debate_path + fill_in_new_debate_title with: "A title for a debate" + fill_in_ckeditor "Initial debate text", with: "This is very important because..." + check "debate_terms_of_service" + click_button "Start a debate" - visit root_path(track_id: campaign.track_id) - - expect(page).to have_content "Sign out" + expect(page).to have_content "Debate created successfully." visit admin_stats_path within("#stats") do - click_link campaign.name + click_link "Debates" end - expect(page).to have_content "#{campaign.name} (1)" + expect(page).to have_content "Debates (1)" within("#graph") do expect(page).to have_content Date.current.strftime("%Y-%m-%d") diff --git a/spec/system/campaigns_spec.rb b/spec/system/campaigns_spec.rb deleted file mode 100644 index 7fe4b6afe..000000000 --- a/spec/system/campaigns_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "rails_helper" - -describe "Email campaigns", :admin do - let!(:campaign1) { create(:campaign) } - let!(:campaign2) { create(:campaign) } - - scenario "Track email templates" do - 3.times { visit root_path(track_id: campaign1.track_id) } - 5.times { visit root_path(track_id: campaign2.track_id) } - - visit admin_stats_path - click_link campaign1.name - - expect(page).to have_content "#{campaign1.name} (3)" - - click_link "Go back" - click_link campaign2.name - - expect(page).to have_content "#{campaign2.name} (5)" - end - - scenario "Do not track erroneous track_ids" do - invalid_id = Campaign.last.id + 1 - - visit root_path(track_id: campaign1.track_id) - visit root_path(track_id: invalid_id) - - visit admin_stats_path - - expect(page).to have_content campaign1.name - expect(page).not_to have_content campaign2.name - - click_link campaign1.name - - expect(page).to have_content "#{campaign1.name} (1)" - end -end