From 27fcf9d2dd8a4b5407af3e721c85c30f9d9a7287 Mon Sep 17 00:00:00 2001 From: Vince Martinez Fasoro Date: Wed, 3 Apr 2019 18:49:59 +0100 Subject: [PATCH] Run `rubocop -a` on codebase after 2.6 update. New target is 2.6 --- Gemfile | 7 +- Rakefile | 2 +- app/admin/action.rb | 3 +- app/admin/call.rb | 1 + app/admin/campaign.rb | 1 + app/admin/dashboard.rb | 3 +- app/admin/donation_band.rb | 3 +- app/admin/form.rb | 1 + app/admin/form_element.rb | 1 + app/admin/image.rb | 3 +- app/admin/language.rb | 1 + app/admin/link.rb | 1 + app/admin/liquid_layout.rb | 3 +- app/admin/liquid_partial.rb | 3 +- app/admin/pages_tag.rb | 1 + app/admin/phone_number.rb | 1 + app/admin/tag.rb | 1 + .../api/action_confirmations_controller.rb | 1 + app/controllers/api/analytics_controller.rb | 1 + .../api/email_target_emails_controller.rb | 4 +- app/controllers/api/go_cardless_controller.rb | 4 +- app/controllers/api/members_controller.rb | 1 + .../api/payment/braintree_controller.rb | 4 +- .../api/pension_funds_controller.rb | 1 + .../api/stateless/auth_controller.rb | 1 + .../braintree/payment_methods_controller.rb | 1 + .../braintree/subscriptions_controller.rb | 1 + .../braintree/transactions_controller.rb | 1 + .../go_cardless/payment_methods_controller.rb | 1 + .../go_cardless/subscriptions_controller.rb | 1 + .../go_cardless/transactions_controller.rb | 1 + .../api/stateless/location_controller.rb | 1 + .../api/stateless/stateless_controller.rb | 5 +- .../api/survey_responses_controller.rb | 7 +- app/controllers/campaigns_controller.rb | 3 +- app/controllers/clone_pages_controller.rb | 1 + app/controllers/donation_bands_controller.rb | 3 +- .../email_confirmation_controller.rb | 2 + app/controllers/featured_pages_controller.rb | 3 +- app/controllers/forms_controller.rb | 3 +- app/controllers/home_controller.rb | 1 + app/controllers/images_controller.rb | 1 + app/controllers/links_controller.rb | 1 + app/controllers/liquid_layouts_controller.rb | 3 +- app/controllers/liquid_partials_controller.rb | 3 +- .../member_authentications_controller.rb | 4 +- .../omniauth_callbacks_controller.rb | 1 + app/controllers/page_archives_controller.rb | 1 + app/controllers/plugins/forms_controller.rb | 1 + .../plugins/fundraisers_controller.rb | 1 + .../plugins/petitions_controller.rb | 1 + app/controllers/plugins/surveys_controller.rb | 1 + app/controllers/plugins/texts_controller.rb | 1 + app/controllers/share/shares_controller.rb | 4 +- app/controllers/uris_controller.rb | 3 +- app/controllers/versions_controller.rb | 1 + app/helpers/api/analytics_helper.rb | 1 + app/helpers/api/pages_helper.rb | 2 + app/helpers/application_helper.rb | 1 + app/helpers/layout_select_helper.rb | 2 + app/lib/champaign_queue/clients/sqs.rb | 2 +- app/lib/donations/utils.rb | 2 +- app/lib/forget_member.rb | 1 - app/lib/go_cardless_director.rb | 6 +- app/lib/has_phone_number.rb | 8 +- .../braintree/one_click_from_uri.rb | 2 + .../braintree/subscription.rb | 1 + .../go_cardless/populator.rb | 5 +- .../go_cardless/subscription.rb | 20 ++-- .../go_cardless/transaction.rb | 14 +-- .../webhook_handler/process_events.rb | 9 +- .../webhook_handler/processable.rb | 1 + app/liquid/champaign_liquid_filters.rb | 2 + app/liquid/liquid_file_system.rb | 3 + app/liquid/liquid_helper.rb | 2 + app/liquid/liquid_i18n.rb | 2 + app/liquid/liquid_tag_finder.rb | 2 + app/liquid/shares.rb | 1 + app/models/actionkit_page_type.rb | 1 + app/models/ak_log.rb | 1 + app/models/concerns/has_liquid_partials.rb | 3 + app/models/language.rb | 3 +- app/models/pages_tag.rb | 5 +- app/models/payment/braintree.rb | 77 ++++++------ app/models/payment/go_cardless.rb | 1 + app/models/plugins/has_form.rb | 4 + app/models/share.rb | 1 + app/services/action_collator.rb | 8 +- app/services/action_params_builder.rb | 2 +- app/services/action_reader.rb | 1 + app/services/akid_parser.rb | 1 + .../payment_method_builder.rb | 3 +- .../braintree_services/payment_options.rb | 2 + .../braintree_services/transaction_builder.rb | 24 ++-- app/services/call_tool/call_status_updater.rb | 2 + app/services/call_tool/checksum_validator.rb | 1 + app/services/call_tool/stats.rb | 4 +- app/services/connect_with_oauth_provider.rb | 2 + ...reate_member_for_api_members_controller.rb | 2 + app/services/email_tool_sender.rb | 32 ++--- app/services/email_verifier_service.rb | 1 + app/services/form_duplicator.rb | 1 + app/services/form_element_builder.rb | 11 +- app/services/form_validator.rb | 11 +- .../go_cardless_cancellation_service.rb | 8 +- app/services/manage_action.rb | 6 +- app/services/manage_braintree_donation.rb | 20 ++-- app/services/manage_survey_response.rb | 2 + .../member_services/member_updater.rb | 4 +- app/services/member_with_authentication.rb | 2 +- app/services/mobile_detector.rb | 2 + app/services/name_splitter.rb | 1 + app/services/page_builder.rb | 1 + app/services/page_follower.rb | 3 + app/services/page_updater.rb | 6 +- app/services/postal_validator.rb | 14 +-- app/services/queue_manager.rb | 10 +- app/services/search.rb | 1 + app/services/search/page_searcher.rb | 12 +- app/services/survey_session_manager.rb | 1 + app/validators/action_kit_fields.rb | 8 +- app/views/api/analytics/show.json.jbuilder | 1 + .../cancel_recurring_donation.jbuilder | 1 + app/views/api/member_services/member.jbuilder | 1 + .../subject_access_request.jbuilder | 1 + app/views/api/pages/index.json.jbuilder | 1 + app/views/api/pages/show.json.jbuilder | 1 + .../payment/braintree/one_click.json.jbuilder | 1 + .../payment_methods/index.json.jbuilder | 1 + .../subscriptions/index.json.jbuilder | 1 + .../transactions/index.json.jbuilder | 1 + .../payment_methods/index.json.jbuilder | 1 + .../subscriptions/index.json.jbuilder | 1 + .../transactions/index.json.jbuilder | 1 + .../api/stateless/members/show.json.jbuilder | 1 + .../stateless/members/update.json.jbuilder | 1 + app/views/liquid_layouts/index.json.jbuilder | 1 + app/views/liquid_layouts/show.json.jbuilder | 1 + app/views/liquid_partials/index.json.jbuilder | 1 + app/views/liquid_partials/show.json.jbuilder | 1 + config/environment.rb | 1 + config/environments/production.rb | 8 +- config/initializers/actionkit_connector.rb | 1 + config/initializers/airbrake.rb | 3 +- config/initializers/aws_sdk.rb | 1 + config/initializers/braintree.rb | 1 + config/initializers/config.rb | 1 + config/initializers/cookies_serializer.rb | 1 + config/initializers/countries.rb | 1 + config/initializers/devise.rb | 1 + .../initializers/filter_parameter_logging.rb | 1 + config/initializers/friendly_id.rb | 5 +- config/initializers/geocoder.rb | 1 + config/initializers/liquid.rb | 1 + config/initializers/session_store.rb | 1 + config/initializers/twilio.rb | 1 + config/initializers/wrap_parameters.rb | 1 + config/puma.rb | 6 +- config/spring.rb | 4 +- ...11083418_change_col_name_on_thermometer.rb | 2 +- ...170304151306_migrate_call_target_format.rb | 1 + lib/tasks/action_kit.rake | 8 +- lib/tasks/assets.rake | 1 + lib/tasks/export_member.rake | 4 +- spec/factories/campaigns.rb | 1 + spec/factories/link.rb | 1 + spec/helpers/api/analytics_helper_spec.rb | 1 + spec/helpers/api/pages_helper_spec.rb | 1 + spec/javascripts/fixtures/magic_lamp.rb | 37 +++--- spec/javascripts/support/magic_lamp_config.rb | 1 + .../support/magic_lamp_helpers/auth_stub.rb | 1 + .../braintree/transaction_spec.rb | 14 +-- .../go_cardless/error_processing_spec.rb | 2 +- spec/liquid/champaign_liquid_filters_spec.rb | 1 + spec/liquid/liquid_file_system_spec.rb | 1 + spec/liquid/liquid_helper_spec.rb | 1 + spec/liquid/liquid_i18n_spec.rb | 1 + spec/liquid/liquid_renderer_spec.rb | 2 +- spec/liquid/liquid_tag_finder_spec.rb | 23 ++-- spec/mailers/confirmation_mailer_spec.rb | 1 + .../previews/confirmation_mailer_preview.rb | 1 + spec/models/action_user_spec.rb | 1 + spec/models/ak_log_spec.rb | 1 + spec/models/language_spec.rb | 5 +- spec/models/payment/braintree_spec.rb | 113 +++++++++--------- spec/models/plugins/text.rb | 1 + spec/rails_helper.rb | 2 +- spec/requests/api/action_confirmation_spec.rb | 8 +- spec/requests/api/actions_spec.rb | 36 +++--- spec/requests/api/braintree/failure_spec.rb | 26 ++-- spec/requests/api/cors_spec.rb | 3 +- spec/requests/api/double_opt_in_spec.rb | 8 +- .../api/go_cardless/go_cardless_spec.rb | 28 ++--- spec/requests/api/shared_language_pages.rb | 1 + spec/requests/api/stateless/auth_spec.rb | 1 + .../braintree/payment_methods_spec.rb | 1 + .../stateless/braintree/transactions_spec.rb | 1 + spec/requests/api/stateless/location_spec.rb | 1 + spec/requests/api/stateless/members_spec.rb | 12 +- spec/requests/api/survey_responses_spec.rb | 6 +- spec/requests/email_confirmation_spec.rb | 4 +- spec/requests/form_elements_spec.rb | 5 +- spec/requests/localization_spec.rb | 1 + spec/requests/omniauth_with_devise_spec.rb | 3 +- spec/requests/page_archives_spec.rb | 1 + spec/requests/uris_spec.rb | 1 + spec/routing/api/actions_routing_spec.rb | 1 + spec/routing/liquid_layouts_routing_spec.rb | 1 + spec/routing/liquid_partials_routing_spec.rb | 1 + spec/routing/page_archives_routing_spec.rb | 1 + spec/routing/pages_routing_spec.rb | 1 + spec/services/action_collator_spec.rb | 7 +- spec/services/akid_parser_spec.rb | 1 + spec/services/auth_token_verifier_spec.rb | 1 + .../payment_options_spec.rb | 1 + .../connect_with_oauth_provider_spec.rb | 3 +- spec/services/form_duplicator_spec.rb | 1 + spec/services/form_element_builder_spec.rb | 1 + spec/services/form_element_spec.rb | 1 + spec/services/form_validator_spec.rb | 1 + spec/services/manage_action_spec.rb | 6 +- .../manage_braintree_donation_spec.rb | 8 +- spec/services/member_updater_spec.rb | 3 +- spec/services/name_splitter_spec.rb | 1 + spec/services/page_follower_spec.rb | 1 + spec/services/postal_validator_spec.rb | 1 + .../multiple_search_data.rb | 1 + .../multiple_search_spec.rb | 1 + .../page_searcher/page_searcher_spec.rb | 1 + .../page_searcher/page_searcher_spec_data.rb | 1 + .../search_by_campaign_spec.rb | 1 + .../search_by_language_spec.rb | 1 + .../search_by_layout_spec.rb | 1 + .../search_by_tag_spec.rb | 9 +- .../search_by_text_content_spec.rb | 1 + spec/support/controller_macros.rb | 1 + spec/support/factory_girl.rb | 1 + spec/support/helper_functions.rb | 1 + spec/support/omni_auth_helper.rb | 1 + spec/support/paperclip.rb | 1 + spec/support/request_helpers.rb | 1 + spec/teaspoon_env.rb | 1 + spec/validators/action_kit_fields_spec.rb | 5 +- spec/views/shared_examples.rb | 3 +- 244 files changed, 600 insertions(+), 418 deletions(-) diff --git a/Gemfile b/Gemfile index e76eadd55..fac92d0a5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -# coding: utf-8 # frozen_string_literal: true source 'https://rubygems.org' @@ -36,10 +35,10 @@ gem 'slim-rails' ## Use Paper Trail for containing a full history of our edits. gem 'action_parameter' gem 'aws-sdk-core', '~> 3' +gem 'aws-sdk-dynamodb', '~> 1.21' gem 'aws-sdk-s3', '~> 1.30' gem 'aws-sdk-sns', '~> 1.3' gem 'aws-sdk-sqs', '~> 1.10' -gem 'aws-sdk-dynamodb', '~> 1.21' gem 'paper_trail', '~> 10.2' gem 'paperclip', '~> 6.0' gem 'rmagick' # rmagick for image processing @@ -71,6 +70,7 @@ gem 'uglifier' gem 'webpacker', '~> 3.5' group :development, :test do + gem 'byebug' gem 'capybara' # Capybara for integration testing gem 'database_cleaner' gem 'factory_bot_rails' @@ -80,7 +80,6 @@ group :development, :test do gem 'rubocop', '~> 0.66', require: false gem 'spring-commands-rspec' gem 'vcr' - gem 'byebug' end group :development do @@ -96,7 +95,7 @@ group :test do gem 'poltergeist' gem 'rails-controller-testing' gem 'rspec-json_expectations' + gem 'rubocop-rspec' gem 'timecop' gem 'webmock' - gem 'rubocop-rspec' end diff --git a/Rakefile b/Rakefile index da4efd575..e51cf0e17 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) Rails.application.load_tasks diff --git a/app/admin/action.rb b/app/admin/action.rb index 3c7593fdf..2c6ec19f2 100644 --- a/app/admin/action.rb +++ b/app/admin/action.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + ActiveAdmin.register Action do - actions :all, except: [:new, :edit] + actions :all, except: %i[new edit] index pagination_total: false config.per_page = 20 diff --git a/app/admin/call.rb b/app/admin/call.rb index dbe3690b7..0e03ec308 100644 --- a/app/admin/call.rb +++ b/app/admin/call.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register Call do actions :index diff --git a/app/admin/campaign.rb b/app/admin/campaign.rb index aa6a40998..1c556c153 100644 --- a/app/admin/campaign.rb +++ b/app/admin/campaign.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register Campaign do permit_params :name, :active diff --git a/app/admin/dashboard.rb b/app/admin/dashboard.rb index 82c6f9ca0..21064f98e 100644 --- a/app/admin/dashboard.rb +++ b/app/admin/dashboard.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register_page 'Dashboard' do menu priority: 1, label: proc { I18n.t('active_admin.dashboard') } @@ -29,5 +30,5 @@ # end # end # end - end # content + end end diff --git a/app/admin/donation_band.rb b/app/admin/donation_band.rb index b4d7b978d..394214758 100644 --- a/app/admin/donation_band.rb +++ b/app/admin/donation_band.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + ActiveAdmin.register DonationBand do - actions :all, except: [:new, :edit] + actions :all, except: %i[new edit] index pagination_total: false config.per_page = 20 diff --git a/app/admin/form.rb b/app/admin/form.rb index 5eb3664a5..94ecc0bb2 100644 --- a/app/admin/form.rb +++ b/app/admin/form.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register Form do permit_params :name, :description, :visible, :master diff --git a/app/admin/form_element.rb b/app/admin/form_element.rb index 5011ddf35..ff8abdb66 100644 --- a/app/admin/form_element.rb +++ b/app/admin/form_element.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register FormElement do permit_params :label, :data_type, :default_value, :required, :visible, :name, :position diff --git a/app/admin/image.rb b/app/admin/image.rb index 3b2594d1f..efd12af1d 100644 --- a/app/admin/image.rb +++ b/app/admin/image.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + ActiveAdmin.register Image do - actions :all, except: [:new, :edit, :destroy] + actions :all, except: %i[new edit destroy] index pagination_total: false config.per_page = 20 diff --git a/app/admin/language.rb b/app/admin/language.rb index 43b14f329..bb3bc20d9 100644 --- a/app/admin/language.rb +++ b/app/admin/language.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register Language do permit_params :code, :name config.filters = false diff --git a/app/admin/link.rb b/app/admin/link.rb index e359ca4c1..6ee518148 100644 --- a/app/admin/link.rb +++ b/app/admin/link.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register Link do permit_params :url, :title, :date, :source, :link_id diff --git a/app/admin/liquid_layout.rb b/app/admin/liquid_layout.rb index f8ae5e773..8c4c4c1cc 100644 --- a/app/admin/liquid_layout.rb +++ b/app/admin/liquid_layout.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + ActiveAdmin.register LiquidLayout do - actions :all, except: [:new, :edit] + actions :all, except: %i[new edit] index pagination_total: false config.per_page = 20 diff --git a/app/admin/liquid_partial.rb b/app/admin/liquid_partial.rb index 46b48d730..e67965253 100644 --- a/app/admin/liquid_partial.rb +++ b/app/admin/liquid_partial.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + ActiveAdmin.register LiquidPartial do - actions :all, except: [:new, :edit, :destroy] + actions :all, except: %i[new edit destroy] filter :title filter :content diff --git a/app/admin/pages_tag.rb b/app/admin/pages_tag.rb index 0f140ffb4..660098e3c 100644 --- a/app/admin/pages_tag.rb +++ b/app/admin/pages_tag.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register PagesTag do permit_params :page_id, :tag_id diff --git a/app/admin/phone_number.rb b/app/admin/phone_number.rb index c4e45c6f5..7fe41c701 100644 --- a/app/admin/phone_number.rb +++ b/app/admin/phone_number.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register PhoneNumber do actions :all diff --git a/app/admin/tag.rb b/app/admin/tag.rb index e1c428de5..8d862b0f7 100644 --- a/app/admin/tag.rb +++ b/app/admin/tag.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveAdmin.register Tag do permit_params :name, :actionkit_uri diff --git a/app/controllers/api/action_confirmations_controller.rb b/app/controllers/api/action_confirmations_controller.rb index 286303446..0caa88aae 100644 --- a/app/controllers/api/action_confirmations_controller.rb +++ b/app/controllers/api/action_confirmations_controller.rb @@ -5,6 +5,7 @@ class Api::ActionConfirmationsController < ApplicationController def resend_confirmations return head :forbidden unless valid_api_key? + PendingActionService::Reminders.send head :ok diff --git a/app/controllers/api/analytics_controller.rb b/app/controllers/api/analytics_controller.rb index 404223945..be848f174 100644 --- a/app/controllers/api/analytics_controller.rb +++ b/app/controllers/api/analytics_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Api::AnalyticsController < ApplicationController layout false diff --git a/app/controllers/api/email_target_emails_controller.rb b/app/controllers/api/email_target_emails_controller.rb index f30848718..7f6403c89 100644 --- a/app/controllers/api/email_target_emails_controller.rb +++ b/app/controllers/api/email_target_emails_controller.rb @@ -18,9 +18,7 @@ def index table_name: Settings.dynamodb_mailer_table } - if params[:next] - opts[:exclusive_start_key] = JSON.parse(params[:next]) - end + opts[:exclusive_start_key] = JSON.parse(params[:next]) if params[:next] resp = dynamodb_client.query(opts) diff --git a/app/controllers/api/go_cardless_controller.rb b/app/controllers/api/go_cardless_controller.rb index 49b0c6e2c..5a74c6fc8 100644 --- a/app/controllers/api/go_cardless_controller.rb +++ b/app/controllers/api/go_cardless_controller.rb @@ -55,9 +55,7 @@ def payment_options redirect_flow_id: unsafe_params[:redirect_flow_id], session_token: session[:go_cardless_session_id] }.tap do |options| - if unsafe_params[:extra_action_fields].present? - options[:extra_params] = unsafe_params[:extra_action_fields] - end + options[:extra_params] = unsafe_params[:extra_action_fields] if unsafe_params[:extra_action_fields].present? end end diff --git a/app/controllers/api/members_controller.rb b/app/controllers/api/members_controller.rb index f0ad36a62..ac24c46ee 100644 --- a/app/controllers/api/members_controller.rb +++ b/app/controllers/api/members_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Api::MembersController < ApplicationController skip_before_action :verify_authenticity_token, raise: false diff --git a/app/controllers/api/payment/braintree_controller.rb b/app/controllers/api/payment/braintree_controller.rb index f197c154b..6ec515c62 100644 --- a/app/controllers/api/payment/braintree_controller.rb +++ b/app/controllers/api/payment/braintree_controller.rb @@ -34,9 +34,7 @@ def payment_options page_id: unsafe_params[:page_id], store_in_vault: store_in_vault? }.tap do |options| - if unsafe_params[:extra_action_fields].present? - options[:extra_params] = unsafe_params[:extra_action_fields] - end + options[:extra_params] = unsafe_params[:extra_action_fields] if unsafe_params[:extra_action_fields].present? end end diff --git a/app/controllers/api/pension_funds_controller.rb b/app/controllers/api/pension_funds_controller.rb index 100b72a7a..66146dc7f 100644 --- a/app/controllers/api/pension_funds_controller.rb +++ b/app/controllers/api/pension_funds_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Api::PensionFundsController < ApplicationController rescue_from Errno::ENOENT, with: :funds_not_found diff --git a/app/controllers/api/stateless/auth_controller.rb b/app/controllers/api/stateless/auth_controller.rb index aed37bc56..a3fd54b9b 100644 --- a/app/controllers/api/stateless/auth_controller.rb +++ b/app/controllers/api/stateless/auth_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless # Api::AuthController allows clients to authenticate and receive a diff --git a/app/controllers/api/stateless/braintree/payment_methods_controller.rb b/app/controllers/api/stateless/braintree/payment_methods_controller.rb index 89b850bf6..37619c9f5 100644 --- a/app/controllers/api/stateless/braintree/payment_methods_controller.rb +++ b/app/controllers/api/stateless/braintree/payment_methods_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless module Braintree diff --git a/app/controllers/api/stateless/braintree/subscriptions_controller.rb b/app/controllers/api/stateless/braintree/subscriptions_controller.rb index 3a99c64b2..af10a1783 100644 --- a/app/controllers/api/stateless/braintree/subscriptions_controller.rb +++ b/app/controllers/api/stateless/braintree/subscriptions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless module Braintree diff --git a/app/controllers/api/stateless/braintree/transactions_controller.rb b/app/controllers/api/stateless/braintree/transactions_controller.rb index 809b27438..21b62017d 100644 --- a/app/controllers/api/stateless/braintree/transactions_controller.rb +++ b/app/controllers/api/stateless/braintree/transactions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless module Braintree diff --git a/app/controllers/api/stateless/go_cardless/payment_methods_controller.rb b/app/controllers/api/stateless/go_cardless/payment_methods_controller.rb index 25c720aeb..d0b25e169 100644 --- a/app/controllers/api/stateless/go_cardless/payment_methods_controller.rb +++ b/app/controllers/api/stateless/go_cardless/payment_methods_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless module GoCardless diff --git a/app/controllers/api/stateless/go_cardless/subscriptions_controller.rb b/app/controllers/api/stateless/go_cardless/subscriptions_controller.rb index d4506a33d..1930cc0b3 100644 --- a/app/controllers/api/stateless/go_cardless/subscriptions_controller.rb +++ b/app/controllers/api/stateless/go_cardless/subscriptions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless module GoCardless diff --git a/app/controllers/api/stateless/go_cardless/transactions_controller.rb b/app/controllers/api/stateless/go_cardless/transactions_controller.rb index 1e67864fb..c5d3c0e03 100644 --- a/app/controllers/api/stateless/go_cardless/transactions_controller.rb +++ b/app/controllers/api/stateless/go_cardless/transactions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module Stateless module GoCardless diff --git a/app/controllers/api/stateless/location_controller.rb b/app/controllers/api/stateless/location_controller.rb index 9bd1c2304..119bfe285 100644 --- a/app/controllers/api/stateless/location_controller.rb +++ b/app/controllers/api/stateless/location_controller.rb @@ -14,6 +14,7 @@ def index def location @location ||= request.location raise Api::Exceptions::LocationNotFound unless @location + @location.data end diff --git a/app/controllers/api/stateless/stateless_controller.rb b/app/controllers/api/stateless/stateless_controller.rb index 8258297ad..17ac2f1f4 100644 --- a/app/controllers/api/stateless/stateless_controller.rb +++ b/app/controllers/api/stateless/stateless_controller.rb @@ -18,6 +18,7 @@ class StatelessController < ApplicationController # Tries token first then falls back to def authenticate_request! raise Exceptions::UnauthorizedError unless current_member + current_member end @@ -29,15 +30,17 @@ def current_member def authenticate_member_from_token return nil if request.headers['authorization'].nil? + _, token = request.headers['authorization'].split payload = decode_jwt(token) Member.find(payload[:id]) - rescue + rescue StandardError raise Exceptions::UnauthorizedError end def authenticate_member_from_cookie return nil if cookies.encrypted['authorization'].nil? + payload = decode_jwt(cookies.encrypted['authorization']) Member.find(payload[:id]) end diff --git a/app/controllers/api/survey_responses_controller.rb b/app/controllers/api/survey_responses_controller.rb index bcdab9b51..bd25745e0 100644 --- a/app/controllers/api/survey_responses_controller.rb +++ b/app/controllers/api/survey_responses_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Api::SurveyResponsesController < ApplicationController skip_before_action :verify_authenticity_token, raise: false before_action :localize_from_page_id, only: :create @@ -23,9 +24,9 @@ def session_manager end def survey_response_params - params. - to_unsafe_hash. - slice(*form.form_elements.map(&:name), 'akid', 'source', 'referring_akid', 'rid', 'referrer_id') + params + .to_unsafe_hash + .slice(*form.form_elements.map(&:name), 'akid', 'source', 'referring_akid', 'rid', 'referrer_id') end def form diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 72acbc903..6f2b295a6 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class CampaignsController < ApplicationController before_action :authenticate_user! - before_action :find_campaign, only: [:show, :edit, :update, :destroy] + before_action :find_campaign, only: %i[show edit update destroy] def index end diff --git a/app/controllers/clone_pages_controller.rb b/app/controllers/clone_pages_controller.rb index 5ec89b93e..856acfe58 100644 --- a/app/controllers/clone_pages_controller.rb +++ b/app/controllers/clone_pages_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ClonePagesController < ApplicationController before_action :authenticate_user! before_action :find_page diff --git a/app/controllers/donation_bands_controller.rb b/app/controllers/donation_bands_controller.rb index 64bcd5198..20525a528 100644 --- a/app/controllers/donation_bands_controller.rb +++ b/app/controllers/donation_bands_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class DonationBandsController < ApplicationController before_action :authenticate_user! - before_action :find_donation_band, only: [:edit, :update] + before_action :find_donation_band, only: %i[edit update] def new @donation_band = DonationBand.new diff --git a/app/controllers/email_confirmation_controller.rb b/app/controllers/email_confirmation_controller.rb index 17cb641ae..89f87cc74 100644 --- a/app/controllers/email_confirmation_controller.rb +++ b/app/controllers/email_confirmation_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class EmailConfirmationController < ApplicationController before_action :find_member @@ -18,6 +19,7 @@ def verify def find_member raise ActiveRecord::RecordNotFound if params[:email].blank? + @member = Member.find_by_email!(params[:email]) end end diff --git a/app/controllers/featured_pages_controller.rb b/app/controllers/featured_pages_controller.rb index ee003d5ba..555c78fb5 100644 --- a/app/controllers/featured_pages_controller.rb +++ b/app/controllers/featured_pages_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class FeaturedPagesController < ApplicationController before_action :authenticate_user! - before_action :find_page, only: [:create, :destroy] + before_action :find_page, only: %i[create destroy] def create @page.update(featured: true) diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index f3c44d20e..9a9147a3c 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + # TODO: Needs a controller spec class FormsController < ApplicationController before_action :authenticate_user! - before_action :find_form, only: [:show, :edit] + before_action :find_form, only: %i[show edit] def index end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 6859b5f9e..7228d1a7e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class HomeController < ApplicationController def index if user_signed_in? diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 7ae0cd818..4522c9b02 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ImagesController < ApplicationController before_action :authenticate_user! before_action :find_page diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index 0d1088d9d..555c810d2 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class LinksController < ApplicationController before_action :authenticate_user! diff --git a/app/controllers/liquid_layouts_controller.rb b/app/controllers/liquid_layouts_controller.rb index 3433e9c27..259d7419b 100644 --- a/app/controllers/liquid_layouts_controller.rb +++ b/app/controllers/liquid_layouts_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class LiquidLayoutsController < ApplicationController before_action :authenticate_user! - before_action :set_liquid_layout, only: [:show, :edit, :update, :destroy] + before_action :set_liquid_layout, only: %i[show edit update destroy] def index @liquid_layouts = LiquidLayout.all diff --git a/app/controllers/liquid_partials_controller.rb b/app/controllers/liquid_partials_controller.rb index ee53e58a1..d397e0ea3 100644 --- a/app/controllers/liquid_partials_controller.rb +++ b/app/controllers/liquid_partials_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class LiquidPartialsController < ApplicationController before_action :authenticate_user! - before_action :set_liquid_partial, only: [:show, :edit, :update, :destroy] + before_action :set_liquid_partial, only: %i[show edit update destroy] def index @liquid_partials = LiquidPartial.all diff --git a/app/controllers/member_authentications_controller.rb b/app/controllers/member_authentications_controller.rb index f3b5449d8..adabc3194 100644 --- a/app/controllers/member_authentications_controller.rb +++ b/app/controllers/member_authentications_controller.rb @@ -42,8 +42,6 @@ def localize_by_recent_action def redirect_signed_up_members member = params['email'].present? && Member.find_by_email(params[:email]) - if member && member.authentication.present? - redirect_to params[:follow_up_url] || Settings.home_page_url - end + redirect_to params[:follow_up_url] || Settings.home_page_url if member && member.authentication.present? end end diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 3ef50bb19..79f4ed7e0 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class OmniauthCallbacksController < Devise::OmniauthCallbacksController def google_oauth2 @user = ConnectWithOauthProvider.connect(request.env['omniauth.auth']) diff --git a/app/controllers/page_archives_controller.rb b/app/controllers/page_archives_controller.rb index 76dc1af42..914c4c03e 100644 --- a/app/controllers/page_archives_controller.rb +++ b/app/controllers/page_archives_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class PageArchivesController < ApplicationController before_action :authenticate_user! def create diff --git a/app/controllers/plugins/forms_controller.rb b/app/controllers/plugins/forms_controller.rb index 1c333d83c..c7c76edd3 100644 --- a/app/controllers/plugins/forms_controller.rb +++ b/app/controllers/plugins/forms_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Plugins::FormsController < ApplicationController def create master = Form.find permitted_params[:master_id] diff --git a/app/controllers/plugins/fundraisers_controller.rb b/app/controllers/plugins/fundraisers_controller.rb index eed1b283c..f349c704f 100644 --- a/app/controllers/plugins/fundraisers_controller.rb +++ b/app/controllers/plugins/fundraisers_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Plugins::FundraisersController < Plugins::BaseController private diff --git a/app/controllers/plugins/petitions_controller.rb b/app/controllers/plugins/petitions_controller.rb index b563ef653..cbba6a705 100644 --- a/app/controllers/plugins/petitions_controller.rb +++ b/app/controllers/plugins/petitions_controller.rb @@ -20,6 +20,7 @@ def update def find_form return unless params[:plugins_petition][:form_id] + Form.find params[:plugins_petition][:form_id] end diff --git a/app/controllers/plugins/surveys_controller.rb b/app/controllers/plugins/surveys_controller.rb index c9dc7e882..6c43cd108 100644 --- a/app/controllers/plugins/surveys_controller.rb +++ b/app/controllers/plugins/surveys_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Plugins::SurveysController < Plugins::BaseController def add_form survey = Plugins.find_for('survey', unsafe_params[:plugin_id]) diff --git a/app/controllers/plugins/texts_controller.rb b/app/controllers/plugins/texts_controller.rb index 9cc0fbd1b..37067a927 100644 --- a/app/controllers/plugins/texts_controller.rb +++ b/app/controllers/plugins/texts_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Plugins::TextsController < Plugins::BaseController private diff --git a/app/controllers/share/shares_controller.rb b/app/controllers/share/shares_controller.rb index eebfa1453..def8814e4 100644 --- a/app/controllers/share/shares_controller.rb +++ b/app/controllers/share/shares_controller.rb @@ -43,9 +43,7 @@ def update_url @page.share_buttons.each do |button| url = params[button.share_type.to_sym] - if url - ShareVariantBuilder.update_button_url(url, button) - end + ShareVariantBuilder.update_button_url(url, button) if url end render :update_url_form diff --git a/app/controllers/uris_controller.rb b/app/controllers/uris_controller.rb index 1e27812ed..d3322135e 100644 --- a/app/controllers/uris_controller.rb +++ b/app/controllers/uris_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class UrisController < ApplicationController before_action :authenticate_user!, except: [:show] - before_action :find_uri, only: [:edit, :update, :destroy] + before_action :find_uri, only: %i[edit update destroy] def index @uris = Uri.all diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 6bbed9dbb..a8adc2c95 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class VersionsController < ApplicationController before_action :authenticate_user! diff --git a/app/helpers/api/analytics_helper.rb b/app/helpers/api/analytics_helper.rb index 00211195c..ff5f2894d 100644 --- a/app/helpers/api/analytics_helper.rb +++ b/app/helpers/api/analytics_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api::AnalyticsHelper def total_actions_by_hour(page) map_data page.total_actions_over_time(period: :hour) diff --git a/app/helpers/api/pages_helper.rb b/app/helpers/api/pages_helper.rb index d83e1d405..8b0ac8497 100644 --- a/app/helpers/api/pages_helper.rb +++ b/app/helpers/api/pages_helper.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true + module Api::PagesHelper def image_url(page) path = page.primary_image.try(:content).try(:url, :medium) return '' if path.blank? + URI.join(ActionController::Base.asset_host, path).to_s end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 71249b93b..15b06f0f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + module ApplicationHelper end diff --git a/app/helpers/layout_select_helper.rb b/app/helpers/layout_select_helper.rb index b96d27000..0d8c5ac2e 100644 --- a/app/helpers/layout_select_helper.rb +++ b/app/helpers/layout_select_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module LayoutSelectHelper def construct_layout_select_class(liquid_layout, page, field) hidden = check_hidden(liquid_layout, field) @@ -27,6 +28,7 @@ def check_active(liquid_layout, page, field) if field == :follow_up_liquid_layout_id && page.follow_up_plan.to_sym == :with_page return '' # the redirect option will be the active one in this case end + # page.send(field) calls either page.liquid_layout_id or page.follow_up_liquid_layout_id liquid_layout.id == page.send(field) ? 'active' : '' end diff --git a/app/lib/champaign_queue/clients/sqs.rb b/app/lib/champaign_queue/clients/sqs.rb index 0d710458e..46356560b 100644 --- a/app/lib/champaign_queue/clients/sqs.rb +++ b/app/lib/champaign_queue/clients/sqs.rb @@ -18,7 +18,7 @@ def initialize(params, group_id) def push return false if queue_url.blank? - client.send_message(queue_url: queue_url, + client.send_message(queue_url: queue_url, message_body: @params.to_json, message_group_id: @group_id) end diff --git a/app/lib/donations/utils.rb b/app/lib/donations/utils.rb index 6ff965029..19d2e57f3 100644 --- a/app/lib/donations/utils.rb +++ b/app/lib/donations/utils.rb @@ -2,7 +2,7 @@ module Donations module Utils - extend self # rubocop:disable Style/ModuleFunction + extend self EURO_COUNTRY_CODES = %i[AL AD AT BY BE BA BG HR CY CZ DK EE FO FI FR DE GI GR HU IS IE IT LV LI LT LU MK MT MD MC NL NO PL PT RO RU SM RS SK SI ES SE UA VA RS IM RS ME].freeze # rubocop:disable Metrics/LineLength DEFAULT_CURRENCY = 'USD' diff --git a/app/lib/forget_member.rb b/app/lib/forget_member.rb index 102db6fdd..7e4264bd1 100644 --- a/app/lib/forget_member.rb +++ b/app/lib/forget_member.rb @@ -1,4 +1,3 @@ - class ForgetMember attr_reader :member diff --git a/app/lib/go_cardless_director.rb b/app/lib/go_cardless_director.rb index 23cb4db53..246b4f260 100644 --- a/app/lib/go_cardless_director.rb +++ b/app/lib/go_cardless_director.rb @@ -16,8 +16,8 @@ def redirect_url def redirect_flow_instance @redirect_flow_instance ||= client.redirect_flows.create(params: { - session_token: @session_id, - description: description, + session_token: @session_id, + description: description, success_redirect_url: @success_url }) rescue GoCardlessPro::Error => e @@ -39,7 +39,7 @@ def description def client @client ||= GoCardlessPro::Client.new( access_token: Settings.gocardless.token, - environment: Settings.gocardless.environment.to_sym + environment: Settings.gocardless.environment.to_sym ) end diff --git a/app/lib/has_phone_number.rb b/app/lib/has_phone_number.rb index 655048662..b082ffce4 100644 --- a/app/lib/has_phone_number.rb +++ b/app/lib/has_phone_number.rb @@ -2,9 +2,7 @@ module HasPhoneNumber def validate_phone_number(*attrs) attrs.each do |attr| validate do - if send(attr).present? && !Phony.plausible?(send(attr)) - errors.add(attr, 'is an invalid number') - end + errors.add(attr, 'is an invalid number') if send(attr).present? && !Phony.plausible?(send(attr)) end end end @@ -14,8 +12,8 @@ def normalize_phone_number(*attrs) define_method("#{attr}=") do |number| new_value = begin number && "+#{Phony.normalize(number.to_s)}" - rescue Phony::NormalizationError - number + rescue Phony::NormalizationError + number end instance_variable_set("@#{attr}", new_value) end diff --git a/app/lib/payment_processor/braintree/one_click_from_uri.rb b/app/lib/payment_processor/braintree/one_click_from_uri.rb index d5994db56..972885ce9 100644 --- a/app/lib/payment_processor/braintree/one_click_from_uri.rb +++ b/app/lib/payment_processor/braintree/one_click_from_uri.rb @@ -13,6 +13,7 @@ def initialize(params, page:, member: nil, cookied_payment_methods: '') def process return false unless one_click? + PaymentProcessor::Braintree::OneClick.new(options, @cookied_payment_methods).run self end @@ -50,6 +51,7 @@ def options def payment_method_id customer = member&.customer return nil unless customer + customer.valid_payment_method_id(cookied_payment_methods.split(',')) end diff --git a/app/lib/payment_processor/braintree/subscription.rb b/app/lib/payment_processor/braintree/subscription.rb index 6bb2666bd..330a6554b 100644 --- a/app/lib/payment_processor/braintree/subscription.rb +++ b/app/lib/payment_processor/braintree/subscription.rb @@ -141,6 +141,7 @@ def create_customer_options # customer, otherwise we won't be able to tell which # payment_method on the returned customer is the new one return customer_options if existing_customer.present? + customer_options.merge(payment_method_nonce: @nonce, credit_card: { billing_address: billing_options diff --git a/app/lib/payment_processor/go_cardless/populator.rb b/app/lib/payment_processor/go_cardless/populator.rb index 3ce6dd07e..38a6c1ba7 100644 --- a/app/lib/payment_processor/go_cardless/populator.rb +++ b/app/lib/payment_processor/go_cardless/populator.rb @@ -80,6 +80,7 @@ def complete_redirect_flow .complete(@redirect_flow_id, params: { session_token: @session_token }) rescue GoCardlessPro::InvalidStateError => e raise e unless e.message.match?(/already completed/) + @complete_redirect_flow = client.redirect_flows.get(@redirect_flow_id) end @@ -88,9 +89,7 @@ def client end def charge_date - if Settings.gocardless.gbp_charge_day.blank? || !bacs? - return mandate.next_possible_charge_date - end + return mandate.next_possible_charge_date if Settings.gocardless.gbp_charge_day.blank? || !bacs? mandate_date = Date.parse(mandate.next_possible_charge_date) gbp_date = create_gbp_date(mandate_date) diff --git a/app/lib/payment_processor/go_cardless/subscription.rb b/app/lib/payment_processor/go_cardless/subscription.rb index 629db960c..1375b4c5f 100644 --- a/app/lib/payment_processor/go_cardless/subscription.rb +++ b/app/lib/payment_processor/go_cardless/subscription.rb @@ -70,18 +70,18 @@ def subscription_id def action_params @user.merge!( - page_id: @page_id, - amount: amount_in_whole_currency.to_s, - card_num: mandate.id, - currency: currency, - subscription_id: subscription_id, - is_subscription: true, - recurrence_number: 0, + page_id: @page_id, + amount: amount_in_whole_currency.to_s, + card_num: mandate.id, + currency: currency, + subscription_id: subscription_id, + is_subscription: true, + recurrence_number: 0, card_expiration_date: nil, - mandate_reference: mandate.reference, - bank_name: bank_account.bank_name, + mandate_reference: mandate.reference, + bank_name: bank_account.bank_name, account_number_ending: bank_account.account_number_ending, - payment_provider: 'go_cardless' + payment_provider: 'go_cardless' ).merge!(@extra_params) end end diff --git a/app/lib/payment_processor/go_cardless/transaction.rb b/app/lib/payment_processor/go_cardless/transaction.rb index 4b6e455c3..698739b76 100644 --- a/app/lib/payment_processor/go_cardless/transaction.rb +++ b/app/lib/payment_processor/go_cardless/transaction.rb @@ -70,15 +70,15 @@ def transaction_id def action_params @user.merge!( - page_id: @page_id, - amount: amount_in_whole_currency.to_s, - card_num: mandate.id, - currency: currency, - transaction_id: transaction_id, - is_subscription: false, + page_id: @page_id, + amount: amount_in_whole_currency.to_s, + card_num: mandate.id, + currency: currency, + transaction_id: transaction_id, + is_subscription: false, payment_provider: 'go_cardless', mandate_reference: mandate.reference, - bank_name: bank_account.bank_name, + bank_name: bank_account.bank_name, account_number_ending: bank_account.account_number_ending ).merge!(@extra_params) end diff --git a/app/lib/payment_processor/go_cardless/webhook_handler/process_events.rb b/app/lib/payment_processor/go_cardless/webhook_handler/process_events.rb index 16b325cf6..abe35d538 100644 --- a/app/lib/payment_processor/go_cardless/webhook_handler/process_events.rb +++ b/app/lib/payment_processor/go_cardless/webhook_handler/process_events.rb @@ -18,6 +18,7 @@ def initialize(events) def process @events.each do |event| next if already_processed?(event) + handler = process_event(event) record_processing(event, handler) end @@ -38,11 +39,11 @@ def process_event(event) def record_processing(event, handler = nil) ::Payment::GoCardless::WebhookEvent.create( - event_id: event['id'], - action: event['action'], + event_id: event['id'], + action: event['action'], resource_type: event['resource_type'], - resource_id: handler.try(:resource_id), - body: event.to_json + resource_id: handler.try(:resource_id), + body: event.to_json ) end end diff --git a/app/lib/payment_processor/go_cardless/webhook_handler/processable.rb b/app/lib/payment_processor/go_cardless/webhook_handler/processable.rb index 569d09f10..16fbcbeae 100644 --- a/app/lib/payment_processor/go_cardless/webhook_handler/processable.rb +++ b/app/lib/payment_processor/go_cardless/webhook_handler/processable.rb @@ -10,6 +10,7 @@ def initialize(event) def process return unless action && record.try("may_run_#{action}?") + record.send("run_#{action}!", @event) end end diff --git a/app/liquid/champaign_liquid_filters.rb b/app/liquid/champaign_liquid_filters.rb index 482161b6c..453774d3b 100644 --- a/app/liquid/champaign_liquid_filters.rb +++ b/app/liquid/champaign_liquid_filters.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true + module ChampaignLiquidFilters def select_option(tags_string, to_select) # if one is already selected then leave it return tags_string if tags_string.match?(/selected/) + tags_string.gsub(/(/, '\1 selected \2>') end diff --git a/app/liquid/liquid_file_system.rb b/app/liquid/liquid_file_system.rb index 9079a63b4..0fcbe4497 100644 --- a/app/liquid/liquid_file_system.rb +++ b/app/liquid/liquid_file_system.rb @@ -41,6 +41,7 @@ def partials(title) def read_template_file(title) return read(title) unless Settings.liquid_templating_source == 'file' + read_from_file(title) end @@ -56,11 +57,13 @@ def read_from_store(title) def read_from_file(title) return nil if partials(title).empty? + File.read(partials(title).first) end def external_dirs return [] unless Settings.external_assets_path.present? && Settings.external_liquid_path.present? + Settings.external_assets_path.split(':').map { |path| File.join(path, Settings.external_liquid_path) } end end diff --git a/app/liquid/liquid_helper.rb b/app/liquid/liquid_helper.rb index e03374843..27bba5054 100644 --- a/app/liquid/liquid_helper.rb +++ b/app/liquid/liquid_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class LiquidHelper class << self # when possible, I think we should try to make this match with @@ -23,6 +24,7 @@ def country_option_tags(user_country_code = nil) def petition_target(page) return nil unless page.present? + actions = page.plugins.select { |p| p.name == 'Petition' && p.active? } actions.map(&:target).reject(&:blank?).first end diff --git a/app/liquid/liquid_i18n.rb b/app/liquid/liquid_i18n.rb index 7d8658343..bba8b347b 100644 --- a/app/liquid/liquid_i18n.rb +++ b/app/liquid/liquid_i18n.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The LiquidI18nRails module allows us to use the +translate+ # method of Rails' I18n library within liquid templates. To use it, # simply pass the name of the text entry to the +t+ filter: @@ -64,6 +65,7 @@ def parse_interpolation(query) if depth >= MAX_INTERPOLATIONS raise I18n::TooMuchInterpolation, "More than #{MAX_INTERPOLATIONS} interpolation values are not allowed." end + _, key, val, string_params = /, *([a-zA-z_]+): *([^,]+)(.*)/.match(string_params).to_a params[key.to_sym] = val if key.present? && !key.empty? depth += 1 diff --git a/app/liquid/liquid_tag_finder.rb b/app/liquid/liquid_tag_finder.rb index a5e414a0a..5a1e80e25 100644 --- a/app/liquid/liquid_tag_finder.rb +++ b/app/liquid/liquid_tag_finder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # The LiquidTagFinder class is used to help the app understand # the needs and the setup of liquid layouts and partials by parsing # relevant liquid tags. @@ -117,6 +118,7 @@ def partial_name_from_include(incl) def ref_from_include(incl) attrs = incl.instance_values['attributes'] return nil unless attrs.include? 'ref' + strip_quotes(attrs['ref']) end diff --git a/app/liquid/shares.rb b/app/liquid/shares.rb index 7d8cf9ac3..c87dd450d 100644 --- a/app/liquid/shares.rb +++ b/app/liquid/shares.rb @@ -49,6 +49,7 @@ def buttons_with_variants(page) def class_from_html(html) return nil if html.blank? + class_finder = /class *= *['"](.*?)['"]/i html[class_finder, 1] end diff --git a/app/models/actionkit_page_type.rb b/app/models/actionkit_page_type.rb index 4c17eb849..7a5b7ae7d 100644 --- a/app/models/actionkit_page_type.rb +++ b/app/models/actionkit_page_type.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: actionkit_page_types diff --git a/app/models/ak_log.rb b/app/models/ak_log.rb index 81c332ace..d9b737d06 100644 --- a/app/models/ak_log.rb +++ b/app/models/ak_log.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: ak_logs diff --git a/app/models/concerns/has_liquid_partials.rb b/app/models/concerns/has_liquid_partials.rb index 323bcc10c..95e647625 100644 --- a/app/models/concerns/has_liquid_partials.rb +++ b/app/models/concerns/has_liquid_partials.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module HasLiquidPartials extend ActiveSupport::Concern @@ -25,12 +26,14 @@ def no_unknown_partials # def plugin_refs(ref: nil, depth: 0) return [] if depth > 2 + introspector = LiquidTagFinder.new(content) plugin_names = introspector.plugin_names collector = plugin_names.empty? ? [] : [[plugin_names[0], ref]] introspector.partial_refs.each do |partial, child_ref| child_partial = LiquidPartial.where(title: partial).first next if child_partial.blank? + collector += child_partial.plugin_refs(ref: child_ref, depth: depth + 1) end collector.uniq diff --git a/app/models/language.rb b/app/models/language.rb index bfbe96816..a7bedfbe0 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: languages @@ -12,7 +13,7 @@ # class Language < ApplicationRecord - has_paper_trail on: [:update, :destroy] + has_paper_trail on: %i[update destroy] has_many :pages validates :code, :actionkit_uri, :name, presence: true, allow_blank: false diff --git a/app/models/pages_tag.rb b/app/models/pages_tag.rb index bd1b0e37e..f73a0b9c1 100644 --- a/app/models/pages_tag.rb +++ b/app/models/pages_tag.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: pages_tags @@ -9,6 +10,6 @@ # class PagesTag < ApplicationRecord - belongs_to :tag, optional: true - belongs_to :page, optional: true + belongs_to :tag, optional: true + belongs_to :page, optional: true end diff --git a/app/models/payment/braintree.rb b/app/models/payment/braintree.rb index b7f3346ae..fda9bdea5 100644 --- a/app/models/payment/braintree.rb +++ b/app/models/payment/braintree.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Payment::Braintree class << self def table_name_prefix @@ -13,15 +14,15 @@ def write_transaction(bt_result, page_id, member_id, existing_customer, save_cus def write_subscription(payment_method_id, customer_id, subscription_result, page_id, action_id, currency) if subscription_result.success? - Payment::Braintree::Subscription.create(payment_method_id: payment_method_id, - customer_id: customer_id, - subscription_id: subscription_result.subscription.id, - amount: subscription_result.subscription.price, - merchant_account_id: subscription_result.subscription.merchant_account_id, - billing_day_of_month: subscription_result.subscription.billing_day_of_month, - action_id: action_id, - currency: currency, - page_id: page_id) + Payment::Braintree::Subscription.create(payment_method_id: payment_method_id, + customer_id: customer_id, + subscription_id: subscription_result.subscription.id, + amount: subscription_result.subscription.price, + merchant_account_id: subscription_result.subscription.merchant_account_id, + billing_day_of_month: subscription_result.subscription.billing_day_of_month, + action_id: action_id, + currency: currency, + page_id: page_id) end end @@ -77,20 +78,20 @@ def build end def customer_attrs - card_attrs.merge(customer_id: @bt_customer.id, - member_id: @member_id, - email: @bt_customer.email) + card_attrs.merge(customer_id: @bt_customer.id, + member_id: @member_id, + email: @bt_customer.email) end def card_attrs if @bt_payment_method.is_a? Braintree::CreditCard @bt_payment_method.instance_eval do { - card_type: card_type, - card_bin: bin, - cardholder_name: cardholder_name, - card_debit: debit, - card_last_4: last_4, + card_type: card_type, + card_bin: bin, + cardholder_name: cardholder_name, + card_debit: debit, + card_last_4: last_4, card_unique_number_identifier: unique_number_identifier } end @@ -143,6 +144,7 @@ def build create_payment_method record = create_transaction return false unless successful? + @customer.update(customer_attrs) if @save_customer && @customer record end @@ -176,18 +178,18 @@ def create_transaction def transaction_attrs { - transaction_id: transaction.id, - transaction_type: transaction.type, - payment_instrument_type: transaction.payment_instrument_type, - amount: transaction.amount, - transaction_created_at: transaction.created_at, - merchant_account_id: transaction.merchant_account_id, - processor_response_code: transaction.processor_response_code, - currency: transaction.currency_iso_code, - customer_id: @customer.try(:customer_id), - status: status, - payment_method_id: @local_payment_method_id, - page_id: @page_id + transaction_id: transaction.id, + transaction_type: transaction.type, + payment_instrument_type: transaction.payment_instrument_type, + amount: transaction.amount, + transaction_created_at: transaction.created_at, + merchant_account_id: transaction.merchant_account_id, + processor_response_code: transaction.processor_response_code, + currency: transaction.currency_iso_code, + customer_id: @customer.try(:customer_id), + status: status, + payment_method_id: @local_payment_method_id, + page_id: @page_id }.tap do |data| if transaction.try(:subscription_id) data[:subscription] = Payment::Braintree::Subscription.find_by_subscription_id(transaction.subscription_id) @@ -200,14 +202,14 @@ def customer_attrs # NOTE: we do NOT store card_unique_number_identifier because # that is only returned on Braintree::CreditCard, not on # Braintree::Transaction::CreditCardDetails - card_type: card.card_type, - card_bin: card.bin, - cardholder_name: card.cardholder_name, - card_debit: card.debit, - card_last_4: last_4, - customer_id: transaction.customer_details.id, - email: transaction.customer_details.email, - member_id: @member_id + card_type: card.card_type, + card_bin: card.bin, + cardholder_name: card.cardholder_name, + card_debit: card.debit, + card_last_4: last_4, + customer_id: transaction.customer_details.id, + email: transaction.customer_details.email, + member_id: @member_id } end @@ -228,6 +230,7 @@ def successful? if @bt_result.is_a?(Braintree::WebhookNotification) && @bt_result.kind == 'subscription_charged_successfully' return true end + false end diff --git a/app/models/payment/go_cardless.rb b/app/models/payment/go_cardless.rb index 507895f7b..9c386a52b 100644 --- a/app/models/payment/go_cardless.rb +++ b/app/models/payment/go_cardless.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Payment::GoCardless class << self def table_name_prefix diff --git a/app/models/plugins/has_form.rb b/app/models/plugins/has_form.rb index c3c93acd7..5a3c6edda 100644 --- a/app/models/plugins/has_form.rb +++ b/app/models/plugins/has_form.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Plugins::HasForm extend ActiveSupport::Concern @@ -17,6 +18,7 @@ def name def outstanding_fields(form_values) return [] if form.blank? + FormValidator.new( { form_id: form.id }.merge(form_values || {}) ).errors.keys @@ -24,6 +26,7 @@ def outstanding_fields(form_values) def update_form(new_form) return if new_form.blank? + old_form = form update(form: new_form) old_form.destroy if old_form.present? @@ -42,6 +45,7 @@ def dup def create_form return if form.present? && !form.form_elements.empty? + locale = try(:page).try(:language).try(:code) || I18n.default_locale self.form = FormDuplicator.duplicate( DefaultFormBuilder.find_or_create(locale: locale) diff --git a/app/models/share.rb b/app/models/share.rb index 65becc6c8..40c163750 100644 --- a/app/models/share.rb +++ b/app/models/share.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Share def self.table_name_prefix 'share_' diff --git a/app/services/action_collator.rb b/app/services/action_collator.rb index 0616c7920..c99be767d 100644 --- a/app/services/action_collator.rb +++ b/app/services/action_collator.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + class ActionCollator - PRIVATE_KEYS = %w(action_referrer_email action_referer action_express_donation).freeze - PREFIXES = %w(action_ textentry_ box_ dropdown_ choice_).freeze - COLUMN_KEYS = %w(publish_status id).freeze + PRIVATE_KEYS = %w[action_referrer_email action_referer action_express_donation].freeze + PREFIXES = %w[action_ textentry_ box_ dropdown_ choice_].freeze + COLUMN_KEYS = %w[publish_status id].freeze COMMA = ',' def self.run(actions) @@ -42,6 +43,7 @@ def hashes def keys return @keys if @keys.present? + all_keys = @actions.map { |a| a.form_data.keys }.flatten.uniq @keys = all_keys.reject { |k| PRIVATE_KEYS.include?(k) }.select { |k| ActionKitFields.has_valid_form(k) } @keys = (@keys + COLUMN_KEYS).map(&:to_sym) diff --git a/app/services/action_params_builder.rb b/app/services/action_params_builder.rb index c61b52909..f9c5e1660 100644 --- a/app/services/action_params_builder.rb +++ b/app/services/action_params_builder.rb @@ -29,7 +29,7 @@ def build_params end def base_params - %w(page_id form_id name source akid referring_akid email) + %w[page_id form_id name source akid referring_akid email] end def fields diff --git a/app/services/action_reader.rb b/app/services/action_reader.rb index 34931c4b4..79e993cb4 100644 --- a/app/services/action_reader.rb +++ b/app/services/action_reader.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ActionReader attr_reader :query diff --git a/app/services/akid_parser.rb b/app/services/akid_parser.rb index b7036762d..e5263cfe6 100644 --- a/app/services/akid_parser.rb +++ b/app/services/akid_parser.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'digest' require 'base64' diff --git a/app/services/braintree_services/payment_method_builder.rb b/app/services/braintree_services/payment_method_builder.rb index f224f2f98..b7730a78f 100644 --- a/app/services/braintree_services/payment_method_builder.rb +++ b/app/services/braintree_services/payment_method_builder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module BraintreeServices class PaymentMethodBuilder def initialize(transaction:, customer: nil, store_in_vault: false) @@ -26,7 +27,7 @@ def attributes end def credit_card_attributes - %w(last_4 card_type expiration_date bin token).each_with_object({}) do |attr, attributes| + %w[last_4 card_type expiration_date bin token].each_with_object({}) do |attr, attributes| attributes[attr] = @transaction.credit_card_details.send(attr) end.merge( customer: @customer, diff --git a/app/services/braintree_services/payment_options.rb b/app/services/braintree_services/payment_options.rb index 31d605f1c..5e56edbd0 100644 --- a/app/services/braintree_services/payment_options.rb +++ b/app/services/braintree_services/payment_options.rb @@ -13,6 +13,7 @@ def payment_method @payment_method ||= customer.payment_methods.find(params[:payment][:payment_method_id]) raise PaymentProcessor::Exceptions::PaymentMethodNotFound unless @payment_method + @payment_method end @@ -65,6 +66,7 @@ def currency def customer @customer ||= member.try(:braintree_customer) raise PaymentProcessor::Exceptions::CustomerNotFound unless @customer + @customer end diff --git a/app/services/braintree_services/transaction_builder.rb b/app/services/braintree_services/transaction_builder.rb index eb699da37..b9540ae2b 100644 --- a/app/services/braintree_services/transaction_builder.rb +++ b/app/services/braintree_services/transaction_builder.rb @@ -21,18 +21,18 @@ def status def attributes { - status: status, - amount: transaction.amount, - currency: transaction.currency_iso_code, - transaction_id: transaction.id, - transaction_type: transaction.type, - merchant_account_id: transaction.merchant_account_id, - transaction_created_at: transaction.created_at, - payment_instrument_type: transaction.payment_instrument_type, - processor_response_code: transaction.processor_response_code, - customer_id: payment_options.customer.customer_id, - payment_method: payment_options.payment_method, - page_id: payment_options.page.id + status: status, + amount: transaction.amount, + currency: transaction.currency_iso_code, + transaction_id: transaction.id, + transaction_type: transaction.type, + merchant_account_id: transaction.merchant_account_id, + transaction_created_at: transaction.created_at, + payment_instrument_type: transaction.payment_instrument_type, + processor_response_code: transaction.processor_response_code, + customer_id: payment_options.customer.customer_id, + payment_method: payment_options.payment_method, + page_id: payment_options.page.id } end end diff --git a/app/services/call_tool/call_status_updater.rb b/app/services/call_tool/call_status_updater.rb index 0e1dd4653..38538cb37 100644 --- a/app/services/call_tool/call_status_updater.rb +++ b/app/services/call_tool/call_status_updater.rb @@ -3,12 +3,14 @@ class CallStatusUpdater class << self def start!(call) return unless call.unstarted? + call.started! CallEvent::Update.publish(call) if call.member.present? end def connect!(call) return unless call.started? + call.connected! CallEvent::Update.publish(call) if call.member.present? end diff --git a/app/services/call_tool/checksum_validator.rb b/app/services/call_tool/checksum_validator.rb index b933014d0..c4380ff48 100644 --- a/app/services/call_tool/checksum_validator.rb +++ b/app/services/call_tool/checksum_validator.rb @@ -2,6 +2,7 @@ module CallTool class ChecksumValidator def self.validate(phone_number, checksum) return false if phone_number.blank? || checksum.blank? + unhashed = "#{phone_number}#{Settings.calls.targeting_secret}" checksum == Digest::SHA256.hexdigest(unhashed)[0..5] end diff --git a/app/services/call_tool/stats.rb b/app/services/call_tool/stats.rb index 4869e1291..1a7999c52 100644 --- a/app/services/call_tool/stats.rb +++ b/app/services/call_tool/stats.rb @@ -1,9 +1,7 @@ module CallTool class Stats def self.for(page) - if Plugins::CallTool.where(page: page).exists? - new(page).to_h - end + new(page).to_h if Plugins::CallTool.where(page: page).exists? end def initialize(page) diff --git a/app/services/connect_with_oauth_provider.rb b/app/services/connect_with_oauth_provider.rb index 241fa4baa..0997e8d39 100644 --- a/app/services/connect_with_oauth_provider.rb +++ b/app/services/connect_with_oauth_provider.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Raise if user's email domain is not whitelisted class Champaign::NotWhitelisted < StandardError; end @@ -25,6 +26,7 @@ def connect def whitelisted return true if whitelist.blank? + whitelist.include? email_domain end diff --git a/app/services/create_member_for_api_members_controller.rb b/app/services/create_member_for_api_members_controller.rb index 981e9b5bb..400a33698 100644 --- a/app/services/create_member_for_api_members_controller.rb +++ b/app/services/create_member_for_api_members_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class CreateMemberForApiMembersController attr_reader :member, :errors @@ -29,6 +30,7 @@ def create def member_params return @member_params if @member_params.present? + allowed = Member.new.attributes.keys.map(&:to_sym) + [:name] @member_params = @params.select { |k, _| allowed.include? k } end diff --git a/app/services/email_tool_sender.rb b/app/services/email_tool_sender.rb index 7e8b311b2..9c84b9e28 100644 --- a/app/services/email_tool_sender.rb +++ b/app/services/email_tool_sender.rb @@ -30,13 +30,13 @@ def run def send_email EmailSender.run( - id: @page.slug, + id: @page.slug, recipients: to_emails, - from_name: @params[:from_name], + from_name: @params[:from_name], from_email: from_email, - reply_to: reply_to_emails, - subject: @params[:subject], - body: @params[:body] + reply_to: reply_to_emails, + subject: @params[:subject], + body: @params[:body] ) end @@ -45,12 +45,12 @@ def create_action # No new members for EEA countries @action = ManageAction.create( { - page_id: @page.id, - name: @params[:from_name], - email: @params[:from_email], - action_target: @target&.name, + page_id: @page.id, + name: @params[:from_name], + email: @params[:from_email], + action_target: @target&.name, action_target_email: @target&.email, - country: @params[:country] + country: @params[:country] }.merge(@tracking_params) ) end @@ -93,17 +93,11 @@ def reply_to_emails end def validate_plugin - if @plugin.from_email_address.blank? - add_error(:base, 'Please configure a From email address') - end + add_error(:base, 'Please configure a From email address') if @plugin.from_email_address.blank? - if @plugin.targets.empty? - add_error(:base, 'Please configure at least one target') - end + add_error(:base, 'Please configure at least one target') if @plugin.targets.empty? - if @params[:country].blank? - add_error(:base, 'Please make sure a country is being sent') - end + add_error(:base, 'Please make sure a country is being sent') if @params[:country].blank? target_id = @params[:target_id] if target_id.present? && @plugin.find_target(target_id).nil? diff --git a/app/services/email_verifier_service.rb b/app/services/email_verifier_service.rb index bfd67e8e8..be93f55ad 100644 --- a/app/services/email_verifier_service.rb +++ b/app/services/email_verifier_service.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class EmailVerifierService include AuthToken diff --git a/app/services/form_duplicator.rb b/app/services/form_duplicator.rb index 8cde85afb..e5bc7c6b1 100644 --- a/app/services/form_duplicator.rb +++ b/app/services/form_duplicator.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class FormDuplicator class << self def duplicate(form) diff --git a/app/services/form_element_builder.rb b/app/services/form_element_builder.rb index 43bad04bd..eb24e7044 100644 --- a/app/services/form_element_builder.rb +++ b/app/services/form_element_builder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class FormElementBuilder class << self def create(form, params) @@ -30,17 +31,17 @@ def params def format_many_choices(choice_string) return choice_string unless choice_string.present? && choice_string.is_a?(String) + choice_string.split(/\r?\n/) end def format_choices(choice_list) return choice_list unless choice_list.respond_to?(:map) + choice_list.map do |choice| - begin - JSON.parse(choice) - rescue JSON::ParserError - choice - end + JSON.parse(choice) + rescue JSON::ParserError + choice end end end diff --git a/app/services/form_validator.rb b/app/services/form_validator.rb index 1c52b7d38..3b8e38e94 100644 --- a/app/services/form_validator.rb +++ b/app/services/form_validator.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -# + class FormValidator MAX_LENGTH = { PARAGRAPH: 10_000, TEXT: 250 }.freeze - EMAIL_REGEXP = /\A(?!\.)(?!.*\.{2})(?!.*@\.)(?!.*\.+@)[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\z/i + EMAIL_REGEXP = /\A(?!\.)(?!.*\.{2})(?!.*@\.)(?!.*\.+@)[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\z/i.freeze def initialize(params, form_elements = nil) @params = params.symbolize_keys @@ -33,6 +33,7 @@ def errors def form_elements return @form_elements if @form_elements.present? + if @params[:form_id].present? form = Form.includes(:form_elements).find(@params[:form_id]) @form_elements = form.form_elements.map do |el| @@ -64,12 +65,14 @@ def validate_length(value, form_element) def validate_required(value, form_element) return unless form_element[:required] && value.blank? + @errors[form_element[:name]] << I18n.t('validation.is_required') end def validate_checkbox(value, form_element) return unless form_element[:data_type] == 'checkbox' && form_element[:required] return if value.present? && !value.nil? && value.to_s != '0' + @errors[form_element[:name]] << I18n.t('validation.is_required') end @@ -98,9 +101,7 @@ def validate_postal(postal, form_element) country = (@params[:country].blank? ? :US : @params[:country].to_sym) validator = PostalValidator.new(postal, country_code: country) - unless validator.valid? - @errors[form_element[:name]] += validator.errors - end + @errors[form_element[:name]] += validator.errors unless validator.valid? end def is_email?(candidate) diff --git a/app/services/go_cardless_cancellation_service.rb b/app/services/go_cardless_cancellation_service.rb index 135d2838c..06e91c7bf 100644 --- a/app/services/go_cardless_cancellation_service.rb +++ b/app/services/go_cardless_cancellation_service.rb @@ -16,10 +16,10 @@ def cancel_mandate(current_member, params) ::PaymentProcessor::GoCardless::Populator.client.mandates.cancel(@payment_method.go_cardless_id) @payment_method.update(cancelled_at: Time.now) cancel_active_subscriptions(@payment_method) - return nil + nil rescue *GO_CARDLESS_ERRORS => e Rails.logger.error("#{e.class} occurred when cancelling mandate #{@payment_method.go_cardless_id}: #{e.message}") - return e + e end def cancel_subscription(current_member, params) @@ -30,12 +30,12 @@ def cancel_subscription(current_member, params) PaymentProcessor::GoCardless::Subscription.cancel(@subscription.go_cardless_id) @subscription.update(cancelled_at: Time.now) @subscription.publish_cancellation('user') - return nil + nil rescue *GO_CARDLESS_ERRORS => e Rails.logger.error( "#{e.class} occurred when cancelling subscription #{@subscription.go_cardless_id}: #{e.message}" ) - return e + e end def cancel_active_subscriptions(mandate) diff --git a/app/services/manage_action.rb b/app/services/manage_action.rb index 5d994ba28..8c5b98ef6 100644 --- a/app/services/manage_action.rb +++ b/app/services/manage_action.rb @@ -29,9 +29,7 @@ def create_action page: page }.merge(@extra_attrs) - if requires_double_opt_in - return PendingActionService.create(@params) - end + return PendingActionService.create(@params) if requires_double_opt_in if existing_member.present? action_params[:member] = existing_member @@ -59,11 +57,13 @@ def create_action def previous_action return nil unless existing_member.present? + @previous_action ||= Action.not_donation.where(member: existing_member, page_id: page).first if page.campaign.present? && @previous_action.blank? page.campaign.pages.each do |connected_page| next if connected_page.id == page.id + @previous_action ||= Action.not_donation.where(member: existing_member, page_id: connected_page.id).first end end diff --git a/app/services/manage_braintree_donation.rb b/app/services/manage_braintree_donation.rb index 95fa5a15a..a5fbcbf5f 100644 --- a/app/services/manage_braintree_donation.rb +++ b/app/services/manage_braintree_donation.rb @@ -5,10 +5,10 @@ class ManageBraintreeDonation def self.create(params:, braintree_result:, is_subscription: false, store_in_vault: false) new( - params: params, + params: params, braintree_result: braintree_result, - is_subscription: is_subscription, - store_in_vault: store_in_vault + is_subscription: is_subscription, + store_in_vault: store_in_vault ).create end @@ -25,16 +25,16 @@ def create # with which we will associate ongoing donations, in the event this is a subscription. @params.merge!( { - amount: transaction.amount.to_s, - card_num: card_num, - currency: transaction.currency_iso_code, - transaction_id: transaction.id, - subscription_id: subscription_id, - is_subscription: @is_subscription, + amount: transaction.amount.to_s, + card_num: card_num, + currency: transaction.currency_iso_code, + transaction_id: transaction.id, + subscription_id: subscription_id, + is_subscription: @is_subscription, card_expiration_date: transaction.credit_card_details.expiration_date, payment_provider: 'braintree', action_express_donation: 0, - store_in_vault: @store_in_vault + store_in_vault: @store_in_vault }.tap do |params| params[:recurrence_number] = 0 if @is_subscription end diff --git a/app/services/manage_survey_response.rb b/app/services/manage_survey_response.rb index 459e98e57..c511b8c8b 100644 --- a/app/services/manage_survey_response.rb +++ b/app/services/manage_survey_response.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ManageSurveyResponse attr_accessor :action @@ -32,6 +33,7 @@ def sanitize_params(params, form) def assign_member return unless @params[:email].present? + @action.member = Member.find_or_initialize_by(email: @params[:email].downcase) end diff --git a/app/services/member_services/member_updater.rb b/app/services/member_services/member_updater.rb index 69c5eb738..adf0f43ed 100644 --- a/app/services/member_services/member_updater.rb +++ b/app/services/member_services/member_updater.rb @@ -13,9 +13,7 @@ def initialize(email, params) def run @member = Member.find_by_email(@email) - unless @member - raise ActiveRecord::RecordNotFound - end + raise ActiveRecord::RecordNotFound unless @member @member.update(@params) end diff --git a/app/services/member_with_authentication.rb b/app/services/member_with_authentication.rb index b39e84d60..32e897227 100644 --- a/app/services/member_with_authentication.rb +++ b/app/services/member_with_authentication.rb @@ -48,7 +48,7 @@ def existing_member end def cannot_be_already_authenticated - errors.add(:authentication, 'already exists') if existing_member && existing_member.authentication + errors.add(:authentication, 'already exists') if existing_member&.authentication end def cannot_have_non_matching_passwords diff --git a/app/services/mobile_detector.rb b/app/services/mobile_detector.rb index 127825acf..a3c25f2d3 100644 --- a/app/services/mobile_detector.rb +++ b/app/services/mobile_detector.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'browser' class MobileDetector @@ -18,6 +19,7 @@ def detect def device return 'unknown' if @browser.ua.blank? + if @browser.device.mobile? 'mobile' elsif @browser.device.tablet? diff --git a/app/services/name_splitter.rb b/app/services/name_splitter.rb index 2675947c1..c3c8f994f 100644 --- a/app/services/name_splitter.rb +++ b/app/services/name_splitter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class NameSplitter def initialize(full_name:) @full_name = full_name diff --git a/app/services/page_builder.rb b/app/services/page_builder.rb index aa1fb0bd4..8c465d074 100644 --- a/app/services/page_builder.rb +++ b/app/services/page_builder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class PageBuilder attr_reader :params diff --git a/app/services/page_follower.rb b/app/services/page_follower.rb index 3e1071657..81559e639 100644 --- a/app/services/page_follower.rb +++ b/app/services/page_follower.rb @@ -36,17 +36,20 @@ def follow_up_path def path_to_follow_up_page return nil if @follow_up_page_slug.blank? + member_facing_page_path(@follow_up_page_slug, **url_params) end def path_to_follow_up_layout return nil if @page_slug.blank? || @follow_up_liquid_layout_id.blank? + follow_up_member_facing_page_path(@page_slug, **url_params) end def url_params return {} if @extra_params.blank? return @url_params if @url_params.present? + @url_params = {}.tap do |ps| PARAMS_TO_PASS.each do |key| ps[key] = @extra_params[key] if @extra_params.key?(key) diff --git a/app/services/page_updater.rb b/app/services/page_updater.rb index df347bdec..0c66caec0 100644 --- a/app/services/page_updater.rb +++ b/app/services/page_updater.rb @@ -95,15 +95,14 @@ def important_changes_made def update_page return unless @params[:page] + plugins_before = @page.plugins ak_sensitive_changes = important_changes_made do @page.assign_attributes(@params[:page]) end - if @page.save && ak_sensitive_changes - QueueManager.push(@page, job_type: :update_pages) - end + QueueManager.push(@page, job_type: :update_pages) if @page.save && ak_sensitive_changes @refresh = (@page.plugins != plugins_before) @errors[:page] = @page.errors.to_h unless @page.errors.empty? @@ -112,6 +111,7 @@ def update_page def update_plugin(plugin_params) plugin = plugins.select { |p| p.id == plugin_params[:id].to_i && p.name == plugin_params[:name] }.first raise ActiveRecord::RecordNotFound if plugin.blank? + plugin.update_attributes(plugin_params.except(:name)) plugin.errors end diff --git a/app/services/postal_validator.rb b/app/services/postal_validator.rb index bd55229b8..a3d4f55bb 100644 --- a/app/services/postal_validator.rb +++ b/app/services/postal_validator.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class PostalValidator ZIPCODES_REGEX = { US: /\A\d{5}([ \-]\d{4})?\z/ @@ -25,23 +26,18 @@ def valid? def validate_country_format return unless ZIPCODES_REGEX.key? @country_code - if (ZIPCODES_REGEX[@country_code] =~ @postal_code).nil? - @errors << I18n.t('validation.is_invalid_postal') - end + + @errors << I18n.t('validation.is_invalid_postal') if (ZIPCODES_REGEX[@country_code] =~ @postal_code).nil? end # Matching Braintree validation def validate_characters - if (/\A[a-zA-Z\d\s\-]*\z/ =~ @postal_code).nil? - @errors << I18n.t('validation.postal.has_invalid_characters') - end + @errors << I18n.t('validation.postal.has_invalid_characters') if (/\A[a-zA-Z\d\s\-]*\z/ =~ @postal_code).nil? end # Matching Braintree validation def validate_length stripped_postal = @postal_code.gsub(/[^a-zA-Z\d]/, '') - if stripped_postal.length > MAX_LENGTH - @errors << I18n.t('validation.postal.too_long') - end + @errors << I18n.t('validation.postal.too_long') if stripped_postal.length > MAX_LENGTH end end diff --git a/app/services/queue_manager.rb b/app/services/queue_manager.rb index 6606b36d1..e160f97a9 100644 --- a/app/services/queue_manager.rb +++ b/app/services/queue_manager.rb @@ -46,12 +46,12 @@ def data_for_queue def params { - page_id: page.id, - name: page.slug, - title: page.title, + page_id: page.id, + name: page.slug, + title: page.title, language: page.language.try(:actionkit_uri), - tags: tags, - url: member_facing_page_url(page, host: Settings.host), + tags: tags, + url: member_facing_page_url(page, host: Settings.host), hosted_with: '/rest/v1/hostingplatform/2/', campaign_id: page.campaign_id } diff --git a/app/services/search.rb b/app/services/search.rb index 162769a8f..a4f8677bc 100644 --- a/app/services/search.rb +++ b/app/services/search.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Search # matches content with a WHERE x LIKE query def self.full_text_search(collection, field, query) diff --git a/app/services/search/page_searcher.rb b/app/services/search/page_searcher.rb index 92c260ae9..034a5607e 100644 --- a/app/services/search/page_searcher.rb +++ b/app/services/search/page_searcher.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Search::PageSearcher def self.search(params) new(params).search @@ -12,6 +13,7 @@ def initialize(params) def search @queries.each_pair do |search_type, query| next unless query.present? + case search_type.to_sym when :content_search search_by_text(query) @@ -62,9 +64,7 @@ def search_by_tags(tags) matches_by_tags = [] @collection.each do |page| # if the page has tags and if the queried tags are a subset of the page's tags - if page.tags.any? && (tags.map(&:to_i) - page.tags.pluck('id')).empty? - matches_by_tags.push(page) - end + matches_by_tags.push(page) if page.tags.any? && (tags.map(&:to_i) - page.tags.pluck('id')).empty? end @collection = array_to_relation(Page, matches_by_tags) end @@ -92,12 +92,13 @@ def search_by_plugin_type(query) begin plugin_class = plugin_type.constantize # Rescue for invalid plugin name - constantize throws name error if a constant with the name hasn't been initialized. - rescue + rescue StandardError next end plugin_class.page.each do |page_plugin| # If the page hasn't determined to be filtered from the collection yet next unless filtered_pages.include?(page_plugin.page_id) + # If the plugin is active, add its page to matches if page_plugin.active? matches_by_plugins.push(page_plugin.page_id) @@ -118,12 +119,13 @@ def search_by_publish_status(query) def order_by(query) return unless validate_order_by(query) + query = "#{query[0]} #{query[1]}" if query.is_a? Array @collection = @collection.order(query) end def validate_order_by(query) - acceptable = [:created_at, :updated_at, :title, :featured, :active] + acceptable = %i[created_at updated_at title featured active] if query.is_a? Array acceptable.include? query[0].to_sym else diff --git a/app/services/survey_session_manager.rb b/app/services/survey_session_manager.rb index 036d72641..d6a9e5877 100644 --- a/app/services/survey_session_manager.rb +++ b/app/services/survey_session_manager.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class SurveySessionManager def initialize(session) @session = session diff --git a/app/validators/action_kit_fields.rb b/app/validators/action_kit_fields.rb index 359f3e1da..9428115aa 100644 --- a/app/validators/action_kit_fields.rb +++ b/app/validators/action_kit_fields.rb @@ -28,7 +28,7 @@ # class ActionKitFields < ActiveModel::Validator - VALID_CHARS_RE = /^[0-9a-z_]+$/ + VALID_CHARS_RE = /^[0-9a-z_]+$/.freeze # +VALID_PREFIX_RE+ matches for allowed prefixes for custom fields for ActionKit actions. # @@ -40,7 +40,7 @@ class ActionKitFields < ActiveModel::Validator # https://act.sumofus.org/docs/manual/api/rest/actionprocessing.html#custom-user-fields # https://act.sumofus.org/docs/manual/api/rest/actionprocessing.html#custom-action-fields # - VALID_PREFIX_RE = /^(action)\_[0-9a-z_]+/ + VALID_PREFIX_RE = /^(action)\_[0-9a-z_]+/.freeze ACTIONKIT_FIELDS_WHITELIST = %w[ address1 @@ -74,9 +74,7 @@ def initialize(name) def validate(record) @name = record.name - unless has_valid_form - record.errors[:name] << "'#{record.name}' is not a permitted ActionKit name." - end + record.errors[:name] << "'#{record.name}' is not a permitted ActionKit name." unless has_valid_form unless has_valid_characters record.errors[:name] << "'#{record.name}' may only contain numbers, underscores, and lowercase letters." end diff --git a/app/views/api/analytics/show.json.jbuilder b/app/views/api/analytics/show.json.jbuilder index d2bb63e05..73e15c610 100644 --- a/app/views/api/analytics/show.json.jbuilder +++ b/app/views/api/analytics/show.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.hours total_actions_by_hour(@page) json.days_total total_actions_by_day(@page) json.days_new new_members_by_day(@page) diff --git a/app/views/api/member_services/cancel_recurring_donation.jbuilder b/app/views/api/member_services/cancel_recurring_donation.jbuilder index bff2b6b25..6058d7140 100644 --- a/app/views/api/member_services/cancel_recurring_donation.jbuilder +++ b/app/views/api/member_services/cancel_recurring_donation.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + record = @donations_updater.resource subscription_id = @permitted_params[:provider] == 'braintree' ? record.subscription_id : record.go_cardless_id diff --git a/app/views/api/member_services/member.jbuilder b/app/views/api/member_services/member.jbuilder index b9342d0cd..c2c8c66ac 100644 --- a/app/views/api/member_services/member.jbuilder +++ b/app/views/api/member_services/member.jbuilder @@ -1,2 +1,3 @@ # frozen_string_literal: true + json.member @member, :id, :email, :first_name, :last_name, :postal, :country diff --git a/app/views/api/member_services/subject_access_request.jbuilder b/app/views/api/member_services/subject_access_request.jbuilder index c76f4017f..aa5245fcd 100644 --- a/app/views/api/member_services/subject_access_request.jbuilder +++ b/app/views/api/member_services/subject_access_request.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + @data.keys.each do |key| json.set! key.to_sym, @data[key] end diff --git a/app/views/api/pages/index.json.jbuilder b/app/views/api/pages/index.json.jbuilder index 07ede77a1..a355aa29b 100644 --- a/app/views/api/pages/index.json.jbuilder +++ b/app/views/api/pages/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @pages do |page| json.extract!( page, diff --git a/app/views/api/pages/show.json.jbuilder b/app/views/api/pages/show.json.jbuilder index 7ac1f9c18..9856c517b 100644 --- a/app/views/api/pages/show.json.jbuilder +++ b/app/views/api/pages/show.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.extract!( @page, :id, diff --git a/app/views/api/payment/braintree/one_click.json.jbuilder b/app/views/api/payment/braintree/one_click.json.jbuilder index 9a777b950..658871e13 100644 --- a/app/views/api/payment/braintree/one_click.json.jbuilder +++ b/app/views/api/payment/braintree/one_click.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.success @result.success? unless @result.success? json.params @result.params diff --git a/app/views/api/stateless/braintree/payment_methods/index.json.jbuilder b/app/views/api/stateless/braintree/payment_methods/index.json.jbuilder index 0432c2758..424b89366 100644 --- a/app/views/api/stateless/braintree/payment_methods/index.json.jbuilder +++ b/app/views/api/stateless/braintree/payment_methods/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @payment_methods do |method| json.call(method, :id, :instrument_type, :token, :last_4, :bin, :expiration_date, :email, :card_type) end diff --git a/app/views/api/stateless/braintree/subscriptions/index.json.jbuilder b/app/views/api/stateless/braintree/subscriptions/index.json.jbuilder index c24d0dd04..e7606ecc2 100644 --- a/app/views/api/stateless/braintree/subscriptions/index.json.jbuilder +++ b/app/views/api/stateless/braintree/subscriptions/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @subscriptions do |subscription| json.call subscription, :id, diff --git a/app/views/api/stateless/braintree/transactions/index.json.jbuilder b/app/views/api/stateless/braintree/transactions/index.json.jbuilder index b2a0bbb79..3ae703380 100644 --- a/app/views/api/stateless/braintree/transactions/index.json.jbuilder +++ b/app/views/api/stateless/braintree/transactions/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @transactions do |transaction| json.call transaction, :id, diff --git a/app/views/api/stateless/go_cardless/payment_methods/index.json.jbuilder b/app/views/api/stateless/go_cardless/payment_methods/index.json.jbuilder index 76351e7ba..334a02c6e 100644 --- a/app/views/api/stateless/go_cardless/payment_methods/index.json.jbuilder +++ b/app/views/api/stateless/go_cardless/payment_methods/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @payment_methods do |method| json.call(method, :id, :go_cardless_id, :scheme, :next_possible_charge_date, :created_at) end diff --git a/app/views/api/stateless/go_cardless/subscriptions/index.json.jbuilder b/app/views/api/stateless/go_cardless/subscriptions/index.json.jbuilder index eab29c47b..dc290407d 100644 --- a/app/views/api/stateless/go_cardless/subscriptions/index.json.jbuilder +++ b/app/views/api/stateless/go_cardless/subscriptions/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @subscriptions do |subscription| json.call(subscription, :id, :go_cardless_id, :amount, :currency, :name, :created_at) json.state subscription.aasm_state diff --git a/app/views/api/stateless/go_cardless/transactions/index.json.jbuilder b/app/views/api/stateless/go_cardless/transactions/index.json.jbuilder index 4d5834234..41f35d8fd 100644 --- a/app/views/api/stateless/go_cardless/transactions/index.json.jbuilder +++ b/app/views/api/stateless/go_cardless/transactions/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array! @transactions do |transaction| json.call(transaction, :id, :go_cardless_id, :charge_date, :amount, :description, :currency, :aasm_state) json.payment_method transaction.payment_method, :id, :go_cardless_id, :scheme, :next_possible_charge_date, :created_at diff --git a/app/views/api/stateless/members/show.json.jbuilder b/app/views/api/stateless/members/show.json.jbuilder index 1676409b1..12b00db87 100644 --- a/app/views/api/stateless/members/show.json.jbuilder +++ b/app/views/api/stateless/members/show.json.jbuilder @@ -1,2 +1,3 @@ # frozen_string_literal: true + json.call(@current_member, :id, :first_name, :last_name, :email, :country, :city, :postal, :address1, :address2) diff --git a/app/views/api/stateless/members/update.json.jbuilder b/app/views/api/stateless/members/update.json.jbuilder index 1676409b1..12b00db87 100644 --- a/app/views/api/stateless/members/update.json.jbuilder +++ b/app/views/api/stateless/members/update.json.jbuilder @@ -1,2 +1,3 @@ # frozen_string_literal: true + json.call(@current_member, :id, :first_name, :last_name, :email, :country, :city, :postal, :address1, :address2) diff --git a/app/views/liquid_layouts/index.json.jbuilder b/app/views/liquid_layouts/index.json.jbuilder index c00c57082..9d3a56cb5 100644 --- a/app/views/liquid_layouts/index.json.jbuilder +++ b/app/views/liquid_layouts/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array!(@liquid_layouts) do |liquid_layout| json.extract! liquid_layout, :id, :title, :content json.url liquid_layout_url(liquid_layout, format: :json) diff --git a/app/views/liquid_layouts/show.json.jbuilder b/app/views/liquid_layouts/show.json.jbuilder index 64b086a6e..a88dc0b97 100644 --- a/app/views/liquid_layouts/show.json.jbuilder +++ b/app/views/liquid_layouts/show.json.jbuilder @@ -1,2 +1,3 @@ # frozen_string_literal: true + json.extract! @liquid_layout, :id, :title, :content, :created_at, :updated_at diff --git a/app/views/liquid_partials/index.json.jbuilder b/app/views/liquid_partials/index.json.jbuilder index 7fc2ccb1c..b5e0fa134 100644 --- a/app/views/liquid_partials/index.json.jbuilder +++ b/app/views/liquid_partials/index.json.jbuilder @@ -1,4 +1,5 @@ # frozen_string_literal: true + json.array!(@liquid_partials) do |liquid_partial| json.extract! liquid_partial, :id, :title, :content json.url liquid_partial_url(liquid_partial, format: :json) diff --git a/app/views/liquid_partials/show.json.jbuilder b/app/views/liquid_partials/show.json.jbuilder index b7f38df13..4adef3726 100644 --- a/app/views/liquid_partials/show.json.jbuilder +++ b/app/views/liquid_partials/show.json.jbuilder @@ -1,2 +1,3 @@ # frozen_string_literal: true + json.extract! @liquid_partial, :id, :title, :content, :created_at, :updated_at diff --git a/config/environment.rb b/config/environment.rb index 12ea62f88..d5abe5580 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/production.rb b/config/environments/production.rb index ffdfc13ef..6d05b066e 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -58,9 +58,7 @@ %w[controller action].include? k end log_hash = { 'params' => params.except!(*:bt_payload), 'time' => event.time } - unless event.payload[:exception].blank? - log_hash['exception'] = event.payload[:exception] - end + log_hash['exception'] = event.payload[:exception] unless event.payload[:exception].blank? log_hash end # Prepend all log lines with the following tags. @@ -113,8 +111,8 @@ config.cache_store = :readthis_store, { namespace: 'cache', expires_in: 1.day.to_i, - redis: { host: Settings.cache.host, - port: Settings.cache.port, drive: :hiredis } + redis: { host: Settings.cache.host, + port: Settings.cache.port, drive: :hiredis } } # In production, we only accept CORS request from sumofus.org or its subdomains. diff --git a/config/initializers/actionkit_connector.rb b/config/initializers/actionkit_connector.rb index bc2e0c5f5..d3d804c3a 100644 --- a/config/initializers/actionkit_connector.rb +++ b/config/initializers/actionkit_connector.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + if Settings.ak_api_url.present? ActionKitConnector.config( username: Settings.ak_username, diff --git a/config/initializers/airbrake.rb b/config/initializers/airbrake.rb index a9ffffff6..9a9df9cad 100644 --- a/config/initializers/airbrake.rb +++ b/config/initializers/airbrake.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Airbrake is an online tool that provides robust exception tracking in your Rails # applications. In doing so, it allows you to easily review errors, tie an error # to an individual piece of code, and trace the cause back to recent @@ -44,7 +45,7 @@ # environments. # NOTE: This option *does not* work if you don't set the 'environment' option. # https://github.com/airbrake/airbrake-ruby#ignore_environments - c.ignore_environments = %w(test) + c.ignore_environments = %w[test] # A list of parameters that should be filtered out of what is sent to # Airbrake. By default, all "password" attributes will have their contents diff --git a/config/initializers/aws_sdk.rb b/config/initializers/aws_sdk.rb index 0618c2448..cf3406ddc 100644 --- a/config/initializers/aws_sdk.rb +++ b/config/initializers/aws_sdk.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'aws-sdk-rails' Aws.config.update(region: Settings.aws_region) diff --git a/config/initializers/braintree.rb b/config/initializers/braintree.rb index bc105e7aa..2e4389b6a 100644 --- a/config/initializers/braintree.rb +++ b/config/initializers/braintree.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Braintree::Configuration.environment = (Settings.braintree.environment || :sandbox).to_sym Braintree::Configuration.logger = Logger.new('log/braintree.log') Braintree::Configuration.merchant_id = Settings.braintree.merchant_id diff --git a/config/initializers/config.rb b/config/initializers/config.rb index 94b454f5c..41dee6a16 100644 --- a/config/initializers/config.rb +++ b/config/initializers/config.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Config.setup do |config| config.const_name = 'Settings' end diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index c787b6afd..0a23b25ec 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/countries.rb b/config/initializers/countries.rb index 6341164c4..084f43e03 100644 --- a/config/initializers/countries.rb +++ b/config/initializers/countries.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # ActionKit uses some country names which don't match up to their official # ISO names. So, we need to do some replacement on those names. diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index fd73965a7..8b04eafe0 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index b7fe1231f..7a4f47b4c 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/friendly_id.rb b/config/initializers/friendly_id.rb index 9d143e189..b296780b8 100644 --- a/config/initializers/friendly_id.rb +++ b/config/initializers/friendly_id.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # FriendlyId Global Configuration # # Use this to set up shared configuration options for your entire application. @@ -17,8 +18,8 @@ # undesirable to allow as slugs. Edit this list as needed for your app. config.use :reserved - config.reserved_words = %w(new edit index session login logout users admin - stylesheets assets javascripts images) + config.reserved_words = %w[new edit index session login logout users admin + stylesheets assets javascripts images] # ## Friendly Finders # diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb index 1a5f25322..e6864013c 100644 --- a/config/initializers/geocoder.rb +++ b/config/initializers/geocoder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + if Rails.env.production? Geocoder.configure(freegeoip: { host: Settings.geocoder.host diff --git a/config/initializers/liquid.rb b/config/initializers/liquid.rb index ea1f30c87..552ce2ca7 100644 --- a/config/initializers/liquid.rb +++ b/config/initializers/liquid.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require './app/liquid/liquid_file_system' require './app/liquid/liquid_i18n' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index c1370bb9c..005ddaa91 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,2 +1,3 @@ # frozen_string_literal: true + Champaign::Application.config.session_store :cookie_store diff --git a/config/initializers/twilio.rb b/config/initializers/twilio.rb index 721b4ef07..e36ffa64f 100644 --- a/config/initializers/twilio.rb +++ b/config/initializers/twilio.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Twilio.configure do |config| config.account_sid = Settings.twilio.account_sid config.auth_token = Settings.twilio.auth_token diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 12a2508e2..246168a42 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index 1e19380dc..ccda173c4 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,16 +4,16 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/spring.rb b/config/spring.rb index c9119b40c..9fa7863f9 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,6 @@ -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/db/migrate/20150811083418_change_col_name_on_thermometer.rb b/db/migrate/20150811083418_change_col_name_on_thermometer.rb index baea7cbba..895fcc78e 100644 --- a/db/migrate/20150811083418_change_col_name_on_thermometer.rb +++ b/db/migrate/20150811083418_change_col_name_on_thermometer.rb @@ -2,6 +2,6 @@ class ChangeColNameOnThermometer < ActiveRecord::Migration[4.2] def change - rename_column:plugins_thermometers, :total, :goal + rename_column :plugins_thermometers, :total, :goal end end diff --git a/db/migrate/20170304151306_migrate_call_target_format.rb b/db/migrate/20170304151306_migrate_call_target_format.rb index 07f99964e..d65b8caf0 100644 --- a/db/migrate/20170304151306_migrate_call_target_format.rb +++ b/db/migrate/20170304151306_migrate_call_target_format.rb @@ -15,6 +15,7 @@ def up Call.where.not(target_index: nil).each do |call| call_tool = Plugins::CallTool.find_by_page_id(call.page_id) next unless call_tool.present? + target = call_tool.targets[call.target_index] call.update!(target: target) end diff --git a/lib/tasks/action_kit.rake b/lib/tasks/action_kit.rake index e0004af34..4f0c7f801 100644 --- a/lib/tasks/action_kit.rake +++ b/lib/tasks/action_kit.rake @@ -5,9 +5,7 @@ namespace :action_kit do puts 'Importing languages from ActionKit' response = ActionKitConnector.client.list_languages - unless response.success? - raise "Error connecting to ActionKit: #{response.inspect}" - end + raise "Error connecting to ActionKit: #{response.inspect}" unless response.success? response.parsed_response['objects'].each do |object| Language.create!(code: object['iso_code'], name: object['name'], actionkit_uri: object['resource_uri']) @@ -20,9 +18,7 @@ namespace :action_kit do pages.each_with_index do |response, index| puts "Importing batch ##{index}" - unless response.success? - raise "Error connecting to ActionKit: #{response.inspect}" - end + raise "Error connecting to ActionKit: #{response.inspect}" unless response.success? response.parsed_response['objects'].each do |object| tag = Tag.create name: object['name'], actionkit_uri: object['resource_uri'] diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 77bbdb82d..cd4509692 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -58,6 +58,7 @@ namespace :assets do puts "Downloading external assets from #{url}" response = HTTParty.get url, http_options break if response.success? + errors << "HTTP error while trying to download assets from #{url}: #{response.inspect}" end unless response.success? diff --git a/lib/tasks/export_member.rake b/lib/tasks/export_member.rake index 3d16dd208..a40d4eaa9 100644 --- a/lib/tasks/export_member.rake +++ b/lib/tasks/export_member.rake @@ -1,9 +1,7 @@ namespace :export_member_data do desc 'Export members data as csv files' task :csv, %i[email path] => :environment do |_t, args| - if args[:email].blank? - raise 'usage: rake export_member_data:csv[[,]]' - end + raise 'usage: rake export_member_data:csv[[,]]' if args[:email].blank? member = Member.find_by_email(args[:email]) csv_map = MemberExporter.to_csv(member) diff --git a/spec/factories/campaigns.rb b/spec/factories/campaigns.rb index d5b56f7ce..031420880 100644 --- a/spec/factories/campaigns.rb +++ b/spec/factories/campaigns.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: campaigns diff --git a/spec/factories/link.rb b/spec/factories/link.rb index b0483cf3d..303d7e86f 100644 --- a/spec/factories/link.rb +++ b/spec/factories/link.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryBot.define do factory :link do title { Faker::Company.bs } diff --git a/spec/helpers/api/analytics_helper_spec.rb b/spec/helpers/api/analytics_helper_spec.rb index 6772772da..c18c7a4b9 100644 --- a/spec/helpers/api/analytics_helper_spec.rb +++ b/spec/helpers/api/analytics_helper_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe Api::AnalyticsHelper do diff --git a/spec/helpers/api/pages_helper_spec.rb b/spec/helpers/api/pages_helper_spec.rb index dbbf88a5e..69e7a40d9 100644 --- a/spec/helpers/api/pages_helper_spec.rb +++ b/spec/helpers/api/pages_helper_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe Api::PagesHelper do diff --git a/spec/javascripts/fixtures/magic_lamp.rb b/spec/javascripts/fixtures/magic_lamp.rb index f8f5056b8..b2ebb6a3e 100644 --- a/spec/javascripts/fixtures/magic_lamp.rb +++ b/spec/javascripts/fixtures/magic_lamp.rb @@ -1,30 +1,27 @@ # frozen_string_literal: true + MagicLamp.define(controller: PagesController) do fixture(name: 'pages/fundraiser') do - begin - @page = FactoryBot.create :page, liquid_layout: LiquidLayout.find_by(title: 'Generic Fundraiser') - form = FactoryBot.create :form_with_email_and_optional_country - @page.plugins.each { |pl| if pl.name == 'Fundraiser' then pl.update_attributes(form: form) end } - params[:id] = @page.id - show - rescue StandardError => e # otherwise teaspoon will eat the error - puts "\nError loading fixture 'pages/fundraiser': #{e.inspect}\n#{e.backtrace.first(5).join("\n")}" - raise - end + @page = FactoryBot.create :page, liquid_layout: LiquidLayout.find_by(title: 'Generic Fundraiser') + form = FactoryBot.create :form_with_email_and_optional_country + @page.plugins.each { |pl| pl.update_attributes(form: form) if pl.name == 'Fundraiser' } + params[:id] = @page.id + show + rescue StandardError => e # otherwise teaspoon will eat the error + puts "\nError loading fixture 'pages/fundraiser': #{e.inspect}\n#{e.backtrace.first(5).join("\n")}" + raise end end MagicLamp.define(controller: PagesController) do fixture(name: 'pages/petition') do - begin - @page = FactoryBot.create :page, liquid_layout: LiquidLayout.find_by(title: 'Generic Petition') - form = FactoryBot.create :form_with_all_except_check - @page.plugins.each { |pl| if pl.name == 'Petition' then pl.update_attributes(form: form) end } - params[:id] = @page.id - show - rescue StandardError => e # otherwise teaspoon will eat the error - puts "\nError loading fixture 'pages/petition': #{e.inspect}\n#{e.backtrace.first(5).join("\n")}" - raise - end + @page = FactoryBot.create :page, liquid_layout: LiquidLayout.find_by(title: 'Generic Petition') + form = FactoryBot.create :form_with_all_except_check + @page.plugins.each { |pl| pl.update_attributes(form: form) if pl.name == 'Petition' } + params[:id] = @page.id + show + rescue StandardError => e # otherwise teaspoon will eat the error + puts "\nError loading fixture 'pages/petition': #{e.inspect}\n#{e.backtrace.first(5).join("\n")}" + raise end end diff --git a/spec/javascripts/support/magic_lamp_config.rb b/spec/javascripts/support/magic_lamp_config.rb index 545526f71..cb09f6563 100644 --- a/spec/javascripts/support/magic_lamp_config.rb +++ b/spec/javascripts/support/magic_lamp_config.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'database_cleaner' MagicLamp.configure do |config| diff --git a/spec/javascripts/support/magic_lamp_helpers/auth_stub.rb b/spec/javascripts/support/magic_lamp_helpers/auth_stub.rb index b2598910d..fdf7c060a 100644 --- a/spec/javascripts/support/magic_lamp_helpers/auth_stub.rb +++ b/spec/javascripts/support/magic_lamp_helpers/auth_stub.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module AuthStub def current_user @current_user ||= FactoryBot.create :user diff --git a/spec/lib/payment_processor/braintree/transaction_spec.rb b/spec/lib/payment_processor/braintree/transaction_spec.rb index d70392cd3..620cd9b40 100644 --- a/spec/lib/payment_processor/braintree/transaction_spec.rb +++ b/spec/lib/payment_processor/braintree/transaction_spec.rb @@ -44,17 +44,17 @@ module Braintree it 'passes basic arguments' do expected_arguments = { amount: 100, - payment_method_nonce: 'a_nonce', - merchant_account_id: '123', - device_data: { foo: 'bar' }, + payment_method_nonce: 'a_nonce', + merchant_account_id: '123', + device_data: { foo: 'bar' }, options: { - submit_for_settlement: true, + submit_for_settlement: true, store_in_vault_on_success: false }, customer: { - first_name: 'Bob', - last_name: '', - email: 'test@example.com' + first_name: 'Bob', + last_name: '', + email: 'test@example.com' }, billing: { first_name: 'Bob', diff --git a/spec/lib/payment_processor/go_cardless/error_processing_spec.rb b/spec/lib/payment_processor/go_cardless/error_processing_spec.rb index 24aed05db..2f216b8ad 100644 --- a/spec/lib/payment_processor/go_cardless/error_processing_spec.rb +++ b/spec/lib/payment_processor/go_cardless/error_processing_spec.rb @@ -8,7 +8,7 @@ module GoCardless let(:client) do GoCardlessPro::Client.new( access_token: Settings.gocardless.token, - environment: Settings.gocardless.environment.to_sym + environment: Settings.gocardless.environment.to_sym ) end let(:request_id) { 'dd50eaaf-8213' } diff --git a/spec/liquid/champaign_liquid_filters_spec.rb b/spec/liquid/champaign_liquid_filters_spec.rb index 7bfd295ef..6b2bfda66 100644 --- a/spec/liquid/champaign_liquid_filters_spec.rb +++ b/spec/liquid/champaign_liquid_filters_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe ChampaignLiquidFilters do diff --git a/spec/liquid/liquid_file_system_spec.rb b/spec/liquid/liquid_file_system_spec.rb index 089fe48f9..f18267389 100644 --- a/spec/liquid/liquid_file_system_spec.rb +++ b/spec/liquid/liquid_file_system_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe LiquidFileSystem do diff --git a/spec/liquid/liquid_helper_spec.rb b/spec/liquid/liquid_helper_spec.rb index 15f792274..0581a9cb2 100644 --- a/spec/liquid/liquid_helper_spec.rb +++ b/spec/liquid/liquid_helper_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe LiquidHelper do diff --git a/spec/liquid/liquid_i18n_spec.rb b/spec/liquid/liquid_i18n_spec.rb index 9def783ac..cd79b71c0 100644 --- a/spec/liquid/liquid_i18n_spec.rb +++ b/spec/liquid/liquid_i18n_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe LiquidI18n do diff --git a/spec/liquid/liquid_renderer_spec.rb b/spec/liquid/liquid_renderer_spec.rb index ce943f5a8..ce894d21c 100644 --- a/spec/liquid/liquid_renderer_spec.rb +++ b/spec/liquid/liquid_renderer_spec.rb @@ -108,7 +108,7 @@ let(:page) do create(:page, follow_up_liquid_layout: create(:liquid_layout), - follow_up_page: create(:page)) + follow_up_page: create(:page)) end let(:fake_images) do [instance_double(Image, content: nil, content_file_name: 'smile.jpg'), diff --git a/spec/liquid/liquid_tag_finder_spec.rb b/spec/liquid/liquid_tag_finder_spec.rb index 0e1a782fa..b3c9c9520 100644 --- a/spec/liquid/liquid_tag_finder_spec.rb +++ b/spec/liquid/liquid_tag_finder_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' # are these tests failing? it could be a breaking change in the liquid API. @@ -55,7 +56,7 @@ it 'finds a plugin nested in a ref to the same plugin' do @content = '
{% for field in plugins.Nd_0.fields %}

