diff --git a/.circleci/config.yml b/.circleci/config.yml index 4af84b054..96eedc26f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,19 +3,19 @@ version: 2 defaults: &defaults working_directory: ~/circleci-champaign docker: - - image: soutech/ruby2.4.5_node_awscli:latest + - image: soutech/ruby:2.6-stretch-node-awscli jobs: install_dependencies: <<: *defaults steps: - checkout - # - restore_cache: - # name: Restoring bundler cache - # key: gem-cache-{{ checksum "Gemfile.lock" }} - # - restore_cache: - # name: Restoring node_modules cache - # key: yarn-cache-{{ checksum "yarn.lock" }} + - restore_cache: + name: Restoring bundler cache + key: gems-{{ checksum "Gemfile.lock" }} + - restore_cache: + name: Restoring node_modules cache + key: node-{{ checksum "yarn.lock" }} - run: name: Install gems command: bundle install --path vendor/bundle @@ -27,11 +27,11 @@ jobs: name: Download external assets command: bundle exec rake assets:download_external_assets[$EXTERNAL_ASSETS_PATH,$CUSTOM_ASSETS_URL,$CUSTOM_ASSETS_CREDENTIALS,$CIRCLE_BRANCH] - save_cache: - key: gem-cache-{{ checksum "Gemfile.lock" }} + key: gems-{{ checksum "Gemfile.lock" }} paths: - vendor/bundle - save_cache: - key: yarn-cache-{{ checksum "yarn.lock" }} + key: node-{{ checksum "yarn.lock" }} paths: - node_modules - persist_to_workspace: @@ -107,7 +107,7 @@ jobs: rspec: working_directory: ~/circleci-champaign docker: - - image: soutech/ruby2.4.5_node_awscli:latest + - image: soutech/ruby:2.6-stretch-node-awscli environment: PG_USERNAME: champaign PG_PASSWORD: champaign diff --git a/.rubocop.yml b/.rubocop.yml index 6a8e0673c..57b5d9f82 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ inherit_from: .rubocop_todo.yml AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.6 Exclude: - 'bin/**/*' - 'vendor/**/*' @@ -46,7 +46,7 @@ Naming/VariableNumber: Naming/MemoizedInstanceVariableName: Enabled: false - + Lint/HandleExceptions: Enabled: false diff --git a/.ruby-version b/.ruby-version index 59aa62c1f..097a15a2a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.5 +2.6.2 diff --git a/Dockerfile b/Dockerfile index e6676a938..485f822fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,11 @@ -FROM ruby:2.4.5-stretch +FROM soutech/ruby:2.6-alpine-node ENV APP_ROOT /champaign -# Install ImageMagick and apt-transport-https (to install nodesource) -RUN apt-get update -qq && apt-get install -y apt-transport-https imagemagick - -# Install Node.js 11.x -RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - \ - && apt-get install -y nodejs - -RUN apt-get update -qq && apt-get install -y nodejs - -# Create app folder and add current dir contents RUN mkdir $APP_ROOT ADD . $APP_ROOT WORKDIR $APP_ROOT -RUN gem install bundler RUN bundle install --jobs 4 --deployment --without development:test:doc EXPOSE 3000 diff --git a/Gemfile b/Gemfile index 5948bfafc..8b79eb9a1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,16 +1,15 @@ -# coding: utf-8 # frozen_string_literal: true source 'https://rubygems.org' -ruby '2.4.5' +ruby '2.6.2' gem 'aasm' -gem 'activeadmin' +gem 'activeadmin', '~> 1.4.3' gem 'bcrypt', '~> 3.1.7' -gem 'braintree', '~> 2.54.0' +gem 'braintree', '~> 2' gem 'countries', require: 'countries/global' gem 'country_select' -gem 'devise', '~> 4.3' +gem 'devise', '~> 4.6' gem 'font-awesome-sass', '~> 4.7.0' gem 'geocoder' gem 'gocardless_pro' @@ -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 @@ -49,7 +48,7 @@ gem 'airbrake', '~> 5.7.1' gem 'airbrake-ruby', '1.7.1' gem 'aws-sdk-rails' gem 'bootsnap', require: false -gem 'bootstrap-sass', '~> 3.3.5' +gem 'bootstrap-sass', '~> 3.4.1' gem 'browser', '~> 2.5' gem 'compass-rails' # was using git master branch before gem 'config' @@ -58,7 +57,7 @@ gem 'friendly_id' gem 'jwt' gem 'lograge', '~> 0.10.0' gem 'metamagic' -gem 'money-oxr' +gem 'money-oxr', '~> 0.4.1' gem 'newrelic_rpm' gem 'puma', '~> 3.12.0' gem 'sass-rails' @@ -71,16 +70,16 @@ 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' gem 'faker' gem 'magic_lamp' gem 'rspec-rails', '~> 3.8' - gem 'rubocop', require: false + 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/Gemfile.lock b/Gemfile.lock index fb84ce350..a487bd8f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,30 +22,30 @@ GEM action_parameter (0.0.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - actioncable (5.2.1.1) - actionpack (= 5.2.1.1) + actioncable (5.2.3) + actionpack (= 5.2.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.1.1) - actionpack (= 5.2.1.1) - actionview (= 5.2.1.1) - activejob (= 5.2.1.1) + actionmailer (5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.1.1) - actionview (= 5.2.1.1) - activesupport (= 5.2.1.1) + actionpack (5.2.3) + actionview (= 5.2.3) + activesupport (= 5.2.3) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.1.1) - activesupport (= 5.2.1.1) + actionview (5.2.3) + activesupport (= 5.2.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activeadmin (1.3.1) + activeadmin (1.4.3) arbre (>= 1.1.1) coffee-rails formtastic (~> 3.1) @@ -57,37 +57,37 @@ GEM ransack (>= 1.8.7) sass (~> 3.1) sprockets (< 4.1) - activejob (5.2.1.1) - activesupport (= 5.2.1.1) + activejob (5.2.3) + activesupport (= 5.2.3) globalid (>= 0.3.6) - activemodel (5.2.1.1) - activesupport (= 5.2.1.1) - activerecord (5.2.1.1) - activemodel (= 5.2.1.1) - activesupport (= 5.2.1.1) + activemodel (5.2.3) + activesupport (= 5.2.3) + activerecord (5.2.3) + activemodel (= 5.2.3) + activesupport (= 5.2.3) arel (>= 9.0) - activestorage (5.2.1.1) - actionpack (= 5.2.1.1) - activerecord (= 5.2.1.1) + activestorage (5.2.3) + actionpack (= 5.2.3) + activerecord (= 5.2.3) marcel (~> 0.3.1) - activesupport (5.2.1.1) + activesupport (5.2.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.5.2) + addressable (2.6.0) public_suffix (>= 2.0.2, < 4.0) airbrake (5.7.1) airbrake-ruby (~> 1.7) airbrake-ruby (1.7.1) - annotate (2.6.5) - activerecord (>= 2.3.0) - rake (>= 0.8.7) + annotate (2.7.4) + activerecord (>= 3.2, < 6.0) + rake (>= 10.4, < 13.0) arbre (1.1.1) activesupport (>= 3.0.0) arel (9.0.0) ast (2.4.0) - autoprefixer-rails (7.1.0) + autoprefixer-rails (9.4.10) execjs aws-eventstream (1.0.1) aws-partitions (1.142.0) @@ -123,10 +123,10 @@ GEM bindex (0.5.0) bootsnap (1.3.2) msgpack (~> 1.0) - bootstrap-sass (3.3.7) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) - braintree (2.54.0) + sassc (>= 2.0.0) + braintree (2.95.0) builder (>= 2.0.0) browser (2.5.3) builder (3.2.3) @@ -165,7 +165,7 @@ GEM compass (~> 1.0.0) sass-rails (< 5.1) sprockets (< 4.0) - concurrent-ruby (1.1.4) + concurrent-ruby (1.1.5) config (1.4.0) activesupport (>= 3.0) deep_merge (~> 1.1.1) @@ -189,7 +189,7 @@ GEM crass (1.0.4) database_cleaner (1.7.0) deep_merge (1.1.1) - devise (4.4.3) + devise (4.6.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, < 6.0) @@ -199,7 +199,7 @@ GEM docile (1.1.5) envyable (1.2.0) thor (>= 0.18.1, < 2.0) - erubi (1.7.1) + erubi (1.8.0) execjs (2.7.0) factory_bot (4.11.1) activesupport (>= 3.0.0) @@ -208,7 +208,7 @@ GEM railties (>= 3.0.0) faker (1.9.1) i18n (>= 0.7) - faraday (0.9.2) + faraday (0.15.4) multipart-post (>= 1.2, < 3) ffi (1.9.25) font-awesome-sass (4.7.0) @@ -222,10 +222,10 @@ GEM friendly_id (5.2.1) activerecord (>= 4.0.0) geocoder (1.4.3) - globalid (0.4.1) + globalid (0.4.2) activesupport (>= 4.2.0) - gocardless_pro (2.0.0) - faraday (>= 0.8.9, < 0.10) + gocardless_pro (2.13.0) + faraday (>= 0.9.2, < 1.0) guard (2.15.0) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -243,7 +243,7 @@ GEM has_scope (0.7.2) actionpack (>= 4.1) activesupport (>= 4.1) - hashdiff (0.3.7) + hashdiff (0.3.8) hashie (3.6.0) hiredis (0.6.1) httparty (0.16.4) @@ -259,7 +259,7 @@ GEM has_scope (~> 0.6) railties (>= 4.2, < 5.3) responders - jaro_winkler (1.5.1) + jaro_winkler (1.5.2) jbuilder (2.6.4) activesupport (>= 3.0.0) multi_json (>= 1.2) @@ -310,13 +310,13 @@ GEM mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) - mimemagic (0.3.2) + mimemagic (0.3.3) mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) - money (6.12.0) - i18n (>= 0.6.4, < 1.1) - money-oxr (0.3.0) + money (6.13.2) + i18n (>= 0.6.4, <= 2) + money-oxr (0.4.1) money (~> 6.6) msgpack (1.2.6) multi_json (1.13.1) @@ -325,7 +325,7 @@ GEM nenv (0.3.0) newrelic_rpm (4.1.0.333) nio4r (2.3.1) - nokogiri (1.10.1) + nokogiri (1.10.2) mini_portile2 (~> 2.4.0) notiffany (0.1.1) nenv (~> 0.1) @@ -356,8 +356,8 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - parallel (1.12.1) - parser (2.5.3.0) + parallel (1.17.0) + parser (2.6.2.0) ast (~> 2.4.0) pg (0.20.0) phony (2.16.4) @@ -368,10 +368,10 @@ GEM capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - powerpack (0.1.2) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) + psych (3.1.0) public_suffix (3.0.3) puma (3.12.0) rack (2.0.6) @@ -382,18 +382,18 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.1.1) - actioncable (= 5.2.1.1) - actionmailer (= 5.2.1.1) - actionpack (= 5.2.1.1) - actionview (= 5.2.1.1) - activejob (= 5.2.1.1) - activemodel (= 5.2.1.1) - activerecord (= 5.2.1.1) - activestorage (= 5.2.1.1) - activesupport (= 5.2.1.1) + rails (5.2.3) + actioncable (= 5.2.3) + actionmailer (= 5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + activemodel (= 5.2.3) + activerecord (= 5.2.3) + activestorage (= 5.2.3) + activesupport (= 5.2.3) bundler (>= 1.3.0) - railties (= 5.2.1.1) + railties (= 5.2.3) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.2) actionpack (~> 5.x, >= 5.0.1) @@ -407,15 +407,15 @@ GEM rails-i18n (5.1.1) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.2.1.1) - actionpack (= 5.2.1.1) - activesupport (= 5.2.1.1) + railties (5.2.3) + actionpack (= 5.2.3) + activesupport (= 5.2.3) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.0.0) - rake (12.3.1) - ransack (2.0.1) + rake (12.3.2) + ransack (2.1.1) actionpack (>= 5.0) activerecord (>= 5.0) activesupport (>= 5.0) @@ -429,9 +429,9 @@ GEM redis (3.3.5) request_store (1.4.1) rack (>= 1.4) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) + responders (2.4.1) + actionpack (>= 4.2.0, < 6.0) + railties (>= 4.2.0, < 6.0) rmagick (2.16.0) rspec (3.8.0) rspec-core (~> 3.8.0) @@ -455,19 +455,19 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.60.0) + rubocop (0.66.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) + psych (>= 3.1.0) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.4.0) + unicode-display_width (>= 1.4.0, < 1.6) rubocop-rspec (1.30.1) rubocop (>= 0.60.0) ruby-progressbar (1.10.0) ruby_dep (1.5.0) - safe_yaml (1.0.4) + safe_yaml (1.0.5) sass (3.4.25) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -475,6 +475,9 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + sassc (2.0.1) + ffi (~> 1.9) + rake sentry-raven (2.7.3) faraday (>= 0.7.6, < 1.0) shellany (0.0.1) @@ -528,17 +531,17 @@ GEM thread_safe (~> 0.1) uglifier (3.0.0) execjs (>= 0.3.0, < 3) - unicode-display_width (1.4.0) + unicode-display_width (1.5.0) unicode_utils (1.4.0) vcr (3.0.3) - warden (1.2.7) - rack (>= 1.0) + warden (1.2.8) + rack (>= 2.0.6) web-console (3.5.1) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - webmock (3.4.2) + webmock (3.5.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff @@ -559,7 +562,7 @@ DEPENDENCIES aasm action_parameter actionkit_connector! - activeadmin + activeadmin (~> 1.4.3) airbrake (~> 5.7.1) airbrake-ruby (= 1.7.1) annotate @@ -571,8 +574,8 @@ DEPENDENCIES aws-sdk-sqs (~> 1.10) bcrypt (~> 3.1.7) bootsnap - bootstrap-sass (~> 3.3.5) - braintree (~> 2.54.0) + bootstrap-sass (~> 3.4.1) + braintree (~> 2) browser (~> 2.5) byebug capybara @@ -582,7 +585,7 @@ DEPENDENCIES country_select coveralls (~> 0.8.21) database_cleaner - devise (~> 4.3) + devise (~> 4.6) envyable factory_bot_rails faker @@ -604,7 +607,7 @@ DEPENDENCIES magic_lamp metamagic money - money-oxr + money-oxr (~> 0.4.1) newrelic_rpm omniauth-google-oauth2 (~> 0.6.1) paper_trail (~> 10.2) @@ -623,7 +626,7 @@ DEPENDENCIES rmagick rspec-json_expectations rspec-rails (~> 3.8) - rubocop + rubocop (~> 0.66) rubocop-rspec sass-rails sentry-raven @@ -642,7 +645,7 @@ DEPENDENCIES webpacker (~> 3.5) RUBY VERSION - ruby 2.4.5p335 + ruby 2.6.2p47 BUNDLED WITH 2.0.1 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/admin/user.rb b/app/admin/user.rb index fac8abd6b..f31ffbad8 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + ActiveAdmin.register User do - permit_params :email, :password, :password_confirmation + permit_params :email, :password, :password_confirmation, :admin index do selectable_column @@ -22,6 +23,7 @@ f.input :email f.input :password f.input :password_confirmation + f.input :admin end f.actions end 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/application_controller.rb b/app/controllers/application_controller.rb index a5ca9c274..bc95e10d4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -81,10 +81,15 @@ def recognized_member end def authenticate_super_admin! - return true if authenticate_user! && Settings.admins =~ Regexp.new(current_user.email) + return true if authenticate_user! && admin? + raise SecurityError, "#{current_user.email} is not an administrator." end + def admin? + Settings.admins =~ Regexp.new(current_user.email) || current_user.admin? + end + def unsafe_params params.to_unsafe_hash end 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..7b90e3d2b 100644 --- a/app/controllers/email_confirmation_controller.rb +++ b/app/controllers/email_confirmation_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true + class EmailConfirmationController < ApplicationController before_action :find_member + before_action :find_payment_methods def verify begin @@ -18,6 +20,11 @@ def verify def find_member raise ActiveRecord::RecordNotFound if params[:email].blank? + @member = Member.find_by_email!(params[:email]) end + + def find_payment_methods + @payment_methods = payment_methods + 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/action.rb b/app/models/action.rb index 3739d7bb5..22744ba19 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -5,17 +5,27 @@ # Table name: actions # # id :integer not null, primary key -# page_id :integer -# member_id :integer -# link :string # created_user :boolean +# donation :boolean default(FALSE) +# form_data :jsonb +# link :string +# publish_status :integer default("default"), not null +# subscribed_member :boolean default(TRUE) # subscribed_user :boolean # created_at :datetime not null # updated_at :datetime not null -# form_data :jsonb default("{}") -# subscribed_member :boolean default("true") -# donation :boolean default("false") -# publish_status :integer default("0"), not null +# member_id :integer +# page_id :integer +# +# Indexes +# +# index_actions_on_member_id (member_id) +# index_actions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) +# fk_rails_... (page_id => pages.id) # class Action < ApplicationRecord diff --git a/app/models/actionkit_page.rb b/app/models/actionkit_page.rb index 8e8ea6fad..5ffd8bbb8 100644 --- a/app/models/actionkit_page.rb +++ b/app/models/actionkit_page.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: actionkit_pages @@ -7,6 +8,10 @@ # actionkit_id :integer not null # actionkit_page_type_id :integer not null # +# Foreign Keys +# +# fk_rails_... (actionkit_page_type_id => actionkit_page_types.id) +# class ActionkitPage < ApplicationRecord belongs_to :page 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/call.rb b/app/models/call.rb index 79214c3f9..f8a139f53 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -5,17 +5,21 @@ # Table name: calls # # id :integer not null, primary key -# page_id :integer -# member_id :integer +# member_call_events :json is an Array # member_phone_number :string +# status :integer default("unstarted") +# target :json +# target_call_info :jsonb not null +# twilio_error_code :integer # created_at :datetime # updated_at :datetime -# target_call_info :jsonb default("{}"), not null -# member_call_events :json default("{}"), is an Array -# twilio_error_code :integer -# target :json -# status :integer default("0") # action_id :integer +# member_id :integer +# page_id :integer +# +# Indexes +# +# index_calls_on_target_call_info (target_call_info) USING gin # class Call < ApplicationRecord @@ -70,15 +74,12 @@ def caller_id def member_phone_number_is_valid return if member_phone_number.blank? + valid_characters = (/\A[0-9\-\+\(\) \.]+\z/i =~ member_phone_number).present? has_at_least_six_numbers = (member_phone_number.scan(/[0-9]/).size > 5) - unless valid_characters - errors.add(:member_phone_number, I18n.t('validation.is_invalid_phone')) - end + errors.add(:member_phone_number, I18n.t('validation.is_invalid_phone')) unless valid_characters - unless has_at_least_six_numbers - errors.add(:member_phone_number, I18n.t('call_tool.errors.phone_number.too_short')) - end + errors.add(:member_phone_number, I18n.t('call_tool.errors.phone_number.too_short')) unless has_at_least_six_numbers unless Phony.plausible?(member_phone_number) errors.add(:member_phone_number, I18n.t('call_tool.errors.phone_number.is_invalid')) 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/donation_band.rb b/app/models/donation_band.rb index f6f226121..8470180a2 100644 --- a/app/models/donation_band.rb +++ b/app/models/donation_band.rb @@ -5,8 +5,8 @@ # Table name: donation_bands # # id :integer not null, primary key +# amounts :integer default([]), is an Array # name :string -# amounts :integer default("{}"), is an Array # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/form.rb b/app/models/form.rb index 243af7adb..a4e9b2932 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -5,15 +5,19 @@ # Table name: forms # # id :integer not null, primary key -# name :string # description :string +# formable_type :string +# master :boolean default(FALSE) +# name :string +# position :integer default(0), not null +# visible :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null -# visible :boolean default("false") -# master :boolean default("false") # formable_id :integer -# formable_type :string -# position :integer default("0"), not null +# +# Indexes +# +# index_forms_on_formable_type_and_formable_id (formable_type,formable_id) # class Form < ApplicationRecord diff --git a/app/models/form_element.rb b/app/models/form_element.rb index 99a791f1a..2fa7a9b8c 100644 --- a/app/models/form_element.rb +++ b/app/models/form_element.rb @@ -5,18 +5,26 @@ # Table name: form_elements # # id :integer not null, primary key -# form_id :integer -# label :string +# choices :jsonb # data_type :string # default_value :string +# display_mode :integer default("all_members") +# label :string +# name :string +# position :integer default(0), not null # required :boolean # visible :boolean # created_at :datetime not null # updated_at :datetime not null -# name :string -# position :integer default("0"), not null -# choices :jsonb default("[]") -# display_mode :integer default("0") +# form_id :integer +# +# Indexes +# +# index_form_elements_on_form_id (form_id) +# +# Foreign Keys +# +# fk_rails_... (form_id => forms.id) # class FormElement < ApplicationRecord @@ -52,11 +60,13 @@ class FormElement < ApplicationRecord def liquid_data return attributes.symbolize_keys unless data_type == 'choice' || data_type == 'dropdown' + attributes.symbolize_keys.merge(choices: formatted_choices) end def formatted_choices return [] if choices.blank? + choices.map do |choice| if choice.is_a? String { label: choice, value: choice, id: choice_id(choice) } @@ -70,6 +80,7 @@ def formatted_choices def choices_is_valid return if choices.nil? + if choices.class != Array errors.add(:choices, 'must be an array of options') return @@ -126,9 +137,7 @@ def field_prefix(data_type) def set_name unless name.blank? || ActionKitFields::ACTIONKIT_FIELDS_WHITELIST.include?(name) - if name !~ ActionKitFields::VALID_PREFIX_RE && name !~ /^(action_)+$/ - self.name = field_prefix(data_type) + name - end + self.name = field_prefix(data_type) + name if name !~ ActionKitFields::VALID_PREFIX_RE && name !~ /^(action_)+$/ end end diff --git a/app/models/image.rb b/app/models/image.rb index 3ff826d80..983970f0f 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -5,14 +5,18 @@ # Table name: images # # id :integer not null, primary key -# content_file_name :string # content_content_type :string -# content_file_size :integer +# content_file_name :string +# content_file_size :bigint(8) # content_updated_at :datetime # created_at :datetime # updated_at :datetime # page_id :integer # +# Indexes +# +# index_images_on_page_id (page_id) +# class Image < ApplicationRecord # At what point should the image format be converted to jpg 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/link.rb b/app/models/link.rb index 926d66212..17d483b2e 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,21 +1,30 @@ # frozen_string_literal: true + # == Schema Information # # Table name: links # # id :integer not null, primary key -# url :string -# title :string # date :string # source :string -# page_id :integer +# title :string +# url :string # created_at :datetime not null # updated_at :datetime not null +# page_id :integer +# +# Indexes +# +# index_links_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Link < ApplicationRecord belongs_to :page, touch: true - has_paper_trail on: [:update, :destroy] + has_paper_trail on: %i[update destroy] validates :url, :title, presence: true, allow_blank: false validate :url_has_protocol @@ -26,9 +35,7 @@ class Link < ApplicationRecord private def url_has_protocol - unless %r{^(https?:)?\/\/}i.match?(url) - errors.add(:url, 'must have a protocol (like http://)') - end + errors.add(:url, 'must have a protocol (like http://)') unless %r{^(https?:)?\/\/}i.match?(url) end def prepend_protocol diff --git a/app/models/liquid_layout.rb b/app/models/liquid_layout.rb index 60129d4f2..116cc7e9b 100644 --- a/app/models/liquid_layout.rb +++ b/app/models/liquid_layout.rb @@ -5,15 +5,15 @@ # Table name: liquid_layouts # # id :integer not null, primary key -# title :string # content :text +# description :text +# experimental :boolean default(FALSE), not null +# post_action_layout :boolean +# primary_layout :boolean +# title :string # created_at :datetime not null # updated_at :datetime not null -# description :text -# experimental :boolean default("false"), not null # default_follow_up_layout_id :integer -# primary_layout :boolean -# post_action_layout :boolean # class LiquidLayout < ApplicationRecord diff --git a/app/models/member.rb b/app/models/member.rb index 75955c5dc..803c6c5ab 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -5,22 +5,28 @@ # Table name: members # # id :integer not null, primary key -# email :string +# address1 :string +# address2 :string +# city :string +# consented :boolean +# consented_updated_at :datetime # country :string +# donor_status :integer default("nondonor"), not null +# email :string # first_name :string # last_name :string -# city :string +# more :jsonb # postal :string # title :string -# address1 :string -# address2 :string # created_at :datetime not null # updated_at :datetime not null # actionkit_user_id :string -# donor_status :integer default("0"), not null -# more :jsonb -# consented_updated_at :datetime -# consented :boolean default("false") +# +# Indexes +# +# index_members_on_actionkit_user_id (actionkit_user_id) +# index_members_on_email (email) +# index_members_on_email_and_id (email,id) # class Member < ApplicationRecord @@ -44,14 +50,13 @@ class Member < ApplicationRecord def self.find_from_request(akid: nil, id: nil) member = find_by_akid(akid) return member if member.present? + id.present? ? find_by(id: id) : nil end def self.find_by_akid(akid) actionkit_user_id = AkidParser.parse(akid, Settings.action_kit.akid_secret)[:actionkit_user_id] - if actionkit_user_id.present? - where(actionkit_user_id: actionkit_user_id).order('created_at ASC').first - end + where(actionkit_user_id: actionkit_user_id).order('created_at ASC').first if actionkit_user_id.present? end def self.find_by_email(email) diff --git a/app/models/member_authentication.rb b/app/models/member_authentication.rb index 38072bf1e..ee036dc19 100644 --- a/app/models/member_authentication.rb +++ b/app/models/member_authentication.rb @@ -1,20 +1,31 @@ # frozen_string_literal: true + # == Schema Information # # Table name: member_authentications # # id :integer not null, primary key -# member_id :integer -# password_digest :string not null -# facebook_uid :string +# confirmed_at :datetime # facebook_token :string # facebook_token_expiry :datetime -# created_at :datetime not null -# updated_at :datetime not null -# token :string -# confirmed_at :datetime +# facebook_uid :string +# password_digest :string not null # reset_password_sent_at :datetime # reset_password_token :string +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# member_id :integer +# +# Indexes +# +# index_member_authentications_on_facebook_uid (facebook_uid) +# index_member_authentications_on_member_id (member_id) +# index_member_authentications_on_reset_password_token (reset_password_token) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) # # diff --git a/app/models/page.rb b/app/models/page.rb index 646852b24..8c46fbc2b 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -5,37 +5,54 @@ # Table name: pages # # id :integer not null, primary key -# language_id :integer -# campaign_id :integer -# title :string not null +# action_count :integer default(0) +# ak_donation_resource_uri :string +# ak_petition_resource_uri :string +# allow_duplicate_actions :boolean default(FALSE) +# canonical_url :string +# compiled_html :text +# content :text default("") +# enforce_styles :boolean default(FALSE), not null +# featured :boolean default(FALSE) +# follow_up_plan :integer default("with_liquid"), not null +# fundraising_goal :decimal(10, 2) default(0.0) +# javascript :text +# messages :text +# meta_description :string +# meta_tags :string +# notes :text +# optimizely_status :integer default("optimizely_enabled"), not null +# publish_actions :integer default("secure"), not null +# publish_status :integer default("unpublished"), not null # slug :string not null +# status :string default("pending") +# title :string not null +# total_donations :decimal(10, 2) default(0.0) # created_at :datetime # updated_at :datetime -# compiled_html :text -# status :string default("pending") -# messages :text -# content :text default("") -# featured :boolean default("false") -# liquid_layout_id :integer +# campaign_id :integer # follow_up_liquid_layout_id :integer -# action_count :integer default("0") -# primary_image_id :integer -# ak_petition_resource_uri :string -# ak_donation_resource_uri :string -# follow_up_plan :integer default("0"), not null # follow_up_page_id :integer -# javascript :text -# publish_status :integer default("1"), not null -# optimizely_status :integer default("0"), not null -# canonical_url :string -# allow_duplicate_actions :boolean default("false") -# enforce_styles :boolean default("false"), not null -# notes :text -# publish_actions :integer default("0"), not null -# meta_tags :string -# meta_description :string -# total_donations :double default("0") -> Total donations in CENTS -# fundraising_goal :double default("0") -> Fundraising goal in CENTS +# language_id :integer +# liquid_layout_id :integer +# primary_image_id :integer +# +# Indexes +# +# index_pages_on_campaign_id (campaign_id) +# index_pages_on_follow_up_liquid_layout_id (follow_up_liquid_layout_id) +# index_pages_on_follow_up_page_id (follow_up_page_id) +# index_pages_on_liquid_layout_id (liquid_layout_id) +# index_pages_on_primary_image_id (primary_image_id) +# index_pages_on_publish_status (publish_status) +# +# Foreign Keys +# +# fk_rails_... (campaign_id => campaigns.id) +# fk_rails_... (follow_up_liquid_layout_id => liquid_layouts.id) +# fk_rails_... (language_id => languages.id) +# fk_rails_... (liquid_layout_id => liquid_layouts.id) +# fk_rails_... (primary_image_id => images.id) # class Page < ApplicationRecord 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/braintree/customer.rb b/app/models/payment/braintree/customer.rb index 842252d1d..1c2dae9e1 100644 --- a/app/models/payment/braintree/customer.rb +++ b/app/models/payment/braintree/customer.rb @@ -1,24 +1,33 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_braintree_customers # # id :integer not null, primary key -# card_type :string # card_bin :string -# cardholder_name :string # card_debit :string # card_last_4 :string -# card_vault_token :string +# card_type :string # card_unique_number_identifier :string +# card_vault_token :string +# cardholder_name :string # email :string # first_name :string # last_name :string -# customer_id :string # created_at :datetime not null # updated_at :datetime not null +# customer_id :string # member_id :integer # +# Indexes +# +# index_payment_braintree_customers_on_member_id (member_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) +# class Payment::Braintree::Customer < ApplicationRecord belongs_to :member diff --git a/app/models/payment/braintree/payment_method.rb b/app/models/payment/braintree/payment_method.rb index b679855dd..1041f6155 100644 --- a/app/models/payment/braintree/payment_method.rb +++ b/app/models/payment/braintree/payment_method.rb @@ -5,19 +5,24 @@ # Table name: payment_braintree_payment_methods # # id :integer not null, primary key -# token :string -# created_at :datetime not null -# updated_at :datetime not null -# customer_id :integer -# card_type :string # bin :string +# cancelled_at :datetime +# card_type :string # cardholder_name :string -# last_4 :string +# email :string # expiration_date :string # instrument_type :string -# email :string -# store_in_vault :boolean default("false") -# cancelled_at :datetime +# last_4 :string +# store_in_vault :boolean default(FALSE) +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# customer_id :integer +# +# Indexes +# +# braintree_customer_index (customer_id) +# index_payment_braintree_payment_methods_on_store_in_vault (store_in_vault) # class Payment::Braintree::PaymentMethod < ApplicationRecord diff --git a/app/models/payment/braintree/subscription.rb b/app/models/payment/braintree/subscription.rb index 7f4210260..7378591af 100644 --- a/app/models/payment/braintree/subscription.rb +++ b/app/models/payment/braintree/subscription.rb @@ -5,18 +5,28 @@ # Table name: payment_braintree_subscriptions # # id :integer not null, primary key -# subscription_id :string -# merchant_account_id :string -# created_at :datetime not null -# updated_at :datetime not null -# page_id :integer # amount :decimal(10, 2) +# billing_day_of_month :integer +# cancelled_at :datetime # currency :string +# created_at :datetime not null +# updated_at :datetime not null # action_id :integer -# cancelled_at :datetime # customer_id :string -# billing_day_of_month :integer +# merchant_account_id :string +# page_id :integer # payment_method_id :integer +# subscription_id :string +# +# Indexes +# +# index_payment_braintree_subscriptions_on_action_id (action_id) +# index_payment_braintree_subscriptions_on_page_id (page_id) +# index_payment_braintree_subscriptions_on_subscription_id (subscription_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Payment::Braintree::Subscription < ApplicationRecord diff --git a/app/models/payment/braintree/transaction.rb b/app/models/payment/braintree/transaction.rb index 6e5b6eeae..eb457be12 100644 --- a/app/models/payment/braintree/transaction.rb +++ b/app/models/payment/braintree/transaction.rb @@ -5,22 +5,32 @@ # Table name: payment_braintree_transactions # # id :integer not null, primary key -# transaction_id :string -# transaction_type :string -# transaction_created_at :datetime +# amount :decimal(10, 2) +# currency :string +# payment_instrument_type :string # payment_method_token :string -# customer_id :string +# processor_response_code :string +# status :integer +# transaction_created_at :datetime +# transaction_type :string # created_at :datetime not null # updated_at :datetime not null +# customer_id :string # merchant_account_id :string -# currency :string # page_id :integer -# payment_instrument_type :string -# status :integer -# amount :decimal(10, 2) -# processor_response_code :string # payment_method_id :integer # subscription_id :integer +# transaction_id :string +# +# Indexes +# +# braintree_payment_method_index (payment_method_id) +# braintree_transaction_subscription (subscription_id) +# index_payment_braintree_transactions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Payment::Braintree::Transaction < ApplicationRecord 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/payment/go_cardless/customer.rb b/app/models/payment/go_cardless/customer.rb index f05f69e8a..4961bedbf 100644 --- a/app/models/payment/go_cardless/customer.rb +++ b/app/models/payment/go_cardless/customer.rb @@ -1,19 +1,28 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_customers # # id :integer not null, primary key -# go_cardless_id :string +# country_code :string # email :string -# given_name :string # family_name :string -# postal_code :string -# country_code :string +# given_name :string # language :string -# member_id :integer +# postal_code :string # created_at :datetime not null # updated_at :datetime not null +# go_cardless_id :string +# member_id :integer +# +# Indexes +# +# index_payment_go_cardless_customers_on_member_id (member_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) # class Payment::GoCardless::Customer < ApplicationRecord diff --git a/app/models/payment/go_cardless/payment_method.rb b/app/models/payment/go_cardless/payment_method.rb index 00f51e871..362a3fcc9 100644 --- a/app/models/payment/go_cardless/payment_method.rb +++ b/app/models/payment/go_cardless/payment_method.rb @@ -1,29 +1,38 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_payment_methods # # id :integer not null, primary key -# go_cardless_id :string +# aasm_state :string +# cancelled_at :datetime +# next_possible_charge_date :date # reference :string # scheme :string -# next_possible_charge_date :date -# customer_id :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string -# cancelled_at :datetime +# customer_id :integer +# go_cardless_id :string +# +# Indexes +# +# index_payment_go_cardless_payment_methods_on_customer_id (customer_id) +# +# Foreign Keys +# +# fk_rails_... (customer_id => payment_go_cardless_customers.id) # class Payment::GoCardless::PaymentMethod < ApplicationRecord include AASM ACTION_FROM_STATE = { - created: :create, - submitted: :submit, - active: :activate, - cancelled: :cancel, - expired: :expire + created: :create, + submitted: :submit, + active: :activate, + cancelled: :cancel, + expired: :expire }.freeze aasm do @@ -39,11 +48,11 @@ class Payment::GoCardless::PaymentMethod < ApplicationRecord end event :run_submit do - transitions from: [:pending, :created], to: :submitted + transitions from: %i[pending created], to: :submitted end event :run_activate do - transitions from: [:pending, :created, :submitted], to: :active + transitions from: %i[pending created submitted], to: :active end event :run_cancel do diff --git a/app/models/payment/go_cardless/subscription.rb b/app/models/payment/go_cardless/subscription.rb index 5ba102859..b096d4efe 100644 --- a/app/models/payment/go_cardless/subscription.rb +++ b/app/models/payment/go_cardless/subscription.rb @@ -5,20 +5,34 @@ # Table name: payment_go_cardless_subscriptions # # id :integer not null, primary key -# go_cardless_id :string +# aasm_state :string # amount :decimal(, ) +# cancelled_at :datetime # currency :string -# status :integer # name :string # payment_reference :string -# page_id :integer -# action_id :integer -# payment_method_id :integer -# customer_id :integer +# status :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string -# cancelled_at :datetime +# action_id :integer +# customer_id :integer +# go_cardless_id :string +# page_id :integer +# payment_method_id :integer +# +# Indexes +# +# index_payment_go_cardless_subscriptions_on_action_id (action_id) +# index_payment_go_cardless_subscriptions_on_customer_id (customer_id) +# index_payment_go_cardless_subscriptions_on_page_id (page_id) +# index_payment_go_cardless_subscriptions_on_payment_method_id (payment_method_id) +# +# Foreign Keys +# +# fk_rails_... (action_id => actions.id) +# fk_rails_... (customer_id => payment_go_cardless_customers.id) +# fk_rails_... (page_id => pages.id) +# fk_rails_... (payment_method_id => payment_go_cardless_payment_methods.id) # class Payment::GoCardless::Subscription < ApplicationRecord diff --git a/app/models/payment/go_cardless/transaction.rb b/app/models/payment/go_cardless/transaction.rb index 1d17f26b7..e3745abf6 100644 --- a/app/models/payment/go_cardless/transaction.rb +++ b/app/models/payment/go_cardless/transaction.rb @@ -5,22 +5,35 @@ # Table name: payment_go_cardless_transactions # # id :integer not null, primary key -# go_cardless_id :string -# charge_date :date +# aasm_state :string # amount :decimal(, ) -# description :string +# amount_refunded :decimal(, ) +# charge_date :date # currency :string -# status :integer +# description :string # reference :string -# amount_refunded :decimal(, ) -# page_id :integer -# payment_method_id :integer -# customer_id :integer +# status :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string +# customer_id :integer +# go_cardless_id :string +# page_id :integer +# payment_method_id :integer # subscription_id :integer # +# Indexes +# +# go_cardless_transaction_subscription (subscription_id) +# index_payment_go_cardless_transactions_on_customer_id (customer_id) +# index_payment_go_cardless_transactions_on_page_id (page_id) +# index_payment_go_cardless_transactions_on_payment_method_id (payment_method_id) +# +# Foreign Keys +# +# fk_rails_... (customer_id => payment_go_cardless_customers.id) +# fk_rails_... (page_id => pages.id) +# fk_rails_... (payment_method_id => payment_go_cardless_payment_methods.id) +# class Payment::GoCardless::Transaction < ApplicationRecord include AASM diff --git a/app/models/payment/go_cardless/webhook_event.rb b/app/models/payment/go_cardless/webhook_event.rb index 8a1be54ef..8fa874653 100644 --- a/app/models/payment/go_cardless/webhook_event.rb +++ b/app/models/payment/go_cardless/webhook_event.rb @@ -1,17 +1,22 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_webhook_events # # id :integer not null, primary key -# event_id :string -# resource_type :string # action :string # body :text +# resource_type :string # created_at :datetime not null # updated_at :datetime not null +# event_id :string # resource_id :string # +# Indexes +# +# index_payment_go_cardless_webhook_events_on_event_id (event_id) +# class Payment::GoCardless::WebhookEvent < ApplicationRecord end diff --git a/app/models/pending_action.rb b/app/models/pending_action.rb index 2f905f0ee..fe12ce390 100644 --- a/app/models/pending_action.rb +++ b/app/models/pending_action.rb @@ -1,5 +1,31 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: pending_actions +# +# id :bigint(8) not null, primary key +# bounced_at :datetime +# clicked :string default([]), is an Array +# complaint :boolean +# confirmed_at :datetime +# consented :boolean +# data :jsonb +# delivered_at :datetime +# email :string +# email_count :integer default(0) +# emailed_at :datetime +# opened_at :datetime +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# page_id :bigint(8) +# +# Indexes +# +# index_pending_actions_on_page_id (page_id) +# + class PendingAction < ApplicationRecord scope :not_confirmed, -> { where(confirmed_at: nil) } scope :only_emailed_once, -> { where(email_count: 1) } diff --git a/app/models/plugins/actions_thermometer.rb b/app/models/plugins/actions_thermometer.rb index 6983e5275..5b1c39957 100644 --- a/app/models/plugins/actions_thermometer.rb +++ b/app/models/plugins/actions_thermometer.rb @@ -5,14 +5,22 @@ # Table name: plugins_thermometers # # id :integer not null, primary key -# type :string not null -# title :string +# active :boolean default(FALSE) # offset :integer -# page_id :integer -# active :boolean default("false") +# ref :string +# title :string +# type :string default("ActionsThermometer"), not null # created_at :datetime not null # updated_at :datetime not null -# ref :string +# page_id :integer +# +# Indexes +# +# index_plugins_thermometers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Plugins::ActionsThermometer < Plugins::Thermometer diff --git a/app/models/plugins/call_tool.rb b/app/models/plugins/call_tool.rb index 5074dabb4..3dc401c9a 100644 --- a/app/models/plugins/call_tool.rb +++ b/app/models/plugins/call_tool.rb @@ -5,25 +5,25 @@ # Table name: plugins_call_tools # # id :integer not null, primary key -# page_id :integer # active :boolean -# ref :string -# created_at :datetime -# updated_at :datetime -# title :string -# targets :json default("{}"), is an Array -# sound_clip_file_name :string -# sound_clip_content_type :string -# sound_clip_file_size :integer -# sound_clip_updated_at :datetime # description :text -# menu_sound_clip_file_name :string # menu_sound_clip_content_type :string -# menu_sound_clip_file_size :integer +# menu_sound_clip_file_name :string +# menu_sound_clip_file_size :bigint(8) # menu_sound_clip_updated_at :datetime +# ref :string # restricted_country_code :string +# sound_clip_content_type :string +# sound_clip_file_name :string +# sound_clip_file_size :bigint(8) +# sound_clip_updated_at :datetime +# target_by_attributes :string default([]), is an Array +# targets :json is an Array +# title :string +# created_at :datetime +# updated_at :datetime # caller_phone_number_id :integer -# target_by_attributes :string default("{}"), is an Array +# page_id :integer # class Plugins::CallTool < ApplicationRecord diff --git a/app/models/plugins/donations_thermometer.rb b/app/models/plugins/donations_thermometer.rb index 88001865b..4e9049f09 100644 --- a/app/models/plugins/donations_thermometer.rb +++ b/app/models/plugins/donations_thermometer.rb @@ -5,14 +5,22 @@ # Table name: plugins_thermometers # # id :integer not null, primary key -# type :string not null +# active :boolean default(FALSE) +# offset :integer +# ref :string # title :string -# offset :integer -> Offset in CENTS -# page_id :integer -# active :boolean default("false") +# type :string default("ActionsThermometer"), not null # created_at :datetime not null # updated_at :datetime not null -# ref :string +# page_id :integer +# +# Indexes +# +# index_plugins_thermometers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Plugins::DonationsThermometer < Plugins::Thermometer diff --git a/app/models/plugins/email_pension.rb b/app/models/plugins/email_pension.rb index 17b2a9ada..edcea8d00 100644 --- a/app/models/plugins/email_pension.rb +++ b/app/models/plugins/email_pension.rb @@ -4,19 +4,24 @@ # # Table name: plugins_email_pensions # -# id :integer not null, primary key -# ref :string -# page_id :integer -# active :boolean default("false") -# email_subjects :string default("{}"), is an Array -# email_body :text -# created_at :datetime -# updated_at :datetime -# test_email_address :string -# email_body_header :text -# email_body_footer :text -# use_member_email :boolean default("false") -# from_email_address_id :integer +# id :integer not null, primary key +# active :boolean default(FALSE) +# email_body :text +# email_body_footer :text +# email_body_header :text +# email_subjects :string default([]), is an Array +# ref :string +# test_email_address :string +# use_member_email :boolean default(FALSE) +# created_at :datetime +# updated_at :datetime +# from_email_address_id :integer +# page_id :integer +# registered_target_endpoint_id :integer +# +# Indexes +# +# index_plugins_email_pensions_on_page_id (page_id) # class Plugins::EmailPension < ApplicationRecord diff --git a/app/models/plugins/email_tool.rb b/app/models/plugins/email_tool.rb index a6e96a12a..5fe44024b 100644 --- a/app/models/plugins/email_tool.rb +++ b/app/models/plugins/email_tool.rb @@ -4,22 +4,26 @@ # # Table name: plugins_email_tools # -# id :integer not null, primary key -# ref :string -# page_id :integer -# active :boolean default("false") -# email_subjects :string default("{}"), is an Array +# id :bigint(8) not null, primary key +# active :boolean default(FALSE) # email_body :text -# email_body_header :text # email_body_footer :text +# email_body_header :text +# email_subjects :string default([]), is an Array +# ref :string +# targeting_mode :integer default("member_selected_target") +# targets :json is an Array # test_email_address :string -# targets :json default("{}"), is an Array +# title :string default("") +# use_member_email :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null -# use_member_email :boolean default("false") # from_email_address_id :integer -# targeting_mode :integer default("0") -# title :string default("") +# page_id :integer +# +# Indexes +# +# index_plugins_email_tools_on_page_id (page_id) # class Plugins::EmailTool < ApplicationRecord diff --git a/app/models/plugins/fundraiser.rb b/app/models/plugins/fundraiser.rb index 83f8b94d3..9052ed45d 100644 --- a/app/models/plugins/fundraiser.rb +++ b/app/models/plugins/fundraiser.rb @@ -5,16 +5,28 @@ # Table name: plugins_fundraisers # # id :integer not null, primary key -# title :string +# active :boolean default(FALSE) +# preselect_amount :boolean default(FALSE) +# recurring_default :integer default("one_off"), not null # ref :string -# page_id :integer -# active :boolean default("false") +# title :string # created_at :datetime not null # updated_at :datetime not null -# form_id :integer # donation_band_id :integer -# recurring_default :integer default("0"), not null -# preselect_amount :boolean default("false") +# form_id :integer +# page_id :integer +# +# Indexes +# +# index_plugins_fundraisers_on_donation_band_id (donation_band_id) +# index_plugins_fundraisers_on_form_id (form_id) +# index_plugins_fundraisers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (donation_band_id => donation_bands.id) +# fk_rails_... (form_id => forms.id) +# fk_rails_... (page_id => pages.id) # class Plugins::Fundraiser < ApplicationRecord 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/plugins/petition.rb b/app/models/plugins/petition.rb index 78cc42c06..49cdb6c19 100644 --- a/app/models/plugins/petition.rb +++ b/app/models/plugins/petition.rb @@ -5,15 +5,25 @@ # Table name: plugins_petitions # # id :integer not null, primary key -# page_id :integer -# active :boolean default("false") -# form_id :integer -# created_at :datetime not null -# updated_at :datetime not null +# active :boolean default(FALSE) +# cta :string # description :text # ref :string # target :string -# cta :string +# created_at :datetime not null +# updated_at :datetime not null +# form_id :integer +# page_id :integer +# +# Indexes +# +# index_plugins_petitions_on_form_id (form_id) +# index_plugins_petitions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (form_id => forms.id) +# fk_rails_... (page_id => pages.id) # class Plugins::Petition < ApplicationRecord diff --git a/app/models/plugins/survey.rb b/app/models/plugins/survey.rb index c928b21fb..07fb5550a 100644 --- a/app/models/plugins/survey.rb +++ b/app/models/plugins/survey.rb @@ -5,12 +5,16 @@ # Table name: plugins_surveys # # id :integer not null, primary key -# page_id :integer -# active :boolean default("false") +# active :boolean default(FALSE) +# auto_advance :boolean default(TRUE) # ref :string # created_at :datetime # updated_at :datetime -# auto_advance :boolean default("true") +# page_id :integer +# +# Indexes +# +# index_plugins_surveys_on_page_id (page_id) # class Plugins::Survey < ApplicationRecord @@ -41,6 +45,7 @@ def ensure_required_fields ensure_has_a_form REQUIRED_FIELDS.each do |field| next unless fields_with_name(field).empty? + language = page.try(:language).try(:code) || I18n.default_locale data_type = FormElement::VALID_TYPES.include?(field.to_s) ? field : 'text' FormElement.create(name: field, @@ -54,6 +59,7 @@ def ensure_required_fields def ensure_has_a_form return forms if forms.size >= 1 + Form.create(name: "survey_form_#{id}", master: false, formable: self) forms.reload end diff --git a/app/models/plugins/text.rb b/app/models/plugins/text.rb index ef2ae5dca..e7632f7b2 100644 --- a/app/models/plugins/text.rb +++ b/app/models/plugins/text.rb @@ -5,12 +5,16 @@ # Table name: plugins_texts # # id :integer not null, primary key +# active :boolean default(FALSE) # content :text # ref :string -# page_id :integer -# active :boolean default("false") # created_at :datetime # updated_at :datetime +# page_id :integer +# +# Indexes +# +# index_plugins_texts_on_page_id (page_id) # class Plugins::Text < ApplicationRecord diff --git a/app/models/plugins/thermometer.rb b/app/models/plugins/thermometer.rb index fa7570d7a..2087dc1ea 100644 --- a/app/models/plugins/thermometer.rb +++ b/app/models/plugins/thermometer.rb @@ -5,14 +5,22 @@ # Table name: plugins_thermometers # # id :integer not null, primary key -# type :string not null -# title :string +# active :boolean default(FALSE) # offset :integer -# page_id :integer -# active :boolean default("false") +# ref :string +# title :string +# type :string default("ActionsThermometer"), not null # created_at :datetime not null # updated_at :datetime not null -# ref :string +# page_id :integer +# +# Indexes +# +# index_plugins_thermometers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Plugins::Thermometer < ApplicationRecord @@ -40,7 +48,12 @@ def set_defaults def abbreviate_number(number) return number.to_s if number < 1000 return "#{(goal / 1000).to_i}k" if number < 1_000_000 + locale = page.try(:language).try(:code) - "%g #{I18n.t('thermometer.million', locale: locale)}" % (goal / 1_000_000.0).round(1) + format( + '%g %s', + amount: (goal / 1_000_000.0).round(1), + million: I18n.t('thermometer.million', locale: locale) + ) end end diff --git a/app/models/registered_email_address.rb b/app/models/registered_email_address.rb index b3306d8ee..95933efd6 100644 --- a/app/models/registered_email_address.rb +++ b/app/models/registered_email_address.rb @@ -2,7 +2,7 @@ # # Table name: registered_email_addresses # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # email :string # name :string # diff --git a/app/models/registered_target_endpoint.rb b/app/models/registered_target_endpoint.rb index fd307e515..067a37f11 100644 --- a/app/models/registered_target_endpoint.rb +++ b/app/models/registered_target_endpoint.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: registered_target_endpoints +# +# id :bigint(8) not null, primary key +# description :text +# name :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# + class RegisteredTargetEndpoint < ApplicationRecord validates :url, presence: true validates :name, presence: true 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/models/share/button.rb b/app/models/share/button.rb index 2e9961cdf..44e484b5b 100644 --- a/app/models/share/button.rb +++ b/app/models/share/button.rb @@ -4,16 +4,20 @@ # # Table name: share_buttons # -# id :integer not null, primary key -# title :string -# url :string -# created_at :datetime not null -# updated_at :datetime not null -# sp_id :string -# page_id :integer -# share_type :string +# id :integer not null, primary key +# analytics :text # share_button_html :string -# analytics :text +# share_type :string +# title :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# page_id :integer +# sp_id :string +# +# Indexes +# +# index_share_buttons_on_page_id (page_id) # class Share::Button < ApplicationRecord diff --git a/app/models/share/email.rb b/app/models/share/email.rb index 56084744a..8983e8620 100644 --- a/app/models/share/email.rb +++ b/app/models/share/email.rb @@ -1,16 +1,25 @@ # frozen_string_literal: true + # == Schema Information # # Table name: share_emails # # id :integer not null, primary key -# subject :string # body :text -# page_id :integer -# sp_id :string -# button_id :integer +# subject :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# page_id :integer +# sp_id :string +# +# Indexes +# +# index_share_emails_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Share::Email < ApplicationRecord diff --git a/app/models/share/facebook.rb b/app/models/share/facebook.rb index 30f70157f..408e2598b 100644 --- a/app/models/share/facebook.rb +++ b/app/models/share/facebook.rb @@ -1,20 +1,31 @@ # frozen_string_literal: true + # == Schema Information # # Table name: share_facebooks # # id :integer not null, primary key -# title :string +# click_count :integer # description :text # image :string -# button_id :integer +# share_count :integer +# title :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# image_id :integer # page_id :integer -# share_count :integer -# click_count :integer # sp_id :string -# image_id :integer +# +# Indexes +# +# index_share_facebooks_on_button_id (button_id) +# index_share_facebooks_on_image_id (image_id) +# index_share_facebooks_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (image_id => images.id) # class Share::Facebook < ApplicationRecord diff --git a/app/models/share/twitter.rb b/app/models/share/twitter.rb index f788c7d26..05f1355bc 100644 --- a/app/models/share/twitter.rb +++ b/app/models/share/twitter.rb @@ -1,16 +1,25 @@ # frozen_string_literal: true + # == Schema Information # # Table name: share_twitters # # id :integer not null, primary key -# sp_id :integer -# page_id :integer -# title :string # description :string -# button_id :integer +# title :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# page_id :integer +# sp_id :integer +# +# Indexes +# +# index_share_twitters_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Share::Twitter < ApplicationRecord diff --git a/app/models/share/whatsapp.rb b/app/models/share/whatsapp.rb index 28c9d6c26..65c7e9ec9 100644 --- a/app/models/share/whatsapp.rb +++ b/app/models/share/whatsapp.rb @@ -4,14 +4,23 @@ # # Table name: share_whatsapps # -# id :integer not null, primary key -# page_id :integer -# text :string -# button_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# click_count :integer -# conversion_count :integer +# id :bigint(8) not null, primary key +# click_count :integer default(0), not null +# conversion_count :integer default(0), not null +# text :string +# created_at :datetime not null +# updated_at :datetime not null +# button_id :integer +# page_id :bigint(8) +# +# Indexes +# +# index_share_whatsapps_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) +# class Share::Whatsapp < ApplicationRecord include Share::Variant diff --git a/app/models/uri.rb b/app/models/uri.rb index 2a95709be..37a8ede94 100644 --- a/app/models/uri.rb +++ b/app/models/uri.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: uris @@ -6,9 +7,17 @@ # id :integer not null, primary key # domain :string # path :string -# page_id :integer # created_at :datetime not null # updated_at :datetime not null +# page_id :integer +# +# Indexes +# +# index_uris_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # class Uri < ApplicationRecord diff --git a/app/models/user.rb b/app/models/user.rb index 92729c102..027e9cf2b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,21 +5,26 @@ # Table name: users # # id :integer not null, primary key +# admin :boolean +# current_sign_in_at :datetime +# current_sign_in_ip :inet # email :string default(""), not null # encrypted_password :string default(""), not null -# reset_password_token :string -# reset_password_sent_at :datetime -# remember_created_at :datetime -# sign_in_count :integer default("0"), not null -# current_sign_in_at :datetime # last_sign_in_at :datetime -# current_sign_in_ip :inet # last_sign_in_ip :inet -# created_at :datetime -# updated_at :datetime # provider :string +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# sign_in_count :integer default(0), not null # uid :string -# admin :boolean +# created_at :datetime +# updated_at :datetime +# +# Indexes +# +# index_users_on_email (email) UNIQUE +# index_users_on_reset_password_token (reset_password_token) UNIQUE # class User < ApplicationRecord 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/email_confirmation/_member_data.slim b/app/views/email_confirmation/_member_data.slim new file mode 100644 index 000000000..d2964a729 --- /dev/null +++ b/app/views/email_confirmation/_member_data.slim @@ -0,0 +1,7 @@ +javascript: + window.champaign = window.champaign || {}; + window.champaign.personalization = window.champaign.personalization || {}; + + window.champaign.personalization.member = #{(@member || {}).to_json.html_safe}; + window.champaign.personalization.paymentMethods = #{(@payment_methods || {}).to_json.html_safe}; + diff --git a/app/views/email_confirmation/follow_up.slim b/app/views/email_confirmation/follow_up.slim index 5a47fe779..157d8403b 100644 --- a/app/views/email_confirmation/follow_up.slim +++ b/app/views/email_confirmation/follow_up.slim @@ -1,3 +1,4 @@ += render partial: "member_data" .header-logo.header-logo--light a href = t('footer.home_url') .header-logo__logo.sumofus-logo--positive 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/money.rb b/config/initializers/money.rb index 8c2e62667..5162f266b 100644 --- a/config/initializers/money.rb +++ b/config/initializers/money.rb @@ -1,6 +1,9 @@ require 'money' require 'money_oxr/bank' +# Currency formatting depends on the locale, not the currency +Money.locale_backend = :i18n + Money.default_bank = MoneyOXR::Bank.new( app_id: Settings.oxr_app_id, cache_path: 'tmp/oxr.json', 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/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 000000000..74765fdc8 --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,54 @@ +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +if Rails.env.development? + require 'annotate' + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + 'routes' => 'false', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'show_foreign_keys' => 'true', + 'show_complete_foreign_keys' => 'false', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'false', + 'exclude_fixtures' => 'false', + 'exclude_factories' => 'false', + 'exclude_serializers' => 'false', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'exclude_sti_subclasses' => 'false', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => 'integer,boolean', + 'hide_default_column_types' => 'json,jsonb,hstore', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'classified_sort' => 'true', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil, + 'with_comment' => true + ) + end + + Annotate.load_tasks +end 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/actions.rb b/spec/factories/actions.rb index a326fdca9..86f2b20a8 100644 --- a/spec/factories/actions.rb +++ b/spec/factories/actions.rb @@ -5,17 +5,27 @@ # Table name: actions # # id :integer not null, primary key -# page_id :integer -# member_id :integer -# link :string # created_user :boolean +# donation :boolean default(FALSE) +# form_data :jsonb +# link :string +# publish_status :integer default("default"), not null +# subscribed_member :boolean default(TRUE) # subscribed_user :boolean # created_at :datetime not null # updated_at :datetime not null -# form_data :jsonb default("{}") -# subscribed_member :boolean default("true") -# donation :boolean default("false") -# publish_status :integer default("0"), not null +# member_id :integer +# page_id :integer +# +# Indexes +# +# index_actions_on_member_id (member_id) +# index_actions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/calls.rb b/spec/factories/calls.rb index ffdc4b746..7540f1ec4 100644 --- a/spec/factories/calls.rb +++ b/spec/factories/calls.rb @@ -5,17 +5,21 @@ # Table name: calls # # id :integer not null, primary key -# page_id :integer -# member_id :integer +# member_call_events :json is an Array # member_phone_number :string +# status :integer default("unstarted") +# target :json +# target_call_info :jsonb not null +# twilio_error_code :integer # created_at :datetime # updated_at :datetime -# target_call_info :jsonb default("{}"), not null -# member_call_events :json default("{}"), is an Array -# twilio_error_code :integer -# target :json -# status :integer default("0") # action_id :integer +# member_id :integer +# page_id :integer +# +# Indexes +# +# index_calls_on_target_call_info (target_call_info) USING gin # FactoryBot.define do 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/donation_bands.rb b/spec/factories/donation_bands.rb index ff7a499aa..d2ec4d979 100644 --- a/spec/factories/donation_bands.rb +++ b/spec/factories/donation_bands.rb @@ -5,8 +5,8 @@ # Table name: donation_bands # # id :integer not null, primary key +# amounts :integer default([]), is an Array # name :string -# amounts :integer default("{}"), is an Array # created_at :datetime not null # updated_at :datetime not null # diff --git a/spec/factories/form_elements.rb b/spec/factories/form_elements.rb index abb1517a1..cd0cf4301 100644 --- a/spec/factories/form_elements.rb +++ b/spec/factories/form_elements.rb @@ -5,18 +5,26 @@ # Table name: form_elements # # id :integer not null, primary key -# form_id :integer -# label :string +# choices :jsonb # data_type :string # default_value :string +# display_mode :integer default("all_members") +# label :string +# name :string +# position :integer default(0), not null # required :boolean # visible :boolean # created_at :datetime not null # updated_at :datetime not null -# name :string -# position :integer default("0"), not null -# choices :jsonb default("[]") -# display_mode :integer default("0") +# form_id :integer +# +# Indexes +# +# index_form_elements_on_form_id (form_id) +# +# Foreign Keys +# +# fk_rails_... (form_id => forms.id) # FactoryBot.define do diff --git a/spec/factories/forms.rb b/spec/factories/forms.rb index 6d254848c..5d85a4569 100644 --- a/spec/factories/forms.rb +++ b/spec/factories/forms.rb @@ -5,15 +5,19 @@ # Table name: forms # # id :integer not null, primary key -# name :string # description :string +# formable_type :string +# master :boolean default(FALSE) +# name :string +# position :integer default(0), not null +# visible :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null -# visible :boolean default("false") -# master :boolean default("false") # formable_id :integer -# formable_type :string -# position :integer default("0"), not null +# +# Indexes +# +# index_forms_on_formable_type_and_formable_id (formable_type,formable_id) # FactoryBot.define do diff --git a/spec/factories/images.rb b/spec/factories/images.rb index 4f4a2f837..b0ed2317d 100644 --- a/spec/factories/images.rb +++ b/spec/factories/images.rb @@ -1,17 +1,22 @@ # frozen_string_literal: true + # == Schema Information # # Table name: images # # id :integer not null, primary key -# content_file_name :string # content_content_type :string -# content_file_size :integer +# content_file_name :string +# content_file_size :bigint(8) # content_updated_at :datetime # created_at :datetime # updated_at :datetime # page_id :integer # +# Indexes +# +# index_images_on_page_id (page_id) +# FactoryBot.define do factory :image do 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/factories/liquid_layouts.rb b/spec/factories/liquid_layouts.rb index 6c62ed045..c6d490f77 100644 --- a/spec/factories/liquid_layouts.rb +++ b/spec/factories/liquid_layouts.rb @@ -5,15 +5,15 @@ # Table name: liquid_layouts # # id :integer not null, primary key -# title :string # content :text +# description :text +# experimental :boolean default(FALSE), not null +# post_action_layout :boolean +# primary_layout :boolean +# title :string # created_at :datetime not null # updated_at :datetime not null -# description :text -# experimental :boolean default("false"), not null # default_follow_up_layout_id :integer -# primary_layout :boolean -# post_action_layout :boolean # FactoryBot.define do diff --git a/spec/factories/member_authentications.rb b/spec/factories/member_authentications.rb index aafb25c70..2646fc91b 100644 --- a/spec/factories/member_authentications.rb +++ b/spec/factories/member_authentications.rb @@ -5,17 +5,27 @@ # Table name: member_authentications # # id :integer not null, primary key -# member_id :integer -# password_digest :string not null -# facebook_uid :string +# confirmed_at :datetime # facebook_token :string # facebook_token_expiry :datetime -# created_at :datetime not null -# updated_at :datetime not null -# token :string -# confirmed_at :datetime +# facebook_uid :string +# password_digest :string not null # reset_password_sent_at :datetime # reset_password_token :string +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# member_id :integer +# +# Indexes +# +# index_member_authentications_on_facebook_uid (facebook_uid) +# index_member_authentications_on_member_id (member_id) +# index_member_authentications_on_reset_password_token (reset_password_token) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) # FactoryBot.define do diff --git a/spec/factories/members.rb b/spec/factories/members.rb index 425484b48..2f54c956b 100644 --- a/spec/factories/members.rb +++ b/spec/factories/members.rb @@ -5,22 +5,28 @@ # Table name: members # # id :integer not null, primary key -# email :string +# address1 :string +# address2 :string +# city :string +# consented :boolean +# consented_updated_at :datetime # country :string +# donor_status :integer default("nondonor"), not null +# email :string # first_name :string # last_name :string -# city :string +# more :jsonb # postal :string # title :string -# address1 :string -# address2 :string # created_at :datetime not null # updated_at :datetime not null # actionkit_user_id :string -# donor_status :integer default("0"), not null -# more :jsonb -# consented_updated_at :datetime -# consented :boolean default("false") +# +# Indexes +# +# index_members_on_actionkit_user_id (actionkit_user_id) +# index_members_on_email (email) +# index_members_on_email_and_id (email,id) # FactoryBot.define do diff --git a/spec/factories/pages.rb b/spec/factories/pages.rb index dd06c3c05..e73c71a34 100644 --- a/spec/factories/pages.rb +++ b/spec/factories/pages.rb @@ -5,37 +5,54 @@ # Table name: pages # # id :integer not null, primary key -# language_id :integer -# campaign_id :integer -# title :string not null +# action_count :integer default(0) +# ak_donation_resource_uri :string +# ak_petition_resource_uri :string +# allow_duplicate_actions :boolean default(FALSE) +# canonical_url :string +# compiled_html :text +# content :text default("") +# enforce_styles :boolean default(FALSE), not null +# featured :boolean default(FALSE) +# follow_up_plan :integer default("with_liquid"), not null +# fundraising_goal :decimal(10, 2) default(0.0) +# javascript :text +# messages :text +# meta_description :string +# meta_tags :string +# notes :text +# optimizely_status :integer default("optimizely_enabled"), not null +# publish_actions :integer default("secure"), not null +# publish_status :integer default("unpublished"), not null # slug :string not null +# status :string default("pending") +# title :string not null +# total_donations :decimal(10, 2) default(0.0) # created_at :datetime # updated_at :datetime -# compiled_html :text -# status :string default("pending") -# messages :text -# content :text default("") -# featured :boolean default("false") -# liquid_layout_id :integer +# campaign_id :integer # follow_up_liquid_layout_id :integer -# action_count :integer default("0") -# primary_image_id :integer -# ak_petition_resource_uri :string -# ak_donation_resource_uri :string -# follow_up_plan :integer default("0"), not null # follow_up_page_id :integer -# javascript :text -# publish_status :integer default("1"), not null -# optimizely_status :integer default("0"), not null -# canonical_url :string -# allow_duplicate_actions :boolean default("false") -# enforce_styles :boolean default("false"), not null -# notes :text -# publish_actions :integer default("0"), not null -# meta_tags :string -# meta_description :string -# total_donations :double default("0") -> Total donations in CENTS -# fundraising_goal :double default("0") -> Fundraising goal in CENTS +# language_id :integer +# liquid_layout_id :integer +# primary_image_id :integer +# +# Indexes +# +# index_pages_on_campaign_id (campaign_id) +# index_pages_on_follow_up_liquid_layout_id (follow_up_liquid_layout_id) +# index_pages_on_follow_up_page_id (follow_up_page_id) +# index_pages_on_liquid_layout_id (liquid_layout_id) +# index_pages_on_primary_image_id (primary_image_id) +# index_pages_on_publish_status (publish_status) +# +# Foreign Keys +# +# fk_rails_... (campaign_id => campaigns.id) +# fk_rails_... (follow_up_liquid_layout_id => liquid_layouts.id) +# fk_rails_... (language_id => languages.id) +# fk_rails_... (liquid_layout_id => liquid_layouts.id) +# fk_rails_... (primary_image_id => images.id) # FactoryBot.define do diff --git a/spec/factories/payment_braintree_customers.rb b/spec/factories/payment_braintree_customers.rb index b92f59807..145557d24 100644 --- a/spec/factories/payment_braintree_customers.rb +++ b/spec/factories/payment_braintree_customers.rb @@ -5,21 +5,29 @@ # Table name: payment_braintree_customers # # id :integer not null, primary key -# card_type :string # card_bin :string -# cardholder_name :string # card_debit :string # card_last_4 :string -# card_vault_token :string +# card_type :string # card_unique_number_identifier :string +# card_vault_token :string +# cardholder_name :string # email :string # first_name :string # last_name :string -# customer_id :string # created_at :datetime not null # updated_at :datetime not null +# customer_id :string # member_id :integer # +# Indexes +# +# index_payment_braintree_customers_on_member_id (member_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) +# FactoryBot.define do factory :payment_braintree_customer, class: 'Payment::Braintree::Customer' do diff --git a/spec/factories/payment_braintree_subscriptions.rb b/spec/factories/payment_braintree_subscriptions.rb index c0c17e1e8..b70e592a0 100644 --- a/spec/factories/payment_braintree_subscriptions.rb +++ b/spec/factories/payment_braintree_subscriptions.rb @@ -5,18 +5,28 @@ # Table name: payment_braintree_subscriptions # # id :integer not null, primary key -# subscription_id :string -# merchant_account_id :string -# created_at :datetime not null -# updated_at :datetime not null -# page_id :integer # amount :decimal(10, 2) +# billing_day_of_month :integer +# cancelled_at :datetime # currency :string +# created_at :datetime not null +# updated_at :datetime not null # action_id :integer -# cancelled_at :datetime # customer_id :string -# billing_day_of_month :integer +# merchant_account_id :string +# page_id :integer # payment_method_id :integer +# subscription_id :string +# +# Indexes +# +# index_payment_braintree_subscriptions_on_action_id (action_id) +# index_payment_braintree_subscriptions_on_page_id (page_id) +# index_payment_braintree_subscriptions_on_subscription_id (subscription_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/payment_braintree_transactions.rb b/spec/factories/payment_braintree_transactions.rb index 098e5f4d6..21110495d 100644 --- a/spec/factories/payment_braintree_transactions.rb +++ b/spec/factories/payment_braintree_transactions.rb @@ -5,22 +5,32 @@ # Table name: payment_braintree_transactions # # id :integer not null, primary key -# transaction_id :string -# transaction_type :string -# transaction_created_at :datetime +# amount :decimal(10, 2) +# currency :string +# payment_instrument_type :string # payment_method_token :string -# customer_id :string +# processor_response_code :string +# status :integer +# transaction_created_at :datetime +# transaction_type :string # created_at :datetime not null # updated_at :datetime not null +# customer_id :string # merchant_account_id :string -# currency :string # page_id :integer -# payment_instrument_type :string -# status :integer -# amount :decimal(10, 2) -# processor_response_code :string # payment_method_id :integer # subscription_id :integer +# transaction_id :string +# +# Indexes +# +# braintree_payment_method_index (payment_method_id) +# braintree_transaction_subscription (subscription_id) +# index_payment_braintree_transactions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/payment_go_cardless_customers.rb b/spec/factories/payment_go_cardless_customers.rb index ed8b9ac77..ea84a094d 100644 --- a/spec/factories/payment_go_cardless_customers.rb +++ b/spec/factories/payment_go_cardless_customers.rb @@ -5,16 +5,24 @@ # Table name: payment_go_cardless_customers # # id :integer not null, primary key -# go_cardless_id :string +# country_code :string # email :string -# given_name :string # family_name :string -# postal_code :string -# country_code :string +# given_name :string # language :string -# member_id :integer +# postal_code :string # created_at :datetime not null # updated_at :datetime not null +# go_cardless_id :string +# member_id :integer +# +# Indexes +# +# index_payment_go_cardless_customers_on_member_id (member_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) # FactoryBot.define do diff --git a/spec/factories/payment_go_cardless_payment_methods.rb b/spec/factories/payment_go_cardless_payment_methods.rb index 0b9f047b1..0b79b110e 100644 --- a/spec/factories/payment_go_cardless_payment_methods.rb +++ b/spec/factories/payment_go_cardless_payment_methods.rb @@ -5,15 +5,23 @@ # Table name: payment_go_cardless_payment_methods # # id :integer not null, primary key -# go_cardless_id :string +# aasm_state :string +# cancelled_at :datetime +# next_possible_charge_date :date # reference :string # scheme :string -# next_possible_charge_date :date -# customer_id :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string -# cancelled_at :datetime +# customer_id :integer +# go_cardless_id :string +# +# Indexes +# +# index_payment_go_cardless_payment_methods_on_customer_id (customer_id) +# +# Foreign Keys +# +# fk_rails_... (customer_id => payment_go_cardless_customers.id) # FactoryBot.define do diff --git a/spec/factories/payment_go_cardless_subscriptions.rb b/spec/factories/payment_go_cardless_subscriptions.rb index 1f7199dc0..ea5e9e983 100644 --- a/spec/factories/payment_go_cardless_subscriptions.rb +++ b/spec/factories/payment_go_cardless_subscriptions.rb @@ -5,20 +5,34 @@ # Table name: payment_go_cardless_subscriptions # # id :integer not null, primary key -# go_cardless_id :string +# aasm_state :string # amount :decimal(, ) +# cancelled_at :datetime # currency :string -# status :integer # name :string # payment_reference :string -# page_id :integer -# action_id :integer -# payment_method_id :integer -# customer_id :integer +# status :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string -# cancelled_at :datetime +# action_id :integer +# customer_id :integer +# go_cardless_id :string +# page_id :integer +# payment_method_id :integer +# +# Indexes +# +# index_payment_go_cardless_subscriptions_on_action_id (action_id) +# index_payment_go_cardless_subscriptions_on_customer_id (customer_id) +# index_payment_go_cardless_subscriptions_on_page_id (page_id) +# index_payment_go_cardless_subscriptions_on_payment_method_id (payment_method_id) +# +# Foreign Keys +# +# fk_rails_... (action_id => actions.id) +# fk_rails_... (customer_id => payment_go_cardless_customers.id) +# fk_rails_... (page_id => pages.id) +# fk_rails_... (payment_method_id => payment_go_cardless_payment_methods.id) # FactoryBot.define do diff --git a/spec/factories/payment_go_cardless_transactions.rb b/spec/factories/payment_go_cardless_transactions.rb index 8a1e4ad27..13d137746 100644 --- a/spec/factories/payment_go_cardless_transactions.rb +++ b/spec/factories/payment_go_cardless_transactions.rb @@ -5,22 +5,35 @@ # Table name: payment_go_cardless_transactions # # id :integer not null, primary key -# go_cardless_id :string -# charge_date :date +# aasm_state :string # amount :decimal(, ) -# description :string +# amount_refunded :decimal(, ) +# charge_date :date # currency :string -# status :integer +# description :string # reference :string -# amount_refunded :decimal(, ) -# page_id :integer -# payment_method_id :integer -# customer_id :integer +# status :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string +# customer_id :integer +# go_cardless_id :string +# page_id :integer +# payment_method_id :integer # subscription_id :integer # +# Indexes +# +# go_cardless_transaction_subscription (subscription_id) +# index_payment_go_cardless_transactions_on_customer_id (customer_id) +# index_payment_go_cardless_transactions_on_page_id (page_id) +# index_payment_go_cardless_transactions_on_payment_method_id (payment_method_id) +# +# Foreign Keys +# +# fk_rails_... (customer_id => payment_go_cardless_customers.id) +# fk_rails_... (page_id => pages.id) +# fk_rails_... (payment_method_id => payment_go_cardless_payment_methods.id) +# FactoryBot.define do factory :payment_go_cardless_transaction, class: 'Payment::GoCardless::Transaction' do diff --git a/spec/factories/payment_go_cardless_webhook_events.rb b/spec/factories/payment_go_cardless_webhook_events.rb index 63d2d61c3..79b6dd8bc 100644 --- a/spec/factories/payment_go_cardless_webhook_events.rb +++ b/spec/factories/payment_go_cardless_webhook_events.rb @@ -5,14 +5,18 @@ # Table name: payment_go_cardless_webhook_events # # id :integer not null, primary key -# event_id :string -# resource_type :string # action :string # body :text +# resource_type :string # created_at :datetime not null # updated_at :datetime not null +# event_id :string # resource_id :string # +# Indexes +# +# index_payment_go_cardless_webhook_events_on_event_id (event_id) +# FactoryBot.define do factory :payment_go_cardless_webhook_event, class: 'Payment::GoCardless::WebhookEvent' do diff --git a/spec/factories/pending_actions.rb b/spec/factories/pending_actions.rb index fd40a1568..7d875abcd 100644 --- a/spec/factories/pending_actions.rb +++ b/spec/factories/pending_actions.rb @@ -1,3 +1,29 @@ +# == Schema Information +# +# Table name: pending_actions +# +# id :bigint(8) not null, primary key +# bounced_at :datetime +# clicked :string default([]), is an Array +# complaint :boolean +# confirmed_at :datetime +# consented :boolean +# data :jsonb +# delivered_at :datetime +# email :string +# email_count :integer default(0) +# emailed_at :datetime +# opened_at :datetime +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# page_id :bigint(8) +# +# Indexes +# +# index_pending_actions_on_page_id (page_id) +# + FactoryBot.define do factory :pending_action do data {} diff --git a/spec/factories/plugins_call_tools.rb b/spec/factories/plugins_call_tools.rb index 100806d4d..40740ed19 100644 --- a/spec/factories/plugins_call_tools.rb +++ b/spec/factories/plugins_call_tools.rb @@ -5,25 +5,25 @@ # Table name: plugins_call_tools # # id :integer not null, primary key -# page_id :integer # active :boolean -# ref :string -# created_at :datetime -# updated_at :datetime -# title :string -# targets :json default("{}"), is an Array -# sound_clip_file_name :string -# sound_clip_content_type :string -# sound_clip_file_size :integer -# sound_clip_updated_at :datetime # description :text -# menu_sound_clip_file_name :string # menu_sound_clip_content_type :string -# menu_sound_clip_file_size :integer +# menu_sound_clip_file_name :string +# menu_sound_clip_file_size :bigint(8) # menu_sound_clip_updated_at :datetime +# ref :string # restricted_country_code :string +# sound_clip_content_type :string +# sound_clip_file_name :string +# sound_clip_file_size :bigint(8) +# sound_clip_updated_at :datetime +# target_by_attributes :string default([]), is an Array +# targets :json is an Array +# title :string +# created_at :datetime +# updated_at :datetime # caller_phone_number_id :integer -# target_by_attributes :string default("{}"), is an Array +# page_id :integer # FactoryBot.define do diff --git a/spec/factories/plugins_email_pensions.rb b/spec/factories/plugins_email_pensions.rb index 85b0e7228..63881bbee 100644 --- a/spec/factories/plugins_email_pensions.rb +++ b/spec/factories/plugins_email_pensions.rb @@ -4,19 +4,24 @@ # # Table name: plugins_email_pensions # -# id :integer not null, primary key -# ref :string -# page_id :integer -# active :boolean default("false") -# email_subjects :string default("{}"), is an Array -# email_body :text -# created_at :datetime -# updated_at :datetime -# test_email_address :string -# email_body_header :text -# email_body_footer :text -# use_member_email :boolean default("false") -# from_email_address_id :integer +# id :integer not null, primary key +# active :boolean default(FALSE) +# email_body :text +# email_body_footer :text +# email_body_header :text +# email_subjects :string default([]), is an Array +# ref :string +# test_email_address :string +# use_member_email :boolean default(FALSE) +# created_at :datetime +# updated_at :datetime +# from_email_address_id :integer +# page_id :integer +# registered_target_endpoint_id :integer +# +# Indexes +# +# index_plugins_email_pensions_on_page_id (page_id) # FactoryBot.define do diff --git a/spec/factories/plugins_email_tools.rb b/spec/factories/plugins_email_tools.rb index 45001ffd1..e94585ed2 100644 --- a/spec/factories/plugins_email_tools.rb +++ b/spec/factories/plugins_email_tools.rb @@ -4,22 +4,26 @@ # # Table name: plugins_email_tools # -# id :integer not null, primary key -# ref :string -# page_id :integer -# active :boolean default("false") -# email_subjects :string default("{}"), is an Array +# id :bigint(8) not null, primary key +# active :boolean default(FALSE) # email_body :text -# email_body_header :text # email_body_footer :text +# email_body_header :text +# email_subjects :string default([]), is an Array +# ref :string +# targeting_mode :integer default("member_selected_target") +# targets :json is an Array # test_email_address :string -# targets :json default("{}"), is an Array +# title :string default("") +# use_member_email :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null -# use_member_email :boolean default("false") # from_email_address_id :integer -# targeting_mode :integer default("0") -# title :string default("") +# page_id :integer +# +# Indexes +# +# index_plugins_email_tools_on_page_id (page_id) # FactoryBot.define do diff --git a/spec/factories/plugins_fundraisers.rb b/spec/factories/plugins_fundraisers.rb index 32110a157..04902f83d 100644 --- a/spec/factories/plugins_fundraisers.rb +++ b/spec/factories/plugins_fundraisers.rb @@ -5,16 +5,28 @@ # Table name: plugins_fundraisers # # id :integer not null, primary key -# title :string +# active :boolean default(FALSE) +# preselect_amount :boolean default(FALSE) +# recurring_default :integer default("one_off"), not null # ref :string -# page_id :integer -# active :boolean default("false") +# title :string # created_at :datetime not null # updated_at :datetime not null -# form_id :integer # donation_band_id :integer -# recurring_default :integer default("0"), not null -# preselect_amount :boolean default("false") +# form_id :integer +# page_id :integer +# +# Indexes +# +# index_plugins_fundraisers_on_donation_band_id (donation_band_id) +# index_plugins_fundraisers_on_form_id (form_id) +# index_plugins_fundraisers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (donation_band_id => donation_bands.id) +# fk_rails_... (form_id => forms.id) +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/plugins_petitions.rb b/spec/factories/plugins_petitions.rb index 62cc26815..b971ddf91 100644 --- a/spec/factories/plugins_petitions.rb +++ b/spec/factories/plugins_petitions.rb @@ -5,15 +5,25 @@ # Table name: plugins_petitions # # id :integer not null, primary key -# page_id :integer -# active :boolean default("false") -# form_id :integer -# created_at :datetime not null -# updated_at :datetime not null +# active :boolean default(FALSE) +# cta :string # description :text # ref :string # target :string -# cta :string +# created_at :datetime not null +# updated_at :datetime not null +# form_id :integer +# page_id :integer +# +# Indexes +# +# index_plugins_petitions_on_form_id (form_id) +# index_plugins_petitions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (form_id => forms.id) +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/plugins_surveys.rb b/spec/factories/plugins_surveys.rb index 4ac1c11a9..a81a43a41 100644 --- a/spec/factories/plugins_surveys.rb +++ b/spec/factories/plugins_surveys.rb @@ -5,12 +5,16 @@ # Table name: plugins_surveys # # id :integer not null, primary key -# page_id :integer -# active :boolean default("false") +# active :boolean default(FALSE) +# auto_advance :boolean default(TRUE) # ref :string # created_at :datetime # updated_at :datetime -# auto_advance :boolean default("true") +# page_id :integer +# +# Indexes +# +# index_plugins_surveys_on_page_id (page_id) # FactoryBot.define do diff --git a/spec/factories/plugins_thermometers.rb b/spec/factories/plugins_thermometers.rb index 55f34dbff..bf933fa6e 100644 --- a/spec/factories/plugins_thermometers.rb +++ b/spec/factories/plugins_thermometers.rb @@ -5,13 +5,22 @@ # Table name: plugins_thermometers # # id :integer not null, primary key -# title :string +# active :boolean default(FALSE) # offset :integer -# page_id :integer -# active :boolean default("false") +# ref :string +# title :string +# type :string default("ActionsThermometer"), not null # created_at :datetime not null # updated_at :datetime not null -# ref :string +# page_id :integer +# +# Indexes +# +# index_plugins_thermometers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/registered_email_addresses.rb b/spec/factories/registered_email_addresses.rb index f8c9f93dc..b768be78e 100644 --- a/spec/factories/registered_email_addresses.rb +++ b/spec/factories/registered_email_addresses.rb @@ -2,7 +2,7 @@ # # Table name: registered_email_addresses # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # email :string # name :string # diff --git a/spec/factories/registered_target_endpoints.rb b/spec/factories/registered_target_endpoints.rb index c27b2fae5..3b5b350b3 100644 --- a/spec/factories/registered_target_endpoints.rb +++ b/spec/factories/registered_target_endpoints.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: registered_target_endpoints +# +# id :bigint(8) not null, primary key +# description :text +# name :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# + FactoryBot.define do factory :registered_target_endpoint do url { 'MyString' } diff --git a/spec/factories/share_buttons.rb b/spec/factories/share_buttons.rb index 34a1b993d..2c413acc1 100644 --- a/spec/factories/share_buttons.rb +++ b/spec/factories/share_buttons.rb @@ -4,16 +4,20 @@ # # Table name: share_buttons # -# id :integer not null, primary key -# title :string -# url :string -# created_at :datetime not null -# updated_at :datetime not null -# sp_id :string -# page_id :integer -# share_type :string +# id :integer not null, primary key +# analytics :text # share_button_html :string -# analytics :text +# share_type :string +# title :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# page_id :integer +# sp_id :string +# +# Indexes +# +# index_share_buttons_on_page_id (page_id) # FactoryBot.define do diff --git a/spec/factories/share_emails.rb b/spec/factories/share_emails.rb index 6bd2745e2..3d9ef1776 100644 --- a/spec/factories/share_emails.rb +++ b/spec/factories/share_emails.rb @@ -5,13 +5,21 @@ # Table name: share_emails # # id :integer not null, primary key -# subject :string # body :text -# page_id :integer -# sp_id :string -# button_id :integer +# subject :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# page_id :integer +# sp_id :string +# +# Indexes +# +# index_share_emails_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/share_facebooks.rb b/spec/factories/share_facebooks.rb index c16f804bd..d451c6cfc 100644 --- a/spec/factories/share_facebooks.rb +++ b/spec/factories/share_facebooks.rb @@ -5,17 +5,27 @@ # Table name: share_facebooks # # id :integer not null, primary key -# title :string +# click_count :integer # description :text # image :string -# button_id :integer +# share_count :integer +# title :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# image_id :integer # page_id :integer -# share_count :integer -# click_count :integer # sp_id :string -# image_id :integer +# +# Indexes +# +# index_share_facebooks_on_button_id (button_id) +# index_share_facebooks_on_image_id (image_id) +# index_share_facebooks_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (image_id => images.id) # FactoryBot.define do diff --git a/spec/factories/share_twitters.rb b/spec/factories/share_twitters.rb index 260737742..b76fd3300 100644 --- a/spec/factories/share_twitters.rb +++ b/spec/factories/share_twitters.rb @@ -5,13 +5,21 @@ # Table name: share_twitters # # id :integer not null, primary key -# sp_id :integer -# page_id :integer -# title :string # description :string -# button_id :integer +# title :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# page_id :integer +# sp_id :integer +# +# Indexes +# +# index_share_twitters_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # FactoryBot.define do diff --git a/spec/factories/share_whatsapps.rb b/spec/factories/share_whatsapps.rb index 1ba86ac71..fee50fa6e 100644 --- a/spec/factories/share_whatsapps.rb +++ b/spec/factories/share_whatsapps.rb @@ -4,14 +4,23 @@ # # Table name: share_whatsapps # -# id :integer not null, primary key -# page_id :integer -# text :string -# button_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# click_count :integer -# conversion_count :integer +# id :bigint(8) not null, primary key +# click_count :integer default(0), not null +# conversion_count :integer default(0), not null +# text :string +# created_at :datetime not null +# updated_at :datetime not null +# button_id :integer +# page_id :bigint(8) +# +# Indexes +# +# index_share_whatsapps_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) +# FactoryBot.define do factory :share_whatsapp, class: 'Share::Whatsapp' do diff --git a/spec/factories/uris.rb b/spec/factories/uris.rb index e86b1c902..34e04d974 100644 --- a/spec/factories/uris.rb +++ b/spec/factories/uris.rb @@ -7,9 +7,17 @@ # id :integer not null, primary key # domain :string # path :string -# page_id :integer # created_at :datetime not null # updated_at :datetime not null +# page_id :integer +# +# Indexes +# +# index_uris_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # FactoryBot.define do 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/braintree/webhook_handler_spec.rb b/spec/lib/payment_processor/braintree/webhook_handler_spec.rb index 295bb435f..c05f6ff56 100644 --- a/spec/lib/payment_processor/braintree/webhook_handler_spec.rb +++ b/spec/lib/payment_processor/braintree/webhook_handler_spec.rb @@ -56,9 +56,7 @@ def notification_faker(type, object_id) success: 1, status: 'completed', amount: /\A\d+[.]\d+\z/, - # We generally use the payment processor ID from the last transaction on the subscription, - # however in the test webhook notification supplied by webhook, the ID on that transaction is nil. - trans_id: nil + trans_id: 'subscription_id' } } @@ -146,10 +144,8 @@ def notification_faker(type, object_id) recurring_id: 'subscription_id', success: 0, status: 'failed', - amount: '0.0', - # We generally use the payment processor ID from the last transaction on the subscription, - # however in the test webhook notification supplied by webhook, the ID on that transaction is nil. - trans_id: nil + amount: /\A\d+[.]\d+\z/, + trans_id: 'subscription_id' } } expect(ChampaignQueue).to receive(:push).with( 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_spec.rb b/spec/models/action_spec.rb index 53e7df3b0..8000f176f 100644 --- a/spec/models/action_spec.rb +++ b/spec/models/action_spec.rb @@ -5,17 +5,27 @@ # Table name: actions # # id :integer not null, primary key -# page_id :integer -# member_id :integer -# link :string # created_user :boolean +# donation :boolean default(FALSE) +# form_data :jsonb +# link :string +# publish_status :integer default("default"), not null +# subscribed_member :boolean default(TRUE) # subscribed_user :boolean # created_at :datetime not null # updated_at :datetime not null -# form_data :jsonb default("{}") -# subscribed_member :boolean default("true") -# donation :boolean default("false") -# publish_status :integer default("0"), not null +# member_id :integer +# page_id :integer +# +# Indexes +# +# index_actions_on_member_id (member_id) +# index_actions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) +# fk_rails_... (page_id => pages.id) # require 'rails_helper' 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/call_spec.rb b/spec/models/call_spec.rb index 517b8249f..ad3f231ab 100644 --- a/spec/models/call_spec.rb +++ b/spec/models/call_spec.rb @@ -5,17 +5,21 @@ # Table name: calls # # id :integer not null, primary key -# page_id :integer -# member_id :integer +# member_call_events :json is an Array # member_phone_number :string +# status :integer default("unstarted") +# target :json +# target_call_info :jsonb not null +# twilio_error_code :integer # created_at :datetime # updated_at :datetime -# target_call_info :jsonb default("{}"), not null -# member_call_events :json default("{}"), is an Array -# twilio_error_code :integer -# target :json -# status :integer default("0") # action_id :integer +# member_id :integer +# page_id :integer +# +# Indexes +# +# index_calls_on_target_call_info (target_call_info) USING gin # require 'rails_helper' diff --git a/spec/models/donation_band_spec.rb b/spec/models/donation_band_spec.rb index 79c0e3319..69e9ec9a0 100644 --- a/spec/models/donation_band_spec.rb +++ b/spec/models/donation_band_spec.rb @@ -5,8 +5,8 @@ # Table name: donation_bands # # id :integer not null, primary key +# amounts :integer default([]), is an Array # name :string -# amounts :integer default("{}"), is an Array # created_at :datetime not null # updated_at :datetime not null # diff --git a/spec/models/form_element_spec.rb b/spec/models/form_element_spec.rb index 39f429c55..25ce9de87 100644 --- a/spec/models/form_element_spec.rb +++ b/spec/models/form_element_spec.rb @@ -5,18 +5,26 @@ # Table name: form_elements # # id :integer not null, primary key -# form_id :integer -# label :string +# choices :jsonb # data_type :string # default_value :string +# display_mode :integer default("all_members") +# label :string +# name :string +# position :integer default(0), not null # required :boolean # visible :boolean # created_at :datetime not null # updated_at :datetime not null -# name :string -# position :integer default("0"), not null -# choices :jsonb default("[]") -# display_mode :integer default("0") +# form_id :integer +# +# Indexes +# +# index_form_elements_on_form_id (form_id) +# +# Foreign Keys +# +# fk_rails_... (form_id => forms.id) # require 'rails_helper' diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 434adfac2..340b7b203 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -5,15 +5,19 @@ # Table name: forms # # id :integer not null, primary key -# name :string # description :string +# formable_type :string +# master :boolean default(FALSE) +# name :string +# position :integer default(0), not null +# visible :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null -# visible :boolean default("false") -# master :boolean default("false") # formable_id :integer -# formable_type :string -# position :integer default("0"), not null +# +# Indexes +# +# index_forms_on_formable_type_and_formable_id (formable_type,formable_id) # require 'rails_helper' diff --git a/spec/models/image_spec.rb b/spec/models/image_spec.rb index 4504535da..0d87b6edb 100644 --- a/spec/models/image_spec.rb +++ b/spec/models/image_spec.rb @@ -1,17 +1,22 @@ # frozen_string_literal: true + # == Schema Information # # Table name: images # # id :integer not null, primary key -# content_file_name :string # content_content_type :string -# content_file_size :integer +# content_file_name :string +# content_file_size :bigint(8) # content_updated_at :datetime # created_at :datetime # updated_at :datetime # page_id :integer # +# Indexes +# +# index_images_on_page_id (page_id) +# describe Image do it { should have_attached_file(:content) } 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/link_spec.rb b/spec/models/link_spec.rb index 3ae938e96..3d5a3b8a3 100644 --- a/spec/models/link_spec.rb +++ b/spec/models/link_spec.rb @@ -5,13 +5,21 @@ # Table name: links # # id :integer not null, primary key -# url :string -# title :string # date :string # source :string -# page_id :integer +# title :string +# url :string # created_at :datetime not null # updated_at :datetime not null +# page_id :integer +# +# Indexes +# +# index_links_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/liquid_layout_spec.rb b/spec/models/liquid_layout_spec.rb index 9f6a93ade..e5419509d 100644 --- a/spec/models/liquid_layout_spec.rb +++ b/spec/models/liquid_layout_spec.rb @@ -5,15 +5,15 @@ # Table name: liquid_layouts # # id :integer not null, primary key -# title :string # content :text +# description :text +# experimental :boolean default(FALSE), not null +# post_action_layout :boolean +# primary_layout :boolean +# title :string # created_at :datetime not null # updated_at :datetime not null -# description :text -# experimental :boolean default("false"), not null # default_follow_up_layout_id :integer -# primary_layout :boolean -# post_action_layout :boolean # require 'rails_helper' diff --git a/spec/models/member_authentication_spec.rb b/spec/models/member_authentication_spec.rb index 31508b3c9..0172a7572 100644 --- a/spec/models/member_authentication_spec.rb +++ b/spec/models/member_authentication_spec.rb @@ -1,20 +1,31 @@ # frozen_string_literal: true + # == Schema Information # # Table name: member_authentications # # id :integer not null, primary key -# member_id :integer -# password_digest :string not null -# facebook_uid :string +# confirmed_at :datetime # facebook_token :string # facebook_token_expiry :datetime -# created_at :datetime not null -# updated_at :datetime not null -# token :string -# confirmed_at :datetime +# facebook_uid :string +# password_digest :string not null # reset_password_sent_at :datetime # reset_password_token :string +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# member_id :integer +# +# Indexes +# +# index_member_authentications_on_facebook_uid (facebook_uid) +# index_member_authentications_on_member_id (member_id) +# index_member_authentications_on_reset_password_token (reset_password_token) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) # require 'rails_helper' diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index e33da5db2..0c932d69e 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -5,22 +5,28 @@ # Table name: members # # id :integer not null, primary key -# email :string +# address1 :string +# address2 :string +# city :string +# consented :boolean +# consented_updated_at :datetime # country :string +# donor_status :integer default("nondonor"), not null +# email :string # first_name :string # last_name :string -# city :string +# more :jsonb # postal :string # title :string -# address1 :string -# address2 :string # created_at :datetime not null # updated_at :datetime not null # actionkit_user_id :string -# donor_status :integer default("0"), not null -# more :jsonb -# consented_updated_at :datetime -# consented :boolean default("false") +# +# Indexes +# +# index_members_on_actionkit_user_id (actionkit_user_id) +# index_members_on_email (email) +# index_members_on_email_and_id (email,id) # require 'rails_helper' diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb index 15a57275c..2ba7080ab 100644 --- a/spec/models/page_spec.rb +++ b/spec/models/page_spec.rb @@ -5,37 +5,54 @@ # Table name: pages # # id :integer not null, primary key -# language_id :integer -# campaign_id :integer -# title :string not null +# action_count :integer default(0) +# ak_donation_resource_uri :string +# ak_petition_resource_uri :string +# allow_duplicate_actions :boolean default(FALSE) +# canonical_url :string +# compiled_html :text +# content :text default("") +# enforce_styles :boolean default(FALSE), not null +# featured :boolean default(FALSE) +# follow_up_plan :integer default("with_liquid"), not null +# fundraising_goal :decimal(10, 2) default(0.0) +# javascript :text +# messages :text +# meta_description :string +# meta_tags :string +# notes :text +# optimizely_status :integer default("optimizely_enabled"), not null +# publish_actions :integer default("secure"), not null +# publish_status :integer default("unpublished"), not null # slug :string not null +# status :string default("pending") +# title :string not null +# total_donations :decimal(10, 2) default(0.0) # created_at :datetime # updated_at :datetime -# compiled_html :text -# status :string default("pending") -# messages :text -# content :text default("") -# featured :boolean default("false") -# liquid_layout_id :integer +# campaign_id :integer # follow_up_liquid_layout_id :integer -# action_count :integer default("0") -# primary_image_id :integer -# ak_petition_resource_uri :string -# ak_donation_resource_uri :string -# follow_up_plan :integer default("0"), not null # follow_up_page_id :integer -# javascript :text -# publish_status :integer default("1"), not null -# optimizely_status :integer default("0"), not null -# canonical_url :string -# allow_duplicate_actions :boolean default("false") -# enforce_styles :boolean default("false"), not null -# notes :text -# publish_actions :integer default("0"), not null -# meta_tags :string -# meta_description :string -# total_donations :double default("0") -# fundraising_goal :double default("0") +# language_id :integer +# liquid_layout_id :integer +# primary_image_id :integer +# +# Indexes +# +# index_pages_on_campaign_id (campaign_id) +# index_pages_on_follow_up_liquid_layout_id (follow_up_liquid_layout_id) +# index_pages_on_follow_up_page_id (follow_up_page_id) +# index_pages_on_liquid_layout_id (liquid_layout_id) +# index_pages_on_primary_image_id (primary_image_id) +# index_pages_on_publish_status (publish_status) +# +# Foreign Keys +# +# fk_rails_... (campaign_id => campaigns.id) +# fk_rails_... (follow_up_liquid_layout_id => liquid_layouts.id) +# fk_rails_... (language_id => languages.id) +# fk_rails_... (liquid_layout_id => liquid_layouts.id) +# fk_rails_... (primary_image_id => images.id) # require 'rails_helper' diff --git a/spec/models/payment/braintree/customer_spec.rb b/spec/models/payment/braintree/customer_spec.rb index b4c81c813..111ad0907 100644 --- a/spec/models/payment/braintree/customer_spec.rb +++ b/spec/models/payment/braintree/customer_spec.rb @@ -1,24 +1,33 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_braintree_customers # # id :integer not null, primary key -# card_type :string # card_bin :string -# cardholder_name :string # card_debit :string # card_last_4 :string -# card_vault_token :string +# card_type :string # card_unique_number_identifier :string +# card_vault_token :string +# cardholder_name :string # email :string # first_name :string # last_name :string -# customer_id :string # created_at :datetime not null # updated_at :datetime not null +# customer_id :string # member_id :integer # +# Indexes +# +# index_payment_braintree_customers_on_member_id (member_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) +# require 'rails_helper' diff --git a/spec/models/payment/braintree/subscription_spec.rb b/spec/models/payment/braintree/subscription_spec.rb index ac0b0671c..31e724cc6 100644 --- a/spec/models/payment/braintree/subscription_spec.rb +++ b/spec/models/payment/braintree/subscription_spec.rb @@ -5,18 +5,28 @@ # Table name: payment_braintree_subscriptions # # id :integer not null, primary key -# subscription_id :string -# merchant_account_id :string -# created_at :datetime not null -# updated_at :datetime not null -# page_id :integer # amount :decimal(10, 2) +# billing_day_of_month :integer +# cancelled_at :datetime # currency :string +# created_at :datetime not null +# updated_at :datetime not null # action_id :integer -# cancelled_at :datetime # customer_id :string -# billing_day_of_month :integer +# merchant_account_id :string +# page_id :integer # payment_method_id :integer +# subscription_id :string +# +# Indexes +# +# index_payment_braintree_subscriptions_on_action_id (action_id) +# index_payment_braintree_subscriptions_on_page_id (page_id) +# index_payment_braintree_subscriptions_on_subscription_id (subscription_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/payment/braintree/transaction_spec.rb b/spec/models/payment/braintree/transaction_spec.rb index dc0001308..574dac04e 100644 --- a/spec/models/payment/braintree/transaction_spec.rb +++ b/spec/models/payment/braintree/transaction_spec.rb @@ -5,22 +5,32 @@ # Table name: payment_braintree_transactions # # id :integer not null, primary key -# transaction_id :string -# transaction_type :string -# transaction_created_at :datetime +# amount :decimal(10, 2) +# currency :string +# payment_instrument_type :string # payment_method_token :string -# customer_id :string +# processor_response_code :string +# status :integer +# transaction_created_at :datetime +# transaction_type :string # created_at :datetime not null # updated_at :datetime not null +# customer_id :string # merchant_account_id :string -# currency :string # page_id :integer -# payment_instrument_type :string -# status :integer -# amount :decimal(10, 2) -# processor_response_code :string # payment_method_id :integer # subscription_id :integer +# transaction_id :string +# +# Indexes +# +# braintree_payment_method_index (payment_method_id) +# braintree_transaction_subscription (subscription_id) +# index_payment_braintree_transactions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' 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/payment/go_cardless/customer_spec.rb b/spec/models/payment/go_cardless/customer_spec.rb index 352274f19..e780fe875 100644 --- a/spec/models/payment/go_cardless/customer_spec.rb +++ b/spec/models/payment/go_cardless/customer_spec.rb @@ -1,19 +1,28 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_customers # # id :integer not null, primary key -# go_cardless_id :string +# country_code :string # email :string -# given_name :string # family_name :string -# postal_code :string -# country_code :string +# given_name :string # language :string -# member_id :integer +# postal_code :string # created_at :datetime not null # updated_at :datetime not null +# go_cardless_id :string +# member_id :integer +# +# Indexes +# +# index_payment_go_cardless_customers_on_member_id (member_id) +# +# Foreign Keys +# +# fk_rails_... (member_id => members.id) # require 'rails_helper' diff --git a/spec/models/payment/go_cardless/payment_method_spec.rb b/spec/models/payment/go_cardless/payment_method_spec.rb index f7c154ea6..219432217 100644 --- a/spec/models/payment/go_cardless/payment_method_spec.rb +++ b/spec/models/payment/go_cardless/payment_method_spec.rb @@ -1,18 +1,27 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_payment_methods # # id :integer not null, primary key -# go_cardless_id :string +# aasm_state :string +# cancelled_at :datetime +# next_possible_charge_date :date # reference :string # scheme :string -# next_possible_charge_date :date -# customer_id :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string -# cancelled_at :datetime +# customer_id :integer +# go_cardless_id :string +# +# Indexes +# +# index_payment_go_cardless_payment_methods_on_customer_id (customer_id) +# +# Foreign Keys +# +# fk_rails_... (customer_id => payment_go_cardless_customers.id) # require 'rails_helper' diff --git a/spec/models/payment/go_cardless/subscription_spec.rb b/spec/models/payment/go_cardless/subscription_spec.rb index 068754fa0..b6966f9ab 100644 --- a/spec/models/payment/go_cardless/subscription_spec.rb +++ b/spec/models/payment/go_cardless/subscription_spec.rb @@ -5,20 +5,34 @@ # Table name: payment_go_cardless_subscriptions # # id :integer not null, primary key -# go_cardless_id :string +# aasm_state :string # amount :decimal(, ) +# cancelled_at :datetime # currency :string -# status :integer # name :string # payment_reference :string -# page_id :integer -# action_id :integer -# payment_method_id :integer -# customer_id :integer +# status :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string -# cancelled_at :datetime +# action_id :integer +# customer_id :integer +# go_cardless_id :string +# page_id :integer +# payment_method_id :integer +# +# Indexes +# +# index_payment_go_cardless_subscriptions_on_action_id (action_id) +# index_payment_go_cardless_subscriptions_on_customer_id (customer_id) +# index_payment_go_cardless_subscriptions_on_page_id (page_id) +# index_payment_go_cardless_subscriptions_on_payment_method_id (payment_method_id) +# +# Foreign Keys +# +# fk_rails_... (action_id => actions.id) +# fk_rails_... (customer_id => payment_go_cardless_customers.id) +# fk_rails_... (page_id => pages.id) +# fk_rails_... (payment_method_id => payment_go_cardless_payment_methods.id) # require 'rails_helper' diff --git a/spec/models/payment/go_cardless/transaction_spec.rb b/spec/models/payment/go_cardless/transaction_spec.rb index ca77d29e6..f1745109e 100644 --- a/spec/models/payment/go_cardless/transaction_spec.rb +++ b/spec/models/payment/go_cardless/transaction_spec.rb @@ -1,25 +1,39 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_transactions # # id :integer not null, primary key -# go_cardless_id :string -# charge_date :date +# aasm_state :string # amount :decimal(, ) -# description :string +# amount_refunded :decimal(, ) +# charge_date :date # currency :string -# status :integer +# description :string # reference :string -# amount_refunded :decimal(, ) -# page_id :integer -# payment_method_id :integer -# customer_id :integer +# status :integer # created_at :datetime not null # updated_at :datetime not null -# aasm_state :string +# customer_id :integer +# go_cardless_id :string +# page_id :integer +# payment_method_id :integer # subscription_id :integer # +# Indexes +# +# go_cardless_transaction_subscription (subscription_id) +# index_payment_go_cardless_transactions_on_customer_id (customer_id) +# index_payment_go_cardless_transactions_on_page_id (page_id) +# index_payment_go_cardless_transactions_on_payment_method_id (payment_method_id) +# +# Foreign Keys +# +# fk_rails_... (customer_id => payment_go_cardless_customers.id) +# fk_rails_... (page_id => pages.id) +# fk_rails_... (payment_method_id => payment_go_cardless_payment_methods.id) +# require 'rails_helper' diff --git a/spec/models/payment/go_cardless/webhook_event_spec.rb b/spec/models/payment/go_cardless/webhook_event_spec.rb index 97e05e905..376cead7e 100644 --- a/spec/models/payment/go_cardless/webhook_event_spec.rb +++ b/spec/models/payment/go_cardless/webhook_event_spec.rb @@ -1,17 +1,22 @@ # frozen_string_literal: true + # == Schema Information # # Table name: payment_go_cardless_webhook_events # # id :integer not null, primary key -# event_id :string -# resource_type :string # action :string # body :text +# resource_type :string # created_at :datetime not null # updated_at :datetime not null +# event_id :string # resource_id :string # +# Indexes +# +# index_payment_go_cardless_webhook_events_on_event_id (event_id) +# require 'rails_helper' diff --git a/spec/models/pending_action_spec.rb b/spec/models/pending_action_spec.rb index 6eb6138e9..1e3464e03 100644 --- a/spec/models/pending_action_spec.rb +++ b/spec/models/pending_action_spec.rb @@ -1,5 +1,31 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: pending_actions +# +# id :bigint(8) not null, primary key +# bounced_at :datetime +# clicked :string default([]), is an Array +# complaint :boolean +# confirmed_at :datetime +# consented :boolean +# data :jsonb +# delivered_at :datetime +# email :string +# email_count :integer default(0) +# emailed_at :datetime +# opened_at :datetime +# token :string +# created_at :datetime not null +# updated_at :datetime not null +# page_id :bigint(8) +# +# Indexes +# +# index_pending_actions_on_page_id (page_id) +# + require 'rails_helper' describe PendingAction do diff --git a/spec/models/plugins/actions_thermometer_spec.rb b/spec/models/plugins/actions_thermometer_spec.rb index e9e9fa10a..72c75a215 100644 --- a/spec/models/plugins/actions_thermometer_spec.rb +++ b/spec/models/plugins/actions_thermometer_spec.rb @@ -5,14 +5,22 @@ # Table name: plugins_thermometers # # id :integer not null, primary key -# type :string not null -# title :string +# active :boolean default(FALSE) # offset :integer -# page_id :integer -# active :boolean default("false") +# ref :string +# title :string +# type :string default("ActionsThermometer"), not null # created_at :datetime not null # updated_at :datetime not null -# ref :string +# page_id :integer +# +# Indexes +# +# index_plugins_thermometers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/plugins/call_tool_spec.rb b/spec/models/plugins/call_tool_spec.rb index 8cc6c23cd..46768ecd3 100644 --- a/spec/models/plugins/call_tool_spec.rb +++ b/spec/models/plugins/call_tool_spec.rb @@ -5,25 +5,25 @@ # Table name: plugins_call_tools # # id :integer not null, primary key -# page_id :integer # active :boolean -# ref :string -# created_at :datetime -# updated_at :datetime -# title :string -# targets :json default("{}"), is an Array -# sound_clip_file_name :string -# sound_clip_content_type :string -# sound_clip_file_size :integer -# sound_clip_updated_at :datetime # description :text -# menu_sound_clip_file_name :string # menu_sound_clip_content_type :string -# menu_sound_clip_file_size :integer +# menu_sound_clip_file_name :string +# menu_sound_clip_file_size :bigint(8) # menu_sound_clip_updated_at :datetime +# ref :string # restricted_country_code :string +# sound_clip_content_type :string +# sound_clip_file_name :string +# sound_clip_file_size :bigint(8) +# sound_clip_updated_at :datetime +# target_by_attributes :string default([]), is an Array +# targets :json is an Array +# title :string +# created_at :datetime +# updated_at :datetime # caller_phone_number_id :integer -# target_by_attributes :string default("{}"), is an Array +# page_id :integer # require 'rails_helper' diff --git a/spec/models/plugins/fundraiser_spec.rb b/spec/models/plugins/fundraiser_spec.rb index 65c4b997f..15fdd477c 100644 --- a/spec/models/plugins/fundraiser_spec.rb +++ b/spec/models/plugins/fundraiser_spec.rb @@ -5,16 +5,28 @@ # Table name: plugins_fundraisers # # id :integer not null, primary key -# title :string +# active :boolean default(FALSE) +# preselect_amount :boolean default(FALSE) +# recurring_default :integer default("one_off"), not null # ref :string -# page_id :integer -# active :boolean default("false") +# title :string # created_at :datetime not null # updated_at :datetime not null -# form_id :integer # donation_band_id :integer -# recurring_default :integer default("0"), not null -# preselect_amount :boolean default("false") +# form_id :integer +# page_id :integer +# +# Indexes +# +# index_plugins_fundraisers_on_donation_band_id (donation_band_id) +# index_plugins_fundraisers_on_form_id (form_id) +# index_plugins_fundraisers_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (donation_band_id => donation_bands.id) +# fk_rails_... (form_id => forms.id) +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/plugins/petition_spec.rb b/spec/models/plugins/petition_spec.rb index d97e7aa8d..a93c73aa1 100644 --- a/spec/models/plugins/petition_spec.rb +++ b/spec/models/plugins/petition_spec.rb @@ -5,15 +5,25 @@ # Table name: plugins_petitions # # id :integer not null, primary key -# page_id :integer -# active :boolean default("false") -# form_id :integer -# created_at :datetime not null -# updated_at :datetime not null +# active :boolean default(FALSE) +# cta :string # description :text # ref :string # target :string -# cta :string +# created_at :datetime not null +# updated_at :datetime not null +# form_id :integer +# page_id :integer +# +# Indexes +# +# index_plugins_petitions_on_form_id (form_id) +# index_plugins_petitions_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (form_id => forms.id) +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/plugins/survey_spec.rb b/spec/models/plugins/survey_spec.rb index dba6476b6..b281c2f9c 100644 --- a/spec/models/plugins/survey_spec.rb +++ b/spec/models/plugins/survey_spec.rb @@ -5,12 +5,16 @@ # Table name: plugins_surveys # # id :integer not null, primary key -# page_id :integer -# active :boolean default("false") +# active :boolean default(FALSE) +# auto_advance :boolean default(TRUE) # ref :string # created_at :datetime # updated_at :datetime -# auto_advance :boolean default("true") +# page_id :integer +# +# Indexes +# +# index_plugins_surveys_on_page_id (page_id) # require 'rails_helper' 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/models/registered_target_endpoint_spec.rb b/spec/models/registered_target_endpoint_spec.rb index c2d4f5846..16911221c 100644 --- a/spec/models/registered_target_endpoint_spec.rb +++ b/spec/models/registered_target_endpoint_spec.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: registered_target_endpoints +# +# id :bigint(8) not null, primary key +# description :text +# name :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# + require 'rails_helper' RSpec.describe RegisteredTargetEndpoint, type: :model do diff --git a/spec/models/share/button_spec.rb b/spec/models/share/button_spec.rb index 1b2dcea60..47f984a1f 100644 --- a/spec/models/share/button_spec.rb +++ b/spec/models/share/button_spec.rb @@ -4,16 +4,20 @@ # # Table name: share_buttons # -# id :integer not null, primary key -# title :string -# url :string -# created_at :datetime not null -# updated_at :datetime not null -# sp_id :string -# page_id :integer -# share_type :string +# id :integer not null, primary key +# analytics :text # share_button_html :string -# analytics :text +# share_type :string +# title :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# page_id :integer +# sp_id :string +# +# Indexes +# +# index_share_buttons_on_page_id (page_id) # require 'rails_helper' diff --git a/spec/models/share/email_spec.rb b/spec/models/share/email_spec.rb index 29824de0b..f5ed8ad48 100644 --- a/spec/models/share/email_spec.rb +++ b/spec/models/share/email_spec.rb @@ -5,13 +5,21 @@ # Table name: share_emails # # id :integer not null, primary key -# subject :string # body :text -# page_id :integer -# sp_id :string -# button_id :integer +# subject :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# page_id :integer +# sp_id :string +# +# Indexes +# +# index_share_emails_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/share/facebook_spec.rb b/spec/models/share/facebook_spec.rb index 89a6f1fd3..e9f0f554c 100644 --- a/spec/models/share/facebook_spec.rb +++ b/spec/models/share/facebook_spec.rb @@ -5,17 +5,27 @@ # Table name: share_facebooks # # id :integer not null, primary key -# title :string +# click_count :integer # description :text # image :string -# button_id :integer +# share_count :integer +# title :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# image_id :integer # page_id :integer -# share_count :integer -# click_count :integer # sp_id :string -# image_id :integer +# +# Indexes +# +# index_share_facebooks_on_button_id (button_id) +# index_share_facebooks_on_image_id (image_id) +# index_share_facebooks_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (image_id => images.id) # require 'rails_helper' diff --git a/spec/models/share/twitter_spec.rb b/spec/models/share/twitter_spec.rb index 633b96875..4f72088ed 100644 --- a/spec/models/share/twitter_spec.rb +++ b/spec/models/share/twitter_spec.rb @@ -5,13 +5,21 @@ # Table name: share_twitters # # id :integer not null, primary key -# sp_id :integer -# page_id :integer -# title :string # description :string -# button_id :integer +# title :string # created_at :datetime not null # updated_at :datetime not null +# button_id :integer +# page_id :integer +# sp_id :integer +# +# Indexes +# +# index_share_twitters_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' diff --git a/spec/models/share/whatsapp_spec.rb b/spec/models/share/whatsapp_spec.rb index d69790289..358a7fbe5 100644 --- a/spec/models/share/whatsapp_spec.rb +++ b/spec/models/share/whatsapp_spec.rb @@ -4,14 +4,23 @@ # # Table name: share_whatsapps # -# id :integer not null, primary key -# page_id :integer -# text :string -# button_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# click_count :integer -# conversion_count :integer +# id :bigint(8) not null, primary key +# click_count :integer default(0), not null +# conversion_count :integer default(0), not null +# text :string +# created_at :datetime not null +# updated_at :datetime not null +# button_id :integer +# page_id :bigint(8) +# +# Indexes +# +# index_share_whatsapps_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) +# require 'rails_helper' diff --git a/spec/models/uri_spec.rb b/spec/models/uri_spec.rb index 91e56175d..31cd7100f 100644 --- a/spec/models/uri_spec.rb +++ b/spec/models/uri_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: uris @@ -6,9 +7,17 @@ # id :integer not null, primary key # domain :string # path :string -# page_id :integer # created_at :datetime not null # updated_at :datetime not null +# page_id :integer +# +# Indexes +# +# index_uris_on_page_id (page_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => pages.id) # require 'rails_helper' 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/braintree/webhook_spec.rb b/spec/requests/api/braintree/webhook_spec.rb index ced55744d..562f36104 100644 --- a/spec/requests/api/braintree/webhook_spec.rb +++ b/spec/requests/api/braintree/webhook_spec.rb @@ -106,9 +106,7 @@ success: 1, status: 'completed', amount: /\A\d+[.]\d+\z/, - # We generally use the payment processor ID from the last transaction on the subscription, - # however in the test webhook notification supplied by webhook, the ID on that transaction is nil. - trans_id: nil + trans_id: Payment::Braintree::Subscription.last.subscription_id } } @@ -177,9 +175,7 @@ success: 1, status: 'completed', amount: /\A\d+[.]\d+\z/, - # We generally use the payment processor ID from the last transaction on the subscription, - # however in the test webhook notification supplied by webhook, the ID on that transaction is nil. - trans_id: nil + trans_id: Payment::Braintree::Subscription.last.subscription_id } } 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/order_by_search_spec.rb b/spec/services/search/page_searcher/single_criterion_search/order_by_search_spec.rb index 032baf91f..d6e1e6525 100644 --- a/spec/services/search/page_searcher/single_criterion_search/order_by_search_spec.rb +++ b/spec/services/search/page_searcher/single_criterion_search/order_by_search_spec.rb @@ -34,14 +34,14 @@ end it 'orders searches based on publish_status' do - expect(page_searcher.new(order_by: %i[publish_status asc]).search) - .to eq(Page.all.order(publish_status: :asc)) + expect(page_searcher.new(order_by: %i[publish_status asc]).search.collect(&:publish_status)) + .to eq(Page.all.order(publish_status: :asc).collect(&:publish_status)) - expect(page_searcher.new(order_by: %i[publish_status desc]).search) - .to eq(Page.all.order(publish_status: :desc)) + expect(page_searcher.new(order_by: %i[publish_status desc]).search.collect(&:publish_status)) + .to eq(Page.all.order(publish_status: :desc).collect(&:publish_status)) - expect(page_searcher.new(order_by: :publish_status).search) - .to eq(Page.all.order(publish_status: :asc)) + expect(page_searcher.new(order_by: :publish_status).search.collect(&:publish_status)) + .to eq(Page.all.order(publish_status: :asc).collect(&:publish_status)) end it 'ignores invalid order_by_queries' do 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