From b11001cdba5353baa8b3a556612c4b547cd84585 Mon Sep 17 00:00:00 2001 From: James Mason Date: Mon, 8 Oct 2018 17:58:41 -0700 Subject: [PATCH] Every campaign has an end. Drop ahoy, because it's more trouble than it's worth. This means dropping visits, campaigns, targets. Campaigns are better run to analytics, such as: * https://matomo.org/docs/tracking-campaigns/ * https://matomo.org/docs/tracking-goals-web-analytics/ * https://support.google.com/analytics/answer/1012040?hl=en --- .haml-lint_todo.yml | 16 -- .rubocop_todo.yml | 10 -- Gemfile | 1 - Gemfile.lock | 19 -- app/assets/javascripts/application.js | 1 - app/assets/javascripts/osem-datepickers.js | 15 -- app/assets/javascripts/osem.js | 25 --- app/controllers/admin/campaigns_controller.rb | 56 ------ .../admin/conferences_controller.rb | 12 +- app/controllers/admin/events_controller.rb | 1 - app/controllers/admin/targets_controller.rb | 54 ------ .../conference_registrations_controller.rb | 3 - app/controllers/proposals_controller.rb | 1 - app/models/admin_ability.rb | 2 - app/models/ahoy/event.rb | 13 -- app/models/campaign.rb | 78 -------- app/models/conference.rb | 33 ---- app/models/target.rb | 85 --------- app/models/visit.rb | 6 - app/views/admin/campaigns/_form.html.haml | 24 --- app/views/admin/campaigns/index.html.haml | 42 ----- .../admin/conferences/_campaigns.html.haml | 40 ----- .../admin/conferences/_targets.html.haml | 32 ---- app/views/admin/conferences/show.html.haml | 7 - app/views/admin/targets/_form.html.haml | 15 -- app/views/admin/targets/index.html.haml | 35 ---- .../versions/_object_desc_and_link.html.haml | 10 -- app/views/layouts/_admin_sidebar.html.haml | 12 -- config/initializers/ahoy.rb | 7 - config/routes.rb | 4 - db/migrate/20181009000259_drop_ahoy_events.rb | 15 ++ db/schema.rb | 66 +------ .../admin/targets_controller_spec.rb | 170 ------------------ spec/factories/campaigns.rb | 11 -- spec/factories/conferences.rb | 2 - spec/factories/targets.rb | 12 -- spec/factories/visits.rb | 8 - spec/features/campaign_spec.rb | 55 ------ spec/features/cfp_ability_spec.rb | 23 --- spec/features/info_desk_ability_spec.rb | 23 --- .../organization_admin_ability_spec.rb | 23 --- spec/features/organizer_ability_spec.rb | 23 --- spec/features/track_organizer_ability_spec.rb | 23 --- spec/features/versions_spec.rb | 24 --- spec/models/campaign_spec.rb | 73 -------- spec/models/conference_spec.rb | 63 ------- spec/models/target_spec.rb | 166 ----------------- 47 files changed, 19 insertions(+), 1420 deletions(-) delete mode 100644 app/controllers/admin/campaigns_controller.rb delete mode 100644 app/controllers/admin/targets_controller.rb delete mode 100644 app/models/ahoy/event.rb delete mode 100644 app/models/campaign.rb delete mode 100644 app/models/target.rb delete mode 100644 app/models/visit.rb delete mode 100644 app/views/admin/campaigns/_form.html.haml delete mode 100644 app/views/admin/campaigns/index.html.haml delete mode 100644 app/views/admin/conferences/_campaigns.html.haml delete mode 100644 app/views/admin/conferences/_targets.html.haml delete mode 100644 app/views/admin/targets/_form.html.haml delete mode 100644 app/views/admin/targets/index.html.haml delete mode 100644 config/initializers/ahoy.rb create mode 100644 db/migrate/20181009000259_drop_ahoy_events.rb delete mode 100644 spec/controllers/admin/targets_controller_spec.rb delete mode 100644 spec/factories/campaigns.rb delete mode 100644 spec/factories/targets.rb delete mode 100644 spec/factories/visits.rb delete mode 100644 spec/features/campaign_spec.rb delete mode 100644 spec/models/campaign_spec.rb delete mode 100644 spec/models/target_spec.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 2f97ea28..a81a0d99 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -19,8 +19,6 @@ linters: - "app/views/admin/booths/index.html.haml" - "app/views/admin/booths/new.html.haml" - "app/views/admin/booths/show.html.haml" - - "app/views/admin/campaigns/_form.html.haml" - - "app/views/admin/campaigns/index.html.haml" - "app/views/admin/cfps/_booths_cfp.html.haml" - "app/views/admin/cfps/_events_cfp.html.haml" - "app/views/admin/cfps/_form.html.haml" @@ -32,13 +30,11 @@ linters: - "app/views/admin/comments/_unread_comments.html.haml" - "app/views/admin/comments/index.html.haml" - "app/views/admin/commercials/index.html.haml" - - "app/views/admin/conferences/_campaigns.html.haml" - "app/views/admin/conferences/_doughnut_chart.html.haml" - "app/views/admin/conferences/_line_chart.html.haml" - "app/views/admin/conferences/_recent_registrations.html.haml" - "app/views/admin/conferences/_recent_submissions.html.haml" - "app/views/admin/conferences/_recent_users.html.haml" - - "app/views/admin/conferences/_targets.html.haml" - "app/views/admin/conferences/_todo_list.html.haml" - "app/views/admin/conferences/_top_submitter.html.haml" - "app/views/admin/conferences/edit.html.haml" @@ -127,8 +123,6 @@ linters: - "app/views/admin/surveys/index.html.haml" - "app/views/admin/surveys/new.html.haml" - "app/views/admin/surveys/show.html.haml" - - "app/views/admin/targets/_form.html.haml" - - "app/views/admin/targets/index.html.haml" - "app/views/admin/tickets/_form.html.haml" - "app/views/admin/tickets/index.html.haml" - "app/views/admin/tickets/show.html.haml" @@ -268,7 +262,6 @@ linters: InstanceVariables: exclude: - "app/views/admin/booths/_change_state_dropdown.html.haml" - - "app/views/admin/campaigns/_form.html.haml" - "app/views/admin/cfps/_booths_cfp.html.haml" - "app/views/admin/cfps/_events_cfp.html.haml" - "app/views/admin/cfps/_form.html.haml" @@ -326,8 +319,6 @@ linters: - "app/views/admin/booths/_change_state_dropdown.html.haml" - "app/views/admin/booths/index.html.haml" - "app/views/admin/booths/show.html.haml" - - "app/views/admin/campaigns/_form.html.haml" - - "app/views/admin/campaigns/index.html.haml" - "app/views/admin/cfps/_form.html.haml" - "app/views/admin/cfps/index.html.haml" - "app/views/admin/cfps/show.html.haml" @@ -335,13 +326,11 @@ linters: - "app/views/admin/comments/_posted_comments.html.haml" - "app/views/admin/comments/_unread_comments.html.haml" - "app/views/admin/commercials/index.html.haml" - - "app/views/admin/conferences/_campaigns.html.haml" - "app/views/admin/conferences/_doughnut_chart.html.haml" - "app/views/admin/conferences/_line_chart.html.haml" - "app/views/admin/conferences/_recent_registrations.html.haml" - "app/views/admin/conferences/_recent_submissions.html.haml" - "app/views/admin/conferences/_recent_users.html.haml" - - "app/views/admin/conferences/_targets.html.haml" - "app/views/admin/conferences/_todo_list.html.haml" - "app/views/admin/conferences/_top_submitter.html.haml" - "app/views/admin/conferences/edit.html.haml" @@ -409,8 +398,6 @@ linters: - "app/views/admin/surveys/_survey_stats.html.haml" - "app/views/admin/surveys/index.html.haml" - "app/views/admin/surveys/show.html.haml" - - "app/views/admin/targets/_form.html.haml" - - "app/views/admin/targets/index.html.haml" - "app/views/admin/tickets/_form.html.haml" - "app/views/admin/tickets/index.html.haml" - "app/views/admin/tickets/show.html.haml" @@ -522,7 +509,6 @@ linters: # Offense count: 23 UnnecessaryStringOutput: exclude: - - "app/views/admin/conferences/_targets.html.haml" - "app/views/admin/event_types/index.html.haml" - "app/views/admin/events/show.html.haml" - "app/views/admin/users/_submissions.html.haml" @@ -551,7 +537,6 @@ linters: - "app/views/admin/schedules/index.html.haml" - "app/views/admin/schedules/show.html.haml" - "app/views/admin/sponsorship_levels/index.html.haml" - - "app/views/admin/targets/index.html.haml" - "app/views/admin/tickets/show.html.haml" - "app/views/admin/tracks/index.html.haml" - "app/views/admin/users/show.html.haml" @@ -606,7 +591,6 @@ linters: - "app/views/admin/events/_form.html.haml" - "app/views/admin/registrations/index.html.haml" - "app/views/admin/sponsors/_form.html.haml" - - "app/views/admin/targets/_form.html.haml" - "app/views/admin/tracks/_form.html.haml" - "app/views/admin/tracks/show.html.haml" - "app/views/admin/venues/show.html.haml" diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3f67db6a..ac245b76 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -461,9 +461,7 @@ Metrics/PerceivedComplexity: # Offense count: 17 Naming/AccessorMethodName: Exclude: - - 'app/models/campaign.rb' - 'app/models/conference.rb' - - 'app/models/target.rb' - 'app/models/user.rb' # Offense count: 2 @@ -512,7 +510,6 @@ RSpec/AnyInstance: Exclude: - 'spec/controllers/admin/rooms_controller_spec.rb' - 'spec/controllers/admin/sponsorship_levels_controller_spec.rb' - - 'spec/controllers/admin/targets_controller_spec.rb' - 'spec/controllers/admin/tracks_controller_spec.rb' - 'spec/controllers/admin/users_controller_spec.rb' - 'spec/controllers/conference_registration_controller_spec.rb' @@ -545,7 +542,6 @@ RSpec/DescribedClass: - 'spec/models/role_spec.rb' - 'spec/models/sponsorship_level_spec.rb' - 'spec/models/survey_question_spec.rb' - - 'spec/models/target_spec.rb' - 'spec/models/ticket_purchase_spec.rb' - 'spec/models/ticket_spec.rb' - 'spec/models/user_spec.rb' @@ -672,14 +668,12 @@ RSpec/ImplicitSubject: - 'spec/ability/ability_spec.rb' - 'spec/models/admin_ability_spec.rb' - 'spec/models/booth_spec.rb' - - 'spec/models/campaign_spec.rb' - 'spec/models/conference_spec.rb' - 'spec/models/event_type_spec.rb' - 'spec/models/organization_spec.rb' - 'spec/models/registration_period_spec.rb' - 'spec/models/sponsor_spec.rb' - 'spec/models/sponsorship_level_spec.rb' - - 'spec/models/target_spec.rb' - 'spec/models/ticket_purchase_spec.rb' - 'spec/models/ticket_spec.rb' @@ -766,7 +760,6 @@ RSpec/RepeatedExample: RSpec/ReturnFromStub: Exclude: - 'spec/helpers/events_helper_spec.rb' - - 'spec/models/target_spec.rb' # Offense count: 49 RSpec/ScatteredLet: @@ -910,7 +903,6 @@ Rails/HasManyOrHasOneDependent: - 'app/models/track.rb' - 'app/models/user.rb' - 'app/models/vday.rb' - - 'app/models/visit.rb' - 'app/models/vposition.rb' # Offense count: 256 @@ -972,7 +964,6 @@ Rails/Presence: Rails/Present: Exclude: - 'app/helpers/users_helper.rb' - - 'app/models/campaign.rb' - 'app/models/cfp.rb' - 'app/models/email_settings.rb' - 'app/models/event.rb' @@ -1027,7 +1018,6 @@ Rails/TimeZone: - 'spec/controllers/admin/comments_controller_spec.rb' - 'spec/controllers/admin/programs_controller_spec.rb' - 'spec/factories/users.rb' - - 'spec/models/campaign_spec.rb' - 'spec/models/conference_spec.rb' # Offense count: 2 diff --git a/Gemfile b/Gemfile index 26bf4446..72d300c4 100644 --- a/Gemfile +++ b/Gemfile @@ -168,7 +168,6 @@ gem 'redcarpet' gem 'rdoc-generator-fivefish' # for visitor tracking -gem 'ahoy_matey' gem 'piwik_analytics', '~> 1.0.1' # for recurring jobs diff --git a/Gemfile.lock b/Gemfile.lock index 6a81976c..c9799613 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,16 +59,6 @@ GEM activerecord (>= 3.0) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) - ahoy_matey (2.1.0) - addressable - browser (~> 2.0) - device_detector - geocoder (>= 1.4.5) - railties (>= 4.2) - referer-parser (>= 0.3) - request_store - safely_block (>= 0.2.1) - user_agent_parser airbrake (7.3.5) airbrake-ruby (~> 2.10) airbrake-ruby (2.11.0) @@ -93,7 +83,6 @@ GEM bootstrap-switch-rails (3.0.2) bootstrap3-datetimepicker-rails (3.0.3) momentjs-rails (>= 2.8.1) - browser (2.5.3) builder (3.2.3) byebug (10.0.2) cancancan (2.3.0) @@ -153,7 +142,6 @@ GEM delayed_job_active_record (4.1.3) activerecord (>= 3.0, < 5.3) delayed_job (>= 3.0, < 5) - device_detector (1.0.1) devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -170,7 +158,6 @@ GEM dotenv-rails (2.5.0) dotenv (= 2.5.0) railties (>= 3.2, < 6.0) - errbase (0.1.0) erubis (2.7.0) execjs (2.7.0) factory_bot (4.11.1) @@ -193,7 +180,6 @@ GEM actionpack (>= 3.2.13) formtastic-bootstrap (3.1.1) formtastic (>= 3.0) - geocoder (1.4.9) globalid (0.4.1) activesupport (>= 4.2.0) gravtastic (3.2.6) @@ -447,7 +433,6 @@ GEM recaptcha (4.12.0) json redcarpet (3.4.0) - referer-parser (0.3.0) request_store (1.4.1) rack (>= 1.4) responders (2.4.0) @@ -503,8 +488,6 @@ GEM sexp_processor (~> 4.9) rubyzip (1.2.2) safe_yaml (1.0.4) - safely_block (0.2.1) - errbase sass (3.5.7) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -573,7 +556,6 @@ GEM unobtrusive_flash (3.3.1) railties url (0.3.2) - user_agent_parser (2.4.1) warden (1.2.7) rack (>= 1.0) web-console (2.3.0) @@ -601,7 +583,6 @@ DEPENDENCIES active_model_serializers acts_as_commentable_with_threading acts_as_list - ahoy_matey airbrake (~> 7.1) ajax-datatables-rails autoprefixer-rails diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a3a9ecc1..0697566f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -22,7 +22,6 @@ //= require bootstrap //= require osem //= require osem-dashboard -//= require ahoy //= require jquery-smooth-scroll //= require trianglify //= require tinycolor diff --git a/app/assets/javascripts/osem-datepickers.js b/app/assets/javascripts/osem-datepickers.js index 04a5c844..ed1db596 100644 --- a/app/assets/javascripts/osem-datepickers.js +++ b/app/assets/javascripts/osem-datepickers.js @@ -112,19 +112,4 @@ $(function () { $("#registration-period-end-datepicker").on("dp.change",function (e) { $('#registration-period-start-datepicker').data("DateTimePicker").setMaxDate(e.date); }); - - $(".target-due-date-datepicker").datetimepicker({ - pickTime: false, - format: "YYYY-MM-DD" - }); - /* Appends the datetimepicker to new injected nested target fields. */ - $('a:contains("Add target")').click(function () { - setTimeout(function () { - $('.target-due-date-datepicker').not('.hasDatepicker').datetimepicker({ - pickTime: false, - format: "YYYY-MM-DD" - }); - }, - 5) - }); } ); diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 2086f813..dcab692c 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -89,31 +89,6 @@ $(function () { } } - /** - /** - * Opens a prompt with the URL to copy to clipboard. - * Used in the campaign index view. - */ - $('.copyLink').on('click', function(){ - var url = $(this).data('url'); - copyToClipboard(url); - }) - function copyToClipboard(text) { - window.prompt("Copy to clipboard: Ctrl+C, Enter", text); - } - - /** - * Toggles the targets on the conference site with a more / less link. - */ - $('.show_targets').click(function () { - if($(this).text().trim() == 'more'){ - $(this).text("less"); - }else{ - $(this).text("more"); - } - $('#' + $(this).data('name')).toggle(); - }); - $(".comment-reply-link").click(function(){ $(".comment-reply", $(this).parent()).toggle(); return false; diff --git a/app/controllers/admin/campaigns_controller.rb b/app/controllers/admin/campaigns_controller.rb deleted file mode 100644 index 81947727..00000000 --- a/app/controllers/admin/campaigns_controller.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -module Admin - class CampaignsController < Admin::BaseController - load_and_authorize_resource :conference, find_by: :short_title - load_and_authorize_resource :campaign, through: :conference - - def index - authorize! :index, Campaign.new(conference_id: @conference.id) - @campaigns = @conference.campaigns - end - - def create - @campaign.attributes = campaign_params - - if @conference.save - redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title), - notice: 'Campaign successfully created.' - else - flash.now[:error] = 'Campaign creation failed. ' + @campaign.errors.full_messages.to_sentence - render action: 'new' - end - end - - def new; end - - def edit; end - - def update - if @campaign.update_attributes(campaign_params) - redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title), - notice: "Campaign '#{@campaign.name}' successfully updated." - else - flash.now[:error] = "Campaign update failed. #{@campaign.errors.full_messages.to_sentence}" - render action: 'edit' - end - end - - def destroy - if @campaign.destroy - redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title), - notice: "Campaign '#{@campaign.name}' successfully deleted." - else - redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title), - error: "Delete of Campaign for #{@conference.short_title} failed."\ - "#{@campaign.errors.full_messages.join('. ')}." - end - end - - private - - def campaign_params - params.require(:campaign).permit(:name, :utm_source, :utm_medium, :utm_term, :utm_content, :utm_campaign, :target_ids, :conference_id) - end - end -end diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 91ab442e..8b06efeb 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -189,14 +189,6 @@ module Admin @top_submitter = @conference.get_top_submitter - # get targets - @registration_targets = @conference.get_targets(Target.units[:registrations]) - @submission_targets = @conference.get_targets(Target.units[:submissions]) - @program_minutes_targets = @conference.get_targets(Target.units[:program_minutes]) - - # get campaigns - @campaigns = @conference.get_campaigns - respond_to do |format| format.html format.json { render json: @conference.to_json } @@ -225,8 +217,8 @@ module Admin :use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers, :color, :sponsorship_levels_attributes, :sponsors_attributes, - :targets, :targets_attributes, - :campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout, :booth_limit) + :registration_limit, :organization_id, :ticket_layout, + :booth_limit) end end end diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index f1486567..3db9321f 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -92,7 +92,6 @@ module Admin @event.submitter = current_user if @event.save - ahoy.track 'Event submission', title: 'New submission' redirect_to admin_conference_program_events_path(@conference.short_title), notice: 'Event was successfully submitted.' else flash.now[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}" diff --git a/app/controllers/admin/targets_controller.rb b/app/controllers/admin/targets_controller.rb deleted file mode 100644 index b6e5c490..00000000 --- a/app/controllers/admin/targets_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -module Admin - class TargetsController < Admin::BaseController - load_and_authorize_resource :conference, find_by: :short_title - load_and_authorize_resource :target, through: :conference - - def index; end - - def new - @target = @conference.targets.new - end - - def create - @target = @conference.targets.new(target_params) - if @target.save(target_params) - redirect_to admin_conference_targets_path(conference_id: @conference.short_title), - notice: 'Target successfully created.' - else - flash.now[:error] = "Creating target failed: #{@target.errors.full_messages.join('. ')}." - render :new - end - end - - def edit; end - - def update - if @target.update_attributes(target_params) - redirect_to admin_conference_targets_path(conference_id: @conference.short_title), - notice: 'Target successfully updated.' - else - flash.now[:error] = "Target update failed: #{@target.errors.full_messages.join('. ')}." - render :edit - end - end - - def destroy - if @target.destroy - redirect_to admin_conference_targets_path(conference_id: @conference.short_title), - notice: 'Target successfully destroyed.' - else - redirect_to admin_conference_targets_path(conference_id: @conference.short_title), - error: "Could not delete target for #{@conference.title}: "\ - "#{@target.errors.full_messages.join('. ')}." - end - end - - private - - def target_params - params.require(:target).permit(:due_date, :target_count, :unit, :conference_id) - end - end -end diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index 001913d3..5c17d8dc 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -52,9 +52,6 @@ class ConferenceRegistrationsController < ApplicationController authorize! :create, @registration if @registration.save - # Trigger ahoy event - ahoy.track 'Registered', title: 'New registration' - # Sign in the new user unless current_user sign_in(@registration.user) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 364f627a..d59cc2d8 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -61,7 +61,6 @@ class ProposalsController < ApplicationController end if @event.save - ahoy.track 'Event submission', title: 'New submission' Mailbot.submitted_proposal_mail(@event).deliver_later if @conference.email_settings.send_on_submitted_proposal redirect_to conference_program_proposals_path(@conference.short_title), notice: 'Proposal was successfully submitted.' else diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 74f83721..a2b17093 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -114,8 +114,6 @@ class AdminAbility can :manage, Splashpage, conference_id: conf_ids can :manage, Contact, conference_id: conf_ids can :manage, EmailSettings, conference_id: conf_ids - can :manage, Campaign, conference_id: conf_ids - can :manage, Target, conference_id: conf_ids can :manage, Commercial, commercialable_type: 'Conference', commercialable_id: conf_ids can :manage, Registration, conference_id: conf_ids diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb deleted file mode 100644 index 54ae0255..00000000 --- a/app/models/ahoy/event.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Ahoy - class Event < ApplicationRecord - include Ahoy::QueryMethods - self.table_name = 'ahoy_events' - - belongs_to :visit - belongs_to :user - - serialize :properties, JSON - end -end diff --git a/app/models/campaign.rb b/app/models/campaign.rb deleted file mode 100644 index b6109065..00000000 --- a/app/models/campaign.rb +++ /dev/null @@ -1,78 +0,0 @@ -# frozen_string_literal: true - -class Campaign < ApplicationRecord - validates :name, :utm_campaign, presence: true - - has_many :targets, dependent: :nullify - belongs_to :conference - - has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } - - ## - # Returns the utm parameters formatted as url. - # - # ====Returns - # * +String+ -> url parameters e.g. ?utm_source=facebook - def url_parameters - kv = [] - get_parameters.each_pair do |k, v| - kv += ["#{k}=#{v}"] - end - '?' + kv.join('&') unless kv.empty? - end - - ## - # Returns the counted visits generated by this campaign. - # - # ====Returns - # * +Fixnum+ -> visits - def visits_count - Visit.where(get_parameters).where('started_at > ?', created_at).count - end - - ## - # Returns the counted registrations generated by this campaign. - # - # ====Returns - # * +Fixnum+ -> visits - def registrations_count - events_by_name('Registered') - end - - ## - # Returns the counted event submissions generated by this campaign. - # - # ====Returns - # * +Fixnum+ -> visits - def submissions_count - events_by_name('Event submission') - end - - private - - ## - # Helper method for submissions and registrations. - # - # ====Returns - # * +Fixnum+ -> registrations / submissions - def events_by_name(event_name) - parameters = get_parameters - parameters['ahoy_events.name'] = event_name - Visit.joins(:ahoy_events).where(parameters).where('started_at > ?', created_at).count - end - - ## - # Helper method to get the parameters for queries. - # - # ====Returns - # * +Hash+ -> parameter => value - def get_parameters - conditions = {} - conditions[:utm_source] = self[:utm_source] unless self[:utm_source].blank? - conditions[:utm_medium] = self[:utm_medium] unless self[:utm_medium].blank? - conditions[:utm_term] = self[:utm_term] unless self[:utm_term].blank? - conditions[:utm_content] = self[:utm_content] unless self[:utm_content].blank? - conditions[:utm_campaign] = self[:utm_campaign] unless self[:utm_campaign].blank? - conditions - end -end diff --git a/app/models/conference.rb b/app/models/conference.rb index 7f606927..7de1c0de 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -45,8 +45,6 @@ class Conference < ApplicationRecord has_many :vpositions, dependent: :destroy has_many :sponsorship_levels, -> { order('position ASC') }, dependent: :destroy has_many :sponsors, dependent: :destroy - has_many :targets, dependent: :destroy - has_many :campaigns, dependent: :destroy has_many :commercials, as: :commercialable, dependent: :destroy has_many :subscriptions, dependent: :destroy has_one :call_for_events, -> { where(cfp_type: 'events') }, through: :program, source: :cfps @@ -76,8 +74,6 @@ class Conference < ApplicationRecord accepts_nested_attributes_for :questions, allow_destroy: true accepts_nested_attributes_for :vdays, allow_destroy: true accepts_nested_attributes_for :vpositions, allow_destroy: true - accepts_nested_attributes_for :targets, allow_destroy: true - accepts_nested_attributes_for :campaigns, allow_destroy: true mount_uploader :picture, PictureUploader, mount_on: :logo_file_name @@ -640,35 +636,6 @@ class Conference < ApplicationRecord ] end - ## - # A map with all conference targets with progress in percent of a certain unit. - # - # ====Returns - # * +Map+ -> target => progress - def get_targets(target_unit) - conference_target = targets.where('unit = ?', target_unit) - result = {} - conference_target.each do |target| - result[target.to_s] = target.get_progress - end - result - end - - ## - # A map with all conference campaigns associated with targets. - # - # ====Returns - # * +Map+ -> campaign => {actual, target, progress} - def get_campaigns - result = {} - campaigns.each do |campaign| - campaign.targets.each do |target| - result["#{target} from #{campaign.name}"] = target.get_campaign - end - end - result - end - ## # Writes an snapshot of the actual event distribution to the database # Triggered each every Sunday 11:55 pm form whenever (config/schedule.rb). diff --git a/app/models/target.rb b/app/models/target.rb deleted file mode 100644 index 424d075f..00000000 --- a/app/models/target.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true - -class Target < ApplicationRecord - include ActionView::Helpers::TextHelper - - default_scope { order('due_date ASC') } - - has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } - - def self.units - { - registrations: 'Registration', - submissions: 'Submission', - program_minutes: 'Program minute' - } - end - - validates :due_date, :target_count, :unit, presence: true - validates :target_count, - allow_nil: false, - numericality: { only_integer: true, greater_than: 0 } - validates :unit, allow_nil: false, inclusion: { in: Target.units.values } - - belongs_to :conference - belongs_to :campaign - - ## - # Returns the actual progress of the target in percent. - # - # ====Returns - # * +String+ -> progress in percent - def get_progress - numerator = - case unit - when Target.units[:submissions] - conference.program.events.where('created_at < ?', due_date).count - when Target.units[:registrations] - conference.registrations.where('created_at < ?', due_date).count - when Target.units[:program_minutes] - conference.current_program_minutes - else - 0 - end - - (100 * numerator / target_count).to_s - end - - ## - # Returns a hash with values of the corresponding campaign. - # - # ====Returns - # * +Hash+ -> target_name, campaign_name, value, unit, created_at, progress, days_left - def get_campaign - numerator = 0 - if unit == Target.units[:submissions] - numerator = campaign.submissions_count - elsif unit == Target.units[:registrations] - numerator = campaign.registrations_count - elsif unit == Target.units[:program_minutes] - numerator = conference.current_program_minutes - end - - progress = (numerator / target_count.to_f * 100).round(0).to_s - result = { - 'target_name' => to_s, - 'campaign_name' => campaign.name, - 'value' => numerator, - 'unit' => unit, - 'created_at' => created_at, - 'progress' => progress, - 'days_left' => days_left - } - result - end - - def to_s - "#{pluralize(target_count, unit)} by #{due_date}" - end - - private - - def days_left - (due_date - Date.today).to_i - end -end diff --git a/app/models/visit.rb b/app/models/visit.rb deleted file mode 100644 index 0afa9183..00000000 --- a/app/models/visit.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -class Visit < ApplicationRecord - has_many :ahoy_events, class_name: 'Ahoy::Event' - belongs_to :user -end diff --git a/app/views/admin/campaigns/_form.html.haml b/app/views/admin/campaigns/_form.html.haml deleted file mode 100644 index 71aa075e..00000000 --- a/app/views/admin/campaigns/_form.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -.row - .col-md-12 - .page-header - %h1 - - if @campaign.new_record? - New - Campaign - = @campaign.name - -.row - .col-md-8 - = semantic_form_for(@campaign, url: (@campaign.new_record? ? admin_conference_campaigns_path : admin_conference_campaign_path(@conference.short_title, @campaign))) do |f| - = f.inputs do - = f.input :name, input_html: { autofocus: true } - = f.inputs name: 'UTM Parameters' do - = f.input :utm_campaign, label: 'Campaign', hint: 'Groups all of the content from one campaign. E.g. 20percentpromocode' - = f.input :utm_source, label: 'Source', hint: 'Which website is sending you traffic. E.g. Facebook, google+, blog' - = f.input :utm_medium, label: 'Medium', hint: 'The type of marketing medium that the link is featured in. E.g. Facebook wallpost or facebook advertisement' - = f.input :utm_term, label: 'Term', hint: 'Campaign keywords. E.g. marketing+conference+opensource' - = f.input :utm_content, label: 'Content', hint: 'Used to track the different types of content that point to the same URL (A/B Test).' - = f.inputs name: 'Targets' do - = f.input :targets, collection: @conference.targets - %p.text-right - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/campaigns/index.html.haml b/app/views/admin/campaigns/index.html.haml deleted file mode 100644 index 7066474e..00000000 --- a/app/views/admin/campaigns/index.html.haml +++ /dev/null @@ -1,42 +0,0 @@ -.row - .col-md-12 - .page-header - %h1 Campaigns - %p.text-muted - Track where people come from -.row - .col-md-12 - %table.table.table-hover#campaigns - %thead - %tr - %th Name - %th Visits - %th Registrations - %th Submissions - %th Link - %th Actions - %tbody - - @campaigns.each do |campaign| - %tr - %td{ 'id' => "name_#{campaign.id}" } - = campaign.name - %td{ 'id' => "visits_#{campaign.id}" } - = campaign.visits_count - %td{ 'id' => "registrations_#{campaign.id}" } - = campaign.registrations_count - %td{ 'id' => "submissions_#{campaign.id}" } - = campaign.submissions_count - %td - %a.copyLink{ 'href' => '#', 'data-url' => root_path + campaign.url_parameters } - Copy link - %td - .btn-group - = link_to 'Edit', - edit_admin_conference_campaign_path(@conference.short_title, campaign.id), - class: 'btn btn-primary' - = link_to 'Delete', - admin_conference_campaign_path(@conference.short_title, campaign.id), - method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the campaign #{campaign.name}?" } -.row - .col-md-12 - = link_to 'New Campaign', new_admin_conference_campaign_path, class: 'btn btn-success pull-right' diff --git a/app/views/admin/conferences/_campaigns.html.haml b/app/views/admin/conferences/_campaigns.html.haml deleted file mode 100644 index e979562a..00000000 --- a/app/views/admin/conferences/_campaigns.html.haml +++ /dev/null @@ -1,40 +0,0 @@ -- if campaigns && !campaigns.empty? - .row - .col-md-12 - %p - Your target "#{campaigns.values[0]['target_name']}" from campaign "#{campaigns.values[0]['campaign_name']}" has generated - %strong - #{pluralize(campaigns.values[0]['value'], campaigns.values[0]['unit'])} - since #{campaigns.values[0]['created_at']}. - %p - That is - %strong{ 'style' => "color: #{target_progress_color(campaigns.values[0]['progress'])};" } - #{campaigns.values[0]['progress']} % - of your target, there are - %strong{ 'style' => "color: #{days_left_color(campaigns.values[0]['days_left'])};" } - #{pluralize(campaigns.values[0]['days_left'], 'day')} left. - .row - .col-md-12 - %div{ 'style' => 'display: none;', 'id' => "#{name}" } - - campaigns.drop(1).each do |(_key, value)| - %div - %p - Your target "#{value['target_name']}" from campaign "#{value['campaign_name']}" has generated - %strong - #{pluralize(value['value'], value['unit'])} - since #{value['created_at']}. - %p - That is - %strong{ 'style' => "color: #{target_progress_color(value['progress'])};" } - #{value['progress']} % - of your target, there are - %strong{ 'style' => "color: #{days_left_color(value['days_left'])};" } - #{pluralize(value['days_left'], 'day')} left. - .row - .col-md-12 - - if campaigns.length > 1 - %a.show_targets{ 'href' => '#', 'data-name' => "#{name}" } - more -- else - %h5.text-warning.text-center - No Campaigns! diff --git a/app/views/admin/conferences/_targets.html.haml b/app/views/admin/conferences/_targets.html.haml deleted file mode 100644 index 88f6c8a1..00000000 --- a/app/views/admin/conferences/_targets.html.haml +++ /dev/null @@ -1,32 +0,0 @@ -- if targets && !targets.empty? - .row - .col-md-8.col-md-offset-2 - .row - .col-md-10 - %h6.text-muted.pull-left - Target 1 - .row - .col-md-10 - .progress{ 'title' => "#{targets.keys[0]}" } - .progress-bar{ 'role' => 'progressbar', 'aria-valuenow' => " #{targets.values[0]}", 'aria-valuemin' => '0', - 'aria-valuemax' => '100', 'style' => "width: #{targets.values[0]}%;" } - = "#{targets.values[0]} %" - .row - .col-md-8.col-md-offset-2 - %div{ 'style' => 'display: none;', 'id' => "#{name}" } - - targets.drop(1).each_with_index do |(key, value), index| - .row - .col-md-10 - %h6.text-muted.pull-left - = "Target #{index + 2}" - .row - .col-md-10 - .progress{ 'title' => "#{key}" } - .progress-bar{ 'role' => 'progressbar', 'aria-valuenow' => "#{value}", 'aria-valuemin' => '0', - 'aria-valuemax' => '100', 'style' => "width: #{value}%;" } - = "#{value} %" - .row - .col-md-2.col-md-offset-2 - - if targets.length > 1 - %a.show_targets{ 'href' => '#', 'data-name' => "#{name}" } - more diff --git a/app/views/admin/conferences/show.html.haml b/app/views/admin/conferences/show.html.haml index 5f70ee6b..ed4d0cd1 100644 --- a/app/views/admin/conferences/show.html.haml +++ b/app/views/admin/conferences/show.html.haml @@ -115,13 +115,6 @@ = render partial: 'recent_submissions', locals: {recent_events: @recent_events} .col-md-4 = render partial: 'top_submitter', locals: {top_submitter: @top_submitter} -.row - .col-md-12 - %h3 - %span - %i.fa.fa-flag - Campaigns - = render partial: 'campaigns', locals: {campaigns: @campaigns, name: 'campaigns'} :javascript $('#recentTable a').click(function (e) { diff --git a/app/views/admin/targets/_form.html.haml b/app/views/admin/targets/_form.html.haml deleted file mode 100644 index df22922e..00000000 --- a/app/views/admin/targets/_form.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -.row - .col-md-12 - .page-header - %h1 - -if @target.new_record? - New - Target -.row - .col-md-8 - = semantic_form_for(@target, url: (@target.new_record? ? admin_conference_targets_path : admin_conference_target_path(@conference.short_title, @target))) do |f| - = f.input :due_date, as: :string, input_html: { class: 'target-due-date-datepicker'}, label: 'Until when do you want to have ' - = f.input :target_count, input_html: { autofocus: true }, label: 'this amount of ' - = f.input :unit, as: :select, label: 'Unit', class: 'form-control', collection: Target.units.values, include_blank: false - %p.text-right - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/targets/index.html.haml b/app/views/admin/targets/index.html.haml deleted file mode 100644 index 9c1ab7b5..00000000 --- a/app/views/admin/targets/index.html.haml +++ /dev/null @@ -1,35 +0,0 @@ -.row - .col-md-12 - .page-header - %h1 Targets - %p.text-muted - Set up goals for your conference -.row - .col-md-12 - %table.table.table-hover#targets - %thead - %tr - %th Due Date - %th Target Count - %th Unit - %th Actions - %tbody - - @targets.each do |target| - %tr - %td{'id'=> "due_date_#{target.id}"} - = target.due_date - %td{'id'=> "count#{target.id}"} - = target.target_count - %td{'id'=> "unit_#{target.id}"} - = target.unit - %td - .btn-group - = link_to 'Edit', - edit_admin_conference_target_path(@conference.short_title, target.id), - class: 'btn btn-primary' - = link_to 'Delete', - admin_conference_target_path(@conference.short_title, target.id), - method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete this target?" } -.row - .col-md-12 - = link_to 'New Target', new_admin_conference_target_path, class: 'btn btn-success pull-right' diff --git a/app/views/admin/versions/_object_desc_and_link.html.haml b/app/views/admin/versions/_object_desc_and_link.html.haml index 3ad17d07..bd06c92a 100644 --- a/app/views/admin/versions/_object_desc_and_link.html.haml +++ b/app/views/admin/versions/_object_desc_and_link.html.haml @@ -74,10 +74,6 @@ = link_to (current_or_last_object_state('Event', event_id).try(:title) || 'deleted event'), admin_conference_program_event_path(conference_short_title, event_id) -- when 'Target' - target - = link_if_alive version, object.to_s, admin_conference_targets_path(conference_short_title), conference - - when 'EventSchedule' event = link_to (current_or_last_object_state('Event', object.event_id).try(:title) || 'deleted'), @@ -187,12 +183,6 @@ admin_conference_ticket_path(conference_short_title, version.item_id), conference -- when 'Campaign' - campaign - = link_if_alive version, object.name, - admin_conference_campaigns_path(conference_short_title), - conference - - when 'DifficultyLevel' difficulty level = link_if_alive version, object.title,admin_conference_program_difficulty_levels_path(conference_short_title), conference diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index eebd7548..2f6ed5a5 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -121,18 +121,6 @@ = link_to admin_conference_booths_path(@conference.short_title) do %span.fa.fa-shopping-bag Booths - - if (can? :manage, @conference.targets.build) || (can? :manage, @conference.campaigns.build) - %li - %a - %span.fa.fa-money - Objectives - %ul - - if can? :update, @conference.campaigns.build - %li{class: active_nav_li(admin_conference_campaigns_path(@conference.short_title))} - = link_to 'Campaigns', admin_conference_campaigns_path(@conference.short_title) - - if can? :update, @conference.targets.build - %li{class: "#{active_nav_li(admin_conference_targets_path(@conference.short_title))}"} - = link_to 'Goals', admin_conference_targets_path(@conference.short_title) - if can? :update, @conference.email_settings %li{class: active_nav_li(admin_conference_emails_path(@conference.short_title))} = link_to(admin_conference_emails_path(@conference.short_title)) do diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb deleted file mode 100644 index e1035570..00000000 --- a/config/initializers/ahoy.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Ahoy - class Store < Ahoy::DatabaseStore - def visit_model - Visit - end - end -end diff --git a/config/routes.rb b/config/routes.rb index 7e46b6be..c287577b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,8 +14,6 @@ Osem::Application.routes.draw do path: 'accounts' end - mount Ahoy::Engine => '/ahoy' - # Use letter_opener_web to open mails in browser (e.g. necessary for Vagrant) if Rails.env.development? mount LetterOpenerWeb::Engine, at: "/letter_opener" @@ -125,8 +123,6 @@ Osem::Application.routes.draw do resources :tickets resources :sponsors, except: [:show] resources :lodgings, except: [:show] - resources :targets, except: [:show] - resources :campaigns, except: [:show] resources :emails, only: [:show, :update, :index] resources :physical_tickets, only: [:index] resources :roles, except: [:new, :create] do diff --git a/db/migrate/20181009000259_drop_ahoy_events.rb b/db/migrate/20181009000259_drop_ahoy_events.rb new file mode 100644 index 00000000..dbf74626 --- /dev/null +++ b/db/migrate/20181009000259_drop_ahoy_events.rb @@ -0,0 +1,15 @@ +class DropAhoyEvents < ActiveRecord::Migration[5.0] + def up + remove_index :visits, [:visit_token] + remove_index :ahoy_events, [:name, :time] + + drop_table :targets + drop_table :campaigns + drop_table :visits + drop_table :ahoy_events + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index dc97c09c..3f55924f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,19 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180924221715) do - - create_table "ahoy_events", force: :cascade do |t| - t.integer "visit_id" - t.integer "user_id" - t.string "name" - t.text "properties" - t.datetime "time" - t.index ["name", "time"], name: "index_ahoy_events_on_name_and_time" - t.index ["time"], name: "index_ahoy_events_on_time" - t.index ["user_id"], name: "index_ahoy_events_on_user_id" - t.index ["visit_id"], name: "index_ahoy_events_on_visit_id" - end +ActiveRecord::Schema.define(version: 20181009000259) do create_table "answers", force: :cascade do |t| t.string "title" @@ -53,18 +41,6 @@ ActiveRecord::Schema.define(version: 20180924221715) do t.datetime "updated_at", null: false end - create_table "campaigns", force: :cascade do |t| - t.integer "conference_id" - t.string "name" - t.string "utm_source" - t.string "utm_medium" - t.string "utm_term" - t.string "utm_content" - t.string "utm_campaign" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "cfps", force: :cascade do |t| t.date "start_date", null: false t.date "end_date", null: false @@ -520,18 +496,7 @@ ActiveRecord::Schema.define(version: 20180924221715) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "target", default: 0 - end - - add_index "surveys", ["surveyable_type", "surveyable_id"], name: "index_surveys_on_surveyable_type_and_surveyable_id" - - create_table "targets", force: :cascade do |t| - t.integer "conference_id" - t.integer "campaign_id" - t.date "due_date" - t.integer "target_count" - t.string "unit" - t.datetime "created_at" - t.datetime "updated_at" + t.index ["surveyable_type", "surveyable_id"], name: "index_surveys_on_surveyable_type_and_surveyable_id" end create_table "ticket_purchases", force: :cascade do |t| @@ -673,33 +638,6 @@ ActiveRecord::Schema.define(version: 20180924221715) do t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" end - create_table "visits", force: :cascade do |t| - t.binary "visitor_id", limit: 16 - t.string "ip" - t.text "user_agent" - t.text "referrer" - t.text "landing_page" - t.integer "user_id" - t.string "referring_domain" - t.string "search_keyword" - t.string "browser" - t.string "os" - t.string "device_type" - t.string "country" - t.string "region" - t.string "city" - t.string "utm_source" - t.string "utm_medium" - t.string "utm_term" - t.string "utm_content" - t.string "utm_campaign" - t.datetime "started_at" - t.string "visit_token" - t.string "visitor_token" - t.index ["user_id"], name: "index_visits_on_user_id" - t.index ["visit_token"], name: "index_visits_on_visit_token", unique: true - end - create_table "votes", force: :cascade do |t| t.integer "event_id" t.integer "rating" diff --git a/spec/controllers/admin/targets_controller_spec.rb b/spec/controllers/admin/targets_controller_spec.rb deleted file mode 100644 index ad0f5a2c..00000000 --- a/spec/controllers/admin/targets_controller_spec.rb +++ /dev/null @@ -1,170 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Admin::TargetsController, type: :controller do - let(:admin) { create(:admin) } - let(:conference) { create(:conference) } - let(:target) { create(:target, conference: conference, target_count: 100) } - - context 'user is admin' do - before { sign_in admin } - - describe 'GET #index' do - before { get :index, conference_id: conference.short_title } - - it 'renders index template' do - expect(response).to render_template('index') - end - - it 'assigns targets and conference variables' do - expect(assigns(:conference)).to eq conference - expect(assigns(:targets)).to eq [target] - end - end - - describe 'GET #new' do - before { get :new, conference_id: conference.short_title } - - it 'renders new template' do - expect(response).to render_template('new') - end - - it 'assigns target variable' do - expect(assigns(:target)).to be_instance_of(Target) - end - end - - describe 'POST #create' do - context 'saves successfuly' do - before do - post :create, target: attributes_for(:target), conference_id: conference.short_title - end - - it 'redirects to admin target index path' do - expect(response).to redirect_to admin_conference_targets_path(conference_id: conference.short_title) - end - - it 'shows success message in flash notice' do - expect(flash[:notice]).to match('Target successfully created.') - end - - it 'creates new target' do - expect(Target.count).to eq 1 - end - end - - context 'save fails' do - before do - allow_any_instance_of(Target).to receive(:save).and_return(false) - post :create, target: attributes_for(:target), conference_id: conference.short_title - end - - it 'renders new template' do - expect(response).to render_template('new') - end - - it 'shows error in flash message' do - expect(flash[:error]).to match("Creating target failed: #{target.errors.full_messages.join('. ')}.") - end - - it 'does not create new target' do - expect(Target.count).to eq 0 - end - end - end - - describe 'GET #edit' do - before { get :edit, conference_id: conference.short_title, id: target.id } - - it 'renders edit template' do - expect(response).to render_template('edit') - end - - it 'assigns target variable' do - expect(assigns(:target)).to eq target - end - end - - describe 'PATCH #update' do - context 'updates successfully' do - before do - patch :update, target: attributes_for(:target, target_count: 2), - conference_id: conference.short_title, - id: target.id - end - - it 'redirects to admin target index path' do - expect(response).to redirect_to admin_conference_targets_path(conference_id: conference.short_title) - end - - it 'shows success message in flash notice' do - expect(flash[:notice]).to match('Target successfully updated.') - end - - it 'updates the target' do - target.reload - expect(target.target_count).to eq 2 - end - end - - context 'update fails' do - before do - allow_any_instance_of(Target).to receive(:save).and_return(false) - patch :update, target: attributes_for(:target, target_count: 2), - conference_id: conference.short_title, - id: target.id - end - - it 'renders edit template' do - expect(response).to render_template('edit') - end - - it 'shows error in flash message' do - expect(flash[:error]).to match("Target update failed: #{target.errors.full_messages.join('. ')}.") - end - - it 'does not update target' do - expect(target.target_count).to eq 100 - end - end - end - - describe 'DELETE #destroy' do - context 'deletes successfully' do - before { delete :destroy, conference_id: conference.short_title, id: target.id } - - it 'redirects to admin target index path' do - expect(response).to redirect_to admin_conference_targets_path(conference_id: conference.short_title) - end - - it 'shows success message in flash notice' do - expect(flash[:notice]).to match('Target successfully destroyed.') - end - - it 'deletes target' do - expect(Target.count).to eq 0 - end - end - - context 'delete fails' do - before do - allow_any_instance_of(Target).to receive(:destroy).and_return(false) - delete :destroy, conference_id: conference.short_title, id: target.id - end - - it 'redirects to admin target index path' do - expect(response).to redirect_to admin_conference_targets_path(conference_id: conference.short_title) - end - - it 'shows error in flash message' do - expect(flash[:error]).to match("Could not delete target for #{conference.title}: #{target.errors.full_messages.join('. ')}.") - end - - it 'does not delete target' do - expect(Target.count).to eq 1 - end - end - end - end -end diff --git a/spec/factories/campaigns.rb b/spec/factories/campaigns.rb deleted file mode 100644 index e8c95b46..00000000 --- a/spec/factories/campaigns.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -# Read about factories at https://github.com/thoughtbot/factory_bot - -FactoryBot.define do - factory :campaign do - name { 'Test Campaign' } - utm_campaign { 'testcampaign' } - conference - end -end diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index 037a58ef..dcb0e662 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -46,8 +46,6 @@ FactoryBot.define do create_list(:sponsor, 2, sponsorship_level: conference.sponsorship_levels.second, conference: conference) create_list(:sponsor, 3, sponsorship_level: conference.sponsorship_levels.third, conference: conference) - create(:campaign, conference: conference) - create(:target, conference: conference) create(:question, conferences: [conference]) # Logo... diff --git a/spec/factories/targets.rb b/spec/factories/targets.rb deleted file mode 100644 index 929ce4ac..00000000 --- a/spec/factories/targets.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -# Read about factories at https://github.com/thoughtbot/factory_bot - -FactoryBot.define do - factory :target do - due_date { 14.days.from_now } - target_count { 100 } - unit { Target.units[:submissions] } - conference - end -end diff --git a/spec/factories/visits.rb b/spec/factories/visits.rb deleted file mode 100644 index 1da2b293..00000000 --- a/spec/factories/visits.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -# Read about factories at https://github.com/thoughtbot/factory_bot - -FactoryBot.define do - factory :visit do - end -end diff --git a/spec/features/campaign_spec.rb b/spec/features/campaign_spec.rb deleted file mode 100644 index 38e9e9cb..00000000 --- a/spec/features/campaign_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -feature Campaign do - - let!(:conference) { create(:conference, short_title: 'osc14') } - let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } - let!(:organizer) { create(:user, role_ids: [organizer_role.id]) } - - shared_examples 'add and update campaign' do - scenario 'adds and update a campaign', feature: true, js: true do - expected_count = Campaign.count + 1 - sign_in organizer - - visit admin_conference_campaigns_path(conference.short_title) - - click_link 'New Campaign' - - click_button 'Create Campaign' - - expect(flash).to eq("Campaign creation failed. Name can't be blank and Utm campaign can't be blank") - - fill_in 'campaign_name', with: 'Test Campaign' - fill_in 'campaign_utm_campaign', with: 'campaign' - fill_in 'campaign_utm_source', with: 'source' - fill_in 'campaign_utm_medium', with: 'medium' - fill_in 'campaign_utm_term', with: 'term' - fill_in 'campaign_utm_content', with: 'content' - - click_button 'Create Campaign' - - # Validations - expect(flash).to eq('Campaign successfully created.') - - expect(page).to have_selector('[id^="name_"]', text: 'Test Campaign') - expect(page).to have_selector('[id^="visits_"]', text: '0') - expect(page).to have_selector('[id^="registrations_"]', text: '0') - expect(page).to have_selector('[id^="submissions_"]', text: '0') - - expect(Campaign.count).to eq(expected_count) - - campaign = Campaign.where('name' => 'Test Campaign').first - visit edit_admin_conference_campaign_path(conference.short_title, campaign.id) - - fill_in 'campaign_name', with: 'Test Campaign 42' - click_button 'Update Campaign' - expect(flash).to eq("Campaign 'Test Campaign 42' successfully updated.") - end - end - - describe 'organizer' do - it_behaves_like 'add and update campaign' - end -end diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb index d5119bd3..4ff56e5b 100644 --- a/spec/features/cfp_ability_spec.rb +++ b/spec/features/cfp_ability_spec.rb @@ -43,9 +43,6 @@ feature 'Has correct abilities' do expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") expect(page).to_not have_link('New Conference', href: '/admin/conferences/new') @@ -250,26 +247,6 @@ feature 'Has correct abilities' do visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) expect(current_path).to eq(root_path) - visit admin_conference_campaigns_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_campaign_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:campaign, conference: conference) - visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) - expect(current_path).to eq(root_path) - - visit admin_conference_targets_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_target_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:target, conference: conference) - visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) - expect(current_path).to eq(root_path) - visit admin_conference_roles_path(conference.short_title) expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) diff --git a/spec/features/info_desk_ability_spec.rb b/spec/features/info_desk_ability_spec.rb index bb485e51..066c95b8 100644 --- a/spec/features/info_desk_ability_spec.rb +++ b/spec/features/info_desk_ability_spec.rb @@ -29,9 +29,6 @@ feature 'Has correct abilities' do expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') @@ -128,26 +125,6 @@ feature 'Has correct abilities' do visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) expect(current_path).to eq(root_path) - visit admin_conference_campaigns_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_campaign_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:campaign, conference: conference) - visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) - expect(current_path).to eq(root_path) - - visit admin_conference_targets_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_target_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:target, conference: conference) - visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) - expect(current_path).to eq(root_path) - visit admin_conference_roles_path(conference.short_title) expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb index 6fa6b090..47aa98ed 100644 --- a/spec/features/organization_admin_ability_spec.rb +++ b/spec/features/organization_admin_ability_spec.rb @@ -52,9 +52,6 @@ feature 'Has correct abilities' do expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") - expect(page).to have_text('Objectives') - expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") - expect(page).to have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") @@ -236,26 +233,6 @@ feature 'Has correct abilities' do visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) expect(current_path).to eq(edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first)) - visit admin_conference_campaigns_path(conference.short_title) - expect(current_path).to eq(admin_conference_campaigns_path(conference.short_title)) - - visit new_admin_conference_campaign_path(conference.short_title) - expect(current_path).to eq(new_admin_conference_campaign_path(conference.short_title)) - - create(:campaign, conference: conference) - visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) - expect(current_path).to eq(edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first)) - - visit admin_conference_targets_path(conference.short_title) - expect(current_path).to eq(admin_conference_targets_path(conference.short_title)) - - visit new_admin_conference_target_path(conference.short_title) - expect(current_path).to eq(new_admin_conference_target_path(conference.short_title)) - - create(:target, conference: conference) - visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) - expect(current_path).to eq(edit_admin_conference_target_path(conference.short_title, conference.targets.first)) - visit admin_conference_program_tracks_path(conference.short_title) expect(current_path).to eq(admin_conference_program_tracks_path(conference.short_title)) diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index b9c8cb5d..1c597c02 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -55,9 +55,6 @@ feature 'Has correct abilities' do expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") - expect(page).to have_text('Objectives') - expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") - expect(page).to have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") @@ -242,26 +239,6 @@ feature 'Has correct abilities' do visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) expect(current_path).to eq(edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first)) - visit admin_conference_campaigns_path(conference.short_title) - expect(current_path).to eq(admin_conference_campaigns_path(conference.short_title)) - - visit new_admin_conference_campaign_path(conference.short_title) - expect(current_path).to eq(new_admin_conference_campaign_path(conference.short_title)) - - create(:campaign, conference: conference) - visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) - expect(current_path).to eq(edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first)) - - visit admin_conference_targets_path(conference.short_title) - expect(current_path).to eq(admin_conference_targets_path(conference.short_title)) - - visit new_admin_conference_target_path(conference.short_title) - expect(current_path).to eq(new_admin_conference_target_path(conference.short_title)) - - create(:target, conference: conference) - visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) - expect(current_path).to eq(edit_admin_conference_target_path(conference.short_title, conference.targets.first)) - visit admin_conference_booths_path(conference.short_title) expect(current_path).to eq(admin_conference_booths_path(conference.short_title)) diff --git a/spec/features/track_organizer_ability_spec.rb b/spec/features/track_organizer_ability_spec.rb index 073c3700..ec2ffdf1 100644 --- a/spec/features/track_organizer_ability_spec.rb +++ b/spec/features/track_organizer_ability_spec.rb @@ -43,9 +43,6 @@ feature 'Has correct abilities' do expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") expect(page).to_not have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to_not have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") @@ -192,26 +189,6 @@ feature 'Has correct abilities' do visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) expect(current_path).to eq root_path - visit admin_conference_campaigns_path(conference.short_title) - expect(current_path).to eq root_path - - visit new_admin_conference_campaign_path(conference.short_title) - expect(current_path).to eq root_path - - create(:campaign, conference: conference) - visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) - expect(current_path).to eq root_path - - visit admin_conference_targets_path(conference.short_title) - expect(current_path).to eq root_path - - visit new_admin_conference_target_path(conference.short_title) - expect(current_path).to eq root_path - - create(:target, conference: conference) - visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) - expect(current_path).to eq root_path - visit admin_conference_program_tracks_path(conference.short_title) expect(current_path).to eq admin_conference_program_tracks_path(conference.short_title) diff --git a/spec/features/versions_spec.rb b/spec/features/versions_spec.rb index 601f4ff9..7f81cb09 100644 --- a/spec/features/versions_spec.rb +++ b/spec/features/versions_spec.rb @@ -374,18 +374,6 @@ feature 'Version' do expect(page).to have_text("Someone (probably via the console) unregistered #{organizer.name} from event #{event.title} in conference #{conference.short_title}") end - scenario 'display changes in target', feature: true, versioning: true, js: true do - target = create(:target, conference: conference) - target.update_attributes(due_date: Date.today, target_count: 1000) - target_id = target.id - target.destroy - - visit admin_revision_history_path - expect(page).to have_text("Someone (probably via the console) created new target 1000 Submissions by #{Date.today} with ID #{target_id} in conference #{conference.short_title}") - expect(page).to have_text("Someone (probably via the console) updated due date and target count of target 1000 Submissions by #{Date.today} with ID #{target_id} in conference #{conference.short_title}") - expect(page).to have_text("Someone (probably via the console) deleted target 1000 Submissions by #{Date.today} with ID #{target_id} in conference #{conference.short_title}") - end - scenario 'display changes in comment', feature: true, versioning: true, js: true do create(:event, program: conference.program, title: 'My first event') event = create(:event, program: conference.program, title: 'My second event') @@ -416,18 +404,6 @@ feature 'Version' do expect(page).to have_text("Someone (probably via the console) re-added #{organizer.name}'s vote on event #{event.title} in conference #{conference.short_title}") end - scenario 'display changes in campaign', feature: true, versioning: true, js: true do - campaign = create(:campaign, conference: conference, name: 'Test Campaign', utm_campaign: 'campaign') - campaign.update_attributes(utm_source: 'source', utm_medium: 'medium', utm_term: 'term', utm_content: 'content') - campaign_id = campaign.id - campaign.destroy - - visit admin_revision_history_path - expect(page).to have_text("Someone (probably via the console) created new campaign Test Campaign with ID #{campaign_id} in conference #{conference.short_title}") - expect(page).to have_text("Someone (probably via the console) updated utm source, utm medium, utm term and utm content of campaign Test Campaign with ID #{campaign_id} in conference #{conference.short_title}") - expect(page).to have_text("Someone (probably via the console) deleted campaign Test Campaign with ID #{campaign_id} in conference #{conference.short_title}") - end - scenario 'display password reset requests', feature: true, versioning: true, js: true do user = create(:user) user.send_reset_password_instructions diff --git a/spec/models/campaign_spec.rb b/spec/models/campaign_spec.rb deleted file mode 100644 index 178717ae..00000000 --- a/spec/models/campaign_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require 'ahoy' - -describe Campaign do - describe 'validations' do - it 'has a valid factory' do - expect(build(:campaign)).to be_valid - end - - it 'is not valid without a name' do - should validate_presence_of(:name) - end - end - - describe '#url_parameters' do - it 'returns the parameters in the correct format' do - campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') - campaign.conference = create(:conference) - - result = '?utm_source=google+&utm_medium=advertisement&utm_term=opensource&utm_content=content&utm_campaign=20percent' - expect(campaign.url_parameters).to eq(result) - end - - it 'returns only utm_campaign parameter if there are no parameters' do - campaign = create(:campaign) - campaign.conference = create(:conference) - expect(campaign.url_parameters).to eq('?utm_campaign=testcampaign') - end - end - - describe '#visits' do - it 'returns one if there is one visit' do - campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') - campaign.conference = build(:conference) - - create(:visit, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent', started_at: Time.now + 1.hour) - expect(campaign.visits_count).to eq(1) - end - - it 'returns zero if there are no visits' do - campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') - campaign.conference = create(:conference) - - expect(campaign.visits_count).to eq(0) - end - end - - describe '#registrations' do - it 'returns zero if there are no registration' do - campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') - campaign.conference = build(:conference) - - expect(campaign.registrations_count).to eq(0) - end - end - - describe '#submissions' do - it 'returns zero if there are no submissions' do - campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') - campaign.conference = build(:conference) - - expect(campaign.submissions_count).to eq(0) - end - end -end diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 2720f5de..e99d18e0 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -302,69 +302,6 @@ describe Conference do end - describe '#get_targets' do - it 'returns 0 if there is no registration' do - target = build(:target, target_count: 10, unit: Target.units[:registrations]) - subject.targets = [target] - result = { - "10 Registrations by #{target.due_date}" => '0' - } - expect(subject.get_targets(Target.units[:registrations])).to eq(result) - end - - it 'returns 10 if there is 1 registration of 10' do - target = build(:target, target_count: 10, unit: Target.units[:registrations]) - subject.targets = [target] - subject.registrations = [create(:registration)] - result = { - "10 Registrations by #{target.due_date}" => '10' - } - expect(subject.get_targets(Target.units[:registrations])).to eq(result) - end - - it 'returns an empty hash if there is no target' do - expect(subject.get_targets(Target.units[:registrations])).to eq({}) - end - - it 'returns 0 if there is no submission' do - target = build(:target, target_count: 10, unit: Target.units[:submissions]) - subject.targets = [target] - result = { - "10 Submissions by #{target.due_date}" => '0' - } - expect(subject.get_targets(Target.units[:submissions])).to eq(result) - end - - it 'returns 10 if there is 1 submissions of 10' do - target = build(:target, target_count: 10, unit: Target.units[:submissions]) - subject.targets = [target] - subject.program.events = [create(:event)] - result = { - "10 Submissions by #{target.due_date}" => '10' - } - expect(subject.get_targets(Target.units[:submissions])).to eq(result) - end - - it 'returns 0 if there is no program minute' do - target = build(:target, target_count: 300, unit: Target.units[:program_minutes]) - subject.targets = [target] - result = { - "300 Program minutes by #{target.due_date}" => '0' - } - expect(subject.get_targets(Target.units[:program_minutes])).to eq(result) - end - - it 'returns 10 if there is 30 program minutes of 300' do - target = build(:target, target_count: 300, unit: Target.units[:program_minutes]) - subject.targets = [target] - subject.program.events = [create(:event)] - result = { - "300 Program minutes by #{target.due_date}" => '10' - } - expect(subject.get_targets(Target.units[:program_minutes])).to eq(result) - end - end - describe 'program hours and minutes' do before(:each) do @long = create(:event_type, length: 120) diff --git a/spec/models/target_spec.rb b/spec/models/target_spec.rb deleted file mode 100644 index 501c1c4c..00000000 --- a/spec/models/target_spec.rb +++ /dev/null @@ -1,166 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Target do - let(:registration_target) { create(:target, target_count: 10, unit: Target.units[:registrations]) } - let(:submission_target) { create(:target, target_count: 10, unit: Target.units[:submissions]) } - let(:program_minutes_target) { create(:target, target_count: 300, unit: Target.units[:program_minutes]) } - - describe 'validation' do - it 'has a valid factory' do - expect(build(:target)).to be_valid - end - - it 'is not valid without a due date' do - should validate_presence_of(:due_date) - end - - it 'is not valid without a target_count' do - should validate_presence_of(:target_count) - end - - it 'is not valid without a unit' do - should validate_presence_of(:unit) - end - - it 'is valid with a target_count greater than zero' do - should allow_value(10).for(:target_count) - end - - it 'is not valid with a target_count equals zero' do - should_not allow_value(0).for(:target_count) - end - - it 'is not valid with a target_count smaller than zero' do - should_not allow_value(-10).for(:target_count) - end - end - - describe 'default scope' do - before do - @first_target = create(:target, due_date: 2.days.from_now) - @second_target = create(:target, due_date: 3.days.from_now) - end - - it 'orders by ascending due_date' do - expect(Target.all).to match_array [@first_target, @second_target] - end - end - - describe 'association' do - it { should belong_to(:conference) } - it { should belong_to(:campaign) } - end - - describe '#get_progress' do - it 'returns zero, when there are no registrations' do - expect(registration_target.get_progress).to eq('0') - end - - it 'returns 10, when there is 1 registration and the target is 10' do - create(:registration, conference: registration_target.conference) - - expect(registration_target.get_progress).to eq('10') - end - - it 'returns zero, when there are no submissions' do - expect(submission_target.get_progress).to eq('0') - end - - it 'returns 10, when there is 1 submission and the target is 10' do - create(:event, program: submission_target.conference.program) - - expect(submission_target.get_progress).to eq('10') - end - - it 'returns zero, when there are no program minutes' do - expect(program_minutes_target.get_progress).to eq('0') - end - - it 'returns 10, when there are 30 program minutes and the target is 300' do - create(:event, program: program_minutes_target.conference.program) - - expect(program_minutes_target.get_progress).to eq('10') - end - end - - describe '#get_campaign' do - context 'submissions' do - before do - submission_target.campaign = create(:campaign, name: 'Submission Campaign', conference: submission_target.conference) - submission_target.created_at = Time.utc(2014, 5, 10) - submission_target.due_date = Date.today + 4.days - allow(submission_target.campaign).to receive(:submissions_count) { 20 } - end - - it 'returns a hash with values of the corresponding campaign submissions' do - result = { - 'target_name' => "10 Submissions by #{Date.today + 4.days}", - 'campaign_name' => 'Submission Campaign', - 'value' => 20, - 'unit' => 'Submission', - 'created_at' => Time.utc(2014, 5, 10).in_time_zone, - 'progress' => '200', - 'days_left' => 4 - } - - expect(submission_target.get_campaign).to eq result - end - end - - context 'registrations' do - before do - registration_target.campaign = create(:campaign, name: 'Registration Campaign', conference: registration_target.conference) - registration_target.created_at = Time.utc(2014, 5, 10) - registration_target.due_date = Date.today + 4.days - allow(registration_target.campaign).to receive(:registrations_count) { 20 } - end - - it 'returns a hash with values of the corresponding campaign registrations' do - result = { - 'target_name' => "10 Registrations by #{Date.today + 4.days}", - 'campaign_name' => 'Registration Campaign', - 'value' => 20, - 'unit' => 'Registration', - 'created_at' => Time.utc(2014, 5, 10).in_time_zone, - 'progress' => '200', - 'days_left' => 4 - } - - expect(registration_target.get_campaign).to eq result - end - end - - context 'program_minutes' do - before do - program_minutes_target.campaign = create(:campaign, name: 'Program Campaign', conference: program_minutes_target.conference) - program_minutes_target.created_at = Time.utc(2014, 5, 10) - program_minutes_target.due_date = Date.today + 4.days - allow(program_minutes_target.conference).to receive(:current_program_minutes) { 20 } - end - - it 'returns a hash with values of the corresponding campaign program minutes' do - result = { - 'target_name' => "300 Program minutes by #{Date.today + 4.days}", - 'campaign_name' => 'Program Campaign', - 'value' => 20, - 'unit' => 'Program minute', - 'created_at' => Time.utc(2014, 5, 10).in_time_zone, - 'progress' => '7', - 'days_left' => 4 - } - - expect(program_minutes_target.get_campaign).to eq result - end - end - end - - describe '#to_s' do - it 'returns a string in the correct format' do - result = "10 Registrations by #{14.days.from_now.to_date}" - - expect(registration_target.to_s).to eq(result) - end - end -end