{{ plugins.chill.title }}

{% endfor %}
' - @expected = %w(Nd_0 chill) + @expected = %w[Nd_0 chill] end it 'finds plugin nested deeply' do @@ -69,7 +70,7 @@ {% endunless %} {% endif %} {% endfor %}" - @expected = %w(Nd_0 chill Nd_1) + @expected = %w[Nd_0 chill Nd_1] end end @@ -104,7 +105,7 @@ {% include 'swell' %} ) - @expected = %w(example swell) + @expected = %w[example swell] end end @@ -124,7 +125,7 @@ end let(:surrounding) { { simple: ['', ''], nested: [nested_top, nested_bottom] } } - [:simple, :nested].each do |nesting| + %i[simple nested].each do |nesting| describe "with a #{nesting} partial" do after :each do liquid_markup = "#{surrounding[nesting][0]}#{@content}#{surrounding[nesting][1]}" @@ -139,27 +140,27 @@ it 'finds a single tag with a ref' do @content = "
{% include 'example', ref: 'juiz' %}
" - @expected = [%w(example juiz)] + @expected = [%w[example juiz]] end it 'finds a single tag with another parameter and a ref' do @content = "
{% include 'example', color: '#43ab05', ref: 'juiz' %}
" - @expected = [%w(example juiz)] + @expected = [%w[example juiz]] end it 'finds two of the same includes with different refs' do @content = "{% include 'example', ref: 'zebra' %}
{% include 'example', ref: 'juiz' %}
" - @expected = [%w(example zebra), %w(example juiz)] + @expected = [%w[example zebra], %w[example juiz]] end it 'finds two of the same includes with one ref' do @content = "{% include 'example', ref: 'zebra' %}
{% include 'example' %}
" - @expected = [%w(example zebra), ['example', nil]] + @expected = [%w[example zebra], ['example', nil]] end it 'condenses two same includes with same ref' do @content = "{% include 'example', ref: 'zebra' %}
{% include 'example', ref: 'zebra' %}
" - @expected = [%w(example zebra)] + @expected = [%w[example zebra]] end it 'condenses two same includes with no refs' do @@ -174,12 +175,12 @@ it 'finds two different includes with different refs' do @content = "{% include 'example', ref: 'zebra' %}
{% include 'la paz', ref: 'juiz' %}
" - @expected = [%w(example zebra), ['la paz', 'juiz']] + @expected = [%w[example zebra], ['la paz', 'juiz']] end it 'finds two different includes with same refs' do @content = "{% include 'example', ref: 'zebra' %}
{% include 'la paz', ref: 'juiz' %}
" - @expected = [%w(example zebra), ['la paz', 'juiz']] + @expected = [%w[example zebra], ['la paz', 'juiz']] end end end diff --git a/spec/mailers/confirmation_mailer_spec.rb b/spec/mailers/confirmation_mailer_spec.rb index 84f8a4ead..ff140660e 100644 --- a/spec/mailers/confirmation_mailer_spec.rb +++ b/spec/mailers/confirmation_mailer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe ConfirmationMailer do diff --git a/spec/mailers/previews/confirmation_mailer_preview.rb b/spec/mailers/previews/confirmation_mailer_preview.rb index 4465727df..0facc1850 100644 --- a/spec/mailers/previews/confirmation_mailer_preview.rb +++ b/spec/mailers/previews/confirmation_mailer_preview.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/confirmation_mailer class ConfirmationMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/confirmation_mailer/confirmation_email diff --git a/spec/models/action_user_spec.rb b/spec/models/action_user_spec.rb index 775a08d46..c1a6f5b3d 100644 --- a/spec/models/action_user_spec.rb +++ b/spec/models/action_user_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe Member do diff --git a/spec/models/ak_log_spec.rb b/spec/models/ak_log_spec.rb index 233157abf..dd7decf42 100644 --- a/spec/models/ak_log_spec.rb +++ b/spec/models/ak_log_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: ak_logs diff --git a/spec/models/language_spec.rb b/spec/models/language_spec.rb index 5d5e5aa99..6ed6873f1 100644 --- a/spec/models/language_spec.rb +++ b/spec/models/language_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: languages @@ -22,7 +23,7 @@ end context 'blank is not allowed for' do - %w(code name actionkit_uri).each do |attr| + %w[code name actionkit_uri].each do |attr| it attr.to_s do subject.send("#{attr}=", '') expect(subject).to_not be_valid @@ -31,7 +32,7 @@ end context 'nil is not allowed for' do - %w(code name actionkit_uri).each do |attr| + %w[code name actionkit_uri].each do |attr| it attr.to_s do subject.send("#{attr}=", nil) expect(subject).to_not be_valid diff --git a/spec/models/payment/braintree_spec.rb b/spec/models/payment/braintree_spec.rb index bce85ff0d..eb185b0e9 100644 --- a/spec/models/payment/braintree_spec.rb +++ b/spec/models/payment/braintree_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' xdescribe Payment::Braintree do @@ -35,12 +36,12 @@ it 'saves relevant fields when successful' do Payment::Braintree.write_subscription(success_result, 'my_page_id', 'my_action_id', 'my_currency') - expect(Payment::Braintree::Subscription).to have_received(:create).with(subscription_id: 'lol', - amount: 12, - merchant_account_id: 'EUR', - currency: 'my_currency', - page_id: 'my_page_id', - action_id: 'my_action_id') + expect(Payment::Braintree::Subscription).to have_received(:create).with(subscription_id: 'lol', + amount: 12, + merchant_account_id: 'EUR', + currency: 'my_currency', + page_id: 'my_page_id', + action_id: 'my_action_id') end it 'does not record when unsuccessful' do @@ -77,14 +78,14 @@ let(:expected_params) do { - customer_id: bt_customer.id, - member_id: member.id, - email: bt_customer.email, - card_type: bt_payment_method.card_type, - card_bin: bt_payment_method.bin, - cardholder_name: bt_payment_method.cardholder_name, - card_debit: bt_payment_method.debit, - card_last_4: bt_payment_method.last_4, + customer_id: bt_customer.id, + member_id: member.id, + email: bt_customer.email, + card_type: bt_payment_method.card_type, + card_bin: bt_payment_method.bin, + cardholder_name: bt_payment_method.cardholder_name, + card_debit: bt_payment_method.debit, + card_last_4: bt_payment_method.last_4, card_unique_number_identifier: bt_payment_method.unique_number_identifier } end @@ -114,10 +115,10 @@ end let(:expected_params) do { - customer_id: bt_customer.id, - member_id: member.id, - email: bt_customer.email, - card_last_4: 'PYPL' + customer_id: bt_customer.id, + member_id: member.id, + email: bt_customer.email, + card_last_4: 'PYPL' } end @@ -179,39 +180,39 @@ let(:transaction_params) do { - transaction_id: transaction.id, - transaction_type: transaction.type, - payment_instrument_type: transaction.payment_instrument_type, - amount: transaction.amount, - transaction_created_at: transaction.created_at, - merchant_account_id: transaction.merchant_account_id, - processor_response_code: transaction.processor_response_code, - currency: transaction.currency_iso_code, - customer_id: existing_customer.customer_id, - status: status, + transaction_id: transaction.id, + transaction_type: transaction.type, + payment_instrument_type: transaction.payment_instrument_type, + amount: transaction.amount, + transaction_created_at: transaction.created_at, + merchant_account_id: transaction.merchant_account_id, + processor_response_code: transaction.processor_response_code, + currency: transaction.currency_iso_code, + customer_id: existing_customer.customer_id, + status: status, # Since we always create a new payment method token before the transaction, the id of the new token will with # the current implementation always be that of the last token created. payment_method_id: Payment::Braintree::PaymentMethod.last.id, - page_id: page_id + page_id: page_id } end let(:new_customer_transaction_params) do { - transaction_id: new_customer_transaction.id, - transaction_type: new_customer_transaction.type, - payment_instrument_type: new_customer_transaction.payment_instrument_type, - amount: new_customer_transaction.amount, - transaction_created_at: new_customer_transaction.created_at, - merchant_account_id: new_customer_transaction.merchant_account_id, - processor_response_code: new_customer_transaction.processor_response_code, - currency: new_customer_transaction.currency_iso_code, - customer_id: '123456', - status: status, + transaction_id: new_customer_transaction.id, + transaction_type: new_customer_transaction.type, + payment_instrument_type: new_customer_transaction.payment_instrument_type, + amount: new_customer_transaction.amount, + transaction_created_at: new_customer_transaction.created_at, + merchant_account_id: new_customer_transaction.merchant_account_id, + processor_response_code: new_customer_transaction.processor_response_code, + currency: new_customer_transaction.currency_iso_code, + customer_id: '123456', + status: status, # Since we always create a new payment method token before the transaction, the id of the new token will with # the current implementation always be that of the last token created. payment_method_id: Payment::Braintree::PaymentMethod.last.id, - page_id: page_id + page_id: page_id } end @@ -226,14 +227,14 @@ let(:payment_method_token) { credit_card_token } let(:customer_params) do { - card_type: credit_card_details.card_type, - card_bin: credit_card_details.bin, - cardholder_name: credit_card_details.cardholder_name, - card_debit: credit_card_details.debit, - card_last_4: credit_card_details.last_4, - customer_id: transaction.customer_details.id, - email: transaction.customer_details.email, - member_id: member.id + card_type: credit_card_details.card_type, + card_bin: credit_card_details.bin, + cardholder_name: credit_card_details.cardholder_name, + card_debit: credit_card_details.debit, + card_last_4: credit_card_details.last_4, + customer_id: transaction.customer_details.id, + email: transaction.customer_details.email, + member_id: member.id } end let(:credit_card_details) do @@ -369,14 +370,14 @@ let(:payment_method_token) { paypal_token } let(:customer_params) do { - card_type: nil, - card_bin: nil, - cardholder_name: nil, - card_debit: 'Unknown', - customer_id: transaction.customer_details.id, - card_last_4: 'PYPL', - email: transaction.customer_details.email, - member_id: member.id + card_type: nil, + card_bin: nil, + cardholder_name: nil, + card_debit: 'Unknown', + customer_id: transaction.customer_details.id, + card_last_4: 'PYPL', + email: transaction.customer_details.email, + member_id: member.id } end let(:credit_card_details) { double('Braintree::Transaction::CreditCardDetails', card_type: nil, last_4: nil, bin: nil, cardholder_name: nil, debit: 'Unknown') } diff --git a/spec/models/plugins/text.rb b/spec/models/plugins/text.rb index 213865205..ac4a522e0 100644 --- a/spec/models/plugins/text.rb +++ b/spec/models/plugins/text.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative 'shared_examples' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9a8a6e403..da02632fa 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,7 +2,7 @@ ENV['RAILS_ENV'] = 'test' require 'spec_helper' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) require 'rspec/rails' require 'rspec/json_expectations' require 'database_cleaner' diff --git a/spec/requests/api/action_confirmation_spec.rb b/spec/requests/api/action_confirmation_spec.rb index 7571bfb6c..431f7ddf1 100644 --- a/spec/requests/api/action_confirmation_spec.rb +++ b/spec/requests/api/action_confirmation_spec.rb @@ -78,11 +78,11 @@ let(:params) do { - email: 'hello@example.com', - form_id: form.id, + email: 'hello@example.com', + form_id: form.id, page_id: page.id, - source: 'fb', - country: 'DE', + source: 'fb', + country: 'DE', name: 'John Doe' } end diff --git a/spec/requests/api/actions_spec.rb b/spec/requests/api/actions_spec.rb index e3436cd2d..9f8ab116c 100644 --- a/spec/requests/api/actions_spec.rb +++ b/spec/requests/api/actions_spec.rb @@ -14,11 +14,11 @@ let(:headers) do { - 'HTTP_ACCEPT' => '*/*', - 'HTTP_ACCEPT_LANGUAGE' => 'en', - 'HTTP_ACCEPT_ENCODING' => '*', - 'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257', - 'referer' => 'www.google.com' + 'HTTP_ACCEPT' => '*/*', + 'HTTP_ACCEPT_LANGUAGE' => 'en', + 'HTTP_ACCEPT_ENCODING' => '*', + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257', + 'referer' => 'www.google.com' } end @@ -28,12 +28,12 @@ let(:params) do { - email: 'hello@example.com', - form_id: form.id, - source: 'fb', - country: 'FR', + email: 'hello@example.com', + form_id: form.id, + source: 'fb', + country: 'FR', consented: 'true', - akid: '1234.5678.tKK7gX', + akid: '1234.5678.tKK7gX', referring_akid: '1234.5678.tKK7gX', name: 'Bob Mash' } @@ -42,23 +42,23 @@ let(:message_body) do { type: 'action', - meta: hash_including(title: 'Foo Bar', - uri: '/a/foo-bar', - slug: 'foo-bar', + meta: hash_including(title: 'Foo Bar', + uri: '/a/foo-bar', + slug: 'foo-bar', first_name: 'Bob', - last_name: 'Mash', + last_name: 'Mash', created_at: be_within(1.second).of(Time.zone.now), country: 'France', subscribed_member: true, action_id: instance_of(Integer)), - params: hash_including(page: 'foo-bar-petition', - email: 'hello@example.com', - name: 'Bob Mash', + params: hash_including(page: 'foo-bar-petition', + email: 'hello@example.com', + name: 'Bob Mash', page_id: page.id.to_s, form_id: form.id.to_s, source: 'fb', - akid: '1234.5678.tKK7gX', + akid: '1234.5678.tKK7gX', referring_akid: '1234.5678.tKK7gX', action_mobile: 'mobile', action_referer: 'www.google.com', diff --git a/spec/requests/api/braintree/failure_spec.rb b/spec/requests/api/braintree/failure_spec.rb index 37b5aee00..f088aa7f4 100644 --- a/spec/requests/api/braintree/failure_spec.rb +++ b/spec/requests/api/braintree/failure_spec.rb @@ -46,20 +46,20 @@ let(:token_format) { /[a-z0-9]{1,36}/i } let(:user) do { - form_id: form.id, - name: 'bob fischer', - email: 'bob@example.com', - postal: '12345', + form_id: form.id, + name: 'bob fischer', + email: 'bob@example.com', + postal: '12345', address1: 'Lynda Vista', - country: 'US' + country: 'US' } end let(:params) do { - currency: 'EUR', - amount: '2002.00', # triggers credit limit exceeded - recurring: false, + currency: 'EUR', + amount: '2002.00', # triggers credit limit exceeded + recurring: false, payment_method_nonce: 'fake-valid-nonce', user: user, store_in_vault: true @@ -78,12 +78,12 @@ describe 'with invalid user fields' do let(:user) do { - form_id: form.id, - name: 'a' * 365, - email: 'bob@example.com', - postal: 'invalid postal code', + form_id: form.id, + name: 'a' * 365, + email: 'bob@example.com', + postal: 'invalid postal code', address1: 'Lynda Vista', - country: 'US' + country: 'US' } end diff --git a/spec/requests/api/cors_spec.rb b/spec/requests/api/cors_spec.rb index 81468ed9e..45df42201 100644 --- a/spec/requests/api/cors_spec.rb +++ b/spec/requests/api/cors_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'CORS support' do @@ -35,7 +36,7 @@ end it 'also allows requests from sumofus.org (no subdomain)' do - options '/api/pages', headers: { accept: 'application/json', origin: 'http://sumofus.org'} + options '/api/pages', headers: { accept: 'application/json', origin: 'http://sumofus.org' } expect(allow_origin).to eq('http://sumofus.org') end diff --git a/spec/requests/api/double_opt_in_spec.rb b/spec/requests/api/double_opt_in_spec.rb index 7e0d2f607..a18c09056 100644 --- a/spec/requests/api/double_opt_in_spec.rb +++ b/spec/requests/api/double_opt_in_spec.rb @@ -5,10 +5,10 @@ describe 'Double opt-in' do let(:params) do { - email: 'hello@example.com', - form_id: form.id, - source: 'fb', - country: 'DE', + email: 'hello@example.com', + form_id: form.id, + source: 'fb', + country: 'DE', name: 'John Doe' } end diff --git a/spec/requests/api/go_cardless/go_cardless_spec.rb b/spec/requests/api/go_cardless/go_cardless_spec.rb index efe21ebfa..d900aee28 100644 --- a/spec/requests/api/go_cardless/go_cardless_spec.rb +++ b/spec/requests/api/go_cardless/go_cardless_spec.rb @@ -1,4 +1,3 @@ -# coding: utf-8 # frozen_string_literal: true require 'rails_helper' @@ -16,12 +15,12 @@ end let(:meta) do - hash_including(title: 'Foo Bar', - uri: '/a/foo-bar', - slug: 'foo-bar', + hash_including(title: 'Foo Bar', + uri: '/a/foo-bar', + slug: 'foo-bar', first_name: 'Bernie', - last_name: 'Sanders', - action_id: instance_of(Integer), + last_name: 'Sanders', + action_id: instance_of(Integer), created_at: be_within(30.seconds).of(Time.now), country: 'United States') end @@ -63,6 +62,7 @@ ) request.params.each_pair do |key, val| next if key.match?(/controller|action/) + expect(success_redirect_params[key]).to eq val end end @@ -158,7 +158,7 @@ 'created_at' => '2016-04-11T19:15:07.713Z', 'links' => { 'creditor' => creditor_id, - 'mandate' => mandate_id, + 'mandate' => mandate_id, 'customer' => customer_id, 'customer_bank_account' => customer_bank_account_id }) @@ -234,11 +234,11 @@ }, order: hash_including( amount: gbp_amount.to_s, - currency: 'GBP', - card_num: 'DDEB', - card_code: '007', + currency: 'GBP', + card_num: 'DDEB', + card_code: '007', exp_date_month: '01', - exp_date_year: '99' + exp_date_year: '99' ), user: hash_including( email: email, @@ -403,10 +403,10 @@ amount: gbp_amount.to_s, currency: 'GBP', recurring_id: subscription_id_regexp, - card_num: 'DDEB', - card_code: '007', + card_num: 'DDEB', + card_code: '007', exp_date_month: '01', - exp_date_year: '99' + exp_date_year: '99' }, user: { email: email, diff --git a/spec/requests/api/shared_language_pages.rb b/spec/requests/api/shared_language_pages.rb index 44fd58043..5a37f61f9 100644 --- a/spec/requests/api/shared_language_pages.rb +++ b/spec/requests/api/shared_language_pages.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.shared_context 'shared language pages' do let!(:german) { create :language, :german } let!(:french) { create :language, :french } diff --git a/spec/requests/api/stateless/auth_spec.rb b/spec/requests/api/stateless/auth_spec.rb index f6be03152..441380452 100644 --- a/spec/requests/api/stateless/auth_spec.rb +++ b/spec/requests/api/stateless/auth_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'API::Stateless Authentication' do diff --git a/spec/requests/api/stateless/braintree/payment_methods_spec.rb b/spec/requests/api/stateless/braintree/payment_methods_spec.rb index bf3f90a08..f42dd80aa 100644 --- a/spec/requests/api/stateless/braintree/payment_methods_spec.rb +++ b/spec/requests/api/stateless/braintree/payment_methods_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'API::Stateless Braintree PaymentMethods' do diff --git a/spec/requests/api/stateless/braintree/transactions_spec.rb b/spec/requests/api/stateless/braintree/transactions_spec.rb index 37c6a075e..84ebd88de 100644 --- a/spec/requests/api/stateless/braintree/transactions_spec.rb +++ b/spec/requests/api/stateless/braintree/transactions_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'API::Stateless Braintree Transactions' do diff --git a/spec/requests/api/stateless/location_spec.rb b/spec/requests/api/stateless/location_spec.rb index 7196eb262..ee5c9512e 100644 --- a/spec/requests/api/stateless/location_spec.rb +++ b/spec/requests/api/stateless/location_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'API::Stateless Location' do diff --git a/spec/requests/api/stateless/members_spec.rb b/spec/requests/api/stateless/members_spec.rb index 68d9ca692..84aa363d1 100644 --- a/spec/requests/api/stateless/members_spec.rb +++ b/spec/requests/api/stateless/members_spec.rb @@ -95,12 +95,12 @@ def auth_headers subject expect(json_hash).to match({ id: member.id, - first_name: 'Harry', - last_name: 'Tubman', - email: 'test+1@example.com', - country: 'United Kingdom', - city: 'London', - postal: '12345', + first_name: 'Harry', + last_name: 'Tubman', + email: 'test+1@example.com', + country: 'United Kingdom', + city: 'London', + postal: '12345', address1: 'Jam Factory 123', address2: nil }.as_json) diff --git a/spec/requests/api/survey_responses_spec.rb b/spec/requests/api/survey_responses_spec.rb index e83bc1f24..35a3e3a1b 100644 --- a/spec/requests/api/survey_responses_spec.rb +++ b/spec/requests/api/survey_responses_spec.rb @@ -106,10 +106,10 @@ @action.reload expect(@action.form_data).to include( - 'email' => 'l@test.com', - 'name' => 'Lucy', + 'email' => 'l@test.com', + 'name' => 'Lucy', 'country' => 'AR', - 'phone' => '123456' + 'phone' => '123456' ) end end diff --git a/spec/requests/email_confirmation_spec.rb b/spec/requests/email_confirmation_spec.rb index d46456af0..c5ea2dc10 100644 --- a/spec/requests/email_confirmation_spec.rb +++ b/spec/requests/email_confirmation_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'Email Confirmation when signing up to express donations' do @@ -32,8 +33,7 @@ let(:params) do { token: auth.token, email: 'test@example.com', - language: 'de' - } + language: 'de' } end it 'sets locale to passed language code' do diff --git a/spec/requests/form_elements_spec.rb b/spec/requests/form_elements_spec.rb index a43d98e51..c3b5f026a 100644 --- a/spec/requests/form_elements_spec.rb +++ b/spec/requests/form_elements_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'form element manipulation' do @@ -85,9 +86,9 @@ end it 'lets the many_choices value override the choices value' do - @params = { form_element: el_params.merge(many_choices: "A\r\nB\r\nC", choices: %w(X Y Z)) } + @params = { form_element: el_params.merge(many_choices: "A\r\nB\r\nC", choices: %w[X Y Z]) } subject - expect(FormElement.last.choices).to eq %w(A B C) + expect(FormElement.last.choices).to eq %w[A B C] end it 'returns 200 if successfully made the element' do diff --git a/spec/requests/localization_spec.rb b/spec/requests/localization_spec.rb index 3220c0264..52038de72 100644 --- a/spec/requests/localization_spec.rb +++ b/spec/requests/localization_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'Localization for pages' do diff --git a/spec/requests/omniauth_with_devise_spec.rb b/spec/requests/omniauth_with_devise_spec.rb index c1c2ba5d3..39f9bcb3a 100644 --- a/spec/requests/omniauth_with_devise_spec.rb +++ b/spec/requests/omniauth_with_devise_spec.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + require 'rails_helper' describe 'Omniauth with Devise' do def login_with_google(email = 'cesar@example.com') - login_with_oauth2(:google_oauth2, uid: '12345', + login_with_oauth2(:google_oauth2, uid: '12345', provider: 'google_oauth2', info: { email: email diff --git a/spec/requests/page_archives_spec.rb b/spec/requests/page_archives_spec.rb index 5ac8ad36a..e2f8c6aa7 100644 --- a/spec/requests/page_archives_spec.rb +++ b/spec/requests/page_archives_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'Page archiving' do diff --git a/spec/requests/uris_spec.rb b/spec/requests/uris_spec.rb index 459f43eee..272a06cac 100644 --- a/spec/requests/uris_spec.rb +++ b/spec/requests/uris_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe 'URI masking' do diff --git a/spec/routing/api/actions_routing_spec.rb b/spec/routing/api/actions_routing_spec.rb index d5fd91e0d..ca1e26cc7 100644 --- a/spec/routing/api/actions_routing_spec.rb +++ b/spec/routing/api/actions_routing_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe Api::ActionsController do diff --git a/spec/routing/liquid_layouts_routing_spec.rb b/spec/routing/liquid_layouts_routing_spec.rb index ab1acbcde..073995914 100644 --- a/spec/routing/liquid_layouts_routing_spec.rb +++ b/spec/routing/liquid_layouts_routing_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe LiquidLayoutsController, type: :routing do diff --git a/spec/routing/liquid_partials_routing_spec.rb b/spec/routing/liquid_partials_routing_spec.rb index 052b9b115..a865d89a9 100644 --- a/spec/routing/liquid_partials_routing_spec.rb +++ b/spec/routing/liquid_partials_routing_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe LiquidPartialsController, type: :routing do diff --git a/spec/routing/page_archives_routing_spec.rb b/spec/routing/page_archives_routing_spec.rb index 22c7b7b0b..d89a3ca80 100644 --- a/spec/routing/page_archives_routing_spec.rb +++ b/spec/routing/page_archives_routing_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe PageArchivesController, type: :routing do diff --git a/spec/routing/pages_routing_spec.rb b/spec/routing/pages_routing_spec.rb index a1f5b0d67..a18e54fa7 100644 --- a/spec/routing/pages_routing_spec.rb +++ b/spec/routing/pages_routing_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe PagesController, type: :routing do diff --git a/spec/services/action_collator_spec.rb b/spec/services/action_collator_spec.rb index 5763fc755..e14f978bc 100644 --- a/spec/services/action_collator_spec.rb +++ b/spec/services/action_collator_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe ActionCollator do @@ -7,20 +8,20 @@ describe 'keys' do it "includes the keys present on any action's form data" do - expect(ActionCollator.new([a1, a2]).keys).to match_array %i(phone name postal action_foo id publish_status) + expect(ActionCollator.new([a1, a2]).keys).to match_array %i[phone name postal action_foo id publish_status] end it "excludes fields that aren't prefixes by action_ or match AK fields" do form_data = { form_id: '123', action_foo: 'bar', postal: '12345', commit: 'G', foo: 'bar' } a = build :action, form_data: form_data - expect(ActionCollator.new([a]).keys).to match_array %i(action_foo postal id publish_status) + expect(ActionCollator.new([a]).keys).to match_array %i[action_foo postal id publish_status] end it 'excludes action_referrer_email and action_express_donation' do form_data = { action_referrer_email: 'a', action_express_donation: '1', action_referer: 'blah', country: 'NI' } a = build :action, form_data: form_data - expect(ActionCollator.new([a]).keys).to match_array %i(country id publish_status) + expect(ActionCollator.new([a]).keys).to match_array %i[country id publish_status] end end diff --git a/spec/services/akid_parser_spec.rb b/spec/services/akid_parser_spec.rb index 203e4c22f..d85ecb6bc 100644 --- a/spec/services/akid_parser_spec.rb +++ b/spec/services/akid_parser_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe AkidParser do diff --git a/spec/services/auth_token_verifier_spec.rb b/spec/services/auth_token_verifier_spec.rb index 548c3a811..196c9f2a6 100644 --- a/spec/services/auth_token_verifier_spec.rb +++ b/spec/services/auth_token_verifier_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe AuthTokenVerifier do diff --git a/spec/services/braintree_services/payment_options_spec.rb b/spec/services/braintree_services/payment_options_spec.rb index 7d06db7c7..94fd360e3 100644 --- a/spec/services/braintree_services/payment_options_spec.rb +++ b/spec/services/braintree_services/payment_options_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe BraintreeServices::PaymentOptions do diff --git a/spec/services/connect_with_oauth_provider_spec.rb b/spec/services/connect_with_oauth_provider_spec.rb index fa5b1fc64..cb673e94d 100644 --- a/spec/services/connect_with_oauth_provider_spec.rb +++ b/spec/services/connect_with_oauth_provider_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe ConnectWithOauthProvider do @@ -23,7 +24,7 @@ describe 'whitelisting' do it 'whitelists domain' do - Settings.oauth_domain_whitelist = %w(sumofus.org exxon.mobi) + Settings.oauth_domain_whitelist = %w[sumofus.org exxon.mobi] expect { ConnectWithOauthProvider.connect(resp) }.to raise_error(Champaign::NotWhitelisted) end diff --git a/spec/services/form_duplicator_spec.rb b/spec/services/form_duplicator_spec.rb index 979100a07..75ac92057 100644 --- a/spec/services/form_duplicator_spec.rb +++ b/spec/services/form_duplicator_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe FormDuplicator do diff --git a/spec/services/form_element_builder_spec.rb b/spec/services/form_element_builder_spec.rb index 0e83a1c5e..fe3164114 100644 --- a/spec/services/form_element_builder_spec.rb +++ b/spec/services/form_element_builder_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe FormElementBuilder do diff --git a/spec/services/form_element_spec.rb b/spec/services/form_element_spec.rb index 4cb6b78ee..aec63c44c 100644 --- a/spec/services/form_element_spec.rb +++ b/spec/services/form_element_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe FormElementBuilder do diff --git a/spec/services/form_validator_spec.rb b/spec/services/form_validator_spec.rb index 4f3510677..0e6087319 100644 --- a/spec/services/form_validator_spec.rb +++ b/spec/services/form_validator_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe FormValidator do diff --git a/spec/services/manage_action_spec.rb b/spec/services/manage_action_spec.rb index c139f155f..c6b5eb065 100644 --- a/spec/services/manage_action_spec.rb +++ b/spec/services/manage_action_spec.rb @@ -31,9 +31,9 @@ title: 'Foo Bar' ), params: hash_including( - page: "#{page.slug}-petition", - email: 'bob@example.com', - page_id: page.id, + page: "#{page.slug}-petition", + email: 'bob@example.com', + page_id: page.id, referring_akid: '123.456.xyz', user_en: 1 ) diff --git a/spec/services/manage_braintree_donation_spec.rb b/spec/services/manage_braintree_donation_spec.rb index 1bc398bdc..d9bee4292 100644 --- a/spec/services/manage_braintree_donation_spec.rb +++ b/spec/services/manage_braintree_donation_spec.rb @@ -30,7 +30,7 @@ VCR.use_cassette('manage braintree donation subscription') do Braintree::Subscription.create( price: '1.00', - payment_method_token: transaction.transaction.credit_card_details.token, + payment_method_token: transaction.transaction.credit_card_details.token, merchant_account_id: 'EUR', plan_id: 'EUR' ) @@ -65,10 +65,10 @@ let(:expected_form_data) do { - name: 'Bob Murphy', - email: 'foo@example.com', + name: 'Bob Murphy', + email: 'foo@example.com', country: 'BO', - page_id: page.id, + page_id: page.id, card_num: '1881', currency: /^\w{3}$/, transaction_id: /^[a-z0-9]*$/ diff --git a/spec/services/member_updater_spec.rb b/spec/services/member_updater_spec.rb index b963ea4a1..c1afb728b 100644 --- a/spec/services/member_updater_spec.rb +++ b/spec/services/member_updater_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe MemberUpdater do @@ -7,7 +8,7 @@ let(:more_params) { { action_hair_color: 'blonde', phone: '2135551234' } } describe '.run' do - [:new, :existing].each do |status, member| + %i[new existing].each do |status, member| describe "with #{status} member" do let(:new_member) { Member.new(email: email) } let(:existing_member) { create(:member, email: email) } diff --git a/spec/services/name_splitter_spec.rb b/spec/services/name_splitter_spec.rb index 5baef6434..79cd22463 100644 --- a/spec/services/name_splitter_spec.rb +++ b/spec/services/name_splitter_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require 'spec_helper' diff --git a/spec/services/page_follower_spec.rb b/spec/services/page_follower_spec.rb index e51080368..da4ea8a24 100644 --- a/spec/services/page_follower_spec.rb +++ b/spec/services/page_follower_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe PageFollower do diff --git a/spec/services/postal_validator_spec.rb b/spec/services/postal_validator_spec.rb index b314d1fe3..5c3bee983 100644 --- a/spec/services/postal_validator_spec.rb +++ b/spec/services/postal_validator_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe PostalValidator do diff --git a/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_data.rb b/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_data.rb index 4613c60d9..0df6f16eb 100644 --- a/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_data.rb +++ b/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_data.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.shared_context 'multiple_search_data' do let!(:matches_by_content_language_campaign_tags_layout) do create(:page, diff --git a/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_spec.rb b/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_spec.rb index 9ca11479a..df5cb9863 100644 --- a/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_spec.rb +++ b/spec/services/search/page_searcher/multiple_criterion_search/multiple_search_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative '../../page_searcher/multiple_criterion_search/multiple_search_data.rb' require_relative '../page_searcher_spec_data.rb' diff --git a/spec/services/search/page_searcher/page_searcher_spec.rb b/spec/services/search/page_searcher/page_searcher_spec.rb index 97eb124c5..84971d00f 100644 --- a/spec/services/search/page_searcher/page_searcher_spec.rb +++ b/spec/services/search/page_searcher/page_searcher_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative 'page_searcher_spec_data.rb' diff --git a/spec/services/search/page_searcher/page_searcher_spec_data.rb b/spec/services/search/page_searcher/page_searcher_spec_data.rb index 404e8d581..45acf9a5a 100644 --- a/spec/services/search/page_searcher/page_searcher_spec_data.rb +++ b/spec/services/search/page_searcher/page_searcher_spec_data.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.shared_context 'page_searcher_spec_data' do let(:test_text) { 'a spectacular test string' } let!(:tag) { create(:tag, name: test_text, actionkit_uri: '/foo/bar') } diff --git a/spec/services/search/page_searcher/single_criterion_search/search_by_campaign_spec.rb b/spec/services/search/page_searcher/single_criterion_search/search_by_campaign_spec.rb index e4e50ad68..552ba4047 100644 --- a/spec/services/search/page_searcher/single_criterion_search/search_by_campaign_spec.rb +++ b/spec/services/search/page_searcher/single_criterion_search/search_by_campaign_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative '../page_searcher_spec_data.rb' diff --git a/spec/services/search/page_searcher/single_criterion_search/search_by_language_spec.rb b/spec/services/search/page_searcher/single_criterion_search/search_by_language_spec.rb index 58f8b7927..50b9275c3 100644 --- a/spec/services/search/page_searcher/single_criterion_search/search_by_language_spec.rb +++ b/spec/services/search/page_searcher/single_criterion_search/search_by_language_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative '../page_searcher_spec_data.rb' diff --git a/spec/services/search/page_searcher/single_criterion_search/search_by_layout_spec.rb b/spec/services/search/page_searcher/single_criterion_search/search_by_layout_spec.rb index 46adfd866..c71214adb 100644 --- a/spec/services/search/page_searcher/single_criterion_search/search_by_layout_spec.rb +++ b/spec/services/search/page_searcher/single_criterion_search/search_by_layout_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative '../page_searcher_spec_data.rb' diff --git a/spec/services/search/page_searcher/single_criterion_search/search_by_tag_spec.rb b/spec/services/search/page_searcher/single_criterion_search/search_by_tag_spec.rb index 61ffcd66d..d8dbde424 100644 --- a/spec/services/search/page_searcher/single_criterion_search/search_by_tag_spec.rb +++ b/spec/services/search/page_searcher/single_criterion_search/search_by_tag_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative '../page_searcher_spec_data.rb' @@ -15,15 +16,15 @@ let!(:intersection_page_1) do create(:page, title: 'has one same tag as intersection page 2', - slug: 'has-same-page-2', - tags: [tag1, tag2, tag3, tag4]) + slug: 'has-same-page-2', + tags: [tag1, tag2, tag3, tag4]) end let!(:intersection_page_2) do create(:page, title: 'has one same tag as intersection page 1', - slug: 'has-same-page-1', - tags: [tag3, tag4, tag5]) + slug: 'has-same-page-1', + tags: [tag3, tag4, tag5]) end let(:tag_searcher) { Search::PageSearcher.new(tags: [tag.id]) } diff --git a/spec/services/search/page_searcher/single_criterion_search/search_by_text_content_spec.rb b/spec/services/search/page_searcher/single_criterion_search/search_by_text_content_spec.rb index 7174c778a..f8c71d84e 100644 --- a/spec/services/search/page_searcher/single_criterion_search/search_by_text_content_spec.rb +++ b/spec/services/search/page_searcher/single_criterion_search/search_by_text_content_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' require_relative '../page_searcher_spec_data.rb' diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index 805d80aea..394888cce 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ControllerMacros def login_user before(:each) do diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb index 68c936990..2e7665cc3 100644 --- a/spec/support/factory_girl.rb +++ b/spec/support/factory_girl.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.configure do |config| config.include FactoryBot::Syntax::Methods end diff --git a/spec/support/helper_functions.rb b/spec/support/helper_functions.rb index 480fada7f..7382eb863 100644 --- a/spec/support/helper_functions.rb +++ b/spec/support/helper_functions.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module HelperFunctions def log_in email = 'test@sumofus.org' diff --git a/spec/support/omni_auth_helper.rb b/spec/support/omni_auth_helper.rb index de37fef82..4cd4c6b42 100644 --- a/spec/support/omni_auth_helper.rb +++ b/spec/support/omni_auth_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module OmniAuthHelper def login_with_oauth2(provider, data) OmniAuth.config.test_mode = true diff --git a/spec/support/paperclip.rb b/spec/support/paperclip.rb index b4a6feeb3..d68c638c9 100644 --- a/spec/support/paperclip.rb +++ b/spec/support/paperclip.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'paperclip/matchers' RSpec.configure do |config| diff --git a/spec/support/request_helpers.rb b/spec/support/request_helpers.rb index c28baea74..a90d5883d 100644 --- a/spec/support/request_helpers.rb +++ b/spec/support/request_helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Requests # Utility methods for converting JSON strings to hashes and ostructs module RequestHelpers diff --git a/spec/teaspoon_env.rb b/spec/teaspoon_env.rb index 9a8b7a447..5a3ded35e 100644 --- a/spec/teaspoon_env.rb +++ b/spec/teaspoon_env.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Teaspoon.configure do |config| # Determines where the Teaspoon routes will be mounted. Changing this to "/jasmine" would allow you to browse to # `http://localhost:3000/jasmine` to run your tests. diff --git a/spec/validators/action_kit_fields_spec.rb b/spec/validators/action_kit_fields_spec.rb index 9af1b64e7..41ac3e92e 100644 --- a/spec/validators/action_kit_fields_spec.rb +++ b/spec/validators/action_kit_fields_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' describe ActionKitFields do @@ -30,14 +31,14 @@ end context 'with unknown field names' do - %w(blah raa kangaroo foo_action foo_user action_ user_).each do |name| + %w[blah raa kangaroo foo_action foo_user action_ user_].each do |name| it "is invalid with #{name}" do expect(subject.new(name: name)).to_not be_valid end end context 'with action_ prefix' do - %w(foo bar exam_aple).each do |name| + %w[foo bar exam_aple].each do |name| unknown_with_prefix = "action_#{name}" it "is valid with #{unknown_with_prefix}" do diff --git a/spec/views/shared_examples.rb b/spec/views/shared_examples.rb index 5730651d2..49a31d0b0 100644 --- a/spec/views/shared_examples.rb +++ b/spec/views/shared_examples.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + require 'rails_helper' shared_examples 'view smoke test' do |model_sym, actions| - actions ||= [:new, :edit, :show, :index] + actions ||= %i[new edit show index] model_plural = model_sym.to_s.pluralize.to_sym model_class = model_sym.to_s.camelcase.constantize