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.
This commit is contained in:
Javi Martín
2024-04-24 02:26:03 +02:00
parent 0b2975194b
commit 448775a5e9
5 changed files with 8 additions and 58 deletions

View File

@@ -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)

View File

@@ -1,2 +0,0 @@
class Campaign < ApplicationRecord
end

View File

@@ -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

View File

@@ -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")

View File

@@ -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