From 49fa422400761a55fb4f95710a8852781cb0f6fd Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 3 Feb 2021 11:23:17 -0800 Subject: [PATCH 001/113] Replace poltergeist with apparition; fix failing tests --- .travis.yml | 2 +- Gemfile | 3 +- Gemfile.lock | 11 ++-- .../action_pages/tweet_action_spec.rb | 4 -- spec/features/admin/action_creation_spec.rb | 58 +++++++++---------- spec/features/users_spec.rb | 40 ------------- spec/rails_helper.rb | 32 +++++----- spec/support/feature_helpers.rb | 7 ++- 8 files changed, 56 insertions(+), 101 deletions(-) delete mode 100644 spec/features/users_spec.rb diff --git a/.travis.yml b/.travis.yml index b4a0ed27c..8ffc83c25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ before_script: - npm install - cp config/database.yml.travis config/database.yml - psql -c 'create database travis_ci_test;' -U postgres - - RAILS_ENV=test bundle exec rails webdrivers:chromedriver:update + - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost & script: - bundle exec rubocop - $(npm bin)/sass-lint -vq diff --git a/Gemfile b/Gemfile index e30d333e3..b18e97543 100644 --- a/Gemfile +++ b/Gemfile @@ -111,6 +111,7 @@ group :development do end group :test do + gem "apparition", "~> 0.6" gem "webmock", "~> 2" end @@ -120,13 +121,11 @@ group :development, :test do gem "cucumber-rails", "1.6.0", require: false gem "database_cleaner", "~> 1" gem "factory_girl_rails", "~> 4" - gem "poltergeist", "~> 1" gem "rails-controller-testing" gem "rspec-core", "~> 3" gem "rspec-rails", "~> 3" gem "rubocop", "0.52.0" gem "rubocop-github", "0.9.0" - gem "selenium-webdriver", "~> 3" gem "webdrivers", "~> 4" end diff --git a/Gemfile.lock b/Gemfile.lock index f70727cfc..17bbf4967 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,6 +69,9 @@ GEM safely_block (>= 0.1.1) user_agent_parser uuidtools + apparition (0.6.0) + capybara (~> 3.13, < 4) + websocket-driver (>= 0.6.5) arel (7.1.4) ast (2.4.0) autoprefixer-rails (9.5.1) @@ -122,7 +125,6 @@ GEM rake (< 13.0) chronic (0.10.2) climate_control (0.2.0) - cliver (0.3.2) cocoon (1.2.12) coderay (1.1.2) concurrent-ruby (1.1.5) @@ -275,10 +277,6 @@ GEM pg_search (2.1.7) activerecord (>= 4.2) activesupport (>= 4.2) - poltergeist (1.18.1) - capybara (>= 2.1, < 4) - cliver (~> 0.3.1) - websocket-driver (>= 0.2.0) powerpack (0.1.2) premailer (1.11.1) addressable @@ -484,6 +482,7 @@ DEPENDENCIES activerecord-session_store (~> 1) acts_as_paranoid! ahoy_matey (~> 1.6) + apparition (~> 0.6) aws-sdk (~> 2.3) aws-sdk-rails (~> 1) better_errors (~> 2) @@ -524,7 +523,6 @@ DEPENDENCIES paperclip (~> 5.2) pg (~> 1.1) pg_search - poltergeist (~> 1) premailer-rails (~> 1) puma (~> 3) rack-attack (~> 5) @@ -561,7 +559,6 @@ DEPENDENCIES sass-rails (~> 5.0) sdoc select2-rails - selenium-webdriver (~> 3) sentry-raven (~> 0.15) sprockets-image_compressor (~> 0) uglifier (>= 1.3.0) diff --git a/spec/features/action_pages/tweet_action_spec.rb b/spec/features/action_pages/tweet_action_spec.rb index a61ff43b8..7c504f65a 100644 --- a/spec/features/action_pages/tweet_action_spec.rb +++ b/spec/features/action_pages/tweet_action_spec.rb @@ -26,15 +26,11 @@ it "allows vistors to tweet at representatives" do visit action_page_path(tweet_action) - expect(page).not_to have_content("THANK YOU!") fill_in "street_address", with: "1630 Ravello Drive" fill_in "zipcode", with: "94109" click_on "Look up your reps" - - expect(page).to have_content("Default message") click_on "Tweet @sisko" - expect(page).to have_content("THANK YOU!") end end diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index ec9fc701e..08cb7e5d8 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -8,16 +8,16 @@ fill_in_basic_info(title: "Very Important Action", summary: "A summary", description: "A description") - click_on "Next" + next_section select_action_type("tweet") fill_in "Message", with: "A message" - click_on "Next" + next_section + + # skip banner selection + next_section - skip_image_selection fill_in_social_media - # Skip partners - click_on "Next" tempermental { click_button "Save" @@ -30,18 +30,18 @@ fill_in_basic_info(title: "Very Important Action", summary: "A summary", description: "A description") - click_on "Next" + next_section select_action_type("petition") fill_in_editor "#action_page_petition_attributes_description", with: "A petititon letter" fill_in "Goal", with: 1000 - click_on "Next" + next_section + + # skip banner selection + next_section - skip_image_selection fill_in_social_media - # Skip partners - click_on "Next" tempermental { click_button "Save" @@ -54,18 +54,18 @@ fill_in_basic_info(title: "Very Important Action", summary: "A summary", description: "A description") - click_on "Next" + next_section select_action_type("email") fill_in "To", with: "test@gmail.com" fill_in "Subject", with: "Subject" fill_in "Message", with: "An email" - click_on "Next" + next_section + + # skip banner selection + next_section - skip_image_selection fill_in_social_media - # Skip partners - click_on "Next" tempermental { click_button "Save" @@ -78,17 +78,17 @@ fill_in_basic_info(title: "Very Important Action", summary: "A summary", description: "A description") - click_on "Next" + next_section select_action_type("congress_message") fill_in "Subject", with: "Subject" fill_in "Message", with: "A message" - click_on "Next" + next_section + + # skip banner selection + next_section - skip_image_selection fill_in_social_media - # Skip partners - click_on "Next" tempermental { click_button "Save" @@ -101,17 +101,17 @@ fill_in_basic_info(title: "Very Important Action", summary: "A summary", description: "A description") - click_on "Next" + next_section select_action_type "call" fill_in_editor "#action_page_call_campaign_attributes_message", with: "Call script" - click_on "Next" + next_section + + # skip banner selection + next_section - skip_image_selection fill_in_social_media - # Skip partners - click_on "Next" tempermental { click_button "Save" @@ -126,17 +126,15 @@ def fill_in_basic_info(title:, summary:, description:) fill_in_select2 "#action_page_category_id", with: category.title end - def skip_image_selection + def next_section click_on "Next" - sleep 0.1 - click_on "Next" - sleep 0.1 + sleep 0.05 end def fill_in_social_media fill_in "Share Message", with: "Twitter message" fill_in "Title", with: "A social media title" - click_on "Next" + next_section end def select_action_type(type) diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb deleted file mode 100644 index 106598e70..000000000 --- a/spec/features/users_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "rails_helper" - -RSpec.describe "Tests about users", type: :feature do - before(:each) do - stub_civicrm - @user = FactoryGirl.create(:user) - end - - it "promoted users lose their old password and need a strong one" do - sign_in_user(@user) - - # Test that we can see that we're at the /account page fine - expect(page).to have_content("Personal information") - - # log user out - find("input[value='Logout']", match: :first).click - - #promote user to activist - @user.admin = true - @user.save - - # try to login and see prompt to add password - sign_in_user(@user) - expect(page).not_to have_content("Personal information") - - # try navigating anywhere else to make sure they can't get around it - visit "/admin/action_pages" - expect(page).to have_content("Your account has been flagged for importance") - - # Submit a strong password and move on like an adult - fill_in "Current Password", with: @user.password - fill_in "New Password", with: "P1" + @user.password - fill_in "Confirm New Password", with: "P1" + @user.password - click_button "Submit" - - # check that the password update nag screen is eliminated - visit "/account" - expect(page).to have_content("Personal information") - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9c8ec65d4..90ba63766 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,8 +5,7 @@ abort("The Rails environment is running in production mode!") if Rails.env.production? require "spec_helper" require "rspec/rails" -require "selenium/webdriver" -require "webdrivers" +require "capybara/apparition" # Add additional requires below this line. Rails is not loaded until this point! @@ -30,24 +29,25 @@ ActiveRecord::Migration.maintain_test_schema! -capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( - :loggingPrefs => { - browser: "ALL", - client: "ALL", - driver: "ALL", - server: "ALL" - }, - "chromeOptions" => { +apparition_opts = { + window_size: [1400, 900], + screen_size: [1920, 1090], + browser_options: { "w3c" => false, - "args" => ["headless", "disable-gpu", "--window-size=1400,900"].tap do |a| - a.push("no-sandbox") if ENV["TRAVIS"] - end + "args" => ["headless", "disable-gpu", "--window-size=1400,900"] } -) +} + +if ENV["TRAVIS"] + apparition_opts[:browser_options] = { + "remote-debugging-address" => "127.0.0.1", + "remote-debugging-port" => 9222 + } + apparition_opts[:remote] = true +end Capybara.register_driver :chrome_headless do |app| - Capybara::Selenium::Driver.new(app, browser: :chrome, - desired_capabilities: capabilities) + Capybara::Apparition::Driver.new(app, apparition_opts) end Capybara.server = :puma diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 2ae488dcf..4e7c8d7c2 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -7,13 +7,18 @@ def sign_in_user(user) click_button "Sign in" end + def sign_out_user(user) + find("#nav-modal-toggle").click + find("input[value='Logout']", visible: :all, match: :first).click + end + def disable_call_tool allow(CallTool).to receive(:enabled?).and_return(false) end def fill_in_editor(locator, with:) within_frame find(locator, visible: :all).sibling("div").find("iframe") do - within_frame find("iframe") do + within_frame find("#epiceditor-editor-frame") do find("body").set(with) end end From 18200f03d4d1733c46cc0d312a8897a3df75b90d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 5 Feb 2021 17:48:12 -0800 Subject: [PATCH 002/113] Upgrade to ruby 2.7.2 --- .ruby-version | 2 +- Dockerfile | 2 +- Gemfile.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.ruby-version b/.ruby-version index 0cadbc1e3..37c2961c2 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.5 +2.7.2 diff --git a/Dockerfile b/Dockerfile index ea4308c07..a70db219e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.5-stretch +FROM ruby:2.7-slim RUN mkdir /opt/actioncenter WORKDIR /opt/actioncenter diff --git a/Gemfile.lock b/Gemfile.lock index 17bbf4967..8423942d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -245,9 +245,9 @@ GEM mail (2.7.1) mini_mime (>= 0.1.1) method_source (0.9.2) - mime-types (3.2.2) + mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) + mime-types-data (3.2020.1104) mimemagic (0.3.3) mini_mime (1.0.2) mini_portile2 (2.4.0) @@ -443,7 +443,7 @@ GEM thor (0.20.3) thread_safe (0.3.6) tilt (2.0.9) - tzinfo (1.2.5) + tzinfo (1.2.9) thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) @@ -571,4 +571,4 @@ DEPENDENCIES xmlrpc BUNDLED WITH - 2.0.1 + 2.1.4 From 2a071516c0b42f12cc6c7a8842d043a80b180219 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 5 Feb 2021 18:32:52 -0800 Subject: [PATCH 003/113] Upgrade gems to fix deprecation errors; fix failing tests --- Gemfile | 2 +- Gemfile.lock | 28 ++++++++++--------- app/controllers/admin/petitions_controller.rb | 2 +- app/models/signature.rb | 2 +- .../admin/petitions_controller_spec.rb | 4 +-- spec/models/signature_spec.rb | 24 ++++++++-------- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Gemfile b/Gemfile index b18e97543..1ca45e7b3 100644 --- a/Gemfile +++ b/Gemfile @@ -112,7 +112,7 @@ end group :test do gem "apparition", "~> 0.6" - gem "webmock", "~> 2" + gem "webmock", "~> 3" end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 8423942d6..822890ab9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,8 +53,8 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) after_commit_action (1.1.0) activerecord (>= 3.0.0) activesupport (>= 3.0.0) @@ -133,8 +133,8 @@ GEM activerecord (>= 4.2) activesupport (>= 4.2) after_commit_action (~> 1.0) - crack (0.4.3) - safe_yaml (~> 1.0.0) + crack (0.4.5) + rexml crass (1.0.5) css_parser (1.7.0) addressable @@ -176,7 +176,7 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.3) - domain_name (0.5.20180417) + domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dotenv (2.7.2) dotenv-rails (2.7.2) @@ -220,8 +220,9 @@ GEM rack groupdate (2.5.3) activesupport (>= 3) - hashdiff (0.3.9) + hashdiff (1.0.1) htmlentities (4.3.4) + http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) http_accept_language (2.1.1) @@ -285,7 +286,7 @@ GEM premailer-rails (1.10.2) actionmailer (>= 3, < 6) premailer (~> 1.7, >= 1.7.9) - public_suffix (3.1.1) + public_suffix (4.0.6) puma (3.12.4) rack (2.0.8) rack-attack (5.4.2) @@ -367,10 +368,12 @@ GEM responders (3.0.0) actionpack (>= 5.0) railties (>= 5.0) - rest-client (2.0.2) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + rexml (3.2.4) rspec-core (3.8.0) rspec-support (~> 3.8.0) rspec-expectations (3.8.3) @@ -399,7 +402,6 @@ GEM rubocop (~> 0.51) ruby-progressbar (1.10.0) rubyzip (1.3.0) - safe_yaml (1.0.5) safely_block (0.2.1) errbase sanitize (4.6.6) @@ -449,7 +451,7 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.6) + unf_ext (0.0.7.7) unicode-display_width (1.5.0) user_agent_parser (2.6.0) uuidtools (2.1.5) @@ -459,10 +461,10 @@ GEM nokogiri (~> 1.6) rubyzip (~> 1.0) selenium-webdriver (>= 3.0, < 4.0) - webmock (2.3.2) + webmock (3.11.2) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) webshims-rails (1.16.0) rails (> 3.1.0) websocket-driver (0.6.5) @@ -564,7 +566,7 @@ DEPENDENCIES uglifier (>= 1.3.0) warden (= 1.2.4) webdrivers (~> 4) - webmock (~> 2) + webmock (~> 3) webshims-rails (~> 1) whenever (~> 0) will_paginate (~> 3.0) diff --git a/app/controllers/admin/petitions_controller.rb b/app/controllers/admin/petitions_controller.rb index 331e767dd..d0d2f30dc 100644 --- a/app/controllers/admin/petitions_controller.rb +++ b/app/controllers/admin/petitions_controller.rb @@ -52,7 +52,7 @@ def set_petition def filtered_signatures @petition.signatures. - filter(params[:query]). + search(params[:query]). order(created_at: :desc). paginate(page: params[:page], per_page: params[:per_page] || 10) end diff --git a/app/models/signature.rb b/app/models/signature.rb index 7d797c471..982ae18b2 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -20,7 +20,7 @@ class Signature < ActiveRecord::Base accepts_nested_attributes_for :affiliations, reject_if: :all_blank - scope :filter, ->(f) do + scope :search, ->(f) do if f.present? where("LOWER(email) LIKE ? " + "OR LOWER(first_name || ' ' || last_name) LIKE ?", diff --git a/spec/controllers/admin/petitions_controller_spec.rb b/spec/controllers/admin/petitions_controller_spec.rb index 86788eb7a..85901c082 100644 --- a/spec/controllers/admin/petitions_controller_spec.rb +++ b/spec/controllers/admin/petitions_controller_spec.rb @@ -17,11 +17,11 @@ expect(response.status).to eq(200) end - it "passes the 'query' param through Signature.filter" do + it "passes the 'query' param through Signature.search" do query = "jo@example.com" expect(Petition).to receive(:find) { petition } - expect(petition.signatures).to receive(:filter) do |q| + expect(petition.signatures).to receive(:search) do |q| expect(q).to eq(query) Signature.all end diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb index 60691093e..1f2e614ba 100644 --- a/spec/models/signature_spec.rb +++ b/spec/models/signature_spec.rb @@ -45,7 +45,7 @@ }.to raise_error ActiveRecord::RecordInvalid end - describe ".filter" do + describe ".search" do let(:jon) { Signature.create!(@attr.merge(email: "xx@example.com", first_name: "Jon", last_name: "A")) } let(:jan) { Signature.create!(@attr.merge(email: "xy@example.com", first_name: "Jan", last_name: "B")) } let(:jeb) { Signature.create!(@attr.merge(email: "wz@example.com", first_name: "Jeb", last_name: "C")) } @@ -54,23 +54,23 @@ let(:all_signatures) { [jon, jan, jeb, jen] } it "should return .all when query is blank" do - expect(Signature.filter(nil)).to contain_exactly(*all_signatures) - expect(Signature.filter("")).to contain_exactly(*all_signatures) - expect(Signature.filter(" \t")).to contain_exactly(*all_signatures) + expect(Signature.search(nil)).to contain_exactly(*all_signatures) + expect(Signature.search("")).to contain_exactly(*all_signatures) + expect(Signature.search(" \t")).to contain_exactly(*all_signatures) end it "should return signatures with matching email (case insensitive)" do - expect(Signature.filter("example.com")).to contain_exactly(*all_signatures) - expect(Signature.filter("EXAMPLE")).to contain_exactly(*all_signatures) - expect(Signature.filter("w")).to contain_exactly(jeb, jen) - expect(Signature.filter("xx")).to contain_exactly(jon) + expect(Signature.search("example.com")).to contain_exactly(*all_signatures) + expect(Signature.search("EXAMPLE")).to contain_exactly(*all_signatures) + expect(Signature.search("w")).to contain_exactly(jeb, jen) + expect(Signature.search("xx")).to contain_exactly(jon) end it "should return signatures with matching names (case insensitive)" do - expect(Signature.filter("J")).to contain_exactly(*all_signatures) - expect(Signature.filter("Jon")).to contain_exactly(jon) - expect(Signature.filter("Jan B")).to contain_exactly(jan) - expect(Signature.filter("Jeb c")).to contain_exactly(jeb) + expect(Signature.search("J")).to contain_exactly(*all_signatures) + expect(Signature.search("Jon")).to contain_exactly(jon) + expect(Signature.search("Jan B")).to contain_exactly(jan) + expect(Signature.search("Jeb c")).to contain_exactly(jeb) end end end From 51ac50591246977e11023eae16b935a551e431fc Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 9 Feb 2021 14:24:59 -0800 Subject: [PATCH 004/113] Upgrade rubocop to v0.82 --- .rubocop.yml | 72 +- .rubocop_todo.yml | 1029 +++++++++++++++++ Gemfile | 11 +- Gemfile.lock | 69 +- app/controllers/action_page_controller.rb | 6 +- .../admin/action_pages_controller.rb | 14 +- app/controllers/admin/events_controller.rb | 6 +- .../admin/institutions_controller.rb | 6 +- app/controllers/admin/partners_controller.rb | 4 +- app/controllers/admin/petitions_controller.rb | 12 +- .../admin/s3_uploads_controller.rb | 10 +- .../admin/topic_categories_controller.rb | 2 +- .../admin/topic_sets_controller.rb | 2 +- app/controllers/admin/users_controller.rb | 2 +- app/controllers/ahoy_controller.rb | 4 +- .../concerns/action_page_display.rb | 7 +- app/controllers/concerns/date_range.rb | 5 +- app/controllers/concerns/tooling.rb | 1 + .../congress_messages_controller.rb | 14 +- app/controllers/partners_controller.rb | 10 +- app/controllers/registrations_controller.rb | 4 +- app/controllers/tools_controller.rb | 20 +- app/controllers/users_controller.rb | 2 +- app/controllers/welcome_controller.rb | 8 +- app/helpers/action_page_helper.rb | 10 +- app/helpers/application_helper.rb | 10 +- app/helpers/congress_message_helper.rb | 13 +- app/helpers/devise_helper.rb | 3 +- app/mailers/user_mailer.rb | 4 +- app/models/action_institution.rb | 5 +- app/models/action_page.rb | 19 +- app/models/ahoy/event.rb | 4 +- app/models/congress_message.rb | 18 +- app/models/email_campaign.rb | 2 +- app/models/featured_action_page.rb | 1 + app/models/institution.rb | 2 + app/models/partner.rb | 3 +- app/models/petition.rb | 5 +- app/models/signature.rb | 14 +- app/models/tweet.rb | 2 +- app/models/tweet_target.rb | 4 +- app/models/twitter.rb | 15 +- app/models/user.rb | 11 +- app/queries/action_page_filters.rb | 4 +- app/validators/email_validator.rb | 2 +- .../step_definitions/active_record_steps.rb | 1 - .../step_definitions/admin/features_steps.rb | 2 - features/step_definitions/congress_steps.rb | 36 +- features/step_definitions/debug_steps.rb | 1 - .../step_definitions/source_file_steps.rb | 1 - features/step_definitions/topic_steps.rb | 1 - features/step_definitions/user_steps.rb | 28 +- lib/call_tool.rb | 8 +- lib/civicrm.rb | 17 +- lib/congress_forms.rb | 5 +- lib/monkey_patches/octet_stream_override.rb | 9 +- lib/places.rb | 1 - lib/related_content.rb | 2 + lib/smarty_streets.rb | 6 +- lib/tasks/congress.rake | 30 +- lib/tasks/cucumber.rake | 92 +- lib/tasks/users.rake | 8 +- .../action_page_controller_spec.rb | 22 +- .../admin/institutions_controller_spec.rb | 18 +- .../concerns/logged_invisible_captcha_spec.rb | 4 +- .../request_origin_validation_spec.rb | 4 +- .../subscriptions_controller_spec.rb | 5 +- spec/controllers/tools_controller_spec.rb | 32 +- spec/factories/action_page.rb | 4 +- spec/factories/ahoy_event.rb | 20 +- spec/factories/congress_message.rb | 26 +- spec/factories/topic_category.rb | 2 +- spec/factories/topic_set.rb | 2 +- .../features/action_pages/call_action_spec.rb | 8 +- .../action_pages/congress_action_spec.rb | 12 +- spec/features/admin/action_creation_spec.rb | 4 +- spec/features/congress_message.rb | 22 +- spec/lib/action_cloner_spec.rb | 4 +- spec/lib/call_tool_spec.rb | 4 +- spec/lib/congress_forms_spec.rb | 44 +- spec/models/action_page_spec.rb | 10 +- spec/models/congress_message_campaign_spec.rb | 1 - spec/models/user_spec.rb | 16 +- spec/queries/action_page_filters_spec.rb | 6 +- spec/rails_helper.rb | 1 - spec/requests/admin/events_spec.rb | 49 +- spec/requests/admin/s3_uploads_spec.rb | 26 +- spec/requests/congress_messages_spec.rb | 58 +- spec/requests/sns_spec.rb | 2 +- spec/spec_helper.rb | 2 +- spec/support/exit_code_helpers.rb | 4 +- spec/support/feature_helpers.rb | 2 +- spec/support/service_helpers.rb | 12 +- 93 files changed, 1624 insertions(+), 521 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 7933b1521..0fd0c44ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,16 +1,69 @@ +# inherit_from: .rubocop_todo.yml + inherit_gem: rubocop-github: - - config/default.yml - - config/rails.yml + - config/default_edge.yml + - config/rails_edge.yml AllCops: - TargetRailsVersion: 4.2 - TargetRubyVersion: 2.3 + TargetRailsVersion: 5.0 + TargetRubyVersion: 2.7 Exclude: - 'db/**/*' - 'config/**/*' - 'bin/**/*' - 'vendor/**/*' + - 'features/**/*' + +# Handle cops not enabled by default +# Should probably be checked on rubocop version upgrades +# Last checked 02/09/21 +# Disables cops marked as unsafe in docs + +Layout/SpaceAroundMethodCallOperator: + Enabled: true + +Lint/RaiseException: + Enabled: true + +Lint/StructNewOverride: + Enabled: true + +Style/ExponentialNotation: + Enabled: true + +Style/HashEachMethods: + Enabled: false + +Style/HashTransformKeys: + Enabled: false + +Style/HashTransformValues: + Enabled: false + +Performance/AncestorsInclude: + Enabled: false + +Performance/BigDecimalWithNumericArgument: + Enabled: true + +Performance/RedundantSortBlock: + Enabled: true + +Performance/RedundantStringChars: + Enabled: true + +Performance/ReverseFirst: + Enabled: true + +Performance/SortReverse: + Enabled: true + +Performance/Squeeze: + Enabled: true + +Performance/StringInclude: + Enabled: true ### Override rubcop-github ### @@ -30,10 +83,6 @@ GitHub/RailsControllerRenderPathsExist: # Doesn't seem to work; can't find templates that exist Enabled: false -GitHub/RailsApplicationRecord: - # Doesn't apply to < Rails 5.0, and ignores TargetRailsVersion - Enabled: false - Lint/Void: Exclude: - 'features/**/*' @@ -69,3 +118,10 @@ Security/JSONLoad: Enabled: true Exclude: - 'spec/**/*' + +GitHub/RailsApplicationRecord: + # Rails/ApplicationRecord does the same thing + Enabled: false + +Rails/HttpStatus: + EnforcedStyle: 'numeric' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..23f915772 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,1029 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 100` +# on 2021-02-10 18:09:54 -0800 using RuboCop version 0.82.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 29 +# Easy fix +GitHub/RailsApplicationRecord: + Exclude: + - 'app/models/action_institution.rb' + - 'app/models/action_page.rb' + - 'app/models/affiliation.rb' + - 'app/models/affiliation_type.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/bounce.rb' + - 'app/models/call_campaign.rb' + - 'app/models/category.rb' + - 'app/models/complaint.rb' + - 'app/models/congress_member.rb' + - 'app/models/congress_message_campaign.rb' + - 'app/models/congress_scorecard.rb' + - 'app/models/email_campaign.rb' + - 'app/models/featured_action_page.rb' + - 'app/models/institution.rb' + - 'app/models/partner.rb' + - 'app/models/partnership.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/source_file.rb' + - 'app/models/subscription.rb' + - 'app/models/topic.rb' + - 'app/models/topic_category.rb' + - 'app/models/topic_set.rb' + - 'app/models/tweet.rb' + - 'app/models/tweet_target.rb' + - 'app/models/user.rb' + - 'app/models/user_preference.rb' + - 'app/models/visit.rb' + +# Offense count: 5 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'app/models/topic_category.rb' + - 'spec/models/action_page_spec.rb' + +# Offense count: 3 +Lint/AmbiguousRegexpLiteral: + Exclude: + - 'app/helpers/application_helper.rb' + - 'spec/models/congress_message_campaign_spec.rb' + +# Offense count: 5 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'lib/civicrm.rb' + - 'lib/tasks/congress.rake' + - 'lib/tasks/signatures.rake' + +# Offense count: 13 +Lint/IneffectiveAccessModifier: + Exclude: + - 'app/controllers/admin/application_controller.rb' + - 'lib/action_cloner.rb' + - 'lib/call_tool.rb' + - 'lib/civicrm.rb' + - 'lib/quotes.rb' + - 'lib/smarty_streets.rb' + +# Offense count: 1 +Lint/ParenthesesAsGroupedExpression: + Exclude: + - 'spec/factories/congress_member.rb' + +# Offense count: 1 +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'lib/tasks/congress.rake' + +# Offense count: 1 +Lint/UriEscapeUnescape: + Exclude: + - 'app/helpers/application_helper.rb' + +# Offense count: 5 +# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. +Lint/UselessAccessModifier: + Exclude: + - 'lib/action_cloner.rb' + - 'lib/call_tool.rb' + - 'lib/civicrm.rb' + - 'lib/quotes.rb' + - 'lib/smarty_streets.rb' + +# Offense count: 23 +Lint/UselessAssignment: + Exclude: + - 'app/controllers/congress_messages_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/helpers/devise_helper.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/featured_action_page.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/topic_category.rb' + - 'app/models/twitter.rb' + - 'app/models/user.rb' + - 'lib/congress_forms.rb' + - 'spec/controllers/admin/institutions_controller_spec.rb' + - 'spec/requests/admin/action_pages_spec.rb' + - 'spec/requests/admin/events_spec.rb' + - 'spec/requests/congress_messages_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 3 +Naming/AccessorMethodName: + Exclude: + - 'spec/requests/congress_messages_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 2 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +Naming/BlockParameterName: + Exclude: + - 'app/views/action_page/index.atom.builder' + - 'app/views/action_page/index.json.jbuilder' + +# Offense count: 3 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'app/controllers/tools_controller.rb' + - 'app/models/action_page.rb' + - 'lib/related_content.rb' + +# Offense count: 7 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +Naming/MethodParameterName: + Exclude: + - 'app/helpers/application_helper.rb' + - 'app/mailers/user_mailer.rb' + - 'app/models/congress_message_campaign.rb' + - 'app/models/institution.rb' + - 'app/queries/action_page_filters.rb' + +# Offense count: 3 +# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. +# NamePrefix: is_, has_, have_ +# ForbiddenPrefixes: is_, has_, have_ +# AllowedMethods: is_a? +# MethodDefinitionMacros: define_method, define_singleton_method +Naming/PredicateName: + Exclude: + - 'spec/**/*' + - 'app/models/source_file.rb' + - 'app/models/twitter.rb' + - 'lib/congress_forms.rb' + +# Offense count: 45 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Exclude: + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/mailer_controller.rb' + - 'app/controllers/admin/petitions_controller.rb' + - 'app/controllers/congress_messages_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/controllers/users_controller.rb' + - 'app/controllers/welcome_controller.rb' + - 'app/helpers/application_helper.rb' + - 'app/helpers/devise_helper.rb' + - 'app/mailers/user_mailer.rb' + - 'app/models/markdown_renderer.rb' + - 'app/views/action_page/index.atom.builder' + - 'app/views/action_page/index.json.jbuilder' + - 'spec/controllers/action_page_controller_spec.rb' + - 'spec/controllers/admin/institutions_controller_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Rails/ApplicationController: + Exclude: + - 'app/controllers/exceptions_controller.rb' + - 'spec/controllers/concerns/request_origin_validation_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Rails/ApplicationMailer: + Exclude: + - 'app/mailers/user_mailer.rb' + +# Offense count: 29 +# Cop supports --auto-correct. +Rails/ApplicationRecord: + Exclude: + - 'app/models/action_institution.rb' + - 'app/models/action_page.rb' + - 'app/models/affiliation.rb' + - 'app/models/affiliation_type.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/bounce.rb' + - 'app/models/call_campaign.rb' + - 'app/models/category.rb' + - 'app/models/complaint.rb' + - 'app/models/congress_member.rb' + - 'app/models/congress_message_campaign.rb' + - 'app/models/congress_scorecard.rb' + - 'app/models/email_campaign.rb' + - 'app/models/featured_action_page.rb' + - 'app/models/institution.rb' + - 'app/models/partner.rb' + - 'app/models/partnership.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/source_file.rb' + - 'app/models/subscription.rb' + - 'app/models/topic.rb' + - 'app/models/topic_category.rb' + - 'app/models/topic_set.rb' + - 'app/models/tweet.rb' + - 'app/models/tweet_target.rb' + - 'app/models/user.rb' + - 'app/models/user_preference.rb' + - 'app/models/visit.rb' + +# Offense count: 4 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: strict, flexible +Rails/Date: + Exclude: + - 'spec/models/congress_message_campaign_spec.rb' + +# Offense count: 3 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: slashes, arguments +Rails/FilePath: + Exclude: + - 'lib/tasks/cucumber.rake' + - 'lib/tasks/webshims_asset_compile.rake' + - 'spec/rails_helper.rb' + +# Offense count: 25 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/HasManyOrHasOneDependent: + Exclude: + - 'app/models/action_page.rb' + - 'app/models/affiliation_type.rb' + - 'app/models/call_campaign.rb' + - 'app/models/congress_message_campaign.rb' + - 'app/models/email_campaign.rb' + - 'app/models/institution.rb' + - 'app/models/partner.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/topic_category.rb' + - 'app/models/tweet.rb' + - 'app/models/user.rb' + - 'app/models/visit.rb' + +# Offense count: 16 +# Configuration parameters: Include. +# Include: app/helpers/**/*.rb +Rails/HelperInstanceVariable: + Exclude: + - 'app/helpers/action_page_helper.rb' + - 'app/helpers/application_helper.rb' + - 'app/helpers/devise_helper.rb' + - 'app/helpers/petition_helper.rb' + +# Offense count: 2 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/InverseOf: + Exclude: + - 'app/models/action_page.rb' + +# Offense count: 6 +# Configuration parameters: Include. +# Include: app/controllers/**/*.rb +Rails/LexicallyScopedActionFilter: + Exclude: + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/partners_controller.rb' + - 'app/controllers/petition_controller.rb' + - 'app/controllers/sessions_controller.rb' + - 'app/controllers/tools_controller.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: **/Rakefile, **/*.rake +Rails/RakeEnvironment: + Exclude: + - 'lib/capistrano/tasks/**/*.rake' + - 'lib/tasks/cucumber.rake' + - 'lib/tasks/test.rake' + +# Offense count: 2 +Rails/ReflectionClassName: + Exclude: + - 'app/models/action_page.rb' + - 'app/models/user.rb' + +# Offense count: 9 +# Configuration parameters: Blacklist, Whitelist. +# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters +Rails/SkipsModelValidations: + Exclude: + - 'app/controllers/registrations_controller.rb' + - 'app/controllers/users_controller.rb' + - 'app/models/congress_scorecard.rb' + - 'lib/tasks/ahoy.rake' + - 'lib/tasks/congress.rake' + - 'spec/requests/congress_messages_spec.rb' + - 'spec/tasks/signatures_spec.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: strict, flexible +Rails/TimeZone: + Exclude: + - 'app/models/congress_member.rb' + - 'spec/factories/congress_member.rb' + - 'spec/models/congress_member_spec.rb' + - 'spec/requests/admin/events_spec.rb' + - 'spec/requests/admin/users_spec.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/Validation: + Exclude: + - 'app/models/category.rb' + - 'app/models/congress_member.rb' + - 'app/models/featured_action_page.rb' + - 'app/models/institution.rb' + - 'app/models/partner.rb' + - 'app/models/signature.rb' + - 'app/models/source_file.rb' + - 'app/models/user_preference.rb' + +# Offense count: 1 +Security/Open: + Exclude: + - 'lib/related_content.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Security/YAMLLoad: + Exclude: + - 'lib/tasks/congress.rake' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'app/models/tweet.rb' + - 'app/models/user.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/concerns/action_page_display.rb' + - 'app/controllers/robots_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/helpers/application_helper.rb' + - 'app/models/congress_message_campaign.rb' + - 'app/models/email_campaign.rb' + - 'app/models/signature.rb' + - 'app/models/tweet_target.rb' + - 'app/models/user.rb' + - 'lib/tasks/signatures.rake' + +# Offense count: 46 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'app/controllers/admin/events_controller.rb' + - 'app/controllers/admin/s3_uploads_controller.rb' + - 'app/helpers/ahoy_helper.rb' + - 'app/models/user.rb' + - 'spec/controllers/action_page_controller_spec.rb' + - 'spec/controllers/admin/institutions_controller_spec.rb' + - 'spec/controllers/tools_controller_spec.rb' + - 'spec/factories/ahoy_event.rb' + - 'spec/features/action_pages/congress_action_spec.rb' + - 'spec/features/action_pages/tweet_action_spec.rb' + - 'spec/features/admin/action_creation_spec.rb' + - 'spec/features/congress_message.rb' + - 'spec/lib/call_tool_spec.rb' + - 'spec/lib/congress_forms_spec.rb' + - 'spec/models/action_page_spec.rb' + - 'spec/models/congress_message_spec.rb' + - 'spec/models/institution_spec.rb' + - 'spec/models/signature_spec.rb' + - 'spec/requests/admin/action_pages_spec.rb' + - 'spec/requests/admin/s3_uploads_spec.rb' + - 'spec/requests/congress_messages_spec.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/application_controller.rb' + - 'app/controllers/admin/categories_controller.rb' + - 'app/controllers/admin/congress_message_campaigns_controller.rb' + - 'app/controllers/admin/events_controller.rb' + - 'app/controllers/admin/images_controller.rb' + - 'app/controllers/admin/institutions_controller.rb' + - 'app/controllers/admin/mailer_controller.rb' + - 'app/controllers/admin/partners_controller.rb' + - 'app/controllers/admin/petitions_controller.rb' + - 'app/controllers/admin/s3_uploads_controller.rb' + - 'app/controllers/admin/topic_categories_controller.rb' + - 'app/controllers/admin/topic_sets_controller.rb' + - 'app/controllers/admin/topics_controller.rb' + - 'app/controllers/admin/users_controller.rb' + - 'app/helpers/admin/affiliation_types_helper.rb' + - 'app/helpers/admin/users_helper.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +Style/ColonMethodCall: + Exclude: + - 'app/controllers/subscriptions_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/models/signature.rb' + - 'lib/civicrm.rb' + - 'spec/controllers/subscriptions_controller_spec.rb' + - 'spec/features/congress_message.rb' + - 'spec/lib/civicrm_spec.rb' + - 'spec/support/service_helpers.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Keywords. +# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW +Style/CommentAnnotation: + Exclude: + - 'lib/call_tool.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'app/controllers/admin/s3_uploads_controller.rb' + - 'app/controllers/users_controller.rb' + - 'app/helpers/congress_message_helper.rb' + +# Offense count: 93 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/application_controller.rb' + - 'app/controllers/admin/categories_controller.rb' + - 'app/controllers/admin/congress_message_campaigns_controller.rb' + - 'app/controllers/admin/events_controller.rb' + - 'app/controllers/admin/images_controller.rb' + - 'app/controllers/admin/institutions_controller.rb' + - 'app/controllers/admin/mailer_controller.rb' + - 'app/controllers/admin/partners_controller.rb' + - 'app/controllers/admin/petitions_controller.rb' + - 'app/controllers/admin/s3_uploads_controller.rb' + - 'app/controllers/admin/topic_categories_controller.rb' + - 'app/controllers/admin/topic_sets_controller.rb' + - 'app/controllers/admin/topics_controller.rb' + - 'app/controllers/admin/users_controller.rb' + - 'app/controllers/ahoy_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/concerns/action_page_display.rb' + - 'app/controllers/concerns/date_range.rb' + - 'app/controllers/concerns/logged_invisible_captcha.rb' + - 'app/controllers/concerns/request_origin_validation.rb' + - 'app/controllers/concerns/tooling.rb' + - 'app/controllers/congress_messages_controller.rb' + - 'app/controllers/exceptions_controller.rb' + - 'app/controllers/partners_controller.rb' + - 'app/controllers/petition_controller.rb' + - 'app/controllers/registrations_controller.rb' + - 'app/controllers/robots_controller.rb' + - 'app/controllers/sessions_controller.rb' + - 'app/controllers/smarty_streets_controller.rb' + - 'app/controllers/subscriptions_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/controllers/users_controller.rb' + - 'app/controllers/welcome_controller.rb' + - 'app/helpers/action_page_helper.rb' + - 'app/helpers/admin/action_pages_helper.rb' + - 'app/helpers/admin/affiliation_types_helper.rb' + - 'app/helpers/admin/topics_helper.rb' + - 'app/helpers/admin/users_helper.rb' + - 'app/helpers/admin_helper.rb' + - 'app/helpers/ahoy_helper.rb' + - 'app/helpers/application_helper.rb' + - 'app/helpers/congress_message_helper.rb' + - 'app/helpers/devise_helper.rb' + - 'app/helpers/petition_helper.rb' + - 'app/helpers/s3_upload_helper.rb' + - 'app/helpers/users_helper.rb' + - 'app/helpers/welcome_helper.rb' + - 'app/mailers/user_mailer.rb' + - 'app/models/action_institution.rb' + - 'app/models/action_page.rb' + - 'app/models/affiliation.rb' + - 'app/models/affiliation_type.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/call_campaign.rb' + - 'app/models/category.rb' + - 'app/models/congress_member.rb' + - 'app/models/congress_message_campaign.rb' + - 'app/models/email_campaign.rb' + - 'app/models/featured_action_page.rb' + - 'app/models/institution.rb' + - 'app/models/markdown_renderer.rb' + - 'app/models/partner.rb' + - 'app/models/partnership.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/source_file.rb' + - 'app/models/subscription.rb' + - 'app/models/topic.rb' + - 'app/models/topic_category.rb' + - 'app/models/topic_set.rb' + - 'app/models/tweet.rb' + - 'app/models/tweet_target.rb' + - 'app/models/twitter.rb' + - 'app/models/user.rb' + - 'app/models/user_preference.rb' + - 'app/models/visit.rb' + - 'app/queries/action_page_filters.rb' + - 'app/validators/email_validator.rb' + - 'lib/action_cloner.rb' + - 'lib/amazon_credentials.rb' + - 'lib/call_tool.rb' + - 'lib/civicrm.rb' + - 'lib/congress_forms.rb' + - 'lib/monkey_patches/octet_stream_override.rb' + - 'lib/places.rb' + - 'lib/quotes.rb' + - 'lib/related_content.rb' + - 'lib/smarty_streets.rb' + +# Offense count: 1 +Style/DoubleNegation: + Exclude: + - 'app/models/source_file.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty, nil, both +Style/EmptyElse: + Exclude: + - 'app/models/ahoy/event.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/EmptyLambdaParameter: + Exclude: + - 'app/models/tweet_target.rb' + - 'app/models/user.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/application_controller.rb' + - 'app/controllers/admin/congress_message_campaigns_controller.rb' + - 'app/controllers/admin/images_controller.rb' + - 'app/controllers/admin/partners_controller.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'Rakefile' + - 'spec/rails_helper.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv +Style/FloatDivision: + Exclude: + - 'app/models/petition.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: format, sprintf, percent +Style/FormatString: + Exclude: + - 'spec/requests/admin/events_spec.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + Exclude: + - 'spec/requests/admin/events_spec.rb' + +# Offense count: 37 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/application_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/concerns/action_page_display.rb' + - 'app/controllers/concerns/request_origin_validation.rb' + - 'app/controllers/concerns/tooling.rb' + - 'app/controllers/congress_messages_controller.rb' + - 'app/controllers/partners_controller.rb' + - 'app/controllers/registrations_controller.rb' + - 'app/controllers/sessions_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/helpers/application_helper.rb' + - 'app/mailers/user_mailer.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/congress_message.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/user.rb' + - 'app/queries/action_page_filters.rb' + - 'app/validators/email_validator.rb' + - 'lib/call_tool.rb' + - 'lib/civicrm.rb' + - 'lib/smarty_streets.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'app/models/action_page.rb' + +# Offense count: 1 +# Configuration parameters: AllowIfModifier. +Style/IfInsideElse: + Exclude: + - 'app/controllers/partners_controller.rb' + +# Offense count: 38 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/application_controller.rb' + - 'app/controllers/admin/institutions_controller.rb' + - 'app/controllers/admin/petitions_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/concerns/action_page_display.rb' + - 'app/controllers/concerns/date_range.rb' + - 'app/controllers/concerns/tooling.rb' + - 'app/controllers/congress_messages_controller.rb' + - 'app/controllers/registrations_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/helpers/action_page_helper.rb' + - 'app/helpers/admin/action_pages_helper.rb' + - 'app/helpers/congress_message_helper.rb' + - 'app/helpers/devise_helper.rb' + - 'app/mailers/user_mailer.rb' + - 'app/models/action_page.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/congress_message.rb' + - 'app/models/petition.rb' + - 'app/models/signature.rb' + - 'app/models/user.rb' + - 'app/queries/action_page_filters.rb' + - 'app/validators/email_validator.rb' + - 'lib/action_cloner.rb' + - 'lib/call_tool.rb' + - 'lib/smarty_streets.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'app/models/ahoy/event.rb' + - 'app/models/congress_member.rb' + - 'app/models/signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/LineEndConcatenation: + Exclude: + - 'app/models/signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: separated, grouped +Style/MixinGrouping: + Exclude: + - 'app/models/action_page.rb' + +# Offense count: 2 +Style/MixinUsage: + Exclude: + - 'app/controllers/admin/petitions_controller.rb' + - 'app/models/signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MultilineIfModifier: + Exclude: + - 'lib/amazon_credentials.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: both, prefix, postfix +Style/NegatedIf: + Exclude: + - 'app/controllers/registrations_controller.rb' + - 'app/controllers/subscriptions_controller.rb' + - 'app/helpers/devise_helper.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/congress_message.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowedMethods. +# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with +Style/NestedParenthesizedCalls: + Exclude: + - 'app/views/action_page/index.atom.builder' + - 'lib/call_tool.rb' + - 'spec/models/topic_category_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Exclude: + - 'lib/tasks/petition.rake' + - 'lib/tasks/signatures.rake' + - 'lib/tasks/webshims_asset_compile.rake' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 7 + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'app/controllers/tools_controller.rb' + - 'app/helpers/application_helper.rb' + - 'app/models/action_page.rb' + - 'app/models/petition.rb' + - 'app/views/action_page/index.atom.builder' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'spec/controllers/tools_controller_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. +Style/ParenthesesAroundCondition: + Exclude: + - 'app/controllers/sessions_controller.rb' + - 'lib/civicrm.rb' + +# Offense count: 24 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'Rakefile' + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/admin/institutions_controller.rb' + - 'app/controllers/admin/partners_controller.rb' + - 'app/controllers/concerns/date_range.rb' + - 'app/controllers/tools_controller.rb' + - 'app/models/action_page.rb' + - 'app/models/ahoy/event.rb' + - 'app/models/congress_message.rb' + - 'app/queries/action_page_filters.rb' + - 'lib/action_cloner.rb' + - 'lib/congress_forms.rb' + - 'lib/tasks/cucumber.rake' + - 'spec/lib/action_cloner_spec.rb' + - 'spec/requests/congress_messages_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'app/controllers/admin/action_pages_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Exclude: + - 'lib/call_tool.rb' + +# Offense count: 12 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'app/controllers/admin/topic_categories_controller.rb' + - 'app/controllers/admin/topic_sets_controller.rb' + - 'app/controllers/admin/topics_controller.rb' + - 'app/controllers/smarty_streets_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'app/models/signature.rb' + - 'lib/civicrm.rb' + - 'lib/congress_forms.rb' + - 'lib/quotes.rb' + - 'lib/smarty_streets.rb' + - 'spec/support/feature_helpers.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantParentheses: + Exclude: + - 'app/controllers/sessions_controller.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'app/controllers/smarty_streets_controller.rb' + - 'app/controllers/sns_controller.rb' + - 'app/helpers/application_helper.rb' + - 'lib/civicrm.rb' + - 'lib/congress_forms.rb' + - 'lib/related_content.rb' + - 'lib/smarty_streets.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'app/models/signature.rb' + - 'app/models/source_file.rb' + - 'app/models/tweet_target.rb' + - 'app/models/user.rb' + - 'lib/civicrm.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'lib/call_tool.rb' + - 'spec/lib/call_tool_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RescueModifier: + Exclude: + - 'app/models/source_file.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'app/controllers/admin/topic_categories_controller.rb' + - 'app/controllers/admin/topic_sets_controller.rb' + - 'app/controllers/admin/topics_controller.rb' + - 'app/controllers/smarty_streets_controller.rb' + - 'app/controllers/tools_controller.rb' + - 'lib/call_tool.rb' + - 'lib/civicrm.rb' + - 'lib/smarty_streets.rb' + - 'lib/tasks/signatures.rake' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'app/controllers/concerns/action_page_display.rb' + - 'app/helpers/application_helper.rb' + - 'app/helpers/devise_helper.rb' + - 'app/models/action_page.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowIfMethodIsEmpty. +Style/SingleLineMethods: + Exclude: + - 'app/models/congress_message.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/StderrPuts: + Exclude: + - 'lib/tasks/cucumber.rake' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiteralsInInterpolation: + Exclude: + - 'app/models/petition.rb' + - 'spec/features/congress_message.rb' + +# Offense count: 38 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + Exclude: + - 'Rakefile' + - 'app/controllers/action_page_controller.rb' + - 'app/controllers/admin/action_pages_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/concerns/action_page_display.rb' + - 'app/controllers/tools_controller.rb' + - 'app/helpers/application_helper.rb' + - 'app/models/action_page.rb' + - 'app/models/institution.rb' + - 'app/models/petition.rb' + - 'app/models/user.rb' + - 'lib/tasks/cucumber.rake' + - 'spec/models/ahoy/event_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'app/models/topic_category.rb' + - 'app/models/user.rb' + - 'lib/tasks/users.rake' + - 'spec/factories/users.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'app/models/action_page.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'app/helpers/congress_message_helper.rb' + - 'lib/call_tool.rb' + - 'lib/congress_forms.rb' + - 'spec/requests/congress_messages_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowNamedUnderscoreVariables. +Style/TrailingUnderscoreVariable: + Exclude: + - 'app/controllers/congress_messages_controller.rb' + +# Offense count: 177 +# Cop supports --auto-correct. +# Configuration parameters: WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: 6 + +# Offense count: 2 +# Cop supports --auto-correct. +Style/ZeroLengthPredicate: + Exclude: + - 'app/models/action_page.rb' + - 'app/views/action_page/index.atom.builder' diff --git a/Gemfile b/Gemfile index 1ca45e7b3..481e86d2b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" gem "rails", "~> 5.0" -#Database +# Database gem "pg", "~> 1.1" gem "pg_search" @@ -117,15 +117,16 @@ end group :development, :test do gem "byebug" - gem "capybara", "~> 3.26" - gem "cucumber-rails", "1.6.0", require: false + gem "capybara", "~> 3" gem "database_cleaner", "~> 1" gem "factory_girl_rails", "~> 4" gem "rails-controller-testing" gem "rspec-core", "~> 3" gem "rspec-rails", "~> 3" - gem "rubocop", "0.52.0" - gem "rubocop-github", "0.9.0" + gem "rubocop" + gem "rubocop-github", "~> 0.16" + gem "rubocop-performance", require: false + gem "rubocop-rails", require: false gem "webdrivers", "~> 4" end diff --git a/Gemfile.lock b/Gemfile.lock index 822890ab9..5a9adf85c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,7 +73,7 @@ GEM capybara (~> 3.13, < 4) websocket-driver (>= 0.6.5) arel (7.1.4) - ast (2.4.0) + ast (2.4.2) autoprefixer-rails (9.5.1) execjs aws-eventstream (1.0.3) @@ -93,7 +93,6 @@ GEM babel-transpiler (0.7.0) babel-source (>= 4.0, < 6) execjs (~> 2.0) - backports (3.14.0) bcrypt (3.1.13) better_errors (2.5.1) coderay (>= 1.0.0) @@ -138,28 +137,6 @@ GEM crass (1.0.5) css_parser (1.7.0) addressable - cucumber (3.1.2) - builder (>= 2.1.2) - cucumber-core (~> 3.2.0) - cucumber-expressions (~> 6.0.1) - cucumber-wire (~> 0.0.1) - diff-lcs (~> 1.3) - gherkin (~> 5.1.0) - multi_json (>= 1.7.5, < 2.0) - multi_test (>= 0.1.2) - cucumber-core (3.2.1) - backports (>= 3.8.0) - cucumber-tag_expressions (~> 1.1.0) - gherkin (~> 5.0) - cucumber-expressions (6.0.1) - cucumber-rails (1.6.0) - capybara (>= 1.1.2, < 4) - cucumber (>= 3.0.2, < 4) - mime-types (>= 1.17, < 4) - nokogiri (~> 1.8) - railties (>= 4, < 6) - cucumber-tag_expressions (1.1.1) - cucumber-wire (0.0.1) daemons (1.3.1) database_cleaner (1.7.0) debug_inspector (0.0.3) @@ -211,7 +188,6 @@ GEM friendly_id (5.2.5) activerecord (>= 4.0.0) geocoder (1.5.1) - gherkin (5.1.0) globalid (0.4.2) activesupport (>= 4.2.0) going_postal (0.1.6) @@ -234,6 +210,7 @@ GEM invisible_captcha (0.12.0) rails (>= 3.2.0) iso_country_codes (0.7.8) + jaro_winkler (1.5.4) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) @@ -254,7 +231,6 @@ GEM mini_portile2 (2.4.0) minitest (5.11.3) multi_json (1.13.1) - multi_test (0.1.2) multi_xml (0.6.0) multipart-post (2.0.0) netrc (0.11.0) @@ -271,14 +247,13 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - parallel (1.17.0) - parser (2.6.3.0) - ast (~> 2.4.0) + parallel (1.20.1) + parser (3.0.0.0) + ast (~> 2.4.1) pg (1.1.4) pg_search (2.1.7) activerecord (>= 4.2) activesupport (>= 4.2) - powerpack (0.1.2) premailer (1.11.1) addressable css_parser (>= 1.6.0) @@ -391,16 +366,25 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.52.0) + rubocop (0.82.0) + jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.4.0.2, < 3.0) - powerpack (~> 0.1) + parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) + rexml ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-github (0.9.0) - rubocop (~> 0.51) - ruby-progressbar (1.10.0) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-github (0.16.0) + rubocop (<= 0.82.0) + rubocop-performance (~> 1.0) + rubocop-rails (~> 2.0) + rubocop-performance (1.7.1) + rubocop (>= 0.82.0) + rubocop-rails (2.6.0) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 0.82.0) + ruby-progressbar (1.11.0) rubyzip (1.3.0) safely_block (0.2.1) errbase @@ -452,7 +436,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.7) - unicode-display_width (1.5.0) + unicode-display_width (1.7.0) user_agent_parser (2.6.0) uuidtools (2.1.5) warden (1.2.4) @@ -494,11 +478,10 @@ DEPENDENCIES bourbon (~> 3) bundler (>= 1.8.4) byebug - capybara (~> 3.26) + capybara (~> 3) chartkick (~> 3) cocoon (~> 1) counter_culture (~> 2.0) - cucumber-rails (= 1.6.0) daemons (~> 1) database_cleaner (~> 1) delayed_job_active_record (~> 4) @@ -555,8 +538,10 @@ DEPENDENCIES rest-client (~> 2) rspec-core (~> 3) rspec-rails (~> 3) - rubocop (= 0.52.0) - rubocop-github (= 0.9.0) + rubocop + rubocop-github (~> 0.16) + rubocop-performance + rubocop-rails sanitize (~> 4) sass-rails (~> 5.0) sdoc diff --git a/app/controllers/action_page_controller.rb b/app/controllers/action_page_controller.rb index 8daf812f5..9a3074cd5 100644 --- a/app/controllers/action_page_controller.rb +++ b/app/controllers/action_page_controller.rb @@ -26,9 +26,9 @@ def show end def index - @actionPages = ActionPage.where(published: true, archived: false, victory: false). - paginate(page: params[:page], per_page: 9). - order(created_at: :desc) + @actionPages = ActionPage.where(published: true, archived: false, victory: false) + .paginate(page: params[:page], per_page: 9) + .order(created_at: :desc) @actionPages = @actionPages.categorized(params[:category]) if params[:category].present? diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index 5045b8f7a..d6dc8303c 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -81,9 +81,9 @@ def update @actionPage.featured_image = nil if params[:destroy_featured_image] @actionPage.og_image = nil if params[:destroy_og_image] - @actionPage.update_attributes(action_page_params) + @actionPage.update(action_page_params) if (institutions_params[:reset] && institutions_params[:reset] == "1") || - (institutions_params[:category] && @actionPage.institutions.empty?) + (institutions_params[:category] && @actionPage.institutions.empty?) ActionInstitution.add(action_page: @actionPage, **institutions_params.to_h.symbolize_keys) end @@ -96,12 +96,11 @@ def destroy redirect_to admin_action_pages_path, notice: "Deleted action page: #{@actionPage.title}" end - def preview @actionPage.attributes = action_page_params if @actionPage.enable_redirect - redirect_to @actionPage.redirect_url, status: 301 + redirect_to @actionPage.redirect_url, status: 301 return end @@ -132,9 +131,9 @@ def events end format.json do render json: @events.chart_data( - type: params[:type], - range: @start_date..@end_date - ) + type: params[:type], + range: @start_date..@end_date + ) end end end @@ -216,6 +215,7 @@ def action_page_params def institutions_params return {} unless params.has_key? :institutions + params.require(:institutions).permit(%i(category reset)) end diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 3bd605300..d2e8beb9f 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -8,9 +8,9 @@ def index format.html { @summary = @events.summary } format.json { render json: @events.chart_data( - type: params[:type], - range: @start_date..@end_date - ) + type: params[:type], + range: @start_date..@end_date + ) } end end diff --git a/app/controllers/admin/institutions_controller.rb b/app/controllers/admin/institutions_controller.rb index 6b6c0a563..c56f40167 100644 --- a/app/controllers/admin/institutions_controller.rb +++ b/app/controllers/admin/institutions_controller.rb @@ -42,11 +42,7 @@ def import if names.empty? redirect_to action: "upload", notice: "Import failed. Please check CSV formatting" else - category = if import_params[:new_category].blank? - import_params[:category] - else - import_params[:new_category] - end + category = import_params[:new_category].presence || import_params[:category] Institution.delay.import(category, names) redirect_to action: "index", notice: "Successfully imported #{names.length} targets" end diff --git a/app/controllers/admin/partners_controller.rb b/app/controllers/admin/partners_controller.rb index d3bb7080b..023e5227e 100644 --- a/app/controllers/admin/partners_controller.rb +++ b/app/controllers/admin/partners_controller.rb @@ -22,10 +22,10 @@ def create respond_to do |format| if @partner.save format.html { redirect_to @partner, notice: "Partner was successfully created." } - format.json { render "show", status: :created, location: @partner } + format.json { render "show", status: 201, location: @partner } else format.html { render "new" } - format.json { render json: @partner.errors, status: :unprocessable_entity } + format.json { render json: @partner.errors, status: 422 } end end end diff --git a/app/controllers/admin/petitions_controller.rb b/app/controllers/admin/petitions_controller.rb index d0d2f30dc..23af4076f 100644 --- a/app/controllers/admin/petitions_controller.rb +++ b/app/controllers/admin/petitions_controller.rb @@ -25,8 +25,8 @@ def affiliation_csv signatures = @petition.signatures if params[:institution_id].present? - signatures = signatures.joins(affiliations: :institution). - where(institutions: { id: params[:institution_id] }) + signatures = signatures.joins(affiliations: :institution) + .where(institutions: { id: params[:institution_id] }) end send_data signatures.to_affiliation_csv, @@ -51,10 +51,10 @@ def set_petition end def filtered_signatures - @petition.signatures. - search(params[:query]). - order(created_at: :desc). - paginate(page: params[:page], per_page: params[:per_page] || 10) + @petition.signatures + .search(params[:query]) + .order(created_at: :desc) + .paginate(page: params[:page], per_page: params[:per_page] || 10) end def search_params diff --git a/app/controllers/admin/s3_uploads_controller.rb b/app/controllers/admin/s3_uploads_controller.rb index 78bca4f4b..12f733057 100644 --- a/app/controllers/admin/s3_uploads_controller.rb +++ b/app/controllers/admin/s3_uploads_controller.rb @@ -24,13 +24,13 @@ def create if @source_file.save format.html { render json: @source_file.to_jq_upload, - content_type: "text/html", - layout: false + content_type: "text/html", + layout: false } - format.json { render json: @source_file.to_jq_upload, status: :created } + format.json { render json: @source_file.to_jq_upload, status: 201 } else format.html { render "new" } - format.json { render json: @source_file.errors, status: :unprocessable_entity } + format.json { render json: @source_file.errors, status: 422 } end end end @@ -52,7 +52,7 @@ def destroy # for /admin/action_page/new # GET /admin/source_files/generate_key def generate_key - uid = SecureRandom.uuid.gsub(/-/, "") + uid = SecureRandom.uuid.delete('-') render json: { key: "uploads/#{uid}/#{params[:filename]}", diff --git a/app/controllers/admin/topic_categories_controller.rb b/app/controllers/admin/topic_categories_controller.rb index 7242e9818..5d3123cee 100644 --- a/app/controllers/admin/topic_categories_controller.rb +++ b/app/controllers/admin/topic_categories_controller.rb @@ -25,7 +25,7 @@ def destroy def update topic_category = TopicCategory.find(params[:id]) - if topic_category.update_attributes(topic_category_params) + if topic_category.update(topic_category_params) render json: topic_category else render json: topic_category.errors, status: 500 diff --git a/app/controllers/admin/topic_sets_controller.rb b/app/controllers/admin/topic_sets_controller.rb index 6ca7cb6db..49a58c879 100644 --- a/app/controllers/admin/topic_sets_controller.rb +++ b/app/controllers/admin/topic_sets_controller.rb @@ -28,7 +28,7 @@ def create def update topic_set = TopicSet.find(params[:id]) - if topic_set.update_attributes(topic_set_params) + if topic_set.update(topic_set_params) render json: topic_set else render json: topic_set.errors, status: 500 diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index eb37ff0bb..38453b79f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -6,7 +6,7 @@ def index def update user = User.find(params[:id]) - if user.update_attributes(user_params) + if user.update(user_params) flash[:notice] = "#{user.email} was updated" else flash[:error] = "Could not update #{user.email}" diff --git a/app/controllers/ahoy_controller.rb b/app/controllers/ahoy_controller.rb index 83a56264c..24676ba15 100644 --- a/app/controllers/ahoy_controller.rb +++ b/app/controllers/ahoy_controller.rb @@ -8,8 +8,8 @@ def visit action_page_id = params.require(:action_page_id) ahoy.track "View", - { type: "action", actionType: action_type, actionPageId: action_page_id }, - action_page_id: action_page_id + { type: "action", actionType: action_type, actionPageId: action_page_id }, + action_page_id: action_page_id send_data image_asset, content_type: "image/gif" end diff --git a/app/controllers/concerns/action_page_display.rb b/app/controllers/concerns/action_page_display.rb index f31507472..d26f8340e 100644 --- a/app/controllers/concerns/action_page_display.rb +++ b/app/controllers/concerns/action_page_display.rb @@ -53,18 +53,17 @@ def set_signatures @institution_signature_count = @signatures.pretty_count elsif @petition.enable_affiliations @signatures = @petition.signatures - .includes(affiliations: [:institution, :affiliation_type]) + .includes(affiliations: [:institution, :affiliation_type]) else @signatures = @petition.signatures end @signatures = @signatures - .paginate(page: params[:page], per_page: 9) - .order(created_at: :desc) + .paginate(page: params[:page], per_page: 9) + .order(created_at: :desc) @signature_count = @petition.signatures.pretty_count @require_location = !@petition.enable_affiliations end end - end diff --git a/app/controllers/concerns/date_range.rb b/app/controllers/concerns/date_range.rb index ccefc3f4f..0a061e702 100644 --- a/app/controllers/concerns/date_range.rb +++ b/app/controllers/concerns/date_range.rb @@ -7,10 +7,11 @@ def set_dates def process_dates(date_range_text: nil, date_text: nil, **_) return parse_date_range(date_range_text) if date_range_text.present? - return [1.month.ago, Time.zone.now] unless date_text.present? + return [1.month.ago, Time.zone.now] if date_text.blank? if date_text == "Action lifetime" && @actionPage.present? return [@actionPage.created_at, Time.zone.now] end + [parse_time_ago(date_text), Time.zone.now] end @@ -22,11 +23,13 @@ def parse_date_range(date_range_string) def parse_time_ago(string) _, count, unit = string.split(" ") return Time.zone.now - 1.month unless %w(days weeks months years).include? unit + Time.zone.now - count.to_i.send(unit) end def date_range_string return "" unless @start_date && @end_date + format = "%Y-%m-%d" "#{@start_date.strftime(format)} - #{@end_date.strftime(format)}" end diff --git a/app/controllers/concerns/tooling.rb b/app/controllers/concerns/tooling.rb index e7b0cbef3..34aa13763 100644 --- a/app/controllers/concerns/tooling.rb +++ b/app/controllers/concerns/tooling.rb @@ -5,6 +5,7 @@ module Tooling def create_partner_subscription return unless @action_page + @action_page.partners.each do |partner| if params["#{partner.code}_subscribe"] == "1" Subscription.create(partner_signup_params.merge(partner: partner)) diff --git a/app/controllers/congress_messages_controller.rb b/app/controllers/congress_messages_controller.rb index 0bc6ab8aa..ddd37f54a 100644 --- a/app/controllers/congress_messages_controller.rb +++ b/app/controllers/congress_messages_controller.rb @@ -22,7 +22,7 @@ def new end forms, @links = CongressForms::Form.find(bioguide_ids) @defunct_members, @members = @members.partition do |m| - @links.keys.include? m.bioguide_id + @links.key?(m.bioguide_id) end @message = CongressMessage.new_from_lookup(location, @campaign, forms) render partial: "form" @@ -46,7 +46,7 @@ def create deliver_thanks_message unless subscribe_user render partial: "tools/share" else - render plain: I18n.t(:invalid_submission, scope: :congress_forms), status: :bad_request + render plain: I18n.t(:invalid_submission, scope: :congress_forms), status: 400 end end @@ -103,16 +103,16 @@ def subscribe_user def track_action customized_message = params[:message] != @campaign.message ahoy.track "Action", - { type: "action", actionType: "congress_message", actionPageId: params[:action_id], - customizedMessage: customized_message }, - action_page: @action_page + { type: "action", actionType: "congress_message", actionPageId: params[:action_id], + customizedMessage: customized_message }, + action_page: @action_page end def address_not_found - render plain: I18n.t(:address_lookup_failed, scope: :congress_forms), status: :bad_request + render plain: I18n.t(:address_lookup_failed, scope: :congress_forms), status: 400 end def congress_forms_request_failed - render plain: I18n.t(:request_failed, scope: :congress_forms), status: :internal_server_error + render plain: I18n.t(:request_failed, scope: :congress_forms), status: 500 end end diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb index 515f87f8b..6be6f8af3 100644 --- a/app/controllers/partners_controller.rb +++ b/app/controllers/partners_controller.rb @@ -6,9 +6,9 @@ class PartnersController < ApplicationController # GET /partners/1 # GET /partners/1.json def show - @subscriptions = @partner.subscriptions. - paginate(page: params[:page], per_page: 10). - order("id desc") + @subscriptions = @partner.subscriptions + .paginate(page: params[:page], per_page: 10) + .order("id desc") end def csv @@ -24,13 +24,13 @@ def update format.json { head :no_content } else format.html { render "edit" } - format.json { render json: @partner.errors, status: :unprocessable_entity } + format.json { render json: @partner.errors, status: 422 } end end end def add_user - user = User.find_by_email(params[:email]) + user = User.find_by(email: params[:email]) if user.nil? flash[:notice] = "Couldn't find a user by email #{params[:email]}" else diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 1254ffa85..74065e02d 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -24,12 +24,12 @@ def handle_nonunique_email resource.errors.delete(:email) if resource.errors.empty? - existing = User.find_by_email(resource.email) + existing = User.find_by(email: resource.email) existing.send_email_taken_notice # Allow unconfirmed users to set a new password by re-registering. if !existing.confirmed? - existing.update_attributes(sign_up_params) + existing.update(sign_up_params) end if resource.persisted? diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index d5fe9158d..c7439261e 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -22,8 +22,8 @@ class ToolsController < ApplicationController def call ahoy.track "Action", - { type: "action", actionType: "call", actionPageId: params[:action_id] }, - action_page: @action_page + { type: "action", actionType: "call", actionPageId: params[:action_id] }, + action_page: @action_page @name = current_user.try :name @@ -85,8 +85,8 @@ def petition end ahoy.track "Action", - { type: "action", actionType: "signature", actionPageId: @action_page.id }, - action_page: @action_page + { type: "action", actionType: "signature", actionPageId: @action_page.id }, + action_page: @action_page respond_to do |format| format.json { render json: { success: true }, status: 200 } @@ -107,16 +107,16 @@ def petition def tweet ahoy.track "Action", - { type: "action", actionType: "tweet", actionPageId: params[:action_id] }, - action_page: @action_page + { type: "action", actionType: "tweet", actionPageId: params[:action_id] }, + action_page: @action_page render json: { success: true }, status: 200 end def email - unless (@user and @user.events.emails.find_by_action_page_id(params[:action_id])) or params[:dnt] == "true" + unless (@user and @user.events.emails.find_by(action_page_id: params[:action_id])) or params[:dnt] == "true" ahoy.track "Action", - { type: "action", actionType: "email", actionPageId: params[:action_id] }, - action_page: @action_page + { type: "action", actionType: "email", actionPageId: params[:action_id] }, + action_page: @action_page end if params[:service] == "copy" @@ -162,7 +162,7 @@ def set_user end def set_action_page - @action_page ||= ActionPage.find_by_id(params[:action_id]) + @action_page ||= ActionPage.find_by(id: params[:action_id]) end def create_newsletter_subscription diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 38f7c87f2..8f6b005bd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,7 +7,7 @@ def show end def update - if current_user.update_attributes(user_params) + if current_user.update(user_params) flash[:notice] = "You updated your account successfully." else flash[:notice] = "Could not update your account." diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 8e018e532..269572d32 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,10 +1,10 @@ class WelcomeController < ApplicationController manifest :welcome def index - @actionPages = FeaturedActionPage.includes(:action_page). - order("weight desc"). - map(&:action_page). - compact + @actionPages = FeaturedActionPage.includes(:action_page) + .order("weight desc") + .map(&:action_page) + .compact @featuredActionPage = @actionPages.pop @actionPages = @actionPages.reverse end diff --git a/app/helpers/action_page_helper.rb b/app/helpers/action_page_helper.rb index 1e78245f3..cadbbdfde 100644 --- a/app/helpers/action_page_helper.rb +++ b/app/helpers/action_page_helper.rb @@ -14,7 +14,6 @@ def twitter_share_url(action_page) "https://twitter.com/intent/tweet?text=#{u message}&related=#{related}" end - def tweet_url(target, message) message = [target, message].compact.join(" ") related = Rails.application.config.twitter_related.to_a.join(",") @@ -70,16 +69,17 @@ def parse_email_text(options = {}) title = @actionPage.title name = html_escape(options[:name]) - email_text. - gsub(/\$TITLE/, title). - gsub(/\$URL/, url). - gsub(/\$NAME/, name) + email_text + .gsub(/\$TITLE/, title) + .gsub(/\$URL/, url) + .gsub(/\$NAME/, name) end def visible_partners mailings_enabled = @actionPage.partners.includes(:partnerships) .where(partnerships: { enable_mailings: true }) return mailings_enabled if params[:partner].blank? + mailings_enabled.where(code: params[:partner]) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 12ff78db6..7c26d7b80 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,11 @@ module ApplicationHelper def page_title - t("page_title", scope: [controller_path.gsub("/", "_"), action_name], - default: [@title, I18n.t("site_title")].compact.join(" | ")) + t("page_title", scope: [controller_path.tr("/", "_"), action_name], + default: [@title, I18n.t("site_title")].compact.join(" | ")) end def escape_page_title - URI.escape(page_title , Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + URI.escape(page_title, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end def twitter_handle @@ -71,7 +71,7 @@ def update_user_data(params = {}) if user_signed_in? p = params.clone p.delete(:email) - current_user.update_attributes p + current_user.update p end end @@ -110,6 +110,7 @@ def messages def percentage(x, y, precision: 0) return "-" unless y > 0 + number_to_percentage((x / y.to_f) * 100, precision: precision) end @@ -122,6 +123,7 @@ def user_session_data_whitelist def current_user_data(field) return nil unless user_session_data_whitelist.include? field + current_user.try(field) end end diff --git a/app/helpers/congress_message_helper.rb b/app/helpers/congress_message_helper.rb index 12659b644..8ca9d4c35 100644 --- a/app/helpers/congress_message_helper.rb +++ b/app/helpers/congress_message_helper.rb @@ -3,6 +3,7 @@ def congress_forms_prefills(campaign, field) if field.value == "$TOPIC" && campaign.topic_category.present? return campaign.topic_category.best_match(field.options_hash) end + { "$NAME_FIRST" => current_first_name, "$NAME_LAST" => current_last_name, @@ -30,11 +31,11 @@ def congress_forms_field(field, campaign, message_attributes, bioguide_id = nil) elsif field.value == "$PHONE" telephone_field_tag name, prefill, congress_forms_field_defaults(field) .merge({ - class: "form-control bfh-phone", - "data-format": "ddd-ddd-dddd", - pattern: "^((5\\d[123467890])|(5[123467890]\\d)|([2346789]\\d\\d))-\\d\\d\\d-\\d\\d\\d\\d$", - title: "Must be a valid US phone number entered in 555-555-5555 format" - }) + class: "form-control bfh-phone", + "data-format": "ddd-ddd-dddd", + pattern: "^((5\\d[123467890])|(5[123467890]\\d)|([2346789]\\d\\d))-\\d\\d\\d-\\d\\d\\d\\d$", + title: "Must be a valid US phone number entered in 555-555-5555 format" + }) elsif field.value == "$EMAIL" email_field_tag name, prefill, congress_forms_field_defaults(field) elsif field.value.include?("ADDRESS") && !field.is_select? @@ -44,7 +45,7 @@ def congress_forms_field(field, campaign, message_attributes, bioguide_id = nil) text_field_tag name, prefill, congress_forms_field_defaults(field, placeholder: address_label, "aria-label": address_label) elsif field.is_select? select_tag name, options_for_select(field.options_hash, prefill), - class: "form-control", "aria-label": field.label, include_blank: field.label, required: true + class: "form-control", "aria-label": field.label, include_blank: field.label, required: true else text_field_tag name, prefill, congress_forms_field_defaults(field) end diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index ff4a7e3ce..1be8f9dab 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -14,6 +14,7 @@ def devise_error_messages! end return "" if resource.errors.empty? && flash_alerts.empty? + @hasErrorMessages = true errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages @@ -42,7 +43,7 @@ def devise_error_messages? end def locked_account? - u = User.find_by_email(@user.email) + u = User.find_by(email: @user.email) u && u.access_locked? end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 185fde7cd..aaa37fb16 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -12,7 +12,7 @@ def thanks_message(email, actionPage, options = {}) mail(to: email, subject: "Thanks for taking action") end - def signup_attempt_with_existing_email(user, options = {}) + def signup_attempt_with_existing_email(user, _options = {}) @user = user @email = user.email @token = user.reset_password_token @@ -22,7 +22,7 @@ def signup_attempt_with_existing_email(user, options = {}) private def check_bounces - unless Bounce.find_by_email(@email.downcase).nil? + unless Bounce.find_by(email: @email.downcase).nil? mail.perform_deliveries = false end end diff --git a/app/models/action_institution.rb b/app/models/action_institution.rb index d1491f79d..8609ba92d 100644 --- a/app/models/action_institution.rb +++ b/app/models/action_institution.rb @@ -4,7 +4,8 @@ class ActionInstitution < ActiveRecord::Base def self.add(action_page:, category:, reset: false) return unless action_page.enable_petition && - action_page.petition.enable_affiliations + action_page.petition.enable_affiliations + action_page.action_institutions.delete_all if reset == "1" institution_ids = Institution.where(category: category).pluck(:id) fast_create(action_page_id: action_page.id, institution_ids: institution_ids) @@ -33,5 +34,5 @@ def self.fast_create(action_page_id:, institution_ids:) # * Check if there are any duplicates in production # * If so, remove them in a way that doesn't break anything else # * Uncomment the following line - #validates_uniqueness_of :institution_id, scope: :action_page_id + # validates_uniqueness_of :institution_id, scope: :action_page_id end diff --git a/app/models/action_page.rb b/app/models/action_page.rb index 104a5149a..ecd7631ca 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -36,25 +36,25 @@ class ActionPage < ActiveRecord::Base belongs_to :call_campaign belongs_to :category, optional: true belongs_to :active_action_page_for_redirect, class_name: "ActionPage", - foreign_key: "archived_redirect_action_page_id" + foreign_key: "archived_redirect_action_page_id" belongs_to :author, class_name: "User", foreign_key: :user_id, optional: true accepts_nested_attributes_for :tweet, :petition, :email_campaign, - :call_campaign, :congress_message_campaign, :affiliation_types, :partnerships, - reject_if: :all_blank + :call_campaign, :congress_message_campaign, :affiliation_types, :partnerships, + reject_if: :all_blank has_attached_file :featured_image, amazon_credentials.merge(default_url: "missing.png") has_attached_file :background_image, amazon_credentials has_attached_file :og_image, amazon_credentials validates_media_type_spoof_detection :featured_image, - if: -> { featured_image.present? && featured_image_file_name_came_from_user? } + if: -> { featured_image.present? && featured_image_file_name_came_from_user? } validates_media_type_spoof_detection :background_image, - if: -> { background_image.present? && background_image_file_name_came_from_user? } + if: -> { background_image.present? && background_image_file_name_came_from_user? } validates_media_type_spoof_detection :og_image, - if: -> { og_image.present? && og_image_file_name_came_from_user? } + if: -> { og_image.present? && og_image_file_name_came_from_user? } do_not_validate_attachment_file_type [:featured_image, :background_image, :og_image] - #validates_length_of :og_title, maximum: 65 + # validates_length_of :og_title, maximum: 65 after_save :no_drafts_on_homepage after_save :set_congress_tag, if: -> { enable_congress_message } @@ -84,6 +84,7 @@ def self.status(status) unless %w(archived victory live draft).include?(status) raise ArgumentError, "unrecognized status #{status}" end + case status when "live" where(published: true, archived: false, victory: false) @@ -151,6 +152,7 @@ def image def actions_taken_percent return 0 if view_count == 0 + @percent ||= (action_count / view_count.to_f) * 100 end @@ -195,7 +197,8 @@ def no_drafts_on_homepage end def set_congress_tag - return unless congress_message_campaign.campaign_tag.blank? + return if congress_message_campaign.campaign_tag.present? + congress_message_campaign.update(campaign_tag: slug) end end diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb index 942bfae6e..de0ff08b9 100644 --- a/app/models/ahoy/event.rb +++ b/app/models/ahoy/event.rb @@ -22,7 +22,7 @@ class Event < ActiveRecord::Base scope :calls, -> { where("properties ->> 'actionType' = 'call'") } scope :signatures, -> { where("properties ->> 'actionType' = 'signature'") } scope :tweets, -> { where("properties ->> 'actionType' = 'tweet'") } - scope :on_page, -> (id) { where(action_page_id: id) } + scope :on_page, ->(id) { where(action_page_id: id) } scope :in_range, ->(start_date, end_date) { where(time: start_date..end_date.tomorrow) } @@ -88,7 +88,7 @@ def self.summary def user_opt_out if user - user_id = nil unless user.record_activity? + user_id = nil unless user.record_activity? end end diff --git a/app/models/congress_message.rb b/app/models/congress_message.rb index b67398c5e..24e41979b 100644 --- a/app/models/congress_message.rb +++ b/app/models/congress_message.rb @@ -11,6 +11,7 @@ class CongressMessage $ADDRESS_STREET $ADDRESS_ZIP5 $EMAIL).freeze def common_attributes() @common_attributes || {}; end + def member_attributes() @member_attributes || {}; end def self.new_from_lookup(location, campaign, forms) @@ -20,13 +21,13 @@ def self.new_from_lookup(location, campaign, forms) } if location common_attributes.merge!({ - "$ADDRESS_STREET" => location.street, - "$ADDRESS_CITY" => location.city, - "$ADDRESS_ZIP4" => location.zip4, - "$ADDRESS_ZIP5" => location.zipcode, - "$ADDRESS_STATE" => location.state, - "$ADDRESS_STATE_POSTAL_ABBREV" => location.state - }) + "$ADDRESS_STREET" => location.street, + "$ADDRESS_CITY" => location.city, + "$ADDRESS_ZIP4" => location.zip4, + "$ADDRESS_ZIP5" => location.zipcode, + "$ADDRESS_STATE" => location.state, + "$ADDRESS_STATE_POSTAL_ABBREV" => location.state + }) end new({ common_attributes: common_attributes, forms: forms, campaign: campaign }) end @@ -45,7 +46,7 @@ def forms_minus_common_fields @forms.map do |form| form_minus = form.dup form_minus.fields = form.fields - .reject { |x| common_fields.include?(x) } + .reject { |x| common_fields.include?(x) } form_minus end end @@ -56,6 +57,7 @@ def targets def attributes_for(bioguide_id) return common_attributes unless member_attributes[bioguide_id] + common_attributes.merge(member_attributes[bioguide_id]) end diff --git a/app/models/email_campaign.rb b/app/models/email_campaign.rb index 604935b9b..6bcc18170 100644 --- a/app/models/email_campaign.rb +++ b/app/models/email_campaign.rb @@ -26,7 +26,7 @@ def extra_fields_explain_text(default) def service_uri(service) mailto_addresses = email_addresses.split(/\s*,\s*/).map do |email| - u(email.gsub(" ", "")).gsub("%40", "@") + u(email.delete(" ")).gsub("%40", "@") end.join(",") { diff --git a/app/models/featured_action_page.rb b/app/models/featured_action_page.rb index 78a0c3bae..aeabadd4e 100644 --- a/app/models/featured_action_page.rb +++ b/app/models/featured_action_page.rb @@ -9,6 +9,7 @@ def initialize(attributes = {}) def self.load_for_edit existing = order(:weight).preload(:action_page) return existing unless existing.length < 4 + weights_to_create = (1..4).to_a - existing.map(&:weight) existing += weights_to_create.map { |w| new(weight: w) } end diff --git a/app/models/institution.rb b/app/models/institution.rb index c81c09f8f..406782ee0 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -25,6 +25,7 @@ def self.process_csv(csv_file) CSV.foreach(csv_file.path, headers: true) do |row| row = row.to_hash return [] unless row["name"] + names << row["name"] end end @@ -55,6 +56,7 @@ def self.top(n, first: 0) def included_in_active_actions? return false if action_pages.empty? + action_pages.map(&:status).any? "live" end end diff --git a/app/models/partner.rb b/app/models/partner.rb index 4f665124f..b6fa608f6 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -8,11 +8,10 @@ class Partner < ActiveRecord::Base has_attached_file :logo, amazon_credentials validates_media_type_spoof_detection :logo, - if: -> { logo.present? && logo_file_name_came_from_user? } + if: -> { logo.present? && logo_file_name_came_from_user? } do_not_validate_attachment_file_type [:logo] validates_uniqueness_of :code - def to_csv(options = {}) column_names = %w[first_name last_name email created_at] CSV.generate(options) do |csv| diff --git a/app/models/petition.rb b/app/models/petition.rb index 6c864dc1b..4141ae083 100644 --- a/app/models/petition.rb +++ b/app/models/petition.rb @@ -5,12 +5,13 @@ class Petition < ActiveRecord::Base def percent_complete return 0 if goal == 0 + [signatures.count.to_f / goal.to_f, 1].min * 100 end def recent_signatures(num) recent = [] - signatures.last(num).reverse.each do |s| + signatures.last(num).reverse_each do |s| if s.anonymous recent.push(s.as_json(only: [], methods: [:time_ago, :location])) else @@ -22,7 +23,7 @@ def recent_signatures(num) def signatures_by_institution(institution) signatures.includes(affiliations: :institution) - .where(institutions: { id: institution }) + .where(institutions: { id: institution }) end def location_required? diff --git a/app/models/signature.rb b/app/models/signature.rb index 982ae18b2..a02f13a40 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -8,7 +8,7 @@ class Signature < ActiveRecord::Base before_validation :format_zipcode before_save :sanitize_input validates_presence_of :first_name, :last_name, :petition_id, - message: "This can't be blank." + message: "This can't be blank." validates_presence_of :country_code, if: :location_required? @@ -38,7 +38,7 @@ def self.to_csv(options = {}) CSV.generate(options) do |csv| csv << column_names - all.each do |sub| + all.find_each do |sub| csv << sub.attributes.values_at(*column_names) end end @@ -50,19 +50,19 @@ def self.to_presentable_csv(options = {}) CSV.generate(options) do |csv| csv << column_names - all.each do |signature| + all.find_each do |signature| csv << signature.to_csv_line end end end def self.to_affiliation_csv(options = {}) - column_names = %w[full_name, institution, affiliation_type] + column_names = %w[full_name institution affiliation_type] CSV.generate(options) do |csv| csv << column_names - all.each do |s| + all.find_each do |s| affiliation = s.affiliations.first or next csv << [ @@ -75,8 +75,8 @@ def self.to_affiliation_csv(options = {}) end def self.institutions - joins(affiliations: :institution). - distinct.pluck("institutions.name, institutions.id").sort + joins(affiliations: :institution) + .distinct.pluck("institutions.name, institutions.id").sort end def self.pretty_count diff --git a/app/models/tweet.rb b/app/models/tweet.rb index ae5d52be7..1034e100b 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -3,7 +3,7 @@ class Tweet < ActiveRecord::Base has_many :tweet_targets alias :targets :tweet_targets accepts_nested_attributes_for :tweet_targets, reject_if: :all_blank, - allow_destroy: true + allow_destroy: true def target_congress? target_house? || target_senate? diff --git a/app/models/tweet_target.rb b/app/models/tweet_target.rb index 57b154db4..b83bf6c41 100644 --- a/app/models/tweet_target.rb +++ b/app/models/tweet_target.rb @@ -12,9 +12,7 @@ def url "https://twitter.com/" + twitter_id end - def image_url - image.url - end + delegate :url, to: :image, prefix: true def attach_twitter_image self.delay.attach_twitter_image_without_delay if image_file_name.nil? and Twitter.has_api_keys? diff --git a/app/models/twitter.rb b/app/models/twitter.rb index 117123ec9..93796ca77 100644 --- a/app/models/twitter.rb +++ b/app/models/twitter.rb @@ -1,17 +1,18 @@ class Twitter def self.has_api_keys? - !Rails.application.secrets.twitter_api_key.blank? && - !Rails.application.secrets.twitter_api_secret.blank? && - !Rails.application.secrets.twitter_oauth_token.blank? && - !Rails.application.secrets.twitter_oauth_token_secret.blank? + Rails.application.secrets.twitter_api_key.present? && + Rails.application.secrets.twitter_api_secret.present? && + Rails.application.secrets.twitter_oauth_token.present? && + Rails.application.secrets.twitter_oauth_token_secret.present? end # ref: https://dev.twitter.com/oauth/overview/single-user def self.prepare_access_token(oauth_token, oauth_token_secret) consumer = OAuth::Consumer.new( - Rails.application.secrets.twitter_api_key, - Rails.application.secrets.twitter_api_secret, - { site: "https://api.twitter.com", scheme: :header }) + Rails.application.secrets.twitter_api_key, + Rails.application.secrets.twitter_api_secret, + { site: "https://api.twitter.com", scheme: :header } + ) # now create the access token object from passed values token_hash = { oauth_token: oauth_token, diff --git a/app/models/user.rb b/app/models/user.rb index 526b66a5c..cd328de22 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,17 +64,18 @@ def name end def display_name - return name unless name.blank? + return name if name.present? + email end def percentile_rank user_action_counts = Rails.cache.fetch("user_action_counts", expires_in: 24.hours) { User.select("users.id, count(ahoy_events.id) AS events_count") - .joins("LEFT OUTER JOIN ahoy_events ON ahoy_events.user_id = users.id") - .where("ahoy_events.name IS null OR ahoy_events.name = ?", "Action") - .group("users.id") - .map { |u| u.events_count } + .joins("LEFT OUTER JOIN ahoy_events ON ahoy_events.user_id = users.id") + .where("ahoy_events.name IS null OR ahoy_events.name = ?", "Action") + .group("users.id") + .map { |u| u.events_count } } user_count = events.actions.count diff --git a/app/queries/action_page_filters.rb b/app/queries/action_page_filters.rb index 98d379cd9..0d962346a 100644 --- a/app/queries/action_page_filters.rb +++ b/app/queries/action_page_filters.rb @@ -14,6 +14,7 @@ def run filters.each do |f, val| next unless valid_query?(f, val) + @relation = if NAMED_SCOPES.include? f relation.send(f, val) else @@ -35,7 +36,8 @@ def empty_value?(val) end def process_date_range - return unless filters[:date_range].present? + return if filters[:date_range].blank? + start_date, end_date = parse_date_range @relation = relation.where(created_at: start_date..(end_date + 1.day)) end diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb index 676a65476..5f51a45cf 100644 --- a/app/validators/email_validator.rb +++ b/app/validators/email_validator.rb @@ -1,6 +1,6 @@ class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + unless /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value) record.errors[attribute] << (options[:message] || "is not an email") end end diff --git a/features/step_definitions/active_record_steps.rb b/features/step_definitions/active_record_steps.rb index f1baf8f42..fd52b45f5 100644 --- a/features/step_definitions/active_record_steps.rb +++ b/features/step_definitions/active_record_steps.rb @@ -1,4 +1,3 @@ - When /^there is a persisted ([\w:]+)$/ do |model| @persisted_records ||= [] @persisted_records << Kernel.const_get(model).create! diff --git a/features/step_definitions/admin/features_steps.rb b/features/step_definitions/admin/features_steps.rb index 77a92cdb2..144876e3d 100644 --- a/features/step_definitions/admin/features_steps.rb +++ b/features/step_definitions/admin/features_steps.rb @@ -1,5 +1,3 @@ - - Given(/^a petition exists with many signatures$/) do @petition = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) end diff --git a/features/step_definitions/congress_steps.rb b/features/step_definitions/congress_steps.rb index b2f9d1938..5a607e47a 100644 --- a/features/step_definitions/congress_steps.rb +++ b/features/step_definitions/congress_steps.rb @@ -8,28 +8,32 @@ proxy.stub( "#{Rails.application.config.congress_forms_url}/retrieve-form-elements", method: "post" ).and_return( - Proc.new { |params, headers, body| { - headers: { "Access-Control-Allow-Origin" => "*" }, - json: { - :"#{body.last(7)}" => { - defunct: false, - contact_url: nil, - required_actions: [ - { value: "$NAME_FIRST", maxlength: nil, options_hash: nil }, - { value: "$NAME_LAST", maxlength: nil, options_hash: nil }, - { value: "$EMAIL", maxlength: nil, options_hash: nil } - ] + Proc.new { |params, headers, body| + { + headers: { "Access-Control-Allow-Origin" => "*" }, + json: { + :"#{body.last(7)}" => { + defunct: false, + contact_url: nil, + required_actions: [ + { value: "$NAME_FIRST", maxlength: nil, options_hash: nil }, + { value: "$NAME_LAST", maxlength: nil, options_hash: nil }, + { value: "$EMAIL", maxlength: nil, options_hash: nil } + ] + } } } - } } + } ) proxy.stub( "#{Rails.application.config.congress_forms_url}/fill-out-form", method: "post" ).and_return( - Proc.new { |params, headers, body| { - headers: { "Access-Control-Allow-Origin" => "*" }, - json: { status: "success" } - } } + Proc.new { |params, headers, body| + { + headers: { "Access-Control-Allow-Origin" => "*" }, + json: { status: "success" } + } + } ) end diff --git a/features/step_definitions/debug_steps.rb b/features/step_definitions/debug_steps.rb index a6ecd1371..be3d98837 100644 --- a/features/step_definitions/debug_steps.rb +++ b/features/step_definitions/debug_steps.rb @@ -1,4 +1,3 @@ - When /^I byebug$/ do byebug end diff --git a/features/step_definitions/source_file_steps.rb b/features/step_definitions/source_file_steps.rb index 74127f530..a7bad345b 100644 --- a/features/step_definitions/source_file_steps.rb +++ b/features/step_definitions/source_file_steps.rb @@ -1,4 +1,3 @@ - When(/^there is an uploaded file named "([^\"]+)"$/) do |file_name| step "there is a persisted SourceFile with:", table(%{ |file_name|#{file_name}| diff --git a/features/step_definitions/topic_steps.rb b/features/step_definitions/topic_steps.rb index 15e74c0c3..fa06ef395 100644 --- a/features/step_definitions/topic_steps.rb +++ b/features/step_definitions/topic_steps.rb @@ -1,4 +1,3 @@ - Then /^the topic set containing "([^\"]+)" should be tier ([\d]+)$/ do |topic, tier| topic_set = TopicSet.joins(:topics).where(topics: { name: topic }).take! expect(topic_set.tier).to eq(tier.to_i) diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 62324726e..db568be67 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -1,15 +1,15 @@ def setup_action @action_info = { title: "this is an important call", - summary: "blablabla", - description: "such bla, such bla" } + summary: "blablabla", + description: "such bla, such bla" } end def create_visitor @visitor ||= { name: "Test User", - email: "me@example.com", - zip_code: "94117", - password: "strong passwords defeat lobsters covering wealth", - password_confirmation: "strong passwords defeat lobsters covering wealth" } + email: "me@example.com", + zip_code: "94117", + password: "strong passwords defeat lobsters covering wealth", + password_confirmation: "strong passwords defeat lobsters covering wealth" } end def delete_user @@ -342,8 +342,8 @@ def import_file_into_editor(name, content) @tweet = FactoryGirl.create(:tweet_targeting_senate) @action_page = @tweet.action_page @action_page.update_attributes(title: @action_info[:title], - summary: @action_info[:summary], - description: @action_info[:description]) + summary: @action_info[:summary], + description: @action_info[:description]) end Then(/^I see a button to lookup my reps$/) do @@ -377,8 +377,8 @@ def import_file_into_editor(name, content) @call_campaign = FactoryGirl.create(:call_campaign, call_campaign_id: senate_call_campaign_id, message: "hey hey") @action_page = @call_campaign.action_page @action_page.update_attributes(title: @action_info[:title], - summary: @action_info[:summary], - description: @action_info[:description]) + summary: @action_info[:summary], + description: @action_info[:description]) end Given(/^a call petition targeting a custom number exists$/) do @@ -386,8 +386,8 @@ def import_file_into_editor(name, content) @call_campaign = FactoryGirl.create(:call_campaign, call_campaign_id: custom_call_campaign_id, message: "hey hey") @action_page = @call_campaign.action_page @action_page.update_attributes(title: @action_info[:title], - summary: @action_info[:summary], - description: @action_info[:description]) + summary: @action_info[:summary], + description: @action_info[:description]) end Then(/^I see form fields for phone number, address, and zip code$/) do @@ -452,8 +452,8 @@ def this_machine_offline? wait_until { WebMock::WebMockMatcher.new(:post, CiviCRM::supporters_api_url).matches?(nil) } - WebMock.should have_requested(:post, CiviCRM::supporters_api_url). - with(body: /.*#{email}.*/) + WebMock.should have_requested(:post, CiviCRM::supporters_api_url) + .with(body: /.*#{email}.*/) end Then(/^I should not have signed up for mailings$/) do diff --git a/lib/call_tool.rb b/lib/call_tool.rb index 9bb969e40..ad69326e3 100644 --- a/lib/call_tool.rb +++ b/lib/call_tool.rb @@ -8,15 +8,15 @@ def self.campaign_call(campaign, phone:, location:, user_id:, action_id:, callba get "/call/create", { campaignId: campaign.to_param, - userPhone: phone, + userPhone: phone, userCountry: "US", userLocation: location, callback_url: callback_url, # TODO - Settle on the schema of the private meta data meta: { - user_id: user_id, - action_id: action_id, + user_id: user_id, + action_id: action_id, action_type: "call" }.to_json, } @@ -56,7 +56,7 @@ def self.get(action, params = {}) end # Don't raise for twilio error 13224: number invalid - unless error.match(/^13224:/) + unless error.match?(/^13224:/) if Rails.application.secrets.sentry_dsn.nil? raise error else diff --git a/lib/civicrm.rb b/lib/civicrm.rb index 7773669b7..6fb8f7ac8 100644 --- a/lib/civicrm.rb +++ b/lib/civicrm.rb @@ -10,21 +10,24 @@ def contact_attributes def subscribe!(opt_in = false, source = "action center") return nil if CiviCRM.skip_crm? + res = CiviCRM::subscribe contact_attributes.merge(opt_in: opt_in, source: source) - update_attributes(contact_id: res["contact_id"]) if (res && res["contact_id"]) + update(contact_id: res["contact_id"]) if (res && res["contact_id"]) res || {} end def contact_id! return nil if CiviCRM.skip_crm? + res = CiviCRM::import_contact contact_attributes - update_attributes(contact_id: res["contact_id"]) if (res && res["contact_id"]) + update(contact_id: res["contact_id"]) if (res && res["contact_id"]) contact_id end def add_civicrm_activity!(action_page_id) return nil if CiviCRM.skip_crm? - if contact_id && action_page = ActionPage.find_by_id(action_page_id) + + if contact_id && action_page = ActionPage.find_by(id: action_page_id) CiviCRM::add_activity( contact_id: contact_id, subject: "Took Action #{action_page.id}: #{action_page.title}" @@ -35,6 +38,7 @@ def add_civicrm_activity!(action_page_id) def manage_subscription_url! checksum = CiviCRM::get_checksum(contact_id) return nil unless checksum + "#{Rails.application.secrets.supporters['host']}/update-your-preferences?" + { cid1: contact_id, cs: checksum @@ -48,11 +52,13 @@ def self.skip_crm? def self.subscribe(params) return {} if skip_crm? + self.import_contact params.merge(subscribe: true) end def self.import_contact(params) return {} if skip_crm? + post base_params.merge( method: "import_contact", data: { @@ -73,6 +79,7 @@ def self.import_contact(params) def self.add_activity(params) return nil if skip_crm? + post base_params.merge( method: "add_activity", data: params.slice(:contact_id, :subject, :activity_type_id).to_json @@ -89,10 +96,11 @@ def self.post(params) begin res = JSON.parse RestClient.post(supporters_api_url, params) raise res["error_message"] if res["error"] + return res rescue => e Raven.capture_exception(e) - Rails.logger.error "#{ e } (#{ e.class })!" + Rails.logger.error "#{e} (#{e.class})!" return false end end @@ -116,6 +124,7 @@ def self.find_contact_by_email_data(params) def self.get_checksum(contact_id) return nil if skip_crm? + # Valid for 24 hours res = post base_params.merge( method: "generate_checksum", diff --git a/lib/congress_forms.rb b/lib/congress_forms.rb index a31c483cf..c76e9b9c0 100644 --- a/lib/congress_forms.rb +++ b/lib/congress_forms.rb @@ -7,7 +7,8 @@ class Form def self.find(bioguide_ids) raw_data = CongressForms.post("/retrieve-form-elements/", { bio_ids: bioguide_ids }) raise CongressForms::RequestFailed if raw_data.empty? - links, forms = raw_data.partition { |id, raw| raw["defunct"] } + + links, forms = raw_data.partition { |_id, raw| raw["defunct"] } [ forms.map { |id, raw| Form.new(id, raw["required_actions"]) }, links.map { |id, raw| [id, raw["contact_url"]] }.to_h @@ -46,6 +47,7 @@ def validate(input) return false if input.nil? return false if max_length && input.length > max_length return false unless options.nil? || options.include?(input) + true end @@ -83,6 +85,7 @@ def options_hash def options return options_hash.values if options_hash.is_a?(Hash) + options_hash end end diff --git a/lib/monkey_patches/octet_stream_override.rb b/lib/monkey_patches/octet_stream_override.rb index f8a95ffa8..e2e5c9d24 100644 --- a/lib/monkey_patches/octet_stream_override.rb +++ b/lib/monkey_patches/octet_stream_override.rb @@ -8,11 +8,11 @@ # Additionally, this only allows paperclip to interact with image files # # The class we're patching is here: https://github.com/thoughtbot/paperclip/blob/fbdcbe8da30138dac5500e4291e7b279491d1316/lib/paperclip/media_type_spoof_detector.rb - module MonkeyPatches module OctetStreamOverride def spoofed? - return true unless is_image? + return true unless image? + override_header_type if supplied_content_type == "binary/octet-stream" if has_name? && has_extension? && media_type_mismatch? && mapping_override_mismatch? Paperclip.log("Content Type Spoof: Filename #{File.basename(@name)} (#{supplied_content_type} from Headers, #{content_types_from_name.map(&:to_s)} from Extension), content type discovered from file command: #{calculated_content_type}. See documentation to allow this combination.") @@ -24,8 +24,9 @@ def spoofed? private - def is_image? - return true if /\Aimage\/.*\Z/.match? calculated_content_type + def image? + return true if %r{\Aimage/.*\Z}.match? calculated_content_type + Paperclip.log("Attempted non-image upload: Filename #{File.basename(@name)} (#{supplied_content_type}") false end diff --git a/lib/places.rb b/lib/places.rb index 8e4825d34..16e84e894 100644 --- a/lib/places.rb +++ b/lib/places.rb @@ -324,5 +324,4 @@ def self.country_codes ["Zimbabwe", "ZW"] ].freeze end - end diff --git a/lib/related_content.rb b/lib/related_content.rb index ab5cd05a6..1c689dcc4 100644 --- a/lib/related_content.rb +++ b/lib/related_content.rb @@ -5,6 +5,7 @@ def initialize(url) def load return if url.blank? + begin open_page @loaded_successfully = true @@ -23,6 +24,7 @@ def title def image return @image if @image + og_url = page.css("meta[property='og:image']") @image = if og_url.blank? "" diff --git a/lib/smarty_streets.rb b/lib/smarty_streets.rb index b7d004434..575900495 100644 --- a/lib/smarty_streets.rb +++ b/lib/smarty_streets.rb @@ -3,7 +3,7 @@ module SmartyStreets def self.get_city_state(zipcode) url = "https://us-zipcode.api.smartystreets.com/lookup" res = post(url, base_params.merge(zipcode: zipcode)) - if res && !res.empty? + if res.present? res.first["city_states"].try :first end end @@ -11,7 +11,7 @@ def self.get_city_state(zipcode) def self.get_location(street, zipcode) url = "https://api.smartystreets.com/street-address" res = post(url, base_params.merge(street: street, zipcode: zipcode)) - raise AddressNotFound if !res || res.empty? + raise AddressNotFound if res.blank? location = OpenStruct.new location.street = street @@ -39,7 +39,7 @@ def self.post(url, params) return res rescue => e Raven.capture_exception(e) - Rails.logger.error "#{ e } (#{ e.class })!" + Rails.logger.error "#{e} (#{e.class})!" return false end end diff --git a/lib/tasks/congress.rake b/lib/tasks/congress.rake index cbf8b5967..72d78d07e 100644 --- a/lib/tasks/congress.rake +++ b/lib/tasks/congress.rake @@ -1,4 +1,3 @@ - namespace :congress do desc "Create/update records of Congress members and their contact info" task update: :environment do @@ -22,29 +21,30 @@ namespace :congress do full_name = info["name"]["official_full"] || "#{info['name']['first']} #{info['name']['last']}" attributes = { - full_name: full_name, - first_name: info["name"]["first"], - last_name: info["name"]["last"], + full_name: full_name, + first_name: info["name"]["first"], + last_name: info["name"]["last"], bioguide_id: info["id"]["bioguide"], - phone: term["phone"], - term_end: term["end"], - chamber: term["type"] == "sen" ? "senate" : "house", - state: term["state"], - district: term["district"].try(:to_s) + phone: term["phone"], + term_end: term["end"], + chamber: term["type"] == "sen" ? "senate" : "house", + state: term["state"], + district: term["district"].try(:to_s) } - CongressMember. - find_or_initialize_by(bioguide_id: info["id"]["bioguide"]). - update_attributes!(attributes) + CongressMember + .find_or_initialize_by(bioguide_id: info["id"]["bioguide"]) + .update!(attributes) end legislator_social_media_sources.each do |repo| data = RestClient.get(repo) YAML.load(data).each do |info| next unless twitter_id = info["social"]["twitter"] - CongressMember. - where(bioguide_id: info["id"]["bioguide"]). - update_all(twitter_id: twitter_id) + + CongressMember + .where(bioguide_id: info["id"]["bioguide"]) + .update_all(twitter_id: twitter_id) end end end diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 8387e041b..f69b99c48 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -6,58 +6,58 @@ unless ARGV.any? { |a| a =~ /^gems/ } # Don't load anything when running the gems:* tasks -vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first -$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + "/../lib") unless vendored_cucumber_bin.nil? - -begin - require "cucumber/rake/task" - - namespace :cucumber do - Cucumber::Rake::Task.new({ ok: "test:prepare" }, "Run features that should pass") do |t| - t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. - t.fork = true # You may get faster startup if you set this to false - t.profile = "default" + vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first + $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + "/../lib") unless vendored_cucumber_bin.nil? + + begin + require "cucumber/rake/task" + + namespace :cucumber do + Cucumber::Rake::Task.new({ ok: "test:prepare" }, "Run features that should pass") do |t| + t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. + t.fork = true # You may get faster startup if you set this to false + t.profile = "default" + end + + Cucumber::Rake::Task.new({ wip: "test:prepare" }, "Run features that are being worked on") do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = "wip" + end + + Cucumber::Rake::Task.new({ rerun: "test:prepare" }, "Record failing features and run only them if any exist") do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = "rerun" + end + + desc "Run all features" + task all: [:ok, :wip] + + task :statsetup do + require "rails/code_statistics" + ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?("features") + ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?("features") + end end + desc "Alias for cucumber:ok" + task cucumber: "cucumber:ok" - Cucumber::Rake::Task.new({ wip: "test:prepare" }, "Run features that are being worked on") do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = "wip" - end + task default: :cucumber - Cucumber::Rake::Task.new({ rerun: "test:prepare" }, "Record failing features and run only them if any exist") do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = "rerun" + task features: :cucumber do + STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" end - desc "Run all features" - task all: [:ok, :wip] - - task :statsetup do - require "rails/code_statistics" - ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?("features") - ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?("features") + # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. + task "test:prepare" do end - end - desc "Alias for cucumber:ok" - task cucumber: "cucumber:ok" - - task default: :cucumber - task features: :cucumber do - STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" - end - - # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. - task "test:prepare" do - end - - task stats: "cucumber:statsetup" -rescue LoadError - desc "cucumber rake task not available (cucumber not installed)" - task :cucumber do - abort "Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin" + task stats: "cucumber:statsetup" + rescue LoadError + desc "cucumber rake task not available (cucumber not installed)" + task :cucumber do + abort "Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin" + end end end -end diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index f186adbc1..26c72fded 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -8,8 +8,8 @@ namespace :users do end desc "Remove admin status from an account, given an email" - task :remove_admin, [:email] => :environment do |t, args| - u = User.find_by_email(args[:email]) + task :remove_admin, [:email] => :environment do |_t, args| + u = User.find_by(email: args[:email]) abort("I couldn't find a user with the email '#{args[:email]}'.") unless u u.admin = false @@ -17,9 +17,9 @@ namespace :users do end desc "Add admin status from an account, given an email" - task :add_admin, [:email] => :environment do |t, args| + task :add_admin, [:email] => :environment do |_t, args| email = args[:email] - u = User.find_by_email(email) + u = User.find_by(email: email) abort("I couldn't find a user with the email '#{email}'.") unless u u.admin = true diff --git a/spec/controllers/action_page_controller_spec.rb b/spec/controllers/action_page_controller_spec.rb index a4b51b512..8e2cd1832 100644 --- a/spec/controllers/action_page_controller_spec.rb +++ b/spec/controllers/action_page_controller_spec.rb @@ -43,8 +43,8 @@ it "redirects to an admin specified url if redirect is enabled" do action_page = FactoryGirl.create :action_page, - enable_redirect: true, - redirect_url: "https://example.com" + enable_redirect: true, + redirect_url: "https://example.com" get :show, params: { id: action_page } expect(response).to redirect_to "https://example.com" end @@ -53,7 +53,7 @@ let(:active_action_page) { FactoryGirl.create :action_page } let(:archived_action_page) { FactoryGirl.create :archived_action_page, - active_action_page_for_redirect: active_action_page + active_action_page_for_redirect: active_action_page } it "redirects archived actions to active actions" do @@ -62,7 +62,7 @@ end it "doesn't redirect away from victories" do - archived_action_page.update_attributes(victory: true) + archived_action_page.update(victory: true) get :show, params: { id: archived_action_page } expect(response.status).to eq(200) end @@ -100,24 +100,24 @@ # Signature with affiliations to two different institutions signature = FactoryGirl.create(:signature, - petition: @petition) + petition: @petition) signature.affiliations << FactoryGirl.create(:affiliation, - institution: @actionPage.institutions.first) + institution: @actionPage.institutions.first) signature.affiliations << FactoryGirl.create(:affiliation, - institution: @actionPage.institutions.last) + institution: @actionPage.institutions.last) # Signature with an affiliation to the second institutions signature = FactoryGirl.create(:signature, - petition: @petition) + petition: @petition) signature.affiliations << FactoryGirl.create(:affiliation, - institution: @actionPage.institutions.last, - affiliation_type: @actionPage.affiliation_types.first) + institution: @actionPage.institutions.last, + affiliation_type: @actionPage.affiliation_types.first) end context "html" do it "assigns signatures filtered by institution" do get :show_by_institution, params: { id: @actionPage.id, - institution_id: @actionPage.institutions.first.id } + institution_id: @actionPage.institutions.first.id } expect(assigns(:institution)).to eq(@actionPage.institutions.first) # it should assign signatures associated with the institution diff --git a/spec/controllers/admin/institutions_controller_spec.rb b/spec/controllers/admin/institutions_controller_spec.rb index 36fbbc72e..04b56087a 100644 --- a/spec/controllers/admin/institutions_controller_spec.rb +++ b/spec/controllers/admin/institutions_controller_spec.rb @@ -32,7 +32,7 @@ it "creates a new institution" do expect { post :create, params: { action_page_id: @actionPage.id, - institution: valid_attributes } + institution: valid_attributes } }.to change(Institution, :count).by(1) end @@ -40,7 +40,7 @@ institution = Institution.create! valid_attributes expect { post :create, params: { action_page_id: @actionPage.id, - institution: valid_attributes } + institution: valid_attributes } }.to_not change(Institution, :count) end end @@ -64,13 +64,13 @@ end it "uploads institutions" do - expect(Institution). - to receive(:import).with( - "University", - ["University of California, Berkeley", - "University of California, Davis", - "University of California, Santa Cruz"] - ) + expect(Institution) + .to receive(:import).with( + "University", + ["University of California, Berkeley", + "University of California, Davis", + "University of California, Santa Cruz"] + ) import_and_work_off end end diff --git a/spec/controllers/concerns/logged_invisible_captcha_spec.rb b/spec/controllers/concerns/logged_invisible_captcha_spec.rb index 7af02623c..bcbbd5d20 100644 --- a/spec/controllers/concerns/logged_invisible_captcha_spec.rb +++ b/spec/controllers/concerns/logged_invisible_captcha_spec.rb @@ -9,11 +9,11 @@ def create; end it "blocks requests that fill the honeypot" do expect(controller).not_to receive(:create) - post :create, foo: "bar" + post :create, params: { foo: "bar" } end it "logs spammy requests to Sentry" do expect(Raven).to receive(:capture_message) - post :create, foo: "bar" + post :create, params: { foo: "bar" } end end diff --git a/spec/controllers/concerns/request_origin_validation_spec.rb b/spec/controllers/concerns/request_origin_validation_spec.rb index 64361b79f..842d22e8f 100644 --- a/spec/controllers/concerns/request_origin_validation_spec.rb +++ b/spec/controllers/concerns/request_origin_validation_spec.rb @@ -58,8 +58,8 @@ it "should raise an error for POST requests" do request["post?"] = true - expect { controller.verify_request_origin }. - to raise_error(ActionController::InvalidCrossOriginRequest) + expect { controller.verify_request_origin } + .to raise_error(ActionController::InvalidCrossOriginRequest) end end end diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index 384937958..d94ef9055 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -41,8 +41,8 @@ describe "without a successful connection to civicrm" do before do - stub_request(:post, CiviCRM::supporters_api_url). - and_return(status: 400, body: "{}", headers: {}) + stub_request(:post, CiviCRM::supporters_api_url) + .and_return(status: 400, body: "{}", headers: {}) end it "fails gracefully" do @@ -52,5 +52,4 @@ end end end - end diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 4379d151b..9bc5aba3b 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -1,17 +1,19 @@ require "rails_helper" RSpec.describe ToolsController, type: :controller do - let(:valid_attributes) { { - signature: { - "petition_id" => "1", - "email" => "rob@eff.org", - "first_name" => "adsf", - "last_name" => "asdf", - "zipcode" => "94109", - "city" => "", - "country_code" => "" + let(:valid_attributes) { + { + signature: { + "petition_id" => "1", + "email" => "rob@eff.org", + "first_name" => "adsf", + "last_name" => "asdf", + "zipcode" => "94109", + "city" => "", + "country_code" => "" + } } - } } + } before(:each) do stub_smarty_streets @@ -49,11 +51,11 @@ expect(CallTool).to receive(:campaign_call) post :call, params: { - phone: "000-000-0000", - location: "00000", - call_campaign_id: call_campaign.id, - action_id: call_campaign.action_page.id - } + phone: "000-000-0000", + location: "00000", + call_campaign_id: call_campaign.id, + action_id: call_campaign.action_page.id + } end end diff --git a/spec/factories/action_page.rb b/spec/factories/action_page.rb index 1ef32505e..f36f1c7eb 100644 --- a/spec/factories/action_page.rb +++ b/spec/factories/action_page.rb @@ -8,7 +8,7 @@ victory_message "We won" trait :with_partner do - after(:create) do |action_page, evaluator| + after(:create) do |action_page, _evaluator| action_page.partners << FactoryGirl.create(:partner) end end @@ -42,7 +42,7 @@ end factory :action_page_with_views, parent: :action_page do - after(:build) do |action_page, evaluator| + after(:build) do |action_page, _evaluator| 10.times do |n| FactoryGirl.create(:ahoy_view, action_page: action_page, diff --git a/spec/factories/ahoy_event.rb b/spec/factories/ahoy_event.rb index d8d0b1311..af6cac44e 100644 --- a/spec/factories/ahoy_event.rb +++ b/spec/factories/ahoy_event.rb @@ -2,20 +2,24 @@ factory :ahoy_view, class: Ahoy::Event do id { SecureRandom.uuid } name "View" - properties { { - type: "action", - actionType: "view" - } } + properties { + { + type: "action", + actionType: "view" + } + } time Time.zone.now end factory :ahoy_signature, class: Ahoy::Event do id { SecureRandom.uuid } name "Action" - properties { { - type: "action", - actionType: "signature" - } } + properties { + { + type: "action", + actionType: "signature" + } + } time Time.zone.now end end diff --git a/spec/factories/congress_message.rb b/spec/factories/congress_message.rb index 0dd0740fc..f262254e8 100644 --- a/spec/factories/congress_message.rb +++ b/spec/factories/congress_message.rb @@ -1,20 +1,20 @@ FactoryGirl.define do form1 = CongressForms::Form.new("C000880", [ - { "value" => "$NAME_FIRST" }, - { "value" => "$NAME_LAST" }, - { "value" => "$ADDRESS_STATE", "options_hash" => { - "CALIFORNIA" => "CA", - "NEW YORK" => "NY" - } } - ]) + { "value" => "$NAME_FIRST" }, + { "value" => "$NAME_LAST" }, + { "value" => "$ADDRESS_STATE", "options_hash" => { + "CALIFORNIA" => "CA", + "NEW YORK" => "NY" + } } + ]) form2 = CongressForms::Form.new("C000881", [ - { "value" => "$ADDRESS_CITY" }, - { "value" => "$ADDRESS_STATE", "options_hash" => { - "CALIFORNIA" => "CA", - "NEW YORK" => "NY" - } } - ]) + { "value" => "$ADDRESS_CITY" }, + { "value" => "$ADDRESS_STATE", "options_hash" => { + "CALIFORNIA" => "CA", + "NEW YORK" => "NY" + } } + ]) factory :congress_message do forms [form1, form2] diff --git a/spec/factories/topic_category.rb b/spec/factories/topic_category.rb index 061dbae76..f538cdbbb 100644 --- a/spec/factories/topic_category.rb +++ b/spec/factories/topic_category.rb @@ -2,7 +2,7 @@ factory :topic_category do name "Demons" - after(:create) do |category, evaluator| + after(:create) do |category, _evaluator| create_list(:topic_set, 2, topic_category: category) end end diff --git a/spec/factories/topic_set.rb b/spec/factories/topic_set.rb index 7a5a2d571..a2075b060 100644 --- a/spec/factories/topic_set.rb +++ b/spec/factories/topic_set.rb @@ -2,7 +2,7 @@ factory :topic_set do sequence(:tier) { |n| n } - after(:create) do |set, evaluator| + after(:create) do |set, _evaluator| create_list(:topic, 2, topic_set: set) end end diff --git a/spec/features/action_pages/call_action_spec.rb b/spec/features/action_pages/call_action_spec.rb index 2c09c4baa..5637af6cf 100644 --- a/spec/features/action_pages/call_action_spec.rb +++ b/spec/features/action_pages/call_action_spec.rb @@ -6,10 +6,10 @@ end let!(:calltool_request) do { - "objects" => [{ "id" => 1, "name" => "call someone", "status" => "live" }], - "required_fields" => { "userLocation" => "" }, - "page" => 1, - "total_pages" => 1 + "objects" => [{ "id" => 1, "name" => "call someone", "status" => "live" }], + "required_fields" => { "userLocation" => "" }, + "page" => 1, + "total_pages" => 1 }.to_json end diff --git a/spec/features/action_pages/congress_action_spec.rb b/spec/features/action_pages/congress_action_spec.rb index 7dc267a68..071a3244c 100644 --- a/spec/features/action_pages/congress_action_spec.rb +++ b/spec/features/action_pages/congress_action_spec.rb @@ -22,12 +22,12 @@ before do allow(SmartyStreets).to receive(:get_location).and_return(location) - stub_request(:post, /retrieve-form-elements/). - with(body: { "bio_ids" => ["C000880", "A000360"] }). - and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) - stub_request(:post, /retrieve-form-elements/). - with(body: { "bio_ids" => ["", "C000880", "A000360"] }). - and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) + stub_request(:post, /retrieve-form-elements/) + .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) + stub_request(:post, /retrieve-form-elements/) + .with(body: { "bio_ids" => ["", "C000880", "A000360"] }) + .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) stub_request(:post, /fill-out-form/).and_return(status: 200, body: "{}") end diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index 08cb7e5d8..f7b443704 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -34,7 +34,7 @@ select_action_type("petition") fill_in_editor "#action_page_petition_attributes_description", - with: "A petititon letter" + with: "A petititon letter" fill_in "Goal", with: 1000 next_section @@ -105,7 +105,7 @@ select_action_type "call" fill_in_editor "#action_page_call_campaign_attributes_message", - with: "Call script" + with: "Call script" next_section # skip banner selection diff --git a/spec/features/congress_message.rb b/spec/features/congress_message.rb index c412e4846..5c7434866 100644 --- a/spec/features/congress_message.rb +++ b/spec/features/congress_message.rb @@ -25,16 +25,16 @@ allow(SmartyStreets).to receive(:get_location).and_return(location) - stub_request(:post, /retrieve-form-elements/). - with(body: { "bio_ids" => ["C000880", "A000360"] }). - and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) + stub_request(:post, /retrieve-form-elements/) + .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) - stub_request(:post, /fill-out-form/). - and_return(status: 200, body: "{}") + stub_request(:post, /fill-out-form/) + .and_return(status: 200, body: "{}") end scenario "User submits a congress message and subscribes to newletters" do - visit "/action/#{action_page.title.downcase.gsub(" ", "-")}?partner=#{partner.code}" + visit "/action/#{action_page.title.downcase.tr(" ", "-")}?partner=#{partner.code}" fill_in "street_address", with: "The Library" fill_in "zipcode", with: "94109" click_button "Submit your message" @@ -51,10 +51,10 @@ expect(page).to have_content "Now help spread the word" expect(partner.subscriptions.count).to eq 1 - expect(WebMock).to have_requested(:post, CiviCRM::supporters_api_url). - with(body: hash_including({ - data: '{"contact_params":{"email":"mrgiles@sunnydale.edu","first_name":"Rupert","last_name":"Giles","source":"action center congress message :: Sample Action Page","subscribe":true,"opt_in":true},"address_params":{"city":"Sunnydale","state":null,"street":"The Library","zip":"94109","country":null},"phone":null}' - })) + expect(WebMock).to have_requested(:post, CiviCRM::supporters_api_url) + .with(body: hash_including({ + data: '{"contact_params":{"email":"mrgiles@sunnydale.edu","first_name":"Rupert","last_name":"Giles","source":"action center congress message :: Sample Action Page","subscribe":true,"opt_in":true},"address_params":{"city":"Sunnydale","state":null,"street":"The Library","zip":"94109","country":null},"phone":null}' + })) end scenario "Logged in user submits a congress message" do @@ -64,7 +64,7 @@ email: "mrgiles@sunnydale.edu") sign_in_user(giles) - visit "/action/#{action_page.title.downcase.gsub(" ", "-")}" + visit "/action/#{action_page.title.downcase.tr(" ", "-")}" click_button "Submit your message" fill_in "common_attributes__NAME_FIRST", with: "Ripper" diff --git a/spec/lib/action_cloner_spec.rb b/spec/lib/action_cloner_spec.rb index 4882833e9..9c22178ad 100644 --- a/spec/lib/action_cloner_spec.rb +++ b/spec/lib/action_cloner_spec.rb @@ -46,7 +46,7 @@ shared_examples "properly duplicates campaign" do |enable_mthd, model| let(:page) do FactoryGirl.create(:action_page, enable_mthd => true, - model => FactoryGirl.create(model)) + model => FactoryGirl.create(model)) end let(:clone) { described_class.run(page) } it "does not persist" do @@ -66,7 +66,7 @@ it_behaves_like "properly duplicates campaign", :enable_petition, :petition it_behaves_like "properly duplicates campaign", :enable_call, :call_campaign it_behaves_like "properly duplicates campaign", :enable_congress_message, - :congress_message_campaign + :congress_message_campaign def filter_attrs(attrs) attrs_not_cloned = %w(published archived created_at updated_at slug id) diff --git a/spec/lib/call_tool_spec.rb b/spec/lib/call_tool_spec.rb index 28a128c48..494b1bb57 100644 --- a/spec/lib/call_tool_spec.rb +++ b/spec/lib/call_tool_spec.rb @@ -95,8 +95,8 @@ } before do - stub_request(:get, %r{/api/campaign\?api_key(.*)?&page=1}). - to_return(status: 200, body: { "objects" => [calltool_campaign], "page" => 1, "total_pages" => 1 }.to_json) + stub_request(:get, %r{/api/campaign\?api_key(.*)?&page=1}) + .to_return(status: 200, body: { "objects" => [calltool_campaign], "page" => 1, "total_pages" => 1 }.to_json) end it "should get call_tool_url/api/campaign and return values with id, name, status" do diff --git a/spec/lib/congress_forms_spec.rb b/spec/lib/congress_forms_spec.rb index 7c01ec8a7..57df97f35 100644 --- a/spec/lib/congress_forms_spec.rb +++ b/spec/lib/congress_forms_spec.rb @@ -4,27 +4,29 @@ describe CongressForms::Form do let(:form) { CongressForms::Form.new("C000880", [ - { "value" => "$NAME_FIRST" }, - { "value" => "$NAME_LAST" }, - { "value" => "$ADDRESS_STATE", "options_hash" => { - "CALIFORNIA" => "CA", - "NEW YORK" => "NY" - } } - ]) + { "value" => "$NAME_FIRST" }, + { "value" => "$NAME_LAST" }, + { "value" => "$ADDRESS_STATE", "options_hash" => { + "CALIFORNIA" => "CA", + "NEW YORK" => "NY" + } } + ]) } - let(:input) { { - "$NAME_FIRST" => "Willow", - "$NAME_LAST" => "Rosenberg", - "$MESSAGE" => "Impeach Mayor Richard Wilkins III", - "$ADDRESS_STATE" => "CA" - } } + let(:input) { + { + "$NAME_FIRST" => "Willow", + "$NAME_LAST" => "Rosenberg", + "$MESSAGE" => "Impeach Mayor Richard Wilkins III", + "$ADDRESS_STATE" => "CA" + } + } describe "::find" do before do - stub_request(:post, /retrieve-form-elements/). - with(body: { "bio_ids" => ["C000880", "A000360"] }). - and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) + stub_request(:post, /retrieve-form-elements/) + .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) end it "retrieves a Form for each bioguide_id" do @@ -38,13 +40,13 @@ describe "#fill" do it "posts to the congress forms API" do - stub_request(:post, /fill-out-form/). - and_return(status: 200, body: "{}") + stub_request(:post, /fill-out-form/) + .and_return(status: 200, body: "{}") campaign = FactoryGirl.build(:congress_message_campaign) form.fill(input, campaign.campaign_tag) - expect(WebMock).to have_requested(:post, /fill-out-form/). - with(body: { bio_id: "C000880", fields: input, - campaign_tag: campaign.campaign_tag }) + expect(WebMock).to have_requested(:post, /fill-out-form/) + .with(body: { bio_id: "C000880", fields: input, + campaign_tag: campaign.campaign_tag }) end end end diff --git a/spec/models/action_page_spec.rb b/spec/models/action_page_spec.rb index e292e1cad..251011420 100644 --- a/spec/models/action_page_spec.rb +++ b/spec/models/action_page_spec.rb @@ -29,7 +29,7 @@ let(:new_slug) { "a-better-slug" } it "has a friendly slug" do - expect(page.slug).to eq(page.title.downcase.gsub(" ", "-")) + expect(page.slug).to eq(page.title.downcase.tr(" ", "-")) end it "updates the slug when title changes" do @@ -149,19 +149,19 @@ before { FactoryGirl.create(:action_page) } it_behaves_like "returns only the given status", "archived", - [:action_page, { archived: true }] + [:action_page, { archived: true }] it_behaves_like "returns only the given status", "victory", - [:action_page, { victory: true }] + [:action_page, { victory: true }] it_behaves_like "returns only the given status", "draft", - [:action_page, { published: false }] + [:action_page, { published: false }] end context "live action" do before { FactoryGirl.create(:action_page, published: false) } it_behaves_like "returns only the given status", "live", - [:action_page, { published: true }] + [:action_page, { published: true }] end it "raises an ArgumentError when an invalid status is given" do diff --git a/spec/models/congress_message_campaign_spec.rb b/spec/models/congress_message_campaign_spec.rb index 601b3d551..58f136c04 100644 --- a/spec/models/congress_message_campaign_spec.rb +++ b/spec/models/congress_message_campaign_spec.rb @@ -1,4 +1,3 @@ - require "rails_helper" describe EmailCampaign do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index af5fd159a..ea7dc5aff 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -17,16 +17,16 @@ describe "password management" do it "resets password reset tokens upon email change" do - user.update_attributes(reset_password_token: "stub_token") - user.update_attributes(email: "2" + user.email) + user.update(reset_password_token: "stub_token") + user.update(email: "2" + user.email) user.confirm expect(user.reset_password_token).to be_nil end it "resets password reset tokens upon password change" do - user.update_attributes(reset_password_token: "stub_token") + user.update(reset_password_token: "stub_token") expect(user.reset_password_token).not_to be_nil - user.update_attributes(password: "My new password is pretty great") + user.update(password: "My new password is pretty great") expect(user.reset_password_token).to be_nil end @@ -85,12 +85,12 @@ def record_several_actions def track_signature(action_page) ahoy.track "Action", - { type: "action", actionType: "signature", actionPageId: action_page.id }, - action_page: action_page + { type: "action", actionType: "signature", actionPageId: action_page.id }, + action_page: action_page end def track_view(action_page) ahoy.track "View", - { type: "action", actionType: "view", actionPageId: action_page.id }, - action_page: action_page + { type: "action", actionType: "view", actionPageId: action_page.id }, + action_page: action_page end diff --git a/spec/queries/action_page_filters_spec.rb b/spec/queries/action_page_filters_spec.rb index c232c9d2f..5f984330c 100644 --- a/spec/queries/action_page_filters_spec.rb +++ b/spec/queries/action_page_filters_spec.rb @@ -34,11 +34,11 @@ it "does not filter when values are blank or 'all'" do FactoryGirl.create(:action_page) FactoryGirl.create(:action_page, enable_tweet: true, - category: FactoryGirl.create(:category)) + category: FactoryGirl.create(:category)) FactoryGirl.create(:action_page, enable_tweet: true, published: false, - created_at: Time.zone.today - 7.days) + created_at: Time.zone.today - 7.days) result = described_class.run(category: "all", type: "", status: "all", - author: "", date_range: "") + author: "", date_range: "") expect(result.size).to eq(3) end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 90ba63766..ebb98f035 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -28,7 +28,6 @@ # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! - apparition_opts = { window_size: [1400, 900], screen_size: [1920, 1090], diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb index f47f72966..362055867 100644 --- a/spec/requests/admin/events_spec.rb +++ b/spec/requests/admin/events_spec.rb @@ -7,44 +7,44 @@ describe "#index" do context "with type param" do it "responds with views over time as JSON" do - expect(Time.zone). - to receive(:now). - and_return(Time.local(2019)). - at_least(:once) + expect(Time.zone) + .to receive(:now) + .and_return(Time.local(2019)) + .at_least(:once) get "/admin/action_pages/#{action_page.slug}/events", - params: { type: "views" }, - headers: { "ACCEPT" => "application/json" } + params: { type: "views" }, + headers: { "ACCEPT" => "application/json" } expect(response.code).to eq "200" # Default is to return data for the previous month. - expect(JSON.parse(response.body).keys). - to include(*(1..31).map { |i| sprintf("Dec %d 2018", i) }) + expect(JSON.parse(response.body).keys) + .to include(*(1..31).map { |i| sprintf("Dec %d 2018", i) }) end it "filters by date" do start_date = Time.utc(2019, 1, 1).strftime("%Y-%m-%d") end_date = Time.utc(2019, 1, 7).strftime("%Y-%m-%d") get "/admin/action_pages/#{action_page.slug}/events", - params: { - date_range_text: "Jan 1, 2019 - Jan 8, 2019", - type: "views" - }, - headers: { "ACCEPT" => "application/json" } + params: { + date_range_text: "Jan 1, 2019 - Jan 8, 2019", + type: "views" + }, + headers: { "ACCEPT" => "application/json" } # Returns one datapoint per day in range. - expect(JSON.parse(response.body).keys). - to eq([ - "Jan 1 2019", - "Jan 2 2019", - "Jan 3 2019", - "Jan 4 2019", - "Jan 5 2019", - "Jan 6 2019", - "Jan 7 2019", - "Jan 8 2019" - ]) + expect(JSON.parse(response.body).keys) + .to eq([ + "Jan 1 2019", + "Jan 2 2019", + "Jan 3 2019", + "Jan 4 2019", + "Jan 5 2019", + "Jan 6 2019", + "Jan 7 2019", + "Jan 8 2019" + ]) end end @@ -67,5 +67,4 @@ end end end - end diff --git a/spec/requests/admin/s3_uploads_spec.rb b/spec/requests/admin/s3_uploads_spec.rb index 7f6eb0bfe..b897432dc 100644 --- a/spec/requests/admin/s3_uploads_spec.rb +++ b/spec/requests/admin/s3_uploads_spec.rb @@ -1,18 +1,20 @@ require "rails_helper" RSpec.describe "S3 Uploads Spec", type: :request do - let(:valid_attributes) { { - "source_file" => { - "bucket" => "actioncenter-staging", - "file_name" => "img.png", - "file_content_type" => "image", - "file_size" => "10", - "key" => "uploads/3be325f2b4e64d9d92a89405577280a4/img.png" - }, - "action" => "create", - "controller" => "admin/s3_uploads", - "format" => "json" - } } + let(:valid_attributes) { + { + "source_file" => { + "bucket" => "actioncenter-staging", + "file_name" => "img.png", + "file_content_type" => "image", + "file_size" => "10", + "key" => "uploads/3be325f2b4e64d9d92a89405577280a4/img.png" + }, + "action" => "create", + "controller" => "admin/s3_uploads", + "format" => "json" + } + } before(:each) do # bypasses a 3rd party lookup (s3) diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index ab20708a0..f49bcd4c4 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -21,17 +21,17 @@ } def stub_congress_forms_find_with_two_reps - stub_request(:post, /retrieve-form-elements/). - with(body: { "bio_ids" => ["C000880", "A000360"] }). - and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) + stub_request(:post, /retrieve-form-elements/) + .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) end def stub_congress_forms_find_with_one_rep forms_body = JSON.parse(file_fixture("retrieve-form-elements.json").read) forms_body.delete("A000360") - stub_request(:post, /retrieve-form-elements/). - with(body: { "bio_ids" => ["C000880"] }). - and_return(status: 200, body: forms_body.to_json) + stub_request(:post, /retrieve-form-elements/) + .with(body: { "bio_ids" => ["C000880"] }) + .and_return(status: 200, body: forms_body.to_json) end before do @@ -81,7 +81,7 @@ def get_congress_message_form end it "to target a single chamber" do - members.last.update_attributes(chamber: "house", district: 10) + members.last.update(chamber: "house", district: 10) campaign = FactoryGirl.create(:congress_message_campaign, :targeting_senate) action_page.update_attribute(:congress_message_campaign, campaign) get_congress_message_form @@ -129,30 +129,30 @@ def submit_congress_message end before do - stub_request(:post, /fill-out-form/). - and_return(status: 200, body: "{}") + stub_request(:post, /fill-out-form/) + .and_return(status: 200, body: "{}") end it "successfully submits good input" do submit_congress_message - expect(WebMock).to have_requested(:post, /fill-out-form/). - with(body: { - "bio_id": "C000880", - "fields": { - "$NAME_FIRST": "Joyce", - "$NAME_LAST": "Summers", - "$ADDRESS_STREET": "1630 Ravello Drive", - "$ADDRESS_CITY": "Sunnydale", - "$ADDRESS_ZIP5": "94109", - "$EMAIL": "jsummers@altavista.com", - "$SUBJECT": "Take Action", - "$NAME_PREFIX": "Mrs.", - "$ADDRESS_STATE_POSTAL_ABBREV": "CA", - "$MESSAGE": "Impeach Mayor Richard Wilkins III", - "$TOPIC": "JU" - }, - campaign_tag: "a campaign tag" - }) + expect(WebMock).to have_requested(:post, /fill-out-form/) + .with(body: { + "bio_id": "C000880", + "fields": { + "$NAME_FIRST": "Joyce", + "$NAME_LAST": "Summers", + "$ADDRESS_STREET": "1630 Ravello Drive", + "$ADDRESS_CITY": "Sunnydale", + "$ADDRESS_ZIP5": "94109", + "$EMAIL": "jsummers@altavista.com", + "$SUBJECT": "Take Action", + "$NAME_PREFIX": "Mrs.", + "$ADDRESS_STATE_POSTAL_ABBREV": "CA", + "$MESSAGE": "Impeach Mayor Richard Wilkins III", + "$TOPIC": "JU" + }, + campaign_tag: "a campaign tag" + }) end it "returns an error when validation fails" do @@ -166,8 +166,8 @@ def submit_congress_message message_attributes[:test] = 1 submit_congress_message expect(response.status).to eq 200 - expect(WebMock).to have_requested(:post, /fill-out-form/). - with(body: hash_including(test: 1)).twice + expect(WebMock).to have_requested(:post, /fill-out-form/) + .with(body: hash_including(test: 1)).twice end it "succeeds with no common attributs" do diff --git a/spec/requests/sns_spec.rb b/spec/requests/sns_spec.rb index 39b6a1643..2195fbb77 100644 --- a/spec/requests/sns_spec.rb +++ b/spec/requests/sns_spec.rb @@ -10,7 +10,7 @@ headers = { "CONTENT_TYPE" => "application/json" } body = File.read("./spec/fixtures/files/sns_complaint.json") post "/complaint/#{Rails.application.secrets.amazon_authorize_key}", - params: body, headers: headers + params: body, headers: headers expect(JSON.parse(response.body)["success"]).to be true expect(Complaint.count).to eq 1 end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 21581c358..967328d04 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require "capybara/rspec" require "webmock/rspec" -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } +Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. diff --git a/spec/support/exit_code_helpers.rb b/spec/support/exit_code_helpers.rb index 2c2eb6614..b1d82e35d 100644 --- a/spec/support/exit_code_helpers.rb +++ b/spec/support/exit_code_helpers.rb @@ -14,11 +14,11 @@ def supports_block_expectations? actual and actual == exp_code end - failure_message do |block| + failure_message do |_block| "expected block to call exit(#{exp_code}) but exit" + (actual.nil? ? " not called" : "(#{actual}) was called") end - failure_message_when_negated do |block| + failure_message_when_negated do |_block| "expected block not to call exit(#{exp_code})" end description do diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 4e7c8d7c2..435b5fd7d 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -7,7 +7,7 @@ def sign_in_user(user) click_button "Sign in" end - def sign_out_user(user) + def sign_out_user(_user) find("#nav-modal-toggle").click find("input[value='Logout']", visible: :all, match: :first).click end diff --git a/spec/support/service_helpers.rb b/spec/support/service_helpers.rb index 5029aae42..5f519577e 100644 --- a/spec/support/service_helpers.rb +++ b/spec/support/service_helpers.rb @@ -1,12 +1,12 @@ module ServiceHelpers def stub_civicrm Rails.application.secrets.supporters["host"] = "https://civicrm.test" - stub_request(:post, CiviCRM::supporters_api_url). - and_return(status: 200, body: "{}", headers: {}) + stub_request(:post, CiviCRM::supporters_api_url) + .and_return(status: 200, body: "{}", headers: {}) - stub_request(:post, CiviCRM::supporters_api_url). - with(body: /generate_checksum/). - and_return(status: 200, body: { checksum: "xyz" }.to_json, headers: {}) + stub_request(:post, CiviCRM::supporters_api_url) + .with(body: /generate_checksum/) + .and_return(status: 200, body: { checksum: "xyz" }.to_json, headers: {}) end end @@ -14,4 +14,4 @@ def stub_civicrm c.include ServiceHelpers end -World(ServiceHelpers) if respond_to?(:World) #cucumber +World(ServiceHelpers) if respond_to?(:World) # cucumber From a47c3582a2d0fca7de642101045516b5099e0f28 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 10 Feb 2021 19:21:44 -0800 Subject: [PATCH 005/113] Remove old tasks --- .rubocop_todo.yml | 10 ------- lib/tasks/cucumber.rake | 63 ----------------------------------------- lib/tasks/test.rake | 4 --- 3 files changed, 77 deletions(-) delete mode 100644 lib/tasks/cucumber.rake delete mode 100644 lib/tasks/test.rake diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 23f915772..667326dc6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -295,16 +295,6 @@ Rails/LexicallyScopedActionFilter: - 'app/controllers/sessions_controller.rb' - 'app/controllers/tools_controller.rb' -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: Include. -# Include: **/Rakefile, **/*.rake -Rails/RakeEnvironment: - Exclude: - - 'lib/capistrano/tasks/**/*.rake' - - 'lib/tasks/cucumber.rake' - - 'lib/tasks/test.rake' - # Offense count: 2 Rails/ReflectionClassName: Exclude: diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake deleted file mode 100644 index f69b99c48..000000000 --- a/lib/tasks/cucumber.rake +++ /dev/null @@ -1,63 +0,0 @@ -# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file -# instead of editing this one. Cucumber will automatically load all features/**/*.rb -# files. - -unless ARGV.any? { |a| a =~ /^gems/ } # Don't load anything when running the gems:* tasks - - vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first - $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + "/../lib") unless vendored_cucumber_bin.nil? - - begin - require "cucumber/rake/task" - - namespace :cucumber do - Cucumber::Rake::Task.new({ ok: "test:prepare" }, "Run features that should pass") do |t| - t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. - t.fork = true # You may get faster startup if you set this to false - t.profile = "default" - end - - Cucumber::Rake::Task.new({ wip: "test:prepare" }, "Run features that are being worked on") do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = "wip" - end - - Cucumber::Rake::Task.new({ rerun: "test:prepare" }, "Record failing features and run only them if any exist") do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = "rerun" - end - - desc "Run all features" - task all: [:ok, :wip] - - task :statsetup do - require "rails/code_statistics" - ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?("features") - ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?("features") - end - end - desc "Alias for cucumber:ok" - task cucumber: "cucumber:ok" - - task default: :cucumber - - task features: :cucumber do - STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" - end - - # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. - task "test:prepare" do - end - - task stats: "cucumber:statsetup" - rescue LoadError - desc "cucumber rake task not available (cucumber not installed)" - task :cucumber do - abort "Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin" - end - end -end diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake deleted file mode 100644 index 049ca5093..000000000 --- a/lib/tasks/test.rake +++ /dev/null @@ -1,4 +0,0 @@ -desc "Run sass-lint" -task :sass_lint do - system("node_modules/.bin/sass-lint -vq") && puts("No sass linting errors! Woo!") -end From bea1fe3333b987cbec88ed072416f5d1990bd0bd Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 10 Feb 2021 19:25:04 -0800 Subject: [PATCH 006/113] Fix rubocop errors --- .rubocop.yml | 32 +- .rubocop_todo.yml | 779 +----------------- Rakefile | 6 +- app/controllers/action_page_controller.rb | 28 +- .../admin/action_pages_controller.rb | 71 +- .../admin/application_controller.rb | 14 +- .../congress_message_campaigns_controller.rb | 3 +- app/controllers/admin/events_controller.rb | 4 +- app/controllers/admin/images_controller.rb | 3 +- .../admin/institutions_controller.rb | 8 +- app/controllers/admin/partners_controller.rb | 5 +- app/controllers/admin/petitions_controller.rb | 6 +- .../admin/s3_uploads_controller.rb | 16 +- .../admin/topic_categories_controller.rb | 10 +- .../admin/topic_sets_controller.rb | 10 +- app/controllers/admin/topics_controller.rb | 10 +- app/controllers/application_controller.rb | 6 +- .../concerns/action_page_display.rb | 10 +- app/controllers/concerns/date_range.rb | 6 +- app/controllers/concerns/tooling.rb | 4 +- .../congress_messages_controller.rb | 8 +- app/controllers/partners_controller.rb | 14 +- app/controllers/registrations_controller.rb | 4 +- app/controllers/robots_controller.rb | 2 +- app/controllers/sessions_controller.rb | 2 +- app/controllers/smarty_streets_controller.rb | 8 +- app/controllers/sns_controller.rb | 2 +- app/controllers/subscriptions_controller.rb | 4 +- app/controllers/tools_controller.rb | 49 +- app/controllers/users_controller.rb | 10 +- app/helpers/action_page_helper.rb | 4 +- app/helpers/admin/action_pages_helper.rb | 64 +- app/helpers/admin/topics_helper.rb | 26 +- app/helpers/ahoy_helper.rb | 4 +- app/helpers/application_helper.rb | 16 +- app/helpers/congress_message_helper.rb | 16 +- app/helpers/devise_helper.rb | 13 +- app/mailers/user_mailer.rb | 4 +- app/models/action_page.rb | 47 +- app/models/ahoy/event.rb | 22 +- app/models/category.rb | 4 +- app/models/congress_member.rb | 10 +- app/models/congress_message.rb | 20 +- app/models/congress_message_campaign.rb | 2 +- app/models/email_campaign.rb | 2 +- app/models/featured_action_page.rb | 4 +- app/models/institution.rb | 14 +- app/models/partner.rb | 2 +- app/models/petition.rb | 12 +- app/models/signature.rb | 36 +- app/models/source_file.rb | 16 +- app/models/topic_category.rb | 4 +- app/models/tweet_target.rb | 6 +- app/models/twitter.rb | 2 +- app/models/user.rb | 26 +- app/models/user_preference.rb | 4 +- app/queries/action_page_filters.rb | 8 +- app/validators/email_validator.rb | 4 +- app/views/action_page/index.atom.builder | 8 +- lib/action_cloner.rb | 8 +- lib/amazon_credentials.rb | 12 +- lib/call_tool.rb | 18 +- lib/civicrm.rb | 47 +- lib/congress_forms.rb | 34 +- lib/places.rb | 340 ++++---- lib/quotes.rb | 10 +- lib/related_content.rb | 2 +- lib/smarty_streets.rb | 22 +- lib/tasks/congress.rake | 11 +- lib/tasks/petition.rake | 22 +- lib/tasks/signatures.rake | 23 +- lib/tasks/users.rake | 4 +- lib/tasks/webshims_asset_compile.rake | 24 +- .../action_page_controller_spec.rb | 8 +- .../admin/institutions_controller_spec.rb | 18 +- .../subscriptions_controller_spec.rb | 2 +- spec/controllers/tools_controller_spec.rb | 10 +- spec/factories/ahoy_event.rb | 8 +- spec/factories/congress_member.rb | 2 +- spec/factories/users.rb | 4 +- .../action_pages/congress_action_spec.rb | 10 +- .../action_pages/tweet_action_spec.rb | 8 +- spec/features/admin/action_creation_spec.rb | 20 +- spec/features/congress_message.rb | 12 +- spec/lib/action_cloner_spec.rb | 2 +- spec/lib/call_tool_spec.rb | 36 +- spec/lib/civicrm_spec.rb | 4 +- spec/lib/congress_forms_spec.rb | 12 +- spec/models/action_page_spec.rb | 9 +- spec/models/ahoy/event_spec.rb | 2 +- spec/models/congress_member_spec.rb | 2 +- spec/models/congress_message_campaign_spec.rb | 6 +- spec/models/congress_message_spec.rb | 4 +- spec/models/institution_spec.rb | 4 +- spec/models/petition_spec.rb | 5 +- spec/models/signature_spec.rb | 12 +- spec/models/topic_category_spec.rb | 6 +- spec/rails_helper.rb | 6 +- spec/requests/admin/action_pages_spec.rb | 10 +- spec/requests/admin/events_spec.rb | 8 +- spec/requests/admin/s3_uploads_spec.rb | 12 +- spec/requests/admin/users_spec.rb | 2 +- spec/requests/congress_messages_spec.rb | 38 +- spec/spec_helper.rb | 72 +- spec/support/feature_helpers.rb | 10 +- spec/support/service_helpers.rb | 4 +- 106 files changed, 768 insertions(+), 1711 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0fd0c44ff..bf629009b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,4 @@ -# inherit_from: .rubocop_todo.yml +inherit_from: .rubocop_todo.yml inherit_gem: rubocop-github: @@ -83,6 +83,10 @@ GitHub/RailsControllerRenderPathsExist: # Doesn't seem to work; can't find templates that exist Enabled: false +GitHub/RailsApplicationRecord: + # Rails/ApplicationRecord does the same thing + Enabled: false + Lint/Void: Exclude: - 'features/**/*' @@ -92,7 +96,7 @@ Lint/Debugger: Exclude: - 'features/step_definitions/debug_steps.rb' -Style/BlockComments: +Lint/AmbiguousBlockAssociation: Exclude: - 'spec/**/*' @@ -114,14 +118,30 @@ Layout/MultilineHashBraceLayout: Layout/SpaceAroundOperators: Enabled: true +Naming/PredicateName: + Exclude: + - 'spec/**/*' + Security/JSONLoad: Enabled: true Exclude: - 'spec/**/*' -GitHub/RailsApplicationRecord: - # Rails/ApplicationRecord does the same thing - Enabled: false - Rails/HttpStatus: EnforcedStyle: 'numeric' + +Style/Alias: + Enabled: false + +Style/BlockComments: + Exclude: + - 'spec/**/*' + +Style/ClassAndModuleChildren: + EnforcedStyle: 'compact' + +Style/Documentation: + Enabled: false + +Style/NumericLiterals: + MinDigits: 6 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 667326dc6..c1fb284f5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,122 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 100` -# on 2021-02-10 18:09:54 -0800 using RuboCop version 0.82.0. +# on 2021-02-11 14:07:46 -0800 using RuboCop version 0.82.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 29 -# Easy fix -GitHub/RailsApplicationRecord: - Exclude: - - 'app/models/action_institution.rb' - - 'app/models/action_page.rb' - - 'app/models/affiliation.rb' - - 'app/models/affiliation_type.rb' - - 'app/models/ahoy/event.rb' - - 'app/models/bounce.rb' - - 'app/models/call_campaign.rb' - - 'app/models/category.rb' - - 'app/models/complaint.rb' - - 'app/models/congress_member.rb' - - 'app/models/congress_message_campaign.rb' - - 'app/models/congress_scorecard.rb' - - 'app/models/email_campaign.rb' - - 'app/models/featured_action_page.rb' - - 'app/models/institution.rb' - - 'app/models/partner.rb' - - 'app/models/partnership.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/source_file.rb' - - 'app/models/subscription.rb' - - 'app/models/topic.rb' - - 'app/models/topic_category.rb' - - 'app/models/topic_set.rb' - - 'app/models/tweet.rb' - - 'app/models/tweet_target.rb' - - 'app/models/user.rb' - - 'app/models/user_preference.rb' - - 'app/models/visit.rb' - -# Offense count: 5 -Lint/AmbiguousBlockAssociation: - Exclude: - - 'app/models/topic_category.rb' - - 'spec/models/action_page_spec.rb' - -# Offense count: 3 -Lint/AmbiguousRegexpLiteral: - Exclude: - - 'app/helpers/application_helper.rb' - - 'spec/models/congress_message_campaign_spec.rb' - -# Offense count: 5 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Exclude: - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'lib/civicrm.rb' - - 'lib/tasks/congress.rake' - - 'lib/tasks/signatures.rake' - -# Offense count: 13 -Lint/IneffectiveAccessModifier: - Exclude: - - 'app/controllers/admin/application_controller.rb' - - 'lib/action_cloner.rb' - - 'lib/call_tool.rb' - - 'lib/civicrm.rb' - - 'lib/quotes.rb' - - 'lib/smarty_streets.rb' - -# Offense count: 1 -Lint/ParenthesesAsGroupedExpression: - Exclude: - - 'spec/factories/congress_member.rb' - -# Offense count: 1 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'lib/tasks/congress.rake' - -# Offense count: 1 -Lint/UriEscapeUnescape: - Exclude: - - 'app/helpers/application_helper.rb' - -# Offense count: 5 -# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. -Lint/UselessAccessModifier: - Exclude: - - 'lib/action_cloner.rb' - - 'lib/call_tool.rb' - - 'lib/civicrm.rb' - - 'lib/quotes.rb' - - 'lib/smarty_streets.rb' - -# Offense count: 23 -Lint/UselessAssignment: - Exclude: - - 'app/controllers/congress_messages_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/helpers/devise_helper.rb' - - 'app/models/ahoy/event.rb' - - 'app/models/featured_action_page.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/topic_category.rb' - - 'app/models/twitter.rb' - - 'app/models/user.rb' - - 'lib/congress_forms.rb' - - 'spec/controllers/admin/institutions_controller_spec.rb' - - 'spec/requests/admin/action_pages_spec.rb' - - 'spec/requests/admin/events_spec.rb' - - 'spec/requests/congress_messages_spec.rb' - - 'spec/spec_helper.rb' - # Offense count: 3 Naming/AccessorMethodName: Exclude: @@ -232,21 +121,12 @@ Rails/ApplicationRecord: - 'app/models/user_preference.rb' - 'app/models/visit.rb' -# Offense count: 4 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: strict, flexible -Rails/Date: - Exclude: - - 'spec/models/congress_message_campaign_spec.rb' - -# Offense count: 3 +# Offense count: 2 # Configuration parameters: EnforcedStyle. # SupportedStyles: slashes, arguments Rails/FilePath: Exclude: - - 'lib/tasks/cucumber.rake' - 'lib/tasks/webshims_asset_compile.rake' - - 'spec/rails_helper.rb' # Offense count: 25 # Configuration parameters: Include. @@ -267,7 +147,7 @@ Rails/HasManyOrHasOneDependent: - 'app/models/user.rb' - 'app/models/visit.rb' -# Offense count: 16 +# Offense count: 15 # Configuration parameters: Include. # Include: app/helpers/**/*.rb Rails/HelperInstanceVariable: @@ -295,12 +175,6 @@ Rails/LexicallyScopedActionFilter: - 'app/controllers/sessions_controller.rb' - 'app/controllers/tools_controller.rb' -# Offense count: 2 -Rails/ReflectionClassName: - Exclude: - - 'app/models/action_page.rb' - - 'app/models/user.rb' - # Offense count: 9 # Configuration parameters: Blacklist, Whitelist. # Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters @@ -314,32 +188,14 @@ Rails/SkipsModelValidations: - 'spec/requests/congress_messages_spec.rb' - 'spec/tasks/signatures_spec.rb' -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: strict, flexible -Rails/TimeZone: - Exclude: - - 'app/models/congress_member.rb' - - 'spec/factories/congress_member.rb' - - 'spec/models/congress_member_spec.rb' - - 'spec/requests/admin/events_spec.rb' - - 'spec/requests/admin/users_spec.rb' - -# Offense count: 13 -# Cop supports --auto-correct. +# Offense count: 3 # Configuration parameters: Include. # Include: app/models/**/*.rb -Rails/Validation: +Rails/UniqueValidationWithoutIndex: Exclude: - - 'app/models/category.rb' - 'app/models/congress_member.rb' - - 'app/models/featured_action_page.rb' - 'app/models/institution.rb' - 'app/models/partner.rb' - - 'app/models/signature.rb' - - 'app/models/source_file.rb' - - 'app/models/user_preference.rb' # Offense count: 1 Security/Open: @@ -348,274 +204,18 @@ Security/Open: # Offense count: 2 # Cop supports --auto-correct. -Security/YAMLLoad: - Exclude: - - 'lib/tasks/congress.rake' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: prefer_alias, prefer_alias_method -Style/Alias: - Exclude: - - 'app/models/tweet.rb' - - 'app/models/user.rb' - -# Offense count: 17 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, conditionals -Style/AndOr: - Exclude: - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/concerns/action_page_display.rb' - - 'app/controllers/robots_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/models/congress_message_campaign.rb' - - 'app/models/email_campaign.rb' - - 'app/models/signature.rb' - - 'app/models/tweet_target.rb' - - 'app/models/user.rb' - - 'lib/tasks/signatures.rake' - -# Offense count: 46 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'app/controllers/admin/events_controller.rb' - - 'app/controllers/admin/s3_uploads_controller.rb' - - 'app/helpers/ahoy_helper.rb' - - 'app/models/user.rb' - - 'spec/controllers/action_page_controller_spec.rb' - - 'spec/controllers/admin/institutions_controller_spec.rb' - - 'spec/controllers/tools_controller_spec.rb' - - 'spec/factories/ahoy_event.rb' - - 'spec/features/action_pages/congress_action_spec.rb' - - 'spec/features/action_pages/tweet_action_spec.rb' - - 'spec/features/admin/action_creation_spec.rb' - - 'spec/features/congress_message.rb' - - 'spec/lib/call_tool_spec.rb' - - 'spec/lib/congress_forms_spec.rb' - - 'spec/models/action_page_spec.rb' - - 'spec/models/congress_message_spec.rb' - - 'spec/models/institution_spec.rb' - - 'spec/models/signature_spec.rb' - - 'spec/requests/admin/action_pages_spec.rb' - - 'spec/requests/admin/s3_uploads_spec.rb' - - 'spec/requests/congress_messages_spec.rb' - -# Offense count: 17 -# Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: Exclude: - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/application_controller.rb' - - 'app/controllers/admin/categories_controller.rb' - - 'app/controllers/admin/congress_message_campaigns_controller.rb' - - 'app/controllers/admin/events_controller.rb' - - 'app/controllers/admin/images_controller.rb' - - 'app/controllers/admin/institutions_controller.rb' - - 'app/controllers/admin/mailer_controller.rb' - - 'app/controllers/admin/partners_controller.rb' - - 'app/controllers/admin/petitions_controller.rb' - - 'app/controllers/admin/s3_uploads_controller.rb' - - 'app/controllers/admin/topic_categories_controller.rb' - - 'app/controllers/admin/topic_sets_controller.rb' - - 'app/controllers/admin/topics_controller.rb' - - 'app/controllers/admin/users_controller.rb' - - 'app/helpers/admin/affiliation_types_helper.rb' - - 'app/helpers/admin/users_helper.rb' - -# Offense count: 13 -# Cop supports --auto-correct. -Style/ColonMethodCall: - Exclude: - - 'app/controllers/subscriptions_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/models/signature.rb' - - 'lib/civicrm.rb' - - 'spec/controllers/subscriptions_controller_spec.rb' - - 'spec/features/congress_message.rb' - - 'spec/lib/civicrm_spec.rb' - - 'spec/support/service_helpers.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Keywords. -# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW -Style/CommentAnnotation: - Exclude: - - 'lib/call_tool.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'app/controllers/admin/s3_uploads_controller.rb' - - 'app/controllers/users_controller.rb' - - 'app/helpers/congress_message_helper.rb' - -# Offense count: 93 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/application_controller.rb' - - 'app/controllers/admin/categories_controller.rb' - - 'app/controllers/admin/congress_message_campaigns_controller.rb' - - 'app/controllers/admin/events_controller.rb' - - 'app/controllers/admin/images_controller.rb' - - 'app/controllers/admin/institutions_controller.rb' - - 'app/controllers/admin/mailer_controller.rb' - - 'app/controllers/admin/partners_controller.rb' - - 'app/controllers/admin/petitions_controller.rb' - - 'app/controllers/admin/s3_uploads_controller.rb' - - 'app/controllers/admin/topic_categories_controller.rb' - - 'app/controllers/admin/topic_sets_controller.rb' - - 'app/controllers/admin/topics_controller.rb' - - 'app/controllers/admin/users_controller.rb' - - 'app/controllers/ahoy_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/concerns/action_page_display.rb' - - 'app/controllers/concerns/date_range.rb' - - 'app/controllers/concerns/logged_invisible_captcha.rb' - - 'app/controllers/concerns/request_origin_validation.rb' - - 'app/controllers/concerns/tooling.rb' - - 'app/controllers/congress_messages_controller.rb' - - 'app/controllers/exceptions_controller.rb' - - 'app/controllers/partners_controller.rb' - - 'app/controllers/petition_controller.rb' - - 'app/controllers/registrations_controller.rb' - - 'app/controllers/robots_controller.rb' - - 'app/controllers/sessions_controller.rb' - - 'app/controllers/smarty_streets_controller.rb' - - 'app/controllers/subscriptions_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/controllers/users_controller.rb' - - 'app/controllers/welcome_controller.rb' - - 'app/helpers/action_page_helper.rb' - - 'app/helpers/admin/action_pages_helper.rb' - - 'app/helpers/admin/affiliation_types_helper.rb' - - 'app/helpers/admin/topics_helper.rb' - - 'app/helpers/admin/users_helper.rb' - - 'app/helpers/admin_helper.rb' - - 'app/helpers/ahoy_helper.rb' - - 'app/helpers/application_helper.rb' - - 'app/helpers/congress_message_helper.rb' - - 'app/helpers/devise_helper.rb' - - 'app/helpers/petition_helper.rb' - - 'app/helpers/s3_upload_helper.rb' - - 'app/helpers/users_helper.rb' - - 'app/helpers/welcome_helper.rb' - - 'app/mailers/user_mailer.rb' - - 'app/models/action_institution.rb' - - 'app/models/action_page.rb' - - 'app/models/affiliation.rb' - - 'app/models/affiliation_type.rb' - 'app/models/ahoy/event.rb' - - 'app/models/call_campaign.rb' - - 'app/models/category.rb' - - 'app/models/congress_member.rb' - - 'app/models/congress_message_campaign.rb' - - 'app/models/email_campaign.rb' - - 'app/models/featured_action_page.rb' - - 'app/models/institution.rb' - - 'app/models/markdown_renderer.rb' - - 'app/models/partner.rb' - - 'app/models/partnership.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/source_file.rb' - - 'app/models/subscription.rb' - - 'app/models/topic.rb' - - 'app/models/topic_category.rb' - - 'app/models/topic_set.rb' - - 'app/models/tweet.rb' - - 'app/models/tweet_target.rb' - - 'app/models/twitter.rb' - - 'app/models/user.rb' - - 'app/models/user_preference.rb' - - 'app/models/visit.rb' - - 'app/queries/action_page_filters.rb' - - 'app/validators/email_validator.rb' - - 'lib/action_cloner.rb' - - 'lib/amazon_credentials.rb' - - 'lib/call_tool.rb' - - 'lib/civicrm.rb' - - 'lib/congress_forms.rb' - 'lib/monkey_patches/octet_stream_override.rb' - - 'lib/places.rb' - - 'lib/quotes.rb' - - 'lib/related_content.rb' - - 'lib/smarty_streets.rb' # Offense count: 1 Style/DoubleNegation: Exclude: - 'app/models/source_file.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty, nil, both -Style/EmptyElse: - Exclude: - - 'app/models/ahoy/event.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/EmptyLambdaParameter: - Exclude: - - 'app/models/tweet_target.rb' - - 'app/models/user.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/application_controller.rb' - - 'app/controllers/admin/congress_message_campaigns_controller.rb' - - 'app/controllers/admin/images_controller.rb' - - 'app/controllers/admin/partners_controller.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Exclude: - - 'Rakefile' - - 'spec/rails_helper.rb' - -# Offense count: 1 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv -Style/FloatDivision: - Exclude: - - 'app/models/petition.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'spec/requests/admin/events_spec.rb' - # Offense count: 1 # Configuration parameters: EnforcedStyle. # SupportedStyles: annotated, template, unannotated @@ -623,157 +223,25 @@ Style/FormatStringToken: Exclude: - 'spec/requests/admin/events_spec.rb' -# Offense count: 37 +# Offense count: 17 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: - 'app/controllers/action_page_controller.rb' - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/application_controller.rb' - 'app/controllers/application_controller.rb' - 'app/controllers/concerns/action_page_display.rb' - 'app/controllers/concerns/request_origin_validation.rb' - - 'app/controllers/concerns/tooling.rb' - 'app/controllers/congress_messages_controller.rb' - 'app/controllers/partners_controller.rb' - 'app/controllers/registrations_controller.rb' - 'app/controllers/sessions_controller.rb' - 'app/controllers/tools_controller.rb' - 'app/helpers/application_helper.rb' - - 'app/mailers/user_mailer.rb' - - 'app/models/ahoy/event.rb' - - 'app/models/congress_message.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/user.rb' - - 'app/queries/action_page_filters.rb' - - 'app/validators/email_validator.rb' - - 'lib/call_tool.rb' - - 'lib/civicrm.rb' - - 'lib/smarty_streets.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'app/models/action_page.rb' - -# Offense count: 1 -# Configuration parameters: AllowIfModifier. -Style/IfInsideElse: - Exclude: - - 'app/controllers/partners_controller.rb' - -# Offense count: 38 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Exclude: - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/application_controller.rb' - - 'app/controllers/admin/institutions_controller.rb' - - 'app/controllers/admin/petitions_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/concerns/action_page_display.rb' - - 'app/controllers/concerns/date_range.rb' - - 'app/controllers/concerns/tooling.rb' - - 'app/controllers/congress_messages_controller.rb' - - 'app/controllers/registrations_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/helpers/action_page_helper.rb' - - 'app/helpers/admin/action_pages_helper.rb' - - 'app/helpers/congress_message_helper.rb' - - 'app/helpers/devise_helper.rb' - - 'app/mailers/user_mailer.rb' - - 'app/models/action_page.rb' - - 'app/models/ahoy/event.rb' - - 'app/models/congress_message.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/user.rb' - - 'app/queries/action_page_filters.rb' - - 'app/validators/email_validator.rb' - - 'lib/action_cloner.rb' - - 'lib/call_tool.rb' - - 'lib/smarty_streets.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'app/models/ahoy/event.rb' - - 'app/models/congress_member.rb' - - 'app/models/signature.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/LineEndConcatenation: - Exclude: - - 'app/models/signature.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: separated, grouped -Style/MixinGrouping: - Exclude: - - 'app/models/action_page.rb' - -# Offense count: 2 -Style/MixinUsage: - Exclude: - - 'app/controllers/admin/petitions_controller.rb' - - 'app/models/signature.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/MultilineIfModifier: - Exclude: - - 'lib/amazon_credentials.rb' - -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: both, prefix, postfix -Style/NegatedIf: - Exclude: - - 'app/controllers/registrations_controller.rb' - - 'app/controllers/subscriptions_controller.rb' - - 'app/helpers/devise_helper.rb' - 'app/models/ahoy/event.rb' - - 'app/models/congress_message.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: AllowedMethods. -# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'app/views/action_page/index.atom.builder' - 'lib/call_tool.rb' - - 'spec/models/topic_category_spec.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Exclude: - - 'lib/tasks/petition.rake' - - 'lib/tasks/signatures.rake' - - 'lib/tasks/webshims_asset_compile.rake' - -# Offense count: 16 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 7 - -# Offense count: 6 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. # SupportedStyles: predicate, comparison @@ -784,236 +252,3 @@ Style/NumericPredicate: - 'app/helpers/application_helper.rb' - 'app/models/action_page.rb' - 'app/models/petition.rb' - - 'app/views/action_page/index.atom.builder' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/ParallelAssignment: - Exclude: - - 'spec/controllers/tools_controller_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. -Style/ParenthesesAroundCondition: - Exclude: - - 'app/controllers/sessions_controller.rb' - - 'lib/civicrm.rb' - -# Offense count: 24 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'Rakefile' - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/institutions_controller.rb' - - 'app/controllers/admin/partners_controller.rb' - - 'app/controllers/concerns/date_range.rb' - - 'app/controllers/tools_controller.rb' - - 'app/models/action_page.rb' - - 'app/models/ahoy/event.rb' - - 'app/models/congress_message.rb' - - 'app/queries/action_page_filters.rb' - - 'lib/action_cloner.rb' - - 'lib/congress_forms.rb' - - 'lib/tasks/cucumber.rake' - - 'spec/lib/action_cloner_spec.rb' - - 'spec/requests/congress_messages_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: short, verbose -Style/PreferredHashMethods: - Exclude: - - 'app/controllers/admin/action_pages_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, exploded -Style/RaiseArgs: - Exclude: - - 'lib/call_tool.rb' - -# Offense count: 12 -# Cop supports --auto-correct. -Style/RedundantBegin: - Exclude: - - 'app/controllers/admin/topic_categories_controller.rb' - - 'app/controllers/admin/topic_sets_controller.rb' - - 'app/controllers/admin/topics_controller.rb' - - 'app/controllers/smarty_streets_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/models/signature.rb' - - 'lib/civicrm.rb' - - 'lib/congress_forms.rb' - - 'lib/quotes.rb' - - 'lib/smarty_streets.rb' - - 'spec/support/feature_helpers.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantParentheses: - Exclude: - - 'app/controllers/sessions_controller.rb' - -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'app/controllers/smarty_streets_controller.rb' - - 'app/controllers/sns_controller.rb' - - 'app/helpers/application_helper.rb' - - 'lib/civicrm.rb' - - 'lib/congress_forms.rb' - - 'lib/related_content.rb' - - 'lib/smarty_streets.rb' - -# Offense count: 10 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'app/models/signature.rb' - - 'app/models/source_file.rb' - - 'app/models/tweet_target.rb' - - 'app/models/user.rb' - - 'lib/civicrm.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'lib/call_tool.rb' - - 'spec/lib/call_tool_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/RescueModifier: - Exclude: - - 'app/models/source_file.rb' - -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'app/controllers/admin/topic_categories_controller.rb' - - 'app/controllers/admin/topic_sets_controller.rb' - - 'app/controllers/admin/topics_controller.rb' - - 'app/controllers/smarty_streets_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'lib/call_tool.rb' - - 'lib/civicrm.rb' - - 'lib/smarty_streets.rb' - - 'lib/tasks/signatures.rake' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. -# AllowedMethods: present?, blank?, presence, try, try! -Style/SafeNavigation: - Exclude: - - 'app/controllers/concerns/action_page_display.rb' - - 'app/helpers/application_helper.rb' - - 'app/helpers/devise_helper.rb' - - 'app/models/action_page.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Exclude: - - 'app/models/congress_message.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/StderrPuts: - Exclude: - - 'lib/tasks/cucumber.rake' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiteralsInInterpolation: - Exclude: - - 'app/models/petition.rb' - - 'spec/features/congress_message.rb' - -# Offense count: 38 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - Exclude: - - 'Rakefile' - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/concerns/action_page_display.rb' - - 'app/controllers/tools_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/models/action_page.rb' - - 'app/models/institution.rb' - - 'app/models/petition.rb' - - 'app/models/user.rb' - - 'lib/tasks/cucumber.rake' - - 'spec/models/ahoy/event_spec.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'app/models/topic_category.rb' - - 'app/models/user.rb' - - 'lib/tasks/users.rake' - - 'spec/factories/users.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Exclude: - - 'app/models/action_page.rb' - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'app/helpers/congress_message_helper.rb' - - 'lib/call_tool.rb' - - 'lib/congress_forms.rb' - - 'spec/requests/congress_messages_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowNamedUnderscoreVariables. -Style/TrailingUnderscoreVariable: - Exclude: - - 'app/controllers/congress_messages_controller.rb' - -# Offense count: 177 -# Cop supports --auto-correct. -# Configuration parameters: WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: 6 - -# Offense count: 2 -# Cop supports --auto-correct. -Style/ZeroLengthPredicate: - Exclude: - - 'app/models/action_page.rb' - - 'app/views/action_page/index.atom.builder' diff --git a/Rakefile b/Rakefile index 506551c8a..4afe39994 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,14 @@ # 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__) Actioncenter::Application.load_tasks -if %w(development test).include? Rails.env +if %w[development test].include? Rails.env require "rubocop/rake_task" RuboCop::RakeTask.new task(:default).clear - task default: [:sass_lint, :rubocop, :spec, :cucumber] + task default: %i[sass_lint rubocop spec cucumber] end diff --git a/app/controllers/action_page_controller.rb b/app/controllers/action_page_controller.rb index 9a3074cd5..202874c13 100644 --- a/app/controllers/action_page_controller.rb +++ b/app/controllers/action_page_controller.rb @@ -5,15 +5,15 @@ class ActionPageController < ApplicationController :protect_unpublished, :redirect_to_specified_url, :redirect_from_archived_to_active_action, - only: [:show, :show_by_institution, :embed_iframe, - :signature_count, :filter] + only: %i[show show_by_institution embed_iframe + signature_count filter] before_action :redirect_to_cannonical_slug, only: [:show] - before_action :set_institution, only: [:show_by_institution, :filter] - before_action :set_action_display_variables, only: [:show, - :show_by_institution, - :embed_iframe, - :signature_count, - :filter] + before_action :set_institution, only: %i[show_by_institution filter] + before_action :set_action_display_variables, only: %i[show + show_by_institution + embed_iframe + signature_count + filter] skip_before_action :verify_authenticity_token, only: :embed @@ -51,8 +51,8 @@ def embed_iframe def signature_count @actionPage = ActionPage.friendly.find(params[:id]) - if petition = @actionPage.petition - render text: petition.signatures.count + if @actionPage.petition + render text: @actionPage.petition.signatures.count else render text: "0" end @@ -83,17 +83,13 @@ def protect_unpublished end def redirect_to_specified_url - if @actionPage.enable_redirect - redirect_to @actionPage.redirect_url, status: 301 - end + redirect_to @actionPage.redirect_url, status: 301 if @actionPage.enable_redirect end def redirect_from_archived_to_active_action if @actionPage.redirect_from_archived_to_active_action? # Users can access actions they've taken in the past as a historical record - unless current_user and (current_user.taken_action? @actionPage or current_user.admin?) - redirect_to @actionPage.active_action_page_for_redirect - end + redirect_to @actionPage.active_action_page_for_redirect unless current_user && (current_user.taken_action?(@actionPage) || current_user.admin?) end end diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index d6dc8303c..231088a82 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -2,23 +2,23 @@ class Admin::ActionPagesController < Admin::ApplicationController include DateRange include ActionPageDisplay - before_action :set_action_page, only: [ - :edit, - :update, - :destroy, - :events, - :events_table, - :duplicate, - :preview, - :status, - :edit_partners + before_action :set_action_page, only: %i[ + edit + update + destroy + events + events_table + duplicate + preview + status + edit_partners ] - before_action :set_petition_targets, only: %i(new edit duplicate) - before_action :set_partners, only: %i(new edit duplicate) - before_action :set_source_files, only: %i(new edit create update duplicate) + before_action :set_petition_targets, only: %i[new edit duplicate] + before_action :set_partners, only: %i[new edit duplicate] + before_action :set_source_files, only: %i[new edit create update duplicate] - after_action :purge_cache, only: [:update, :publish] + after_action :purge_cache, only: %i[update publish] allow_collaborators_to :index, :edit @@ -27,9 +27,7 @@ def index @authors = User.authors.order(:last_name) @actionPages = filter_action_pages - if request.xhr? - render partial: "admin/action_pages/index" - end + render partial: "admin/action_pages/index" if request.xhr? end def new @@ -64,13 +62,10 @@ def edit @actionPage.email_campaign ||= EmailCampaign.new @actionPage.congress_message_campaign ||= CongressMessageCampaign.new 10.times { @actionPage.affiliation_types.build } - if @actionPage.enable_petition && @actionPage.petition.enable_affiliations - @target_category = @actionPage.institutions.first.category - end + @target_category = @actionPage.institutions.first.category if @actionPage.enable_petition && @actionPage.petition.enable_affiliations end - def status - end + def status; end def edit_partners @partners = Partner.order(name: :desc) @@ -143,9 +138,7 @@ def events_table @events = @actionPage.events.in_range(@start_date, @end_date) @counts = @events.table_data @summary = @events.summary - if @actionPage.enable_congress_message? - @fills = @actionPage.congress_message_campaign.date_fills(@start_date, @end_date) - end + @fills = @actionPage.congress_message_campaign.date_fills(@start_date, @end_date) if @actionPage.enable_congress_message? end def homepage @@ -188,19 +181,19 @@ def action_page_params :call_campaign_id, :what_to_say, :redirect_url, :email_text, :enable_redirect, :victory, :victory_message, :archived_redirect_action_page_id, :archived, :status, partner_ids: [], - action_page_images_attributes: [:id, :action_page_image], - call_campaign_attributes: [:id, :title, :message, :call_campaign_id], - petition_attributes: [:id, :title, :description, :goal, :enable_affiliations], - affiliation_types_attributes: [:id, :name], + action_page_images_attributes: %i[id action_page_image], + call_campaign_attributes: %i[id title message call_campaign_id], + petition_attributes: %i[id title description goal enable_affiliations], + affiliation_types_attributes: %i[id name], tweet_attributes: [ :id, :target, :target_house, :target_senate, :message, :cta, :bioguide_id, - tweet_targets_attributes: [:id, :_destroy, :twitter_id, :image] + tweet_targets_attributes: %i[id _destroy twitter_id image] ], - email_campaign_attributes: [ - :id, :message, :subject, :target_house, :target_senate, :target_email, - :email_addresses, :target_bioguide_id, :bioguide_id, :alt_text_email_your_rep, - :alt_text_look_up_your_rep, :alt_text_extra_fields_explain, :topic_category_id, - :alt_text_look_up_helper, :alt_text_customize_message_helper, :campaign_tag + email_campaign_attributes: %i[ + id message subject target_house target_senate target_email + email_addresses target_bioguide_id bioguide_id alt_text_email_your_rep + alt_text_look_up_your_rep alt_text_extra_fields_explain topic_category_id + alt_text_look_up_helper alt_text_customize_message_helper campaign_tag ], congress_message_campaign_attributes: [ :id, :message, :subject, :target_house, :target_senate, { target_bioguide_list: [] }, @@ -209,19 +202,19 @@ def action_page_params :alt_text_customize_message_helper, :campaign_tag, :enable_customization_notice ], - partnerships_attributes: [:id, :enable_mailings] + partnerships_attributes: %i[id enable_mailings] ) end def institutions_params - return {} unless params.has_key? :institutions + return {} unless params.key? :institutions - params.require(:institutions).permit(%i(category reset)) + params.require(:institutions).permit(%i[category reset]) end def filter_params params.permit(:q, :date_range, :utf8, - action_filters: %i(type status author category)) + action_filters: %i[type status author category]) end def purge_cache diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 3eedde808..fee652024 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -6,25 +6,19 @@ def manifest self.class.manifest || "admin" end - protected - + # FLAG_AS_UNUSED def self.allow_collaborators_to(*actions) skip_before_action :must_be_admin, only: actions before_action :must_be_admin_or_collaborator, only: actions end def must_be_admin - unless user_signed_in? && current_user.admin? - raise ActiveRecord::RecordNotFound - end + raise ActiveRecord::RecordNotFound unless user_signed_in? && current_user.admin? end def must_be_admin_or_collaborator - unless user_signed_in? && (current_user.admin? || current_user.collaborator?) - raise ActiveRecord::RecordNotFound - end + raise ActiveRecord::RecordNotFound unless user_signed_in? && (current_user.admin? || current_user.collaborator?) end - def images - end + def images; end end diff --git a/app/controllers/admin/congress_message_campaigns_controller.rb b/app/controllers/admin/congress_message_campaigns_controller.rb index 492ac7fd0..78360652d 100644 --- a/app/controllers/admin/congress_message_campaigns_controller.rb +++ b/app/controllers/admin/congress_message_campaigns_controller.rb @@ -3,8 +3,7 @@ class Admin::CongressMessageCampaignsController < Admin::ApplicationController allow_collaborators_to :congress_tabulation, :staffer_report - def congress_tabulation - end + def congress_tabulation; end def staffer_report @bioguide_id = params[:bioguide_id] diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index d2e8beb9f..97b29d105 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -6,12 +6,12 @@ def index @events = Ahoy::Event.all.in_range(@start_date, @end_date) respond_to do |format| format.html { @summary = @events.summary } - format.json { + format.json do render json: @events.chart_data( type: params[:type], range: @start_date..@end_date ) - } + end end end end diff --git a/app/controllers/admin/images_controller.rb b/app/controllers/admin/images_controller.rb index d89edf4a7..774771fc9 100644 --- a/app/controllers/admin/images_controller.rb +++ b/app/controllers/admin/images_controller.rb @@ -1,4 +1,3 @@ class Admin::ImagesController < Admin::ApplicationController - def index - end + def index; end end diff --git a/app/controllers/admin/institutions_controller.rb b/app/controllers/admin/institutions_controller.rb index c56f40167..924f8a656 100644 --- a/app/controllers/admin/institutions_controller.rb +++ b/app/controllers/admin/institutions_controller.rb @@ -1,13 +1,11 @@ class Admin::InstitutionsController < Admin::ApplicationController - before_action :set_institution, only: %i(destroy edit update) - before_action :set_categories, only: %i(new edit upload index) + before_action :set_institution, only: %i[destroy edit update] + before_action :set_categories, only: %i[new edit upload index] def index @institutions = Institution.includes(:action_pages).all.order(created_at: :desc) @institutions = @institutions.search(params[:q]) if params[:q].present? - if params[:category].present? && params[:category] != "All" - @institutions = @institutions.where(category: params[:category]) - end + @institutions = @institutions.where(category: params[:category]) if params[:category].present? && params[:category] != "All" @institutions = @institutions.paginate(page: params[:page], per_page: 20) end diff --git a/app/controllers/admin/partners_controller.rb b/app/controllers/admin/partners_controller.rb index 023e5227e..3fce9ce28 100644 --- a/app/controllers/admin/partners_controller.rb +++ b/app/controllers/admin/partners_controller.rb @@ -1,7 +1,7 @@ class Admin::PartnersController < Admin::ApplicationController layout "admin" - before_action :set_partner, only: %i(edit update show destroy) + before_action :set_partner, only: %i[edit update show destroy] # GET /partners # GET /partners.json @@ -30,8 +30,7 @@ def create end end - def edit - end + def edit; end def update if @partner.update(partner_params) diff --git a/app/controllers/admin/petitions_controller.rb b/app/controllers/admin/petitions_controller.rb index 23af4076f..1fde4420d 100644 --- a/app/controllers/admin/petitions_controller.rb +++ b/app/controllers/admin/petitions_controller.rb @@ -1,5 +1,5 @@ -include PetitionHelper class Admin::PetitionsController < Admin::ApplicationController + include PetitionHelper before_action :set_petition allow_collaborators_to :show, :destroy_signatures @@ -36,9 +36,7 @@ def affiliation_csv def destroy_signatures @petition.signatures.where(id: params[:signature_ids]).delete_all - if params[:page].to_i > filtered_signatures.total_pages - params[:page] = filtered_signatures.total_pages - end + params[:page] = filtered_signatures.total_pages if params[:page].to_i > filtered_signatures.total_pages redirect_to admin_action_page_petition_path(@petition.action_page, @petition, search_params) diff --git a/app/controllers/admin/s3_uploads_controller.rb b/app/controllers/admin/s3_uploads_controller.rb index 12f733057..5e80050c1 100644 --- a/app/controllers/admin/s3_uploads_controller.rb +++ b/app/controllers/admin/s3_uploads_controller.rb @@ -2,11 +2,11 @@ class Admin::S3UploadsController < Admin::ApplicationController # GET /admin/source_files # GET /admin/source_files.json def index - if params[:f].present? - source_files = SourceFile.where("LOWER(file_name) LIKE ?", "%#{params[:f]}%".downcase) - else - source_files = SourceFile.limit(3) - end + source_files = if params[:f].present? + SourceFile.where("LOWER(file_name) LIKE ?", "%#{params[:f]}%".downcase) + else + SourceFile.limit(3) + end source_files = source_files.order(created_at: :desc) @@ -22,11 +22,11 @@ def create @source_file = SourceFile.new(parameters) respond_to do |format| if @source_file.save - format.html { + format.html do render json: @source_file.to_jq_upload, content_type: "text/html", layout: false - } + end format.json { render json: @source_file.to_jq_upload, status: 201 } else format.html { render "new" } @@ -52,7 +52,7 @@ def destroy # for /admin/action_page/new # GET /admin/source_files/generate_key def generate_key - uid = SecureRandom.uuid.delete('-') + uid = SecureRandom.uuid.delete("-") render json: { key: "uploads/#{uid}/#{params[:filename]}", diff --git a/app/controllers/admin/topic_categories_controller.rb b/app/controllers/admin/topic_categories_controller.rb index 5d3123cee..e33b3883f 100644 --- a/app/controllers/admin/topic_categories_controller.rb +++ b/app/controllers/admin/topic_categories_controller.rb @@ -14,12 +14,10 @@ def create end def destroy - begin - TopicCategory.destroy(params[:id]) - render json: { id: params[:id] } - rescue => e - render text: e.message, status: 500 - end + TopicCategory.destroy(params[:id]) + render json: { id: params[:id] } + rescue StandardError => e + render text: e.message, status: 500 end def update diff --git a/app/controllers/admin/topic_sets_controller.rb b/app/controllers/admin/topic_sets_controller.rb index 49a58c879..c3c7fca41 100644 --- a/app/controllers/admin/topic_sets_controller.rb +++ b/app/controllers/admin/topic_sets_controller.rb @@ -5,12 +5,10 @@ def index end def destroy - begin - TopicSet.destroy(params[:id]) - render json: { id: params[:id] } - rescue => e - render text: e.message, status: 500 - end + TopicSet.destroy(params[:id]) + render json: { id: params[:id] } + rescue StandardError => e + render text: e.message, status: 500 end def create diff --git a/app/controllers/admin/topics_controller.rb b/app/controllers/admin/topics_controller.rb index a635cbb3f..1c3c4f7b1 100644 --- a/app/controllers/admin/topics_controller.rb +++ b/app/controllers/admin/topics_controller.rb @@ -2,12 +2,10 @@ class Admin::TopicsController < Admin::ApplicationController layout "admin" def destroy - begin - Topic.destroy(params[:id]) - render json: { id: params[:id] } - rescue => e - render text: e.message, status: 500 - end + Topic.destroy(params[:id]) + render json: { id: params[:id] } + rescue StandardError => e + render text: e.message, status: 500 end def create diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c4c4f5c2..809cc39e7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -25,9 +25,7 @@ def user_conditional_logic # `cors_allowed_domains` in application.yml, and if it is, the response gets # a header allowing the requesting domain to use this app's CRUD def cors - if Actioncenter::Application.config.cors_allowed_domains.include? request.env["HTTP_ORIGIN"] or Actioncenter::Application.config.cors_allowed_domains.include? "*" - response.headers["Access-Control-Allow-Origin"] = request.env["HTTP_ORIGIN"] - end + response.headers["Access-Control-Allow-Origin"] = request.env["HTTP_ORIGIN"] if Actioncenter::Application.config.cors_allowed_domains.include?(request.env["HTTP_ORIGIN"]) || Actioncenter::Application.config.cors_allowed_domains.include?("*") end def self.manifest(value = nil) @@ -60,7 +58,7 @@ def user_is_being_told_to_reset_pass_or_is_resetting_pass? def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, - keys: [:record_activity, :subscribe]) + keys: %i[record_activity subscribe]) end def set_locale diff --git a/app/controllers/concerns/action_page_display.rb b/app/controllers/concerns/action_page_display.rb index d26f8340e..4c842bd2a 100644 --- a/app/controllers/concerns/action_page_display.rb +++ b/app/controllers/concerns/action_page_display.rb @@ -11,22 +11,20 @@ def set_action_display_variables @congress_message_campaign = @actionPage.congress_message_campaign # Shows a mailing list if no tools enabled - @no_tools = [:tweet, :petition, :call, :email, :congress_message].none? do |tool| + @no_tools = %i[tweet petition call email congress_message].none? do |tool| @actionPage.send "enable_#{tool}".to_sym end set_signatures - if @actionPage.petition and @actionPage.petition.enable_affiliations + if @actionPage.petition&.enable_affiliations @top_institutions = @actionPage.institutions.top(300, first: @institution.try(:id)) @institutions = @actionPage.institutions.order(:name) @institution_category = @institutions.first.category end @topic_category = nil - if @email_campaign and !@email_campaign.topic_category.nil? - @topic_category = @email_campaign.topic_category.as_2d_array - end + @topic_category = @email_campaign.topic_category.as_2d_array if @email_campaign && !@email_campaign.topic_category.nil? # Initialize a temporary signature object for form auto-population current_zipcode = params[:zipcode] || current_user.try(:zipcode) @@ -53,7 +51,7 @@ def set_signatures @institution_signature_count = @signatures.pretty_count elsif @petition.enable_affiliations @signatures = @petition.signatures - .includes(affiliations: [:institution, :affiliation_type]) + .includes(affiliations: %i[institution affiliation_type]) else @signatures = @petition.signatures end diff --git a/app/controllers/concerns/date_range.rb b/app/controllers/concerns/date_range.rb index 0a061e702..eae82f3f3 100644 --- a/app/controllers/concerns/date_range.rb +++ b/app/controllers/concerns/date_range.rb @@ -8,9 +8,7 @@ def set_dates def process_dates(date_range_text: nil, date_text: nil, **_) return parse_date_range(date_range_text) if date_range_text.present? return [1.month.ago, Time.zone.now] if date_text.blank? - if date_text == "Action lifetime" && @actionPage.present? - return [@actionPage.created_at, Time.zone.now] - end + return [@actionPage.created_at, Time.zone.now] if date_text == "Action lifetime" && @actionPage.present? [parse_time_ago(date_text), Time.zone.now] end @@ -22,7 +20,7 @@ def parse_date_range(date_range_string) # Convert Last X (days|weeks|months) to a time def parse_time_ago(string) _, count, unit = string.split(" ") - return Time.zone.now - 1.month unless %w(days weeks months years).include? unit + return Time.zone.now - 1.month unless %w[days weeks months years].include? unit Time.zone.now - count.to_i.send(unit) end diff --git a/app/controllers/concerns/tooling.rb b/app/controllers/concerns/tooling.rb index 34aa13763..cd4cf7040 100644 --- a/app/controllers/concerns/tooling.rb +++ b/app/controllers/concerns/tooling.rb @@ -15,8 +15,6 @@ def create_partner_subscription def deliver_thanks_message @email ||= current_user.try(:email) || params[:email] || params.dig(:subscription, :email) - if @email.present? - UserMailer.thanks_message(@email, @action_page, user: @user, name: @name).deliver_now - end + UserMailer.thanks_message(@email, @action_page, user: @user, name: @name).deliver_now if @email.present? end end diff --git a/app/controllers/congress_messages_controller.rb b/app/controllers/congress_messages_controller.rb index ddd37f54a..b31429683 100644 --- a/app/controllers/congress_messages_controller.rb +++ b/app/controllers/congress_messages_controller.rb @@ -37,7 +37,7 @@ def create else params[:forms][:bioguide_ids] end - @message.forms, _ = CongressForms::Form.find(bioguide_ids) + @message.forms, = CongressForms::Form.find(bioguide_ids) if EmailValidator.valid?(user_params[:email]) && @message.background_submit(params[:test]) @name = user_params[:first_name] # for deliver_thanks_message @@ -84,9 +84,7 @@ def partner_signup_params end def update_user - if params[:update_user_data] == "yes" - current_user.update(user_params.except(:email)) - end + current_user.update(user_params.except(:email)) if params[:update_user_data] == "yes" end def subscribe_user @@ -96,7 +94,7 @@ def subscribe_user source = "action center congress message :: " + @action_page.title user = User.find_or_initialize_by(email: user_params[:email]) user.attributes = user_params - user.subscribe!(opt_in = false, source = source)["requires_confirmation"] + user.subscribe!(opt_in: false, source: source)["requires_confirmation"] end end diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb index 6be6f8af3..ed8c595fd 100644 --- a/app/controllers/partners_controller.rb +++ b/app/controllers/partners_controller.rb @@ -33,15 +33,13 @@ def add_user user = User.find_by(email: params[:email]) if user.nil? flash[:notice] = "Couldn't find a user by email #{params[:email]}" + elsif user.partner == @partner + flash[:notice] = "That user is already linked to #{@partner.name}" + elsif user.partner.nil? + user.partner = @partner + user.save else - if user.partner.nil? - user.partner = @partner - user.save - elsif user.partner == @partner - flash[:notice] = "That user is already linked to #{@partner.name}" - else - flash[:notice] = "That user is linked to another partner: #{user.partner.name}" - end + flash[:notice] = "That user is linked to another partner: #{user.partner.name}" end redirect_to @partner end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 74065e02d..ef390dbcf 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -28,9 +28,7 @@ def handle_nonunique_email existing.send_email_taken_notice # Allow unconfirmed users to set a new password by re-registering. - if !existing.confirmed? - existing.update(sign_up_params) - end + existing.update(sign_up_params) unless existing.confirmed? if resource.persisted? resource.update_attribute(:unconfirmed_email, account_update_params[:email]) diff --git a/app/controllers/robots_controller.rb b/app/controllers/robots_controller.rb index be90d584c..b50b571d3 100644 --- a/app/controllers/robots_controller.rb +++ b/app/controllers/robots_controller.rb @@ -1,6 +1,6 @@ class RobotsController < ApplicationController def show - if Rails.env.development? or Rails.application.secrets.enable_basic_auth == "true" + if Rails.env.development? || (Rails.application.secrets.enable_basic_auth == "true") render text: "User-agent: *\nDisallow: /" else render text: "" diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index c86631eb7..e2f0fc452 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,7 @@ class SessionsController < Devise::SessionsController before_action :unset_logged_in, only: :destroy def set_logged_in - if (user_signed_in?) + if user_signed_in? # Sets a "permanent" cookie (which expires in 20 years from now). # This is exclusively used to never cache content for logged in users cookies.permanent[:logged_in] = "I <3 EFF" diff --git a/app/controllers/smarty_streets_controller.rb b/app/controllers/smarty_streets_controller.rb index 3377aed18..de6fcda85 100644 --- a/app/controllers/smarty_streets_controller.rb +++ b/app/controllers/smarty_streets_controller.rb @@ -38,10 +38,8 @@ def authorize_query(params) end def proxy_request(url) - begin - return RestClient.get url, accept: :json, 'X-Include-Invalid': "true" - rescue => e - logger.error e - end + RestClient.get url, accept: :json, 'X-Include-Invalid': "true" + rescue StandardError => e + logger.error e end end diff --git a/app/controllers/sns_controller.rb b/app/controllers/sns_controller.rb index 00eb8ffb5..191704e3c 100644 --- a/app/controllers/sns_controller.rb +++ b/app/controllers/sns_controller.rb @@ -40,7 +40,7 @@ def set_context def set_message body = JSON.parse(request.body.read) - return JSON.parse(body["Message"]) + JSON.parse(body["Message"]) end def log_request diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 95dcbe585..5ed80bdd6 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -9,14 +9,14 @@ class SubscriptionsController < ApplicationController def create email = params[:subscription][:email] - if !EmailValidator.valid?(email) + unless EmailValidator.valid?(email) render json: { message: "Bad news, something went wrong with your email address. Please check it for typos and try again." }, status: 400 return end update_user_data(email: email) params[:subscription][:opt_in] = params[:subscription][:opt_in] || false - subscription = CiviCRM::subscribe params[:subscription] + subscription = CiviCRM.subscribe params[:subscription] if subscription["error"] render json: { message: subscription["error_message"] }, status: 500 else diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index c7439261e..c0e220726 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -10,10 +10,10 @@ class ToolsController < ApplicationController # Put an invisible captcha on forms are easy to submit programmatically and # create email subscriptions. - invisible_captcha only: [:email, :petition] - before_action :create_newsletter_subscription, only: [:email, :call] - before_action :create_partner_subscription, only: [:email, :call, :petition, :message_congress] - after_action :deliver_thanks_message, only: [:email, :call, :petition, :message_congress] + invisible_captcha only: %i[email petition] + before_action :create_newsletter_subscription, only: %i[email call] + before_action :create_partner_subscription, only: %i[email call petition message_congress] + after_action :deliver_thanks_message, only: %i[email call petition message_congress] skip_after_action :deliver_thanks_message, if: :signature_has_errors # See https://github.com/EFForg/action-center-platform/wiki/Deployment-Notes#csrf-protection @@ -27,9 +27,7 @@ def call @name = current_user.try :name - if params[:update_user_data] == "yes" - update_user_data(call_params) - end + update_user_data(call_params) if params[:update_user_data] == "yes" CallTool.campaign_call(params[:call_campaign_id], phone: params[:phone], @@ -56,12 +54,11 @@ def petition @action_page = Petition.find(params[:signature][:petition_id]).action_page @signature = Signature.new(signature_params.merge(user_id: @user.id)) - if @signature.zipcode.present? && @signature.country_code.blank? - @signature.country_code = "US" - end + @signature.country_code = "US" if @signature.zipcode.present? && @signature.country_code.blank? if @signature.country_code == "US" && !Rails.application.secrets.smarty_streets_id.nil? - if city_state = SmartyStreets.get_city_state(@signature.zipcode) + city_state = SmartyStreets.get_city_state(@signature.zipcode) + if city_state @signature.city = city_state["city"] @signature.state = city_state["state"] end @@ -77,12 +74,10 @@ def petition ) @source = "action center petition :: " + @action_page.title - @user.subscribe!(opt_in = true, source = @source) + @user.subscribe!(opt_in: true, source: @source) end - if params[:update_user_data] - update_user_data(signature_params) - end + update_user_data(signature_params) if params[:update_user_data] ahoy.track "Action", { type: "action", actionType: "signature", actionPageId: @action_page.id }, @@ -91,13 +86,11 @@ def petition respond_to do |format| format.json { render json: { success: true }, status: 200 } format.html do - begin - url = URI.parse(request.referrer) - url.query = [url.query.presence, "thankyou=1"].join("&") - redirect_to url.to_s - rescue - redirect_to welcome_index_path - end + url = URI.parse(request.referrer) + url.query = [url.query.presence, "thankyou=1"].join("&") + redirect_to url.to_s + rescue StandardError + redirect_to welcome_index_path end end else @@ -113,7 +106,7 @@ def tweet end def email - unless (@user and @user.events.emails.find_by(action_page_id: params[:action_id])) or params[:dnt] == "true" + unless (@user && @user.events.emails.find_by(action_page_id: params[:action_id])) || (params[:dnt] == "true") ahoy.track "Action", { type: "action", actionType: "email", actionPageId: params[:action_id] }, action_page: @action_page @@ -170,7 +163,7 @@ def create_newsletter_subscription source = "action center #{@action_page.class.name.downcase} :: " + @action_page.title params[:subscription][:opt_in] = true params[:subscription][:source] = source - CiviCRM::subscribe params[:subscription] + CiviCRM.subscribe params[:subscription] end end @@ -179,9 +172,9 @@ def signature_has_errors end def partner_signup_params - attributes = %i(first_name last_name email) + attributes = %i[first_name last_name email] # Partner signup params might come through the main form or a nested subscription form. - %i(signature subscription).each do |model| + %i[signature subscription].each do |model| return params.require(model).permit(*attributes) if params[model].present? end params.permit(*attributes) @@ -191,8 +184,8 @@ def signature_params params.require(:signature).permit( :first_name, :last_name, :email, :petition_id, :user_id, :street_address, :city, :state, :country_code, :zipcode, :anonymous, - affiliations_attributes: [ - :id, :institution_id, :affiliation_type_id + affiliations_attributes: %i[ + id institution_id affiliation_type_id ] ) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8f6b005bd..99a9bd6a7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,11 +7,11 @@ def show end def update - if current_user.update(user_params) - flash[:notice] = "You updated your account successfully." - else - flash[:notice] = "Could not update your account." - end + flash[:notice] = if current_user.update(user_params) + "You updated your account successfully." + else + "Could not update your account." + end if request.xhr? render json: {}, status: 200 diff --git a/app/helpers/action_page_helper.rb b/app/helpers/action_page_helper.rb index cadbbdfde..7248de14b 100644 --- a/app/helpers/action_page_helper.rb +++ b/app/helpers/action_page_helper.rb @@ -4,9 +4,7 @@ def twitter_share_url(action_page) action_page.share_message, action_page_url(action_page) ].map(&:presence).compact.join(" ") - suffix = if Rails.application.config.twitter_handle - " via @#{Rails.application.config.twitter_handle}" - end + suffix = (" via @#{Rails.application.config.twitter_handle}" if Rails.application.config.twitter_handle) message += suffix if action_page.share_message.to_s.length + suffix.length <= 117 related = Rails.application.config.twitter_related.to_a.join(",") diff --git a/app/helpers/admin/action_pages_helper.rb b/app/helpers/admin/action_pages_helper.rb index dfc8b35dc..d10cd02a5 100644 --- a/app/helpers/admin/action_pages_helper.rb +++ b/app/helpers/admin/action_pages_helper.rb @@ -1,47 +1,43 @@ -module Admin - module ActionPagesHelper - def call_campaign_options_for_select - if CallTool.enabled? - CallTool.campaigns.map do |campaign| - ["#{campaign['name']} (#{campaign['status']})", campaign["id"]] - end.sort_by(&:last).reverse - else - [] - end - rescue SystemCallError, RestClient::Exception +module Admin::ActionPagesHelper + def call_campaign_options_for_select + if CallTool.enabled? + CallTool.campaigns.map do |campaign| + ["#{campaign['name']} (#{campaign['status']})", campaign["id"]] + end.sort_by(&:last).reverse + else [] end + rescue SystemCallError, RestClient::Exception + [] + end - def congress_member_options_for_select(campaign) - selected = (campaign.target_bioguide_ids || "").split(/\s*,\s*/) + def congress_member_options_for_select(campaign) + selected = (campaign.target_bioguide_ids || "").split(/\s*,\s*/) - state_names = Places.us_state_codes.invert + state_names = Places.us_state_codes.invert - congressional_bioguides = [] - grouped_reps = CongressMember.all.group_by do |rep| - congressional_bioguides << rep.bioguide_id - state_names[rep.state] - end + congressional_bioguides = [] + grouped_reps = CongressMember.all.group_by do |rep| + congressional_bioguides << rep.bioguide_id + state_names[rep.state] + end - grouped_reps.each do |state, state_reps| - grouped_reps[state] = state_reps.sort_by(&:last_name).map do |rep| - label = "#{rep.full_name} (#{rep.bioguide_id})" - [label, rep.bioguide_id] - end + grouped_reps.each do |state, state_reps| + grouped_reps[state] = state_reps.sort_by(&:last_name).map do |rep| + label = "#{rep.full_name} (#{rep.bioguide_id})" + [label, rep.bioguide_id] end + end - grouped_reps = grouped_reps.keys.sort.map { |k| [k, grouped_reps[k]] } + grouped_reps = grouped_reps.keys.sort.map { |k| [k, grouped_reps[k]] } - non_congressional_bioguides = [] - CongressMessageCampaign.targets_bioguide_ids.pluck(:target_bioguide_ids).each do |targets| - non_congressional_bioguides.concat(targets.split(/\s*,\s*/) - congressional_bioguides) - end + non_congressional_bioguides = [] + CongressMessageCampaign.targets_bioguide_ids.pluck(:target_bioguide_ids).each do |targets| + non_congressional_bioguides.concat(targets.split(/\s*,\s*/) - congressional_bioguides) + end - if non_congressional_bioguides.present? - grouped_reps.unshift(["Non-congressional", non_congressional_bioguides.sort]) - end + grouped_reps.unshift(["Non-congressional", non_congressional_bioguides.sort]) if non_congressional_bioguides.present? - grouped_options_for_select(grouped_reps, selected) - end + grouped_options_for_select(grouped_reps, selected) end end diff --git a/app/helpers/admin/topics_helper.rb b/app/helpers/admin/topics_helper.rb index cb93a029c..9308f1c89 100644 --- a/app/helpers/admin/topics_helper.rb +++ b/app/helpers/admin/topics_helper.rb @@ -1,19 +1,17 @@ -module Admin - module TopicsHelper - def topic_category_props(topic_category) - topic_sets = topic_category.topic_sets.map do |topic_set| - { - id: topic_set.id, - tier: topic_set.tier, - topics: topic_set.topics.map { |topic| topic.attributes.slice("id", "name") } - } - end - +module Admin::TopicsHelper + def topic_category_props(topic_category) + topic_sets = topic_category.topic_sets.map do |topic_set| { - topicCategoryId: topic_category.id, - topicCategoryName: topic_category.name, - topicSets: topic_sets + id: topic_set.id, + tier: topic_set.tier, + topics: topic_set.topics.map { |topic| topic.attributes.slice("id", "name") } } end + + { + topicCategoryId: topic_category.id, + topicCategoryName: topic_category.name, + topicSets: topic_sets + } end end diff --git a/app/helpers/ahoy_helper.rb b/app/helpers/ahoy_helper.rb index 2bc4f3676..b1ef23a17 100644 --- a/app/helpers/ahoy_helper.rb +++ b/app/helpers/ahoy_helper.rb @@ -1,8 +1,8 @@ module AhoyHelper def ahoy_track_tag(action_type, action_page_id) - content_tag(:div, style: "height: 0; overflow: hidden") { + content_tag(:div, style: "height: 0; overflow: hidden") do params = { action_type: action_type, action_page_id: action_page_id, format: :gif } image_tag(ahoy_visit_url(params), style: "border: 0", alt: "") - } + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7c26d7b80..1eebbc39f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,7 +5,7 @@ def page_title end def escape_page_title - URI.escape(page_title, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + ERB::Util.url_encode page_title end def twitter_handle @@ -21,7 +21,7 @@ def markdown(blogtext) end def substitute_keywords(blogtext) - if @actionPage and @actionPage.description and @petition + if @actionPage&.description && @petition blogtext.gsub("$SIGNATURECOUNT", @petition.signatures.pretty_count) else blogtext @@ -75,20 +75,22 @@ def update_user_data(params = {}) end end + # REFACTOR_FLAG + # use ActiveStorage::Filename#sanitized after upgrading to 5.2 def sanitize_filename(filename) # Split the name when finding a period which is preceded by some # character, and is followed by some character other than a period, # if there is no following period that is followed by something # other than a period (yeah, confusing, I know) - fn = filename.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m + fn = filename.split(/(?<=.)\.(?=[^.])(?!.*\.[^.])/m) # We now have one or two parts (depending on whether we could find # a suitable period). For each of these parts, replace any unwanted # sequence of characters with an underscore - fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, "_" } + fn.map! { |s| s.gsub(/[^a-z0-9\-]+/i, "_") } # Finally, join the parts with a period and return the result - return fn.join "." + fn.join "." end def can?(ability) @@ -117,8 +119,8 @@ def percentage(x, y, precision: 0) private def user_session_data_whitelist - [:email, :last_name, :first_name, :street_address, :city, :state, :zipcode, - :country_code, :phone] + %i[email last_name first_name street_address city state zipcode + country_code phone] end def current_user_data(field) diff --git a/app/helpers/congress_message_helper.rb b/app/helpers/congress_message_helper.rb index 8ca9d4c35..7fb8e7497 100644 --- a/app/helpers/congress_message_helper.rb +++ b/app/helpers/congress_message_helper.rb @@ -1,8 +1,6 @@ module CongressMessageHelper def congress_forms_prefills(campaign, field) - if field.value == "$TOPIC" && campaign.topic_category.present? - return campaign.topic_category.best_match(field.options_hash) - end + return campaign.topic_category.best_match(field.options_hash) if field.value == "$TOPIC" && campaign.topic_category.present? { "$NAME_FIRST" => current_first_name, @@ -11,16 +9,16 @@ def congress_forms_prefills(campaign, field) "$PHONE" => number_to_phone(current_user.try(:phone)), "$ADDRESS_STREET" => current_street_address, "$ADDRESS_CITY" => current_city, - "$SUBJECT" => campaign.subject, + "$SUBJECT" => campaign.subject }[field.value] end def congress_forms_field(field, campaign, message_attributes, bioguide_id = nil) - if bioguide_id - name = "member_attributes[#{bioguide_id}][#{field.value}]" - else - name = "common_attributes[#{field.value}]" - end + name = if bioguide_id + "member_attributes[#{bioguide_id}][#{field.value}]" + else + "common_attributes[#{field.value}]" + end # Try to guess the input based on saved info about the campaign + user. prefill = congress_forms_prefills(campaign, field) diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index 1be8f9dab..c4bfed8b0 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -2,15 +2,13 @@ module DeviseHelper # Customized to add model error instead of flashing the error. def devise_error_messages! flash_alerts = [] - error_key = "errors.messages.not_saved" flash_alerts.push("This account was locked due to too many failed login attempts. Check your email for a link to unlock.") if locked_account? - if !flash.empty? + unless flash.empty? flash_alerts.push(flash[:error]) if flash[:error] flash_alerts.push(flash[:alert]) if flash[:alert] flash_alerts.push(flash[:notice]) if flash[:notice] - error_key = "devise.failure.invalid" end return "" if resource.errors.empty? && flash_alerts.empty? @@ -19,12 +17,7 @@ def devise_error_messages! errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages messages = errors.map { |msg| content_tag(:p, msg) }.join - sentence = I18n.t(error_key, count: errors.count, - resource: resource.class.model_name.human.downcase) - - if !flash[:notice] | flash[:alert] - panel_title = "

Error

" - end + panel_title = "

Error

" if !flash[:notice] | flash[:alert] html = <<-HTML
@@ -44,6 +37,6 @@ def devise_error_messages? def locked_account? u = User.find_by(email: @user.email) - u && u.access_locked? + u&.access_locked? end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index aaa37fb16..7609415fe 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -22,8 +22,6 @@ def signup_attempt_with_existing_email(user, _options = {}) private def check_bounces - unless Bounce.find_by(email: @email.downcase).nil? - mail.perform_deliveries = false - end + mail.perform_deliveries = false unless Bounce.find_by(email: @email.downcase).nil? end end diff --git a/app/models/action_page.rb b/app/models/action_page.rb index ecd7631ca..cd2fb691a 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -1,28 +1,29 @@ class ActionPage < ActiveRecord::Base - extend FriendlyId, AmazonCredentials + extend AmazonCredentials + extend FriendlyId include PgSearch pg_search_scope :search, - against: [ - :title, - :slug, - :summary, - :description, - :email_text, + against: %i[ + title + slug + summary + description + email_text ], associated_against: { - call_campaign: [:title, :message], - congress_message_campaign: [:subject, :message, :campaign_tag], - email_campaign: [:subject, :message], - petition: [:title, :description], - tweet: [:target, :message, :cta] + call_campaign: %i[title message], + congress_message_campaign: %i[subject message campaign_tag], + email_campaign: %i[subject message], + petition: %i[title description], + tweet: %i[target message cta] }, using: { tsearch: { prefix: true } } - friendly_id :title, use: [:slugged, :history] + friendly_id :title, use: %i[slugged history] scope :published, -> { where(published: true) } - has_many :events, class_name: Ahoy::Event + has_many :events, class_name: "Ahoy::Event" has_many :partnerships has_many :partners, through: :partnerships has_many :action_institutions @@ -52,7 +53,7 @@ class ActionPage < ActiveRecord::Base if: -> { background_image.present? && background_image_file_name_came_from_user? } validates_media_type_spoof_detection :og_image, if: -> { og_image.present? && og_image_file_name_came_from_user? } - do_not_validate_attachment_file_type [:featured_image, :background_image, :og_image] + do_not_validate_attachment_file_type %i[featured_image background_image og_image] # validates_length_of :og_title, maximum: 65 after_save :no_drafts_on_homepage @@ -62,18 +63,16 @@ class ActionPage < ActiveRecord::Base def self.type(*types) scopes = Array(types).flatten.map do |t| - unless %w(call congress_message email petition tweet redirect).include?(t) - raise ArgumentError, "unrecognized type #{t}" - end + raise ArgumentError, "unrecognized type #{t}" unless %w[call congress_message email petition tweet redirect].include?(t) - where(:"enable_#{t}" => true) + where("enable_#{t}": true) end scopes.inject(:or) || all end def action_type - %w(call congress_message email petition tweet redirect).each do |type| + %w[call congress_message email petition tweet redirect].each do |type| return type.titleize if self[:"enable_#{type}"] end @@ -81,9 +80,7 @@ def action_type end def self.status(status) - unless %w(archived victory live draft).include?(status) - raise ArgumentError, "unrecognized status #{status}" - end + raise ArgumentError, "unrecognized status #{status}" unless %w[archived victory live draft].include?(status) case status when "live" @@ -107,14 +104,14 @@ def should_generate_new_friendly_id? def call_tool_title call_campaign && - call_campaign.title.length > 0 && + !call_campaign.title.empty? && call_campaign.title || "Call Your Legislators" end def message_rendered # TODO: just write a test for this and rename this to .to_md - call_campaign && call_campaign.message || "" + call_campaign&.message || "" end def verb diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb index de0ff08b9..3fd248da4 100644 --- a/app/models/ahoy/event.rb +++ b/app/models/ahoy/event.rb @@ -10,8 +10,6 @@ class Event < ActiveRecord::Base "action_count" elsif record.name == "View" "view_count" - else - nil end } @@ -23,7 +21,7 @@ class Event < ActiveRecord::Base scope :signatures, -> { where("properties ->> 'actionType' = 'signature'") } scope :tweets, -> { where("properties ->> 'actionType' = 'tweet'") } scope :on_page, ->(id) { where(action_page_id: id) } - scope :in_range, ->(start_date, end_date) { + scope :in_range, lambda { |start_date, end_date| where(time: start_date..end_date.tomorrow) } @@ -31,16 +29,16 @@ class Event < ActiveRecord::Base before_save :anonymize_views after_create :record_civicrm - TYPES = %i(views emails tweets calls signatures congress_messages).freeze + TYPES = %i[views emails tweets calls signatures congress_messages].freeze def self.action_types(action_page = nil) TYPES.dup.tap do |t| if action_page.present? - t.delete(:calls) if !action_page.enable_call - t.delete(:congress_messages) if !action_page.enable_congress_message - t.delete(:emails) if !action_page.enable_email - t.delete(:signatures) if !action_page.enable_petition - t.delete(:tweets) if !action_page.enable_tweet + t.delete(:calls) unless action_page.enable_call + t.delete(:congress_messages) unless action_page.enable_congress_message + t.delete(:emails) unless action_page.enable_email + t.delete(:signatures) unless action_page.enable_petition + t.delete(:tweets) unless action_page.enable_tweet end end end @@ -88,14 +86,12 @@ def self.summary def user_opt_out if user - user_id = nil unless user.record_activity? + self.user_id = nil unless user.record_activity? end end def record_civicrm - if name == "Action" && user && action_page_id - user.add_civicrm_activity! action_page_id - end + user.add_civicrm_activity! action_page_id if name == "Action" && user && action_page_id end def anonymize_views diff --git a/app/models/category.rb b/app/models/category.rb index e3960204f..20d05d870 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,4 @@ class Category < ActiveRecord::Base - validates_presence_of :title - validates_format_of :title, with: /\A[\w\s&]+\Z/ + validates :title, presence: true + validates :title, format: { with: /\A[\w\s&]+\Z/ } end diff --git a/app/models/congress_member.rb b/app/models/congress_member.rb index 43317fa2f..ced3628f1 100644 --- a/app/models/congress_member.rb +++ b/app/models/congress_member.rb @@ -1,19 +1,19 @@ class CongressMember < ActiveRecord::Base - validates_uniqueness_of :bioguide_id + validates :bioguide_id, uniqueness: true - scope :current, -> { where("? <= term_end", Time.now) } + scope :current, -> { where("? <= term_end", Time.zone.now) } - scope :filter, ->(f) do + scope :filter, lambda { |f| if f.present? fields = "first_name || ' ' || last_name || ' ' || full_name || ' ' || bioguide_id" where("LOWER(#{fields}) LIKE ?", "%#{f.downcase}%") else all end - end + } def current? - Time.now <= term_end + Time.zone.now <= term_end end def senate? diff --git a/app/models/congress_message.rb b/app/models/congress_message.rb index 24e41979b..7b1c33c26 100644 --- a/app/models/congress_message.rb +++ b/app/models/congress_message.rb @@ -7,12 +7,16 @@ class CongressMessage attr_accessor :forms, :campaign attr_writer :common_attributes, :member_attributes - ALWAYS_COMMON = %w($NAME_FIRST $NAME_LAST $ADDRESS_CITY $ADDRESS_STATE - $ADDRESS_STREET $ADDRESS_ZIP5 $EMAIL).freeze + ALWAYS_COMMON = %w[$NAME_FIRST $NAME_LAST $ADDRESS_CITY $ADDRESS_STATE + $ADDRESS_STREET $ADDRESS_ZIP5 $EMAIL].freeze - def common_attributes() @common_attributes || {}; end + def common_attributes + @common_attributes || {} + end - def member_attributes() @member_attributes || {}; end + def member_attributes + @member_attributes || {} + end def self.new_from_lookup(location, campaign, forms) common_attributes = { @@ -62,9 +66,7 @@ def attributes_for(bioguide_id) end def background_submit(test = false) - if valid? - @forms.each { |f| f.delay.fill(attributes_for(f.bioguide_id), campaign.campaign_tag, test) } - end + @forms.each { |f| f.delay.fill(attributes_for(f.bioguide_id), campaign.campaign_tag, test) } if valid? end def update_common_attributes(**attrs) @@ -79,9 +81,7 @@ def attributes_satisfy_forms @forms.each do |form| attributes = attributes_for(form.bioguide_id) form.fields.each do |field| - if !field.validate(attributes[field.value]) - errors.add(:base, "Invalid input for #{field.value}") - end + errors.add(:base, "Invalid input for #{field.value}") unless field.validate(attributes[field.value]) end end end diff --git a/app/models/congress_message_campaign.rb b/app/models/congress_message_campaign.rb index 3ec85b171..4d33b5edf 100644 --- a/app/models/congress_message_campaign.rb +++ b/app/models/congress_message_campaign.rb @@ -65,7 +65,7 @@ def target_specific_legislators private def target_bioguide_text_or_default(custom_text, default) - if !target_bioguide_ids or custom_text.blank? + if !target_bioguide_ids || custom_text.blank? default else custom_text diff --git a/app/models/email_campaign.rb b/app/models/email_campaign.rb index 6bcc18170..5adb8479d 100644 --- a/app/models/email_campaign.rb +++ b/app/models/email_campaign.rb @@ -48,7 +48,7 @@ def query(hash) end def target_bioguide_text_or_default(custom_text, default) - if !target_bioguide_id or custom_text.blank? + if !target_bioguide_id || custom_text.blank? default else custom_text diff --git a/app/models/featured_action_page.rb b/app/models/featured_action_page.rb index aeabadd4e..bdbe57360 100644 --- a/app/models/featured_action_page.rb +++ b/app/models/featured_action_page.rb @@ -1,6 +1,6 @@ class FeaturedActionPage < ActiveRecord::Base belongs_to :action_page - validates_presence_of :action_page, :weight + validates :action_page, :weight, presence: true def initialize(attributes = {}) super(attributes.reverse_merge(weight: 0)) @@ -11,6 +11,6 @@ def self.load_for_edit return existing unless existing.length < 4 weights_to_create = (1..4).to_a - existing.map(&:weight) - existing += weights_to_create.map { |w| new(weight: w) } + existing + weights_to_create.map { |w| new(weight: w) } end end diff --git a/app/models/institution.rb b/app/models/institution.rb index 406782ee0..be453aad4 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -2,13 +2,13 @@ class Institution < ActiveRecord::Base require "csv" extend FriendlyId - friendly_id :name, use: [:slugged, :history] + friendly_id :name, use: %i[slugged history] include PgSearch pg_search_scope :search, - against: [ - :name, - :category + against: %i[ + name + category ], using: { tsearch: { prefix: true } } @@ -16,9 +16,9 @@ class Institution < ActiveRecord::Base has_many :action_pages, through: :action_institutions has_many :affiliations - validates_presence_of :name - validates_uniqueness_of :name - validates_presence_of :category + validates :name, presence: true + validates :name, uniqueness: true + validates :category, presence: true def self.process_csv(csv_file) [].tap do |names| diff --git a/app/models/partner.rb b/app/models/partner.rb index b6fa608f6..b198042d9 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -10,7 +10,7 @@ class Partner < ActiveRecord::Base validates_media_type_spoof_detection :logo, if: -> { logo.present? && logo_file_name_came_from_user? } do_not_validate_attachment_file_type [:logo] - validates_uniqueness_of :code + validates :code, uniqueness: true def to_csv(options = {}) column_names = %w[first_name last_name email created_at] diff --git a/app/models/petition.rb b/app/models/petition.rb index 4141ae083..e7f5dd393 100644 --- a/app/models/petition.rb +++ b/app/models/petition.rb @@ -6,16 +6,16 @@ class Petition < ActiveRecord::Base def percent_complete return 0 if goal == 0 - [signatures.count.to_f / goal.to_f, 1].min * 100 + [signatures.count / goal.to_f, 1].min * 100 end def recent_signatures(num) recent = [] signatures.last(num).reverse_each do |s| if s.anonymous - recent.push(s.as_json(only: [], methods: [:time_ago, :location])) + recent.push(s.as_json(only: [], methods: %i[time_ago location])) else - recent.push(s.as_json(only: [:first_name, :last_name, :city], methods: [:time_ago, :location])) + recent.push(s.as_json(only: %i[first_name last_name city], methods: %i[time_ago location])) end end recent @@ -31,14 +31,12 @@ def location_required? end def to_s - "#{title}-exported_on-#{DateTime.now.strftime("%Y-%m-%d")}" + "#{title}-exported_on-#{DateTime.now.strftime('%Y-%m-%d')}" end private def set_goal - if new_record? - goal = 100 - end + self.goal = 100 if new_record? end end diff --git a/app/models/signature.rb b/app/models/signature.rb index a02f13a40..a587b35f1 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -1,16 +1,16 @@ -include GoingPostal - class Signature < ActiveRecord::Base + include GoingPostal + belongs_to :user belongs_to :petition has_many :affiliations before_validation :format_zipcode before_save :sanitize_input - validates_presence_of :first_name, :last_name, :petition_id, - message: "This can't be blank." + validates :first_name, :last_name, :petition_id, + presence: { message: "This can't be blank." } - validates_presence_of :country_code, if: :location_required? + validates :country_code, presence: { if: :location_required? } validates :email, email: true validates :email, uniqueness: { scope: :petition_id, @@ -20,15 +20,15 @@ class Signature < ActiveRecord::Base accepts_nested_attributes_for :affiliations, reject_if: :all_blank - scope :search, ->(f) do + scope :search, lambda { |f| if f.present? - where("LOWER(email) LIKE ? " + + where("LOWER(email) LIKE ? " \ "OR LOWER(first_name || ' ' || last_name) LIKE ?", "%#{f}%".downcase, "%#{f}%".downcase) else all end - end + } include ActionView::Helpers::DateHelper @@ -80,13 +80,11 @@ def self.institutions end def self.pretty_count - ActiveSupport::NumberHelper::number_to_delimited(self.count, delimiter: ",") + ActiveSupport::NumberHelper.number_to_delimited(count, delimiter: ",") end def arbitrary_opinion_of_country_string_validity - if country_code.present? and full_country_name.nil? - errors.add(:country_code, "Country Code might come from a spam bot.") - end + errors.add(:country_code, "Country Code might come from a spam bot.") if country_code.present? && full_country_name.nil? end def name @@ -118,17 +116,15 @@ def location_required? end def full_country_name - begin - IsoCountryCodes.find(country_code).name - rescue IsoCountryCodes::UnknownCodeError - nil - end + IsoCountryCodes.find(country_code).name + rescue IsoCountryCodes::UnknownCodeError + nil end private def format_zipcode - zipcode = GoingPostal.format_zipcode(zipcode, country_code) || zipcode + self.zipcode = GoingPostal.format_zipcode(zipcode, country_code) || zipcode end def sanitize_input @@ -143,8 +139,6 @@ def sanitize_input end def validate_zipcode - unless GoingPostal.valid_zipcode?(zipcode, country_code) - errors.add(:zipcode, "Invalid zip/postal code for country") - end + errors.add(:zipcode, "Invalid zip/postal code for country") unless GoingPostal.valid_zipcode?(zipcode, country_code) end end diff --git a/app/models/source_file.rb b/app/models/source_file.rb index 63b1022ca..799def1b4 100644 --- a/app/models/source_file.rb +++ b/app/models/source_file.rb @@ -1,7 +1,7 @@ class SourceFile < ActiveRecord::Base include Rails.application.routes.url_helpers - validates_presence_of :file_name, :file_content_type, :file_size, :key, :bucket + validates :file_name, :file_content_type, :file_size, :key, :bucket, presence: true delegate :secrets, to: "Rails.application".to_sym @@ -23,8 +23,16 @@ class SourceFile < ActiveRecord::Base def pull_down_s3_object_attributes Rails.logger.debug "Trying to validate S3 object." self.file_name = key.split("/").last if key - self.file_size ||= s3_object.content_length rescue nil - self.file_content_type ||= s3_object.content_type rescue nil + self.file_size ||= begin + s3_object.content_length + rescue StandardError + nil + end + self.file_content_type ||= begin + s3_object.content_type + rescue StandardError + nil + end false end @@ -43,7 +51,7 @@ def to_jq_upload "name" => file_name, "size" => file_size, "full_url" => full_url, - "image" => self.is_image?, + "image" => is_image?, "delete_url" => Rails.application.routes.url_helpers.admin_source_file_path(self, format: :json) } end diff --git a/app/models/topic_category.rb b/app/models/topic_category.rb index fd08268bc..2abd4a57c 100644 --- a/app/models/topic_category.rb +++ b/app/models/topic_category.rb @@ -6,14 +6,14 @@ class TopicCategory < ActiveRecord::Base def as_2d_array arr = [] topic_sets.order(:tier).each do |ts| - arr.push ts.topics.map { |t| t.name } + arr.push ts.topics.map(&:name) end arr end def best_match(options) topics = topic_sets.order(:tier).reduce([]) do |arr, ts| - arr += ts.topics + arr + ts.topics end topics.each do |topic| diff --git a/app/models/tweet_target.rb b/app/models/tweet_target.rb index b83bf6c41..53489eca9 100644 --- a/app/models/tweet_target.rb +++ b/app/models/tweet_target.rb @@ -4,7 +4,7 @@ class TweetTarget < ActiveRecord::Base belongs_to :tweet has_attached_file :image, amazon_credentials - validates_media_type_spoof_detection :image, if: ->() { image_file_name.present? } + validates_media_type_spoof_detection :image, if: -> { image_file_name.present? } do_not_validate_attachment_file_type :image after_save :attach_twitter_image @@ -15,7 +15,7 @@ def url delegate :url, to: :image, prefix: true def attach_twitter_image - self.delay.attach_twitter_image_without_delay if image_file_name.nil? and Twitter.has_api_keys? + delay.attach_twitter_image_without_delay if image_file_name.nil? && Twitter.has_api_keys? end def attach_twitter_image_without_delay @@ -27,6 +27,6 @@ def attach_twitter_image_without_delay user_image_url = user_info["profile_image_url_https"].gsub(/_normal\./, "_bigger.") self.image = URI.parse(user_image_url) - self.save + save end end diff --git a/app/models/twitter.rb b/app/models/twitter.rb index 93796ca77..0ea83eaac 100644 --- a/app/models/twitter.rb +++ b/app/models/twitter.rb @@ -17,6 +17,6 @@ def self.prepare_access_token(oauth_token, oauth_token_secret) # now create the access token object from passed values token_hash = { oauth_token: oauth_token, oauth_token_secret: oauth_token_secret } - access_token = OAuth::AccessToken.from_hash(consumer, token_hash) + OAuth::AccessToken.from_hash(consumer, token_hash) end end diff --git a/app/models/user.rb b/app/models/user.rb index cd328de22..fbc45c175 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ class User < ActiveRecord::Base include CiviCRM::UserMethods include PgSearch - pg_search_scope :search, against: [:email, :first_name, :last_name] + pg_search_scope :search, against: %i[email first_name last_name] # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable @@ -12,7 +12,7 @@ class User < ActiveRecord::Base remember_for: 90.days has_many :signatures has_many :user_preferences - has_many :events, class_name: Ahoy::Event + has_many :events, class_name: "Ahoy::Event" belongs_to :partner validates :email, email: true validate :password_complexity @@ -25,7 +25,7 @@ class User < ActiveRecord::Base alias :preferences :user_preferences - scope :authors, ->() { joins(:action_pages).distinct } + scope :authors, -> { joins(:action_pages).distinct } def self.group_created_in_range(start_date, end_date) if start_date == end_date @@ -46,7 +46,7 @@ def email_taken? end def send_email_taken_notice - if self.confirmed? + if confirmed? UserMailer.signup_attempt_with_existing_email(self).deliver_now else send_confirmation_instructions @@ -54,9 +54,7 @@ def send_email_taken_notice end def password_complexity - if admin? && password.present? and password.length < 30 - errors.add :password, "must be at least 30 (try choosing 6 memorable words)" - end + errors.add :password, "must be at least 30 (try choosing 6 memorable words)" if admin? && password.present? && (password.length < 30) end def name @@ -70,16 +68,16 @@ def display_name end def percentile_rank - user_action_counts = Rails.cache.fetch("user_action_counts", expires_in: 24.hours) { + user_action_counts = Rails.cache.fetch("user_action_counts", expires_in: 24.hours) do User.select("users.id, count(ahoy_events.id) AS events_count") .joins("LEFT OUTER JOIN ahoy_events ON ahoy_events.user_id = users.id") .where("ahoy_events.name IS null OR ahoy_events.name = ?", "Action") .group("users.id") - .map { |u| u.events_count } - } + .map(&:events_count) + end user_count = events.actions.count - percentile = user_action_counts.percentile_rank(user_count - 1).round(0) + user_action_counts.percentile_rank(user_count - 1).round(0) end def signed?(petition) @@ -125,19 +123,19 @@ def privileged_role? # This is here for collission avoidance when generating new user names in tests def self.next_id - self.last.nil? ? 1 : self.last.id + 1 + last.nil? ? 1 : last.id + 1 end # We're allowing unconfirmed users to reset their passwords by # re-registering. In that case, they shouldn't get a password reset # notification. def send_password_change_notification? - self.confirmed? && super + confirmed? && super end protected def after_confirmation - subscribe!(opt_in = true) if self.subscribe? + subscribe!(opt_in: true) if subscribe? end end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 9e7860cb4..2bf83b6da 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,5 +1,5 @@ class UserPreference < ActiveRecord::Base belongs_to :user - validates_presence_of :name - validates_presence_of :value + validates :name, presence: true + validates :value, presence: true end diff --git a/app/queries/action_page_filters.rb b/app/queries/action_page_filters.rb index 0d962346a..d0ba042d3 100644 --- a/app/queries/action_page_filters.rb +++ b/app/queries/action_page_filters.rb @@ -26,8 +26,8 @@ def run private - NAMED_SCOPES = %i(type status).freeze - VALID_FILTERS = %i(type status author category).freeze + NAMED_SCOPES = %i[type status].freeze + VALID_FILTERS = %i[type status author category].freeze attr_accessor :relation, :filters @@ -52,8 +52,6 @@ def valid_query?(f, val) end def validate_filter_name(f) - unless VALID_FILTERS.include? f - raise ArgumentError, "unrecognized filter #{f}" - end + raise ArgumentError, "unrecognized filter #{f}" unless VALID_FILTERS.include? f end end diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb index 5f51a45cf..874cce619 100644 --- a/app/validators/email_validator.rb +++ b/app/validators/email_validator.rb @@ -1,7 +1,5 @@ class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value) - record.errors[attribute] << (options[:message] || "is not an email") - end + record.errors[attribute] << (options[:message] || "is not an email") unless /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value) end end diff --git a/app/views/action_page/index.atom.builder b/app/views/action_page/index.atom.builder index cf969cdc4..20788a34a 100644 --- a/app/views/action_page/index.atom.builder +++ b/app/views/action_page/index.atom.builder @@ -1,7 +1,7 @@ atom_feed do |feed| - feed.title(t :site_title) - feed.subtitle(t :summary) - feed.updated(@actionPages[0].created_at) if @actionPages.length > 0 + feed.title(t(:site_title)) + feed.subtitle(t(:summary)) + feed.updated(@actionPages[0].created_at) unless @actionPages.empty? @actionPages.each do |actionPage| feed.entry(actionPage) do |entry| @@ -13,7 +13,7 @@ atom_feed do |feed| entry.content(markdown(actionPage.description), type: "html") entry.author do |author| - author.name(t :organization_name) + author.name(t(:organization_name)) end end end diff --git a/lib/action_cloner.rb b/lib/action_cloner.rb index 45a63f02b..253d73fb4 100644 --- a/lib/action_cloner.rb +++ b/lib/action_cloner.rb @@ -7,13 +7,9 @@ def self.run(original) clone_tools(original, clone) end - private - def self.clone_tools(original, clone) - %i(tweet email_campaign petition congress_message_campaign call_campaign).each do |tool_sym| - if original.send("#{tool_sym}_id").present? - clone.send("#{tool_sym}=", original.send(tool_sym).dup) - end + %i[tweet email_campaign petition congress_message_campaign call_campaign].each do |tool_sym| + clone.send("#{tool_sym}=", original.send(tool_sym).dup) if original.send("#{tool_sym}_id").present? end clone end diff --git a/lib/amazon_credentials.rb b/lib/amazon_credentials.rb index 17840b5cb..5363d8ea1 100644 --- a/lib/amazon_credentials.rb +++ b/lib/amazon_credentials.rb @@ -2,11 +2,13 @@ module AmazonCredentials # This module is primarily for paperclip config def amazon_credentials bucket_url_options = {} - bucket_url_options = { - s3_host_alias: Rails.application.secrets.amazon_bucket_url, - url: ":s3_alias_url", - path: "/:class/:attachment/:id_partition/:style/:filename" - } unless Rails.application.secrets.amazon_bucket_url.nil? + unless Rails.application.secrets.amazon_bucket_url.nil? + bucket_url_options = { + s3_host_alias: Rails.application.secrets.amazon_bucket_url, + url: ":s3_alias_url", + path: "/:class/:attachment/:id_partition/:style/:filename" + } + end { storage: Rails.application.secrets.storage.to_sym, diff --git a/lib/call_tool.rb b/lib/call_tool.rb index ad69326e3..685b446f0 100644 --- a/lib/call_tool.rb +++ b/lib/call_tool.rb @@ -2,9 +2,7 @@ module CallTool def self.campaign_call(campaign, phone:, location:, user_id:, action_id:, callback_url:) - unless [campaign, phone, location, action_id, callback_url].all? - raise ArgumentError.new("required argument is nil") - end + raise ArgumentError, "required argument is nil" unless [campaign, phone, location, action_id, callback_url].all? get "/call/create", { campaignId: campaign.to_param, @@ -12,13 +10,11 @@ def self.campaign_call(campaign, phone:, location:, user_id:, action_id:, callba userCountry: "US", userLocation: location, callback_url: callback_url, - - # TODO - Settle on the schema of the private meta data meta: { user_id: user_id, action_id: action_id, action_type: "call" - }.to_json, + }.to_json } end @@ -32,7 +28,7 @@ def self.campaigns api_response = { "total_pages" => 1, "page" => 0 } until api_response["page"] >= api_response["total_pages"] - api_response = JSON.parse(get "/api/campaign", { api_key: api_key, page: api_response["page"] + 1 }) + api_response = JSON.parse(get("/api/campaign", { api_key: api_key, page: api_response["page"] + 1 })) campaigns.concat(api_response["objects"].map { |campaign| campaign.slice("id", "name", "allow_call_in", "phone_numbers", "status") }) end @@ -44,14 +40,12 @@ def self.enabled? Rails.application.secrets.fetch_values(:call_tool_url, :call_tool_api_key).all? end - private - def self.get(action, params = {}) RestClient.get endpoint(action), params: params rescue RestClient::BadRequest => e begin error = JSON.parse(e.http_body)["error"] - rescue + rescue StandardError raise end @@ -66,8 +60,8 @@ def self.get(action, params = {}) end def self.endpoint(action) - base = Rails.application.config.call_tool_url.sub(/\/$/, "") - action = action.sub(/^\//, "") + base = Rails.application.config.call_tool_url.sub(%r{/$}, "") + action = action.sub(%r{^/}, "") "#{base}/#{action}" end diff --git a/lib/civicrm.rb b/lib/civicrm.rb index 6fb8f7ac8..403019b15 100644 --- a/lib/civicrm.rb +++ b/lib/civicrm.rb @@ -8,35 +8,36 @@ def contact_attributes ) end - def subscribe!(opt_in = false, source = "action center") + def subscribe!(opt_in: false, source: "action center") return nil if CiviCRM.skip_crm? - res = CiviCRM::subscribe contact_attributes.merge(opt_in: opt_in, source: source) - update(contact_id: res["contact_id"]) if (res && res["contact_id"]) + res = CiviCRM.subscribe contact_attributes.merge(opt_in: opt_in, source: source) + update(contact_id: res["contact_id"]) if res && res["contact_id"] res || {} end def contact_id! return nil if CiviCRM.skip_crm? - res = CiviCRM::import_contact contact_attributes - update(contact_id: res["contact_id"]) if (res && res["contact_id"]) + res = CiviCRM.import_contact contact_attributes + update(contact_id: res["contact_id"]) if res && res["contact_id"] contact_id end def add_civicrm_activity!(action_page_id) return nil if CiviCRM.skip_crm? - if contact_id && action_page = ActionPage.find_by(id: action_page_id) - CiviCRM::add_activity( - contact_id: contact_id, - subject: "Took Action #{action_page.id}: #{action_page.title}" - ) - end + action_page = ActionPage.find_by(id: action_page_id) + return unless contact_id && action_page + + CiviCRM.add_activity( + contact_id: contact_id, + subject: "Took Action #{action_page.id}: #{action_page.title}" + ) end def manage_subscription_url! - checksum = CiviCRM::get_checksum(contact_id) + checksum = CiviCRM.get_checksum(contact_id) return nil unless checksum "#{Rails.application.secrets.supporters['host']}/update-your-preferences?" + { @@ -53,7 +54,7 @@ def self.skip_crm? def self.subscribe(params) return {} if skip_crm? - self.import_contact params.merge(subscribe: true) + import_contact params.merge(subscribe: true) end def self.import_contact(params) @@ -90,19 +91,15 @@ def self.supporters_api_url "#{Rails.application.secrets.supporters['host']}/#{Rails.application.secrets.supporters['path']}" end - private - def self.post(params) - begin - res = JSON.parse RestClient.post(supporters_api_url, params) - raise res["error_message"] if res["error"] - - return res - rescue => e - Raven.capture_exception(e) - Rails.logger.error "#{e} (#{e.class})!" - return false - end + res = JSON.parse RestClient.post(supporters_api_url, params) + raise res["error_message"] if res["error"] + + res + rescue StandardError => e + Raven.capture_exception(e) + Rails.logger.error "#{e} (#{e.class})!" + false end def self.send_email_template_data(params) diff --git a/lib/congress_forms.rb b/lib/congress_forms.rb index c76e9b9c0..ecc2b0fac 100644 --- a/lib/congress_forms.rb +++ b/lib/congress_forms.rb @@ -22,7 +22,7 @@ def initialize(bioguide_id, fields) end def order_fields - order = %w($NAME_PREFIX $NAME_FIRST $NAME_LAST $PHONE $EMAIL $SUBJECT $TOPIC) + order = %w[$NAME_PREFIX $NAME_FIRST $NAME_LAST $PHONE $EMAIL $SUBJECT $TOPIC] @fields = @fields.sort_by { |f| order.index(f.value) || Float::INFINITY } end @@ -98,7 +98,7 @@ def self.date_fills_path(campaign_tag = nil, start_date = nil, end_date = nil, b params = { date_start: start_date, date_end: end_date, - campaign_tag: campaign_tag, + campaign_tag: campaign_tag }.compact data_path("/successful-fills-by-date/", params, bioguide_id) end @@ -113,30 +113,26 @@ def self.date_fills(*args) def self.data_path(base_path, params = {}, bioguide_id = nil) base_path += bioguide_id unless bioguide_id.nil? - base_path += "?" + { - debug_key: Rails.application.secrets.congress_forms_debug_key, + base_path + "?" + { + debug_key: Rails.application.secrets.congress_forms_debug_key }.merge(params).to_query end def self.get(path) - begin - JSON.parse RestClient.get(base_url + path) - rescue RestClient::ExceptionWithResponse => e - Raven.capture_exception(e) - Rails.logger.error e - return {} - end + JSON.parse RestClient.get(base_url + path) + rescue RestClient::ExceptionWithResponse => e + Raven.capture_exception(e) + Rails.logger.error e + {} end def self.post(path, body = {}) - begin - JSON.parse RestClient.post(base_url + path, body.to_json, - { content_type: :json, accept: :json }) - rescue RestClient::ExceptionWithResponse => e - Raven.capture_exception(e) - Rails.logger.error e - raise RequestFailed - end + JSON.parse RestClient.post(base_url + path, body.to_json, + { content_type: :json, accept: :json }) + rescue RestClient::ExceptionWithResponse => e + Raven.capture_exception(e) + Rails.logger.error e + raise RequestFailed end def self.base_url diff --git a/lib/places.rb b/lib/places.rb index 16e84e894..e313a8bd5 100644 --- a/lib/places.rb +++ b/lib/places.rb @@ -69,193 +69,193 @@ def self.us_states def self.country_codes [ - ["Afghanistan", "AF"], + %w[Afghanistan AF], ["Aland Islands", "AX"], - ["Albania", "AL"], - ["Algeria", "DZ"], + %w[Albania AL], + %w[Algeria DZ], ["American Samoa", "AS"], - ["Andorra", "AD"], - ["Angola", "AO"], - ["Anguilla", "AI"], - ["Antarctica", "AQ"], + %w[Andorra AD], + %w[Angola AO], + %w[Anguilla AI], + %w[Antarctica AQ], ["Antigua and Barbuda", "AG"], - ["Argentina", "AR"], - ["Armenia", "AM"], - ["Aruba", "AW"], + %w[Argentina AR], + %w[Armenia AM], + %w[Aruba AW], ["Ascension Island", "AC"], - ["Australia", "AU"], - ["Austria", "AT"], - ["Azerbaijan", "AZ"], - ["Bahamas", "BS"], - ["Bahrain", "BH"], - ["Bangladesh", "BD"], - ["Barbados", "BB"], - ["Belarus", "BY"], - ["Belgium", "BE"], - ["Belize", "BZ"], - ["Benin", "BJ"], - ["Bermuda", "BM"], - ["Bhutan", "BT"], + %w[Australia AU], + %w[Austria AT], + %w[Azerbaijan AZ], + %w[Bahamas BS], + %w[Bahrain BH], + %w[Bangladesh BD], + %w[Barbados BB], + %w[Belarus BY], + %w[Belgium BE], + %w[Belize BZ], + %w[Benin BJ], + %w[Bermuda BM], + %w[Bhutan BT], ["Bolivia, Plurinational State of", "BO"], ["Bonaire, Sint Eustatius and Saba", "BQ"], ["Bosnia and Herzegovina", "BA"], - ["Botswana", "BW"], + %w[Botswana BW], ["Bouvet Island", "BV"], - ["Brazil", "BR"], + %w[Brazil BR], ["British Indian Ocean Territory", "IO"], ["Brunei Darussalam", "BN"], - ["Bulgaria", "BG"], + %w[Bulgaria BG], ["Burkina Faso", "BF"], - ["Burundi", "BI"], - ["Cambodia", "KH"], - ["Cameroon", "CM"], - ["Canada", "CA"], + %w[Burundi BI], + %w[Cambodia KH], + %w[Cameroon CM], + %w[Canada CA], ["Cape Verde", "CV"], ["Cayman Islands", "KY"], ["Central African Republic", "CF"], - ["Chad", "TD"], - ["Chile", "CL"], - ["China", "CN"], + %w[Chad TD], + %w[Chile CL], + %w[China CN], ["Christmas Island", "CX"], ["Cocos (Keeling) Islands", "CC"], - ["Colombia", "CO"], - ["Comoros", "KM"], - ["Congo", "CG"], + %w[Colombia CO], + %w[Comoros KM], + %w[Congo CG], ["Congo, the Democratic Republic of the", "CD"], ["Cook Islands", "CK"], ["Costa Rica", "CR"], ["Cote d'Ivoire", "CI"], - ["Croatia", "HR"], - ["Cuba", "CU"], - ["Curacao", "CW"], - ["Cyprus", "CY"], + %w[Croatia HR], + %w[Cuba CU], + %w[Curacao CW], + %w[Cyprus CY], ["Czech Republic", "CZ"], - ["Denmark", "DK"], - ["Djibouti", "DJ"], - ["Dominica", "DM"], + %w[Denmark DK], + %w[Djibouti DJ], + %w[Dominica DM], ["Dominican Republic", "DO"], - ["Ecuador", "EC"], - ["Egypt", "EG"], + %w[Ecuador EC], + %w[Egypt EG], ["El Salvador", "SV"], ["Equatorial Guinea", "GQ"], - ["Eritrea", "ER"], - ["Estonia", "EE"], - ["Ethiopia", "ET"], + %w[Eritrea ER], + %w[Estonia EE], + %w[Ethiopia ET], ["Falkland Islands (Malvinas)", "FK"], ["Faroe Islands", "FO"], - ["Fiji", "FJ"], - ["Finland", "FI"], - ["France", "FR"], + %w[Fiji FJ], + %w[Finland FI], + %w[France FR], ["French Guiana", "GF"], ["French Polynesia", "PF"], ["French Southern Territories", "TF"], - ["Gabon", "GA"], - ["Gambia", "GM"], - ["Georgia", "GE"], - ["Germany", "DE"], - ["Ghana", "GH"], - ["Gibraltar", "GI"], - ["Greece", "GR"], - ["Greenland", "GL"], - ["Grenada", "GD"], - ["Guadeloupe", "GP"], - ["Guam", "GU"], - ["Guatemala", "GT"], - ["Guernsey", "GG"], - ["Guinea", "GN"], - ["Guinea-Bissau", "GW"], - ["Guyana", "GY"], - ["Haiti", "HT"], + %w[Gabon GA], + %w[Gambia GM], + %w[Georgia GE], + %w[Germany DE], + %w[Ghana GH], + %w[Gibraltar GI], + %w[Greece GR], + %w[Greenland GL], + %w[Grenada GD], + %w[Guadeloupe GP], + %w[Guam GU], + %w[Guatemala GT], + %w[Guernsey GG], + %w[Guinea GN], + %w[Guinea-Bissau GW], + %w[Guyana GY], + %w[Haiti HT], ["Heard Island and McDonald Islands", "HM"], ["Holy See (Vatican City State)", "VA"], - ["Honduras", "HN"], + %w[Honduras HN], ["Hong Kong", "HK"], - ["Hungary", "HU"], - ["Iceland", "IS"], - ["India", "IN"], - ["Indonesia", "ID"], + %w[Hungary HU], + %w[Iceland IS], + %w[India IN], + %w[Indonesia ID], ["Iran, Islamic Republic of", "IR"], - ["Iraq", "IQ"], - ["Ireland", "IE"], + %w[Iraq IQ], + %w[Ireland IE], ["Isle of Man", "IM"], - ["Israel", "IL"], - ["Italy", "IT"], - ["Jamaica", "JM"], - ["Japan", "JP"], - ["Jersey", "JE"], - ["Jordan", "JO"], - ["Kazakhstan", "KZ"], - ["Kenya", "KE"], - ["Kiribati", "KI"], + %w[Israel IL], + %w[Italy IT], + %w[Jamaica JM], + %w[Japan JP], + %w[Jersey JE], + %w[Jordan JO], + %w[Kazakhstan KZ], + %w[Kenya KE], + %w[Kiribati KI], ["Korea, Democratic People's Republic of", "KP"], ["Korea, Republic of", "KR"], - ["Kosovo", "KV"], - ["Kuwait", "KW"], - ["Kyrgyzstan", "KG"], + %w[Kosovo KV], + %w[Kuwait KW], + %w[Kyrgyzstan KG], ["Lao People's Democratic Republic", "LA"], - ["Latvia", "LV"], - ["Lebanon", "LB"], - ["Lesotho", "LS"], - ["Liberia", "LR"], - ["Libya", "LY"], - ["Liechtenstein", "LI"], - ["Lithuania", "LT"], - ["Luxembourg", "LU"], - ["Macao", "MO"], + %w[Latvia LV], + %w[Lebanon LB], + %w[Lesotho LS], + %w[Liberia LR], + %w[Libya LY], + %w[Liechtenstein LI], + %w[Lithuania LT], + %w[Luxembourg LU], + %w[Macao MO], ["Macedonia, The Former Yugoslav Republic Of", "MK"], - ["Madagascar", "MG"], - ["Malawi", "MW"], - ["Malaysia", "MY"], - ["Maldives", "MV"], - ["Mali", "ML"], - ["Malta", "MT"], + %w[Madagascar MG], + %w[Malawi MW], + %w[Malaysia MY], + %w[Maldives MV], + %w[Mali ML], + %w[Malta MT], ["Marshall Islands", "MH"], - ["Martinique", "MQ"], - ["Mauritania", "MR"], - ["Mauritius", "MU"], - ["Mayotte", "YT"], - ["Mexico", "MX"], + %w[Martinique MQ], + %w[Mauritania MR], + %w[Mauritius MU], + %w[Mayotte YT], + %w[Mexico MX], ["Micronesia, Federated States of", "FM"], ["Moldova, Republic of", "MD"], - ["Monaco", "MC"], - ["Mongolia", "MN"], - ["Montenegro", "ME"], - ["Montserrat", "MS"], - ["Morocco", "MA"], - ["Mozambique", "MZ"], - ["Myanmar", "MM"], - ["Namibia", "NA"], - ["Nauru", "NR"], - ["Nepal", "NP"], - ["Netherlands", "NL"], + %w[Monaco MC], + %w[Mongolia MN], + %w[Montenegro ME], + %w[Montserrat MS], + %w[Morocco MA], + %w[Mozambique MZ], + %w[Myanmar MM], + %w[Namibia NA], + %w[Nauru NR], + %w[Nepal NP], + %w[Netherlands NL], ["Netherlands Antilles", "AN"], ["New Caledonia", "NC"], ["New Zealand", "NZ"], - ["Nicaragua", "NI"], - ["Niger", "NE"], - ["Nigeria", "NG"], - ["Niue", "NU"], + %w[Nicaragua NI], + %w[Niger NE], + %w[Nigeria NG], + %w[Niue NU], ["Norfolk Island", "NF"], ["Northern Mariana Islands", "MP"], - ["Norway", "NO"], - ["Oman", "OM"], - ["Pakistan", "PK"], - ["Palau", "PW"], + %w[Norway NO], + %w[Oman OM], + %w[Pakistan PK], + %w[Palau PW], ["Palestinian Territory, Occupied", "PS"], - ["Panama", "PA"], + %w[Panama PA], ["Papua New Guinea", "PG"], - ["Paraguay", "PY"], - ["Peru", "PE"], - ["Philippines", "PH"], - ["Pitcairn", "PN"], - ["Poland", "PL"], - ["Portugal", "PT"], + %w[Paraguay PY], + %w[Peru PE], + %w[Philippines PH], + %w[Pitcairn PN], + %w[Poland PL], + %w[Portugal PT], ["Puerto Rico", "PR"], - ["Qatar", "QA"], - ["Reunion", "RE"], - ["Romania", "RO"], + %w[Qatar QA], + %w[Reunion RE], + %w[Romania RO], ["Russian Federation", "RU"], - ["Rwanda", "RW"], + %w[Rwanda RW], ["Saint Barthelemy", "BL"], ["Saint Helena, Ascension and Tristan da Cunha", "SH"], ["Saint Kitts and Nevis", "KN"], @@ -263,65 +263,65 @@ def self.country_codes ["Saint Martin (French part)", "MF"], ["Saint Pierre and Miquelon", "PM"], ["Saint Vincent and the Grenadines", "VC"], - ["Samoa", "WS"], + %w[Samoa WS], ["San Marino", "SM"], ["Sao Tome and Principe", "ST"], ["Saudi Arabia", "SA"], - ["Senegal", "SN"], - ["Serbia", "RS"], - ["Seychelles", "SC"], + %w[Senegal SN], + %w[Serbia RS], + %w[Seychelles SC], ["Sierra Leone", "SL"], - ["Singapore", "SG"], + %w[Singapore SG], ["Sint Maarten (Dutch part)", "SX"], - ["Slovakia", "SK"], - ["Slovenia", "SI"], + %w[Slovakia SK], + %w[Slovenia SI], ["Solomon Islands", "SB"], - ["Somalia", "SO"], + %w[Somalia SO], ["South Africa", "ZA"], ["South Georgia and the South Sandwich Islands", "GS"], ["South Sudan, Republic of", "SS"], - ["Spain", "ES"], + %w[Spain ES], ["Sri Lanka", "LK"], - ["Sudan", "SD"], - ["Suriname", "SR"], + %w[Sudan SD], + %w[Suriname SR], ["Svalbard and Jan Mayen", "SJ"], - ["Swaziland", "SZ"], - ["Sweden", "SE"], - ["Switzerland", "CH"], + %w[Swaziland SZ], + %w[Sweden SE], + %w[Switzerland CH], ["Syrian Arab Republic", "SY"], - ["Taiwan", "TW"], - ["Tajikistan", "TJ"], + %w[Taiwan TW], + %w[Tajikistan TJ], ["Tanzania, United Republic of", "TZ"], - ["Thailand", "TH"], - ["Timor-Leste", "TL"], - ["Togo", "TG"], - ["Tokelau", "TK"], - ["Tonga", "TO"], + %w[Thailand TH], + %w[Timor-Leste TL], + %w[Togo TG], + %w[Tokelau TK], + %w[Tonga TO], ["Trinidad and Tobago", "TT"], ["Tristan da Cunha", "TA"], - ["Tunisia", "TN"], - ["Turkey", "TR"], - ["Turkmenistan", "TM"], + %w[Tunisia TN], + %w[Turkey TR], + %w[Turkmenistan TM], ["Turks and Caicos Islands", "TC"], - ["Tuvalu", "TV"], - ["Uganda", "UG"], - ["Ukraine", "UA"], + %w[Tuvalu TV], + %w[Uganda UG], + %w[Ukraine UA], ["United Arab Emirates", "AE"], ["United Kingdom", "GB"], ["United States", "US"], ["United States Minor Outlying Islands", "UM"], - ["Uruguay", "UY"], - ["Uzbekistan", "UZ"], - ["Vanuatu", "VU"], + %w[Uruguay UY], + %w[Uzbekistan UZ], + %w[Vanuatu VU], ["Venezuela, Bolivarian Republic of", "VE"], ["Viet Nam", "VN"], ["Virgin Islands, British", "VG"], ["Virgin Islands, U.S.", "VI"], ["Wallis and Futuna", "WF"], ["Western Sahara", "EH"], - ["Yemen", "YE"], - ["Zambia", "ZM"], - ["Zimbabwe", "ZW"] + %w[Yemen YE], + %w[Zambia ZM], + %w[Zimbabwe ZW] ].freeze end end diff --git a/lib/quotes.rb b/lib/quotes.rb index 1ac906603..fff4641d2 100644 --- a/lib/quotes.rb +++ b/lib/quotes.rb @@ -3,13 +3,9 @@ def self.get quotes.sample end - private - def self.quotes - begin - @quotes ||= YAML.load_file("config/custom_quotes.yml") - rescue Errno::ENOENT - @quotes ||= YAML.load_file("config/quotes.yml") - end + @quotes ||= YAML.load_file("config/custom_quotes.yml") + rescue Errno::ENOENT + @quotes ||= YAML.load_file("config/quotes.yml") end end diff --git a/lib/related_content.rb b/lib/related_content.rb index 1c689dcc4..6e3fc3066 100644 --- a/lib/related_content.rb +++ b/lib/related_content.rb @@ -10,7 +10,7 @@ def load open_page @loaded_successfully = true rescue OpenURI::HTTPError - return + nil end end diff --git a/lib/smarty_streets.rb b/lib/smarty_streets.rb index 575900495..b67b52cf1 100644 --- a/lib/smarty_streets.rb +++ b/lib/smarty_streets.rb @@ -3,9 +3,7 @@ module SmartyStreets def self.get_city_state(zipcode) url = "https://us-zipcode.api.smartystreets.com/lookup" res = post(url, base_params.merge(zipcode: zipcode)) - if res.present? - res.first["city_states"].try :first - end + res.first["city_states"].try :first if res.present? end def self.get_location(street, zipcode) @@ -21,7 +19,7 @@ def self.get_location(street, zipcode) location.state = res[0]["components"]["state_abbreviation"] location.district = res[0]["metadata"]["congressional_district"] location.district = "0" if location.district == "AL" - return location + location end def self.get_congressional_district(street, zipcode) @@ -31,17 +29,13 @@ def self.get_congressional_district(street, zipcode) class AddressNotFound < StandardError; end - private - def self.post(url, params) - begin - res = JSON.parse RestClient.get("#{url}?#{params.to_query}") - return res - rescue => e - Raven.capture_exception(e) - Rails.logger.error "#{e} (#{e.class})!" - return false - end + res = JSON.parse RestClient.get("#{url}?#{params.to_query}") + res + rescue StandardError => e + Raven.capture_exception(e) + Rails.logger.error "#{e} (#{e.class})!" + false end def self.base_params diff --git a/lib/tasks/congress.rake b/lib/tasks/congress.rake index 72d78d07e..9b26a577f 100644 --- a/lib/tasks/congress.rake +++ b/lib/tasks/congress.rake @@ -14,7 +14,7 @@ namespace :congress do legislator_sources.each do |repo| data = RestClient.get(repo) - YAML.load(data).each do |info| + YAML.safe_load(data).each do |info| term = info["terms"].last next if term["start"] < "2011-01-01" # don't get too historical @@ -37,10 +37,11 @@ namespace :congress do .update!(attributes) end - legislator_social_media_sources.each do |repo| - data = RestClient.get(repo) - YAML.load(data).each do |info| - next unless twitter_id = info["social"]["twitter"] + legislator_social_media_sources.each do |s_repo| + data = RestClient.get(s_repo) + YAML.safe_load(data).each do |info| + twitter_id = info["social"]["twitter"] + next unless twitter_id CongressMember .where(bioguide_id: info["id"]["bioguide"]) diff --git a/lib/tasks/petition.rake b/lib/tasks/petition.rake index 2575f6ec9..74b1176e3 100644 --- a/lib/tasks/petition.rake +++ b/lib/tasks/petition.rake @@ -39,19 +39,19 @@ namespace :petition do Petition.all.each do |petition| goal = petition.goal count = petition.signatures.count - if count > goal - if goal == goals.last - petition.goal = 100000 if count > 70000 - elsif goal < goals.last - petition.goal = next_goal(petition.goal) - end + next unless count > goal - if petition.changed? - petition.save - print "Petition #{petition.id} updated. Goal: #{petition.goal}\n" - # TODO: email admins - end + if goal == goals.last + petition.goal = 100_000 if count > 70000 + elsif goal < goals.last + petition.goal = next_goal(petition.goal) end + + next unless petition.changed? + + petition.save + print "Petition #{petition.id} updated. Goal: #{petition.goal}\n" + # TODO: email admins end end end diff --git a/lib/tasks/signatures.rake b/lib/tasks/signatures.rake index b16f22c47..115061d31 100644 --- a/lib/tasks/signatures.rake +++ b/lib/tasks/signatures.rake @@ -2,17 +2,18 @@ namespace :signatures do desc "Fill in US States from zipcodes" task fill_us_states: :environment do Signature.where(country_code: "US").where("zipcode is not NULL").each do |sig| - if sig.city.blank? and sig.state.blank? and GoingPostal.valid_zipcode?(sig.zipcode, "US") - begin - if city_state = SmartyStreets.get_city_state(sig.zipcode) - sig.city = city_state["city"] - sig.state = city_state["state"] - sig.save - puts "Updated: #{sig.inspect}" - end - rescue - puts "Lookup failed for signature #{sig.id}" - end + next unless sig.city.blank? && sig.state.blank? && GoingPostal.valid_zipcode?(sig.zipcode, "US") + + begin + city_state = SmartyStreets.get_city_state(sig.zipcode) + next unless city_state + + sig.city = city_state["city"] + sig.state = city_state["state"] + sig.save + puts "Updated: #{sig.inspect}" + rescue StandardError + puts "Lookup failed for signature #{sig.id}" end end end diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 26c72fded..21825e07d 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -1,9 +1,7 @@ namespace :users do desc "List the emails of all admin accounts" task list_admins: :environment do - admins = User.where(admin: true).map do |u| - u.email - end.sort + admins = User.where(admin: true).map(&:email).sort puts admins.empty? ? "No Admin Users" : admins end diff --git a/lib/tasks/webshims_asset_compile.rake b/lib/tasks/webshims_asset_compile.rake index f6ddb9fce..b4368efa8 100644 --- a/lib/tasks/webshims_asset_compile.rake +++ b/lib/tasks/webshims_asset_compile.rake @@ -23,18 +23,18 @@ namespace :webshims do manifest_data["assets"].each do |logical_path, digested_path| logical_pathname = Pathname.new logical_path - if ["webshims/**/*"].any? { |testpath| logical_pathname.fnmatch?(testpath, File::FNM_PATHNAME) } - full_digested_path = Rails.root.join("public/assets", digested_path) - full_nondigested_path = Rails.root.join("public/assets", logical_path) - - logger.info "(Webshims) Copying to #{full_nondigested_path}" - - # Use FileUtils.copy_file with true third argument to copy - # file attributes (eg mtime) too, as opposed to FileUtils.cp - # Making symlnks with FileUtils.ln_s would be another option, not - # sure if it would have unexpected issues. - FileUtils.copy_file full_digested_path, full_nondigested_path, true - end + next unless ["webshims/**/*"].any? { |testpath| logical_pathname.fnmatch?(testpath, File::FNM_PATHNAME) } + + full_digested_path = Rails.root.join("public/assets", digested_path) + full_nondigested_path = Rails.root.join("public/assets", logical_path) + + logger.info "(Webshims) Copying to #{full_nondigested_path}" + + # Use FileUtils.copy_file with true third argument to copy + # file attributes (eg mtime) too, as opposed to FileUtils.cp + # Making symlnks with FileUtils.ln_s would be another option, not + # sure if it would have unexpected issues. + FileUtils.copy_file full_digested_path, full_nondigested_path, true end end end diff --git a/spec/controllers/action_page_controller_spec.rb b/spec/controllers/action_page_controller_spec.rb index 8e2cd1832..5d0b52c8e 100644 --- a/spec/controllers/action_page_controller_spec.rb +++ b/spec/controllers/action_page_controller_spec.rb @@ -51,10 +51,10 @@ context "archived" do let(:active_action_page) { FactoryGirl.create :action_page } - let(:archived_action_page) { + let(:archived_action_page) do FactoryGirl.create :archived_action_page, active_action_page_for_redirect: active_action_page - } + end it "redirects archived actions to active actions" do get :show, params: { id: archived_action_page } @@ -72,9 +72,9 @@ let(:unpublished_action_page) { FactoryGirl.create :action_page, published: false } it "hides unpublished pages from unprivileged users" do - expect { + expect do get :show, params: { id: unpublished_action_page } - }.to raise_error ActiveRecord::RecordNotFound + end.to raise_error ActiveRecord::RecordNotFound end it "notifies admin users that a page is unpublished" do diff --git a/spec/controllers/admin/institutions_controller_spec.rb b/spec/controllers/admin/institutions_controller_spec.rb index 04b56087a..a7c76244d 100644 --- a/spec/controllers/admin/institutions_controller_spec.rb +++ b/spec/controllers/admin/institutions_controller_spec.rb @@ -6,9 +6,9 @@ # This should return the minimal set of attributes required to create a valid # Admin::Institution. As you add validations to Admin::InstitutionSet, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { name: "San Francisco State University", category: "University" } - } + end before(:each) do # Admin login @@ -30,18 +30,18 @@ describe "POST #create" do context "with valid params" do it "creates a new institution" do - expect { + expect do post :create, params: { action_page_id: @actionPage.id, institution: valid_attributes } - }.to change(Institution, :count).by(1) + end.to change(Institution, :count).by(1) end it "does not create duplicate institutions" do - institution = Institution.create! valid_attributes - expect { + Institution.create! valid_attributes + expect do post :create, params: { action_page_id: @actionPage.id, institution: valid_attributes } - }.to_not change(Institution, :count) + end.to_not change(Institution, :count) end end end @@ -92,9 +92,9 @@ describe "DELETE #destroy" do it "deletes the institution" do institution = Institution.create! valid_attributes - expect { + expect do delete :destroy, params: { id: institution.to_param } - }.to change(Institution, :count).by(-1) + end.to change(Institution, :count).by(-1) end end end diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index d94ef9055..9f91be8fd 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -41,7 +41,7 @@ describe "without a successful connection to civicrm" do before do - stub_request(:post, CiviCRM::supporters_api_url) + stub_request(:post, CiviCRM.supporters_api_url) .and_return(status: 400, body: "{}", headers: {}) end diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 9bc5aba3b..8928993ac 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe ToolsController, type: :controller do - let(:valid_attributes) { + let(:valid_attributes) do { signature: { "petition_id" => "1", @@ -13,7 +13,7 @@ "country_code" => "" } } - } + end before(:each) do stub_smarty_streets @@ -63,8 +63,10 @@ let(:email_campaign) { FactoryGirl.create(:email_campaign) } it "should redirect to ActionPage#service_uri(service)" do - service, uri = "gmail", "https://composeurl.example.com" - expect(ActionPage).to receive(:find_by_id) { email_campaign.action_page } + action_page = email_campaign.action_page + service = "gmail" + uri = "https://composeurl.example.com" + expect(ActionPage).to receive(:find_by).with(id: action_page.id.to_s) { action_page } expect(email_campaign).to receive(:service_uri).with(service) { uri } get :email, params: { action_id: email_campaign.action_page.id, service: service } expect(response).to redirect_to(uri) diff --git a/spec/factories/ahoy_event.rb b/spec/factories/ahoy_event.rb index af6cac44e..69c73fd29 100644 --- a/spec/factories/ahoy_event.rb +++ b/spec/factories/ahoy_event.rb @@ -2,24 +2,24 @@ factory :ahoy_view, class: Ahoy::Event do id { SecureRandom.uuid } name "View" - properties { + properties do { type: "action", actionType: "view" } - } + end time Time.zone.now end factory :ahoy_signature, class: Ahoy::Event do id { SecureRandom.uuid } name "Action" - properties { + properties do { type: "action", actionType: "signature" } - } + end time Time.zone.now end end diff --git a/spec/factories/congress_member.rb b/spec/factories/congress_member.rb index 5fb948655..c313e48ec 100644 --- a/spec/factories/congress_member.rb +++ b/spec/factories/congress_member.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :congress_member do sequence(:bioguide_id) { |n| "A00000#{n}" } - term_end (Time.now + 1.year).strftime("%Y-%m-%d") + term_end { (Time.zone.now + 1.year).strftime("%Y-%m-%d") } full_name "Alice Mars" first_name "Alice" last_name "Mars" diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2dc8954c4..0de4642a8 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -7,9 +7,7 @@ end factory :user, parent: :unconfirmed_user do - after(:build) do |user| - user.skip_confirmation! - end + after(:build, &:skip_confirmation!) end factory :admin_user, parent: :user do diff --git a/spec/features/action_pages/congress_action_spec.rb b/spec/features/action_pages/congress_action_spec.rb index 071a3244c..de1cb8780 100644 --- a/spec/features/action_pages/congress_action_spec.rb +++ b/spec/features/action_pages/congress_action_spec.rb @@ -4,13 +4,13 @@ let!(:action) do FactoryGirl.create(:action_page_with_congress_message) end - let!(:members) { + let!(:members) do [FactoryGirl.create(:congress_member, twitter_id: "sisko", state: "CA", bioguide_id: "C000880"), FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] - } - let(:location) { + end + let(:location) do OpenStruct.new(success: true, street: "1630 Ravello Drive", city: "Sunnydale", @@ -18,12 +18,12 @@ zip4: 1234, state: "CA", district: 10) - } + end before do allow(SmartyStreets).to receive(:get_location).and_return(location) stub_request(:post, /retrieve-form-elements/) - .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .with(body: { "bio_ids" => %w[C000880 A000360] }) .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) stub_request(:post, /retrieve-form-elements/) .with(body: { "bio_ids" => ["", "C000880", "A000360"] }) diff --git a/spec/features/action_pages/tweet_action_spec.rb b/spec/features/action_pages/tweet_action_spec.rb index 7c504f65a..cd291bf43 100644 --- a/spec/features/action_pages/tweet_action_spec.rb +++ b/spec/features/action_pages/tweet_action_spec.rb @@ -4,13 +4,13 @@ let!(:tweet_action) do FactoryGirl.create(:tweet, message: "Default message").action_page end - let!(:members) { + let!(:members) do [FactoryGirl.create(:congress_member, twitter_id: "sisko", state: "CA", bioguide_id: "C000880"), FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] - } - let(:location) { + end + let(:location) do OpenStruct.new(success: true, street: "1630 Ravello Drive", city: "Sunnydale", @@ -18,7 +18,7 @@ zip4: 1234, state: "CA", district: 10) - } + end before do allow(SmartyStreets).to receive(:get_location).and_return(location) diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index f7b443704..38e15ecd0 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -19,10 +19,10 @@ fill_in_social_media - tempermental { + tempermental do click_button "Save" expect(page).to have_content("Very Important Action", wait: 10) - } + end end it "can create basic petition actions" do @@ -43,10 +43,10 @@ fill_in_social_media - tempermental { + tempermental do click_button "Save" expect(page).to have_content("Very Important Action", wait: 10) - } + end end it "can create email actions" do @@ -67,10 +67,10 @@ fill_in_social_media - tempermental { + tempermental do click_button "Save" expect(page).to have_content("Very Important Action", wait: 10) - } + end end it "can create congress actions" do @@ -90,10 +90,10 @@ fill_in_social_media - tempermental { + tempermental do click_button "Save" expect(page).to have_content("Very Important Action", wait: 10) - } + end end it "can create call actions" do @@ -113,10 +113,10 @@ fill_in_social_media - tempermental { + tempermental do click_button "Save" expect(page).to have_content("Very Important Action", wait: 10) - } + end end def fill_in_basic_info(title:, summary:, description:) diff --git a/spec/features/congress_message.rb b/spec/features/congress_message.rb index 5c7434866..9bcab6be2 100644 --- a/spec/features/congress_message.rb +++ b/spec/features/congress_message.rb @@ -5,10 +5,10 @@ let(:partner) { action_page.partners.first } - let!(:members) { + let!(:members) do [FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "C000880"), FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] - } + end let(:location) do OpenStruct.new(success: true, @@ -26,7 +26,7 @@ allow(SmartyStreets).to receive(:get_location).and_return(location) stub_request(:post, /retrieve-form-elements/) - .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .with(body: { "bio_ids" => %w[C000880 A000360] }) .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) stub_request(:post, /fill-out-form/) @@ -34,7 +34,7 @@ end scenario "User submits a congress message and subscribes to newletters" do - visit "/action/#{action_page.title.downcase.tr(" ", "-")}?partner=#{partner.code}" + visit "/action/#{action_page.title.downcase.tr(' ', '-')}?partner=#{partner.code}" fill_in "street_address", with: "The Library" fill_in "zipcode", with: "94109" click_button "Submit your message" @@ -51,7 +51,7 @@ expect(page).to have_content "Now help spread the word" expect(partner.subscriptions.count).to eq 1 - expect(WebMock).to have_requested(:post, CiviCRM::supporters_api_url) + expect(WebMock).to have_requested(:post, CiviCRM.supporters_api_url) .with(body: hash_including({ data: '{"contact_params":{"email":"mrgiles@sunnydale.edu","first_name":"Rupert","last_name":"Giles","source":"action center congress message :: Sample Action Page","subscribe":true,"opt_in":true},"address_params":{"city":"Sunnydale","state":null,"street":"The Library","zip":"94109","country":null},"phone":null}' })) @@ -64,7 +64,7 @@ email: "mrgiles@sunnydale.edu") sign_in_user(giles) - visit "/action/#{action_page.title.downcase.tr(" ", "-")}" + visit "/action/#{action_page.title.downcase.tr(' ', '-')}" click_button "Submit your message" fill_in "common_attributes__NAME_FIRST", with: "Ripper" diff --git a/spec/lib/action_cloner_spec.rb b/spec/lib/action_cloner_spec.rb index 9c22178ad..1779aeee5 100644 --- a/spec/lib/action_cloner_spec.rb +++ b/spec/lib/action_cloner_spec.rb @@ -69,7 +69,7 @@ :congress_message_campaign def filter_attrs(attrs) - attrs_not_cloned = %w(published archived created_at updated_at slug id) + attrs_not_cloned = %w[published archived created_at updated_at slug id] attrs.tap do |hash| attrs_not_cloned.each { |a| hash.delete a } end diff --git a/spec/lib/call_tool_spec.rb b/spec/lib/call_tool_spec.rb index 494b1bb57..908db5bea 100644 --- a/spec/lib/call_tool_spec.rb +++ b/spec/lib/call_tool_spec.rb @@ -9,7 +9,7 @@ describe ".campaign_call" do let(:campaign) { FactoryGirl.create(:call_campaign) } - let(:keywords) { + let(:keywords) do { phone: "000-000-0000", location: "00000", @@ -17,11 +17,11 @@ action_id: 789, callback_url: "/" } - } + end it "should get call_tool_url/call/create, transforming keyword arguments into params" do expect(RestClient).to receive(:get) do |url, opts| - base_href = Rails.application.config.call_tool_url.sub(/\/$/, "") + base_href = Rails.application.config.call_tool_url.sub(%r{/$}, "") expect(url).to eq("#{base_href}/call/create") expect(opts[:params]).not_to be_nil expect(opts[:params][:campaignId]).to eq(campaign.to_param) @@ -40,29 +40,29 @@ it "should raise ArgumentError if a required param is missing" do allow(RestClient).to receive(:get) - expect { + expect do CallTool.campaign_call(nil, **keywords) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CallTool.campaign_call(campaign, **keywords.dup.tap { |x| x[:phone] = nil }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CallTool.campaign_call(campaign, **keywords.dup.tap { |x| x[:location] = nil }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CallTool.campaign_call(campaign, **keywords.dup.tap { |x| x[:action_id] = nil }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CallTool.campaign_call(campaign, **keywords.dup.tap { |x| x[:callback_url] = nil }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CallTool.campaign_call(campaign, **keywords.dup.tap { |x| x[:user_id] = nil }) - }.not_to raise_error + end.not_to raise_error end it "should not raise any errors for twilio 'number invalid' error" do @@ -79,7 +79,7 @@ it "should get call_tool_url/api/campaign/:id with the call tool api key" do campaign = 12345 expect(RestClient).to receive(:get) do |url, opts| - base_href = Rails.application.config.call_tool_url.sub(/\/$/, "") + base_href = Rails.application.config.call_tool_url.sub(%r{/$}, "") expect(url).to eq("#{base_href}/api/campaign/#{campaign}") expect(opts[:params][:api_key]).to eq(Rails.application.secrets.call_tool_api_key) OpenStruct.new(body: { required_fields: { userLocation: "postal", userPhone: "US" } }.to_json) @@ -90,9 +90,9 @@ end describe ".campaigns" do - let(:calltool_campaign) { + let(:calltool_campaign) do { "id" => 1, "name" => "call someone", "status" => "live" } - } + end before do stub_request(:get, %r{/api/campaign\?api_key(.*)?&page=1}) diff --git a/spec/lib/civicrm_spec.rb b/spec/lib/civicrm_spec.rb index d4929ed2e..54f7ce3ce 100644 --- a/spec/lib/civicrm_spec.rb +++ b/spec/lib/civicrm_spec.rb @@ -7,8 +7,8 @@ describe "self.get_checksum" do it "calls the civicrm API with method 'generate_checksum'" do - CiviCRM::get_checksum(123) - assert_requested :post, CiviCRM::supporters_api_url, body: /generate_checksum/ + CiviCRM.get_checksum(123) + assert_requested :post, CiviCRM.supporters_api_url, body: /generate_checksum/ end end end diff --git a/spec/lib/congress_forms_spec.rb b/spec/lib/congress_forms_spec.rb index 57df97f35..f6293b7c3 100644 --- a/spec/lib/congress_forms_spec.rb +++ b/spec/lib/congress_forms_spec.rb @@ -2,7 +2,7 @@ describe CongressForms do describe CongressForms::Form do - let(:form) { + let(:form) do CongressForms::Form.new("C000880", [ { "value" => "$NAME_FIRST" }, { "value" => "$NAME_LAST" }, @@ -11,26 +11,26 @@ "NEW YORK" => "NY" } } ]) - } + end - let(:input) { + let(:input) do { "$NAME_FIRST" => "Willow", "$NAME_LAST" => "Rosenberg", "$MESSAGE" => "Impeach Mayor Richard Wilkins III", "$ADDRESS_STATE" => "CA" } - } + end describe "::find" do before do stub_request(:post, /retrieve-form-elements/) - .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .with(body: { "bio_ids" => %w[C000880 A000360] }) .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) end it "retrieves a Form for each bioguide_id" do - forms = CongressForms::Form.find(["C000880", "A000360"]).first + forms = CongressForms::Form.find(%w[C000880 A000360]).first expect(forms.length).to eq 2 lamar = forms.first expect(lamar.fields.length).to eq 11 diff --git a/spec/models/action_page_spec.rb b/spec/models/action_page_spec.rb index 251011420..24a27d269 100644 --- a/spec/models/action_page_spec.rb +++ b/spec/models/action_page_spec.rb @@ -4,9 +4,9 @@ let(:attr) { FactoryGirl.attributes_for :action_page } it "creates a new instance given a valid attribute" do - expect { + expect do ActionPage.create!(attr) - }.to change { ActionPage.count }.by(1) + end.to change { ActionPage.count }.by(1) end it "knows when to redirect from an archived action" do @@ -33,8 +33,7 @@ end it "updates the slug when title changes" do - expect { page.update(title: "something else") } - .to change { page.slug } + expect { page.update(title: "something else") }.to change { page.slug } end it "does not update slug when unrelated attr changes" do @@ -124,7 +123,7 @@ calls = ActionPage.type("call") expect(calls).to contain_exactly(call) - calls_and_tweets = ActionPage.type(["call", "tweet"]) + calls_and_tweets = ActionPage.type(%w[call tweet]) expect(calls_and_tweets).to contain_exactly(call, tweet) all = ActionPage.type("call", "congress_message", "email", "petition", "tweet") diff --git a/spec/models/ahoy/event_spec.rb b/spec/models/ahoy/event_spec.rb index 749615d91..6b00eddda 100644 --- a/spec/models/ahoy/event_spec.rb +++ b/spec/models/ahoy/event_spec.rb @@ -4,7 +4,7 @@ describe "#types" do it "returns event types for an action" do action_page = FactoryGirl.create(:action_page_with_tweet) - expect(Ahoy::Event.action_types(action_page)).to eq([:views, :tweets]) + expect(Ahoy::Event.action_types(action_page)).to eq(%i[views tweets]) end end diff --git a/spec/models/congress_member_spec.rb b/spec/models/congress_member_spec.rb index 0018d4cfb..765804953 100644 --- a/spec/models/congress_member_spec.rb +++ b/spec/models/congress_member_spec.rb @@ -2,7 +2,7 @@ describe CongressMember do let(:legislators) do - end_date = (Time.now + 1.year).strftime("%Y-%m-%d") + end_date = (Time.zone.now + 1.year).strftime("%Y-%m-%d") [ CongressMember.new( "bioguide_id" => "A000001", diff --git a/spec/models/congress_message_campaign_spec.rb b/spec/models/congress_message_campaign_spec.rb index 58f136c04..cf01e56a9 100644 --- a/spec/models/congress_message_campaign_spec.rb +++ b/spec/models/congress_message_campaign_spec.rb @@ -4,7 +4,9 @@ let(:campaign) { FactoryGirl.create :congress_message_campaign } it "generates a url for fills by date" do - expect(campaign.date_fills_url(Date.today - 30.days, Date.today)).to include "campaign_tag=a+campaign+tag" - expect(campaign.date_fills_url(Date.today - 30.days, Date.today)).to match /date_end=\d{4}-\d{2}-\d{2}&date_start=\d{4}-\d{2}-\d{2}/ + expect(campaign.date_fills_url(Time.zone.today - 30.days, Time.zone.today)).to \ + include("campaign_tag=a+campaign+tag") + expect(campaign.date_fills_url(Time.zone.today - 30.days, Time.zone.today)).to \ + match(/date_end=\d{4}-\d{2}-\d{2}&date_start=\d{4}-\d{2}-\d{2}/) end end diff --git a/spec/models/congress_message_spec.rb b/spec/models/congress_message_spec.rb index b3cd1cba6..55b0d1dcd 100644 --- a/spec/models/congress_message_spec.rb +++ b/spec/models/congress_message_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" describe CongressMessage do - subject { + subject do FactoryGirl.build(:congress_message) - } + end describe "#common_fields" do it "groups matching opt_hashes" do diff --git a/spec/models/institution_spec.rb b/spec/models/institution_spec.rb index 208318ca9..952a5ba2c 100644 --- a/spec/models/institution_spec.rb +++ b/spec/models/institution_spec.rb @@ -45,9 +45,9 @@ end it "adds institutions by name" do - expect { + expect do described_class.import("University", names) - }.to change(Institution.where(category: "University"), :count).by(names.count) + end.to change(Institution.where(category: "University"), :count).by(names.count) end end end diff --git a/spec/models/petition_spec.rb b/spec/models/petition_spec.rb index 21abb0e54..6c30b7923 100644 --- a/spec/models/petition_spec.rb +++ b/spec/models/petition_spec.rb @@ -15,10 +15,9 @@ it "should output useful CSV files" do p = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) - expected_first_record = "John Doe,#{p.signatures.to_a.first.email},San Francisco,CA,United States of America\n" - + expected_first_record = "John Doe,#{p.signatures.order(:id).first.email},"\ + "San Francisco,CA,United States of America\n" csv = p.signatures.to_presentable_csv - columns = csv.lines.first first_record = csv.lines[1] diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb index 1f2e614ba..203ef1abb 100644 --- a/spec/models/signature_spec.rb +++ b/spec/models/signature_spec.rb @@ -23,26 +23,26 @@ it "should reject spammy emails" do invalid_email = @attr.merge(email: "a@b") - expect { + expect do Signature.create!(invalid_email) - }.to raise_error ActiveRecord::RecordInvalid + end.to raise_error ActiveRecord::RecordInvalid end it "should impose an arbitrary opinion as to whether a string of text may refer to a country" do # note: it is my personal belief that there is no such thing as a country/ nation =) arbitrarily_invalid_opinion = @attr.merge(country_code: "laserland") - expect { + expect do Signature.create!(arbitrarily_invalid_opinion) - }.to raise_error ActiveRecord::RecordInvalid + end.to raise_error ActiveRecord::RecordInvalid end it "should reject long zipcodes" do long_zip = @attr.merge(zipcode: "9" * 13) - expect { + expect do Signature.create!(long_zip) - }.to raise_error ActiveRecord::RecordInvalid + end.to raise_error ActiveRecord::RecordInvalid end describe ".search" do diff --git a/spec/models/topic_category_spec.rb b/spec/models/topic_category_spec.rb index f863aeac4..bc12fac9b 100644 --- a/spec/models/topic_category_spec.rb +++ b/spec/models/topic_category_spec.rb @@ -5,13 +5,13 @@ describe "#best_match" do it "selects the best match from a list of options" do - options = ["Spike", "Vampire3", "Drusilla", "Vampire2", "Harmony"].map { |o| [o] * 2 } - expect(subject.best_match options).to eq "Vampire2" + options = %w[Spike Vampire3 Drusilla Vampire2 Harmony].map { |o| [o] * 2 } + expect(subject.best_match(options)).to eq "Vampire2" end it "ignores case, whitespace, and punctuation when matching" do options = ["Vampire3", "VamPire 2!"].map { |o| [o] * 2 } - expect(subject.best_match options).to eq "VamPire 2!" + expect(subject.best_match(options)).to eq "VamPire 2!" end after do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ebb98f035..a5c1a57e4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,6 +1,6 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= "test" -require File.expand_path("../../config/environment", __FILE__) +require File.expand_path("../config/environment", __dir__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require "spec_helper" @@ -59,7 +59,7 @@ config.include Warden::Test::Helpers, type: :feature # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = Rails.root.join("spec/fixtures") # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false @@ -92,7 +92,7 @@ disable_call_tool end - FileUtils.mkdir_p("#{Rails.root}/tmp/cache") + FileUtils.mkdir_p(Rails.root.join("tmp/cache")) config.before(:each) do Rails.cache.clear end diff --git a/spec/requests/admin/action_pages_spec.rb b/spec/requests/admin/action_pages_spec.rb index 4362c8570..83650516e 100644 --- a/spec/requests/admin/action_pages_spec.rb +++ b/spec/requests/admin/action_pages_spec.rb @@ -16,9 +16,9 @@ describe "Non-Privileged Users" do it "should prevent them creating action pages" do - expect { + expect do post "/admin/action_pages", params: valid_attributes - }.to raise_exception(ActiveRecord::RecordNotFound) + end.to raise_exception(ActiveRecord::RecordNotFound) end end @@ -61,9 +61,9 @@ xhr :get, "/admin/action_pages?q=border+surveil" - expect(response.body).to include("borderpetition") - expect(response.body).to include("bordertweet") - expect(response.body).not_to include("privacypetition") + expect(response.body).to include(border.title) + expect(response.body).to include(tweet.title) + expect(response.body).not_to include(privacy.title) end end end diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb index 362055867..95b541669 100644 --- a/spec/requests/admin/events_spec.rb +++ b/spec/requests/admin/events_spec.rb @@ -9,7 +9,7 @@ it "responds with views over time as JSON" do expect(Time.zone) .to receive(:now) - .and_return(Time.local(2019)) + .and_return(Time.zone.local(2019)) .at_least(:once) get "/admin/action_pages/#{action_page.slug}/events", @@ -20,12 +20,10 @@ # Default is to return data for the previous month. expect(JSON.parse(response.body).keys) - .to include(*(1..31).map { |i| sprintf("Dec %d 2018", i) }) + .to include(*(1..31).map { |i| format("Dec %d 2018", i) }) end it "filters by date" do - start_date = Time.utc(2019, 1, 1).strftime("%Y-%m-%d") - end_date = Time.utc(2019, 1, 7).strftime("%Y-%m-%d") get "/admin/action_pages/#{action_page.slug}/events", params: { date_range_text: "Jan 1, 2019 - Jan 8, 2019", @@ -50,7 +48,7 @@ context "without type param" do before do - allow(Time.zone).to receive(:now).and_return(Time.local(2019)) + allow(Time.zone).to receive(:now).and_return(Time.zone.local(2019)) action_page.update( enable_petition: true, petition_id: Petition.create.id diff --git a/spec/requests/admin/s3_uploads_spec.rb b/spec/requests/admin/s3_uploads_spec.rb index b897432dc..5f0babe2d 100644 --- a/spec/requests/admin/s3_uploads_spec.rb +++ b/spec/requests/admin/s3_uploads_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe "S3 Uploads Spec", type: :request do - let(:valid_attributes) { + let(:valid_attributes) do { "source_file" => { "bucket" => "actioncenter-staging", @@ -14,7 +14,7 @@ "controller" => "admin/s3_uploads", "format" => "json" } - } + end before(:each) do # bypasses a 3rd party lookup (s3) @@ -22,17 +22,17 @@ end it "should deny non-admins" do - expect { + expect do post "/admin/source_files", params: valid_attributes - }.to raise_exception(ActiveRecord::RecordNotFound) + end.to raise_exception(ActiveRecord::RecordNotFound) end it "should allow admins" do @admin = FactoryGirl.create(:admin_user) login @admin - expect { + expect do post "/admin/source_files", params: valid_attributes - }.to change { SourceFile.count }.by(1) + end.to change { SourceFile.count }.by(1) end end diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb index bb1bf9dab..2b165d9fb 100644 --- a/spec/requests/admin/users_spec.rb +++ b/spec/requests/admin/users_spec.rb @@ -9,7 +9,7 @@ describe "#index" do before do 10.times do |n| - FactoryGirl.create(:user, created_at: Time.now - n.days, email: "user-#{n}@example.com") + FactoryGirl.create(:user, created_at: Time.zone.now - n.days, email: "user-#{n}@example.com") end end diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index f49bcd4c4..c8101ab5a 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -1,16 +1,16 @@ require "rails_helper" RSpec.describe "Congress Messages", type: :request do - let!(:members) { + let!(:members) do [FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "C000880"), FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] - } + end - let(:action_page) { + let(:action_page) do FactoryGirl.create(:action_page_with_congress_message) - } + end - let(:location) { + let(:location) do OpenStruct.new(success: true, street: "1630 Ravello Drive", city: "Sunnydale", @@ -18,11 +18,11 @@ zip4: 1234, state: "CA", district: 10) - } + end def stub_congress_forms_find_with_two_reps stub_request(:post, /retrieve-form-elements/) - .with(body: { "bio_ids" => ["C000880", "A000360"] }) + .with(body: { "bio_ids" => %w[C000880 A000360] }) .and_return(status: 200, body: file_fixture("retrieve-form-elements.json")) end @@ -101,13 +101,13 @@ def get_congress_message_form "$ADDRESS_CITY" => "Sunnydale", "$ADDRESS_ZIP5" => "94109", "$EMAIL" => "jsummers@altavista.com", - "$NAME_PREFIX" => "Mrs.", + "$NAME_PREFIX" => "Mrs." }, member_attributes: { "C000880" => { "$SUBJECT" => "Take Action", "$ADDRESS_STATE_POSTAL_ABBREV" => "CA", - "$TOPIC" => "JU", + "$TOPIC" => "JU" }, "A000360" => { "$ADDRESS_STATE" => "CA", @@ -115,7 +115,7 @@ def get_congress_message_form } }, forms: { - bioguide_ids: %w(C000880 A000360) + bioguide_ids: %w[C000880 A000360] }, message: "Impeach Mayor Richard Wilkins III" } @@ -172,24 +172,6 @@ def submit_congress_message it "succeeds with no common attributs" do stub_congress_forms_find_with_one_rep - message_attributes = { - member_attributes: { - "C000880" => { - "$NAME_FIRST" => "Joyce", - "$NAME_LAST" => "Summers", - "$ADDRESS_STREET" => "1630 Ravello Drive", - "$ADDRESS_CITY" => "Sunnydale", - "$ADDRESS_ZIP5" => "94109", - "$EMAIL" => "jsummers@altavista.com", - "$NAME_PREFIX" => "Mrs.", - "$MESSAGE" => "Impeach Mayor Richard Wilkins III", - "$SUBJECT" => "Take Action", - "$ADDRESS_STATE_POSTAL_ABBREV" => "CA", - "$TOPIC" => "JU", - } - }, - bioguide_ids: "C000880" - } submit_congress_message expect(response.status).to eq 200 end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 967328d04..e27524490 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,24 +2,6 @@ require "webmock/rspec" Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } -# This file was generated by the `rails generate rspec:install` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# The `.rspec` file also contains a few flags that are not defaults but that -# users commonly want. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| config.before(:each) do DatabaseCleaner.clean_with :truncation @@ -52,56 +34,6 @@ config.include FeatureHelpers, type: :feature WebMock.disable_net_connect!(allow_localhost: true) - -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # These two settings work together to allow you to limit a spec run - # to individual examples or groups you care about by tagging them with - # `:focus` metadata. When nothing is tagged with `:focus`, all examples - # get run. - config.filter_run :focus - config.run_all_when_everything_filtered = true - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end end # Don't prevent form fills by bots during the test run @@ -124,12 +56,12 @@ def set_weak_password(user) weak_password = "12345678" user.password = weak_password user.password_confirmation = weak_password - result = user.save + user.save end def set_strong_password(user) weak_password = "strong passwords defeat lobsters covering wealth" user.password = weak_password user.password_confirmation = weak_password - result = user.save + user.save end diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 435b5fd7d..9b791f99c 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -31,12 +31,10 @@ def fill_in_select2(locator, with:) def tempermental(try: 2.times) try.each do |attempt| - begin - yield - break - rescue RSpec::Expectations::ExpectationNotMetError => e - raise e if attempt == try.size - 1 - end + yield + break + rescue RSpec::Expectations::ExpectationNotMetError => e + raise e if attempt == try.size - 1 end end end diff --git a/spec/support/service_helpers.rb b/spec/support/service_helpers.rb index 5f519577e..21d808a4c 100644 --- a/spec/support/service_helpers.rb +++ b/spec/support/service_helpers.rb @@ -1,10 +1,10 @@ module ServiceHelpers def stub_civicrm Rails.application.secrets.supporters["host"] = "https://civicrm.test" - stub_request(:post, CiviCRM::supporters_api_url) + stub_request(:post, CiviCRM.supporters_api_url) .and_return(status: 200, body: "{}", headers: {}) - stub_request(:post, CiviCRM::supporters_api_url) + stub_request(:post, CiviCRM.supporters_api_url) .with(body: /generate_checksum/) .and_return(status: 200, body: { checksum: "xyz" }.to_json, headers: {}) end From a2bf91d3f2e3dc23a9510595910245916238fd18 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 11 Feb 2021 14:29:48 -0800 Subject: [PATCH 007/113] Disable some naming cops inline --- .rubocop_todo.yml | 36 ----------------------- app/controllers/tools_controller.rb | 4 ++- app/helpers/application_helper.rb | 2 +- app/mailers/user_mailer.rb | 2 ++ app/models/action_page.rb | 2 ++ app/models/congress_message_campaign.rb | 2 +- app/models/institution.rb | 2 +- app/models/source_file.rb | 2 +- app/models/twitter.rb | 2 +- app/queries/action_page_filters.rb | 4 +-- app/views/action_page/index.atom.builder | 2 +- app/views/action_page/index.json.jbuilder | 2 ++ lib/congress_forms.rb | 2 +- lib/related_content.rb | 4 ++- spec/requests/congress_messages_spec.rb | 2 +- spec/spec_helper.rb | 4 +-- 16 files changed, 24 insertions(+), 50 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c1fb284f5..9e4939b78 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,39 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -Naming/AccessorMethodName: - Exclude: - - 'spec/requests/congress_messages_spec.rb' - - 'spec/spec_helper.rb' - -# Offense count: 2 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -Naming/BlockParameterName: - Exclude: - - 'app/views/action_page/index.atom.builder' - - 'app/views/action_page/index.json.jbuilder' - -# Offense count: 3 -# Configuration parameters: EnforcedStyleForLeadingUnderscores. -# SupportedStylesForLeadingUnderscores: disallowed, required, optional -Naming/MemoizedInstanceVariableName: - Exclude: - - 'app/controllers/tools_controller.rb' - - 'app/models/action_page.rb' - - 'lib/related_content.rb' - -# Offense count: 7 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp -Naming/MethodParameterName: - Exclude: - - 'app/helpers/application_helper.rb' - - 'app/mailers/user_mailer.rb' - - 'app/models/congress_message_campaign.rb' - - 'app/models/institution.rb' - - 'app/queries/action_page_filters.rb' - # Offense count: 3 # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. # NamePrefix: is_, has_, have_ @@ -48,9 +15,6 @@ Naming/MethodParameterName: Naming/PredicateName: Exclude: - 'spec/**/*' - - 'app/models/source_file.rb' - - 'app/models/twitter.rb' - - 'lib/congress_forms.rb' # Offense count: 45 # Configuration parameters: EnforcedStyle. diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index c0e220726..a501e96ad 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -154,9 +154,11 @@ def set_user @user = current_user end - def set_action_page + # rubocop:todo Naming/MemoizedInstanceVariableName + def set_action_page # rubocop:todo Naming/MemoizedInstanceVariableName @action_page ||= ActionPage.find_by(id: params[:action_id]) end + # rubocop:enable Naming/MemoizedInstanceVariableName def create_newsletter_subscription if params[:subscribe] && EmailValidator.valid?(params[:subscription][:email]) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1eebbc39f..1fd886bdf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -110,7 +110,7 @@ def messages safe_join(messages) end - def percentage(x, y, precision: 0) + def percentage(x, y, precision: 0) # rubocop:todo Naming/MethodParameterName return "-" unless y > 0 number_to_percentage((x / y.to_f) * 100, precision: precision) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 7609415fe..6222a217b 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -4,6 +4,7 @@ class UserMailer < ActionMailer::Base layout "email" after_action :check_bounces + # rubocop:todo Naming/MethodParameterName def thanks_message(email, actionPage, options = {}) @email = email @user = options[:user] @@ -11,6 +12,7 @@ def thanks_message(email, actionPage, options = {}) @name = options[:name].presence || "Friend of Digital Freedom" mail(to: email, subject: "Thanks for taking action") end + # rubocop:enable Naming/MethodParameterName def signup_attempt_with_existing_email(user, _options = {}) @user = user diff --git a/app/models/action_page.rb b/app/models/action_page.rb index cd2fb691a..70d534d74 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -147,11 +147,13 @@ def image [og_image, background_image, featured_image].find(&:present?) end + # rubocop:todo Naming/MemoizedInstanceVariableName def actions_taken_percent return 0 if view_count == 0 @percent ||= (action_count / view_count.to_f) * 100 end + # rubocop:enable Naming/MemoizedInstanceVariableName def status if archived? diff --git a/app/models/congress_message_campaign.rb b/app/models/congress_message_campaign.rb index 4d33b5edf..00177abad 100644 --- a/app/models/congress_message_campaign.rb +++ b/app/models/congress_message_campaign.rb @@ -50,7 +50,7 @@ def member_fills_url CongressForms.member_fills_url(campaign_tag) end - def target_bioguide_list=(x) + def target_bioguide_list=(x) # rubocop:todo Naming/MethodParameterName self.target_bioguide_ids = x.map(&:presence).compact.join(",") end diff --git a/app/models/institution.rb b/app/models/institution.rb index be453aad4..e8bc393a9 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -45,7 +45,7 @@ def self.categories # Sort institutions by most popular. # Put `first` at the top of the list if it exists. - def self.top(n, first: 0) + def self.top(n, first: 0) # rubocop:todo Naming/MethodParameterName select("institutions.*, COUNT(signatures.id) AS s_count") .joins("LEFT OUTER JOIN affiliations ON institutions.id = affiliations.institution_id") .joins("LEFT OUTER JOIN signatures ON affiliations.signature_id = signatures.id") diff --git a/app/models/source_file.rb b/app/models/source_file.rb index 799def1b4..b5c167c5e 100644 --- a/app/models/source_file.rb +++ b/app/models/source_file.rb @@ -56,7 +56,7 @@ def to_jq_upload } end - def is_image? + def is_image? # rubocop:todo Naming/PredicateName !!file_content_type.try(:match, /image/) end diff --git a/app/models/twitter.rb b/app/models/twitter.rb index 0ea83eaac..9801034f8 100644 --- a/app/models/twitter.rb +++ b/app/models/twitter.rb @@ -1,5 +1,5 @@ class Twitter - def self.has_api_keys? + def self.has_api_keys? # rubocop:todo Naming/PredicateName Rails.application.secrets.twitter_api_key.present? && Rails.application.secrets.twitter_api_secret.present? && Rails.application.secrets.twitter_oauth_token.present? && diff --git a/app/queries/action_page_filters.rb b/app/queries/action_page_filters.rb index d0ba042d3..64f362821 100644 --- a/app/queries/action_page_filters.rb +++ b/app/queries/action_page_filters.rb @@ -46,12 +46,12 @@ def parse_date_range filters[:date_range].split(" - ").map { |d| Time.zone.parse(d) } end - def valid_query?(f, val) + def valid_query?(f, val) # rubocop:todo Naming/MethodParameterName validate_filter_name f !empty_value? val end - def validate_filter_name(f) + def validate_filter_name(f) # rubocop:todo Naming/MethodParameterName raise ArgumentError, "unrecognized filter #{f}" unless VALID_FILTERS.include? f end end diff --git a/app/views/action_page/index.atom.builder b/app/views/action_page/index.atom.builder index 20788a34a..bb5377c9f 100644 --- a/app/views/action_page/index.atom.builder +++ b/app/views/action_page/index.atom.builder @@ -3,7 +3,7 @@ atom_feed do |feed| feed.subtitle(t(:summary)) feed.updated(@actionPages[0].created_at) unless @actionPages.empty? - @actionPages.each do |actionPage| + @actionPages.each do |actionPage| # rubocop:todo Naming/BlockParameterName feed.entry(actionPage) do |entry| entry.link(rel: "enclosure", type: actionPage.featured_image.content_type || "image/png", href: URI.join(root_url, image_path(actionPage.featured_image))) diff --git a/app/views/action_page/index.json.jbuilder b/app/views/action_page/index.json.jbuilder index 761f1f25b..892d699b7 100644 --- a/app/views/action_page/index.json.jbuilder +++ b/app/views/action_page/index.json.jbuilder @@ -1,3 +1,4 @@ +# rubocop:todo Naming/BlockParameterName json.array! @actionPages do |actionPage| json.url action_page_url actionPage json.title actionPage.title @@ -9,3 +10,4 @@ json.array! @actionPages do |actionPage| end end end +# rubocop:enable Naming/BlockParameterName diff --git a/lib/congress_forms.rb b/lib/congress_forms.rb index ecc2b0fac..732637a72 100644 --- a/lib/congress_forms.rb +++ b/lib/congress_forms.rb @@ -55,7 +55,7 @@ def label I18n.t value, scope: :congress_forms, default: value.sub("$", "").humanize end - def is_select? + def is_select? # rubocop:todo Naming/PredicateName options_hash != nil end diff --git a/lib/related_content.rb b/lib/related_content.rb index 6e3fc3066..444994815 100644 --- a/lib/related_content.rb +++ b/lib/related_content.rb @@ -37,7 +37,9 @@ def image attr_reader :url, :page, :loaded_successfully - def open_page + # rubocop:todo Naming/MemoizedInstanceVariableName + def open_page # rubocop:todo Naming/MemoizedInstanceVariableName @page ||= Nokogiri::HTML(open(url)) end + # rubocop:enable Naming/MemoizedInstanceVariableName end diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index c8101ab5a..8a1640873 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -40,7 +40,7 @@ def stub_congress_forms_find_with_one_rep end describe "#new" do - def get_congress_message_form + def get_congress_message_form # rubocop:todo Naming/AccessorMethodName campaign_id = action_page.congress_message_campaign_id get("/congress_message_campaigns/#{campaign_id}/congress_messages/new", params: { street_address: location.street, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e27524490..4a7965289 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,14 +52,14 @@ def login_as_collaborator sign_in FactoryGirl.create(:collaborator_user) end -def set_weak_password(user) +def set_weak_password(user) # rubocop:todo Naming/AccessorMethodName weak_password = "12345678" user.password = weak_password user.password_confirmation = weak_password user.save end -def set_strong_password(user) +def set_strong_password(user) # rubocop:todo Naming/AccessorMethodName weak_password = "strong passwords defeat lobsters covering wealth" user.password = weak_password user.password_confirmation = weak_password From e245d5a931db5e50842d24e9d5160b2f67e19d4d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 11 Feb 2021 14:32:00 -0800 Subject: [PATCH 008/113] Disable some rails cops inline --- .rubocop_todo.yml | 20 -------------------- app/controllers/registrations_controller.rb | 2 ++ app/controllers/tools_controller.rb | 2 +- app/controllers/users_controller.rb | 2 ++ app/models/action_page.rb | 4 ++++ app/models/congress_scorecard.rb | 2 ++ lib/related_content.rb | 2 +- lib/tasks/ahoy.rake | 2 ++ lib/tasks/congress.rake | 2 ++ spec/requests/congress_messages_spec.rb | 4 ++++ spec/tasks/signatures_spec.rb | 4 ++++ 11 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9e4939b78..48cf7f9fe 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -121,13 +121,6 @@ Rails/HelperInstanceVariable: - 'app/helpers/devise_helper.rb' - 'app/helpers/petition_helper.rb' -# Offense count: 2 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/InverseOf: - Exclude: - - 'app/models/action_page.rb' - # Offense count: 6 # Configuration parameters: Include. # Include: app/controllers/**/*.rb @@ -139,19 +132,6 @@ Rails/LexicallyScopedActionFilter: - 'app/controllers/sessions_controller.rb' - 'app/controllers/tools_controller.rb' -# Offense count: 9 -# Configuration parameters: Blacklist, Whitelist. -# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters -Rails/SkipsModelValidations: - Exclude: - - 'app/controllers/registrations_controller.rb' - - 'app/controllers/users_controller.rb' - - 'app/models/congress_scorecard.rb' - - 'lib/tasks/ahoy.rake' - - 'lib/tasks/congress.rake' - - 'spec/requests/congress_messages_spec.rb' - - 'spec/tasks/signatures_spec.rb' - # Offense count: 3 # Configuration parameters: Include. # Include: app/models/**/*.rb diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index ef390dbcf..e2a0f2dba 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -31,7 +31,9 @@ def handle_nonunique_email existing.update(sign_up_params) unless existing.confirmed? if resource.persisted? + # rubocop:todo Rails/SkipsModelValidations resource.update_attribute(:unconfirmed_email, account_update_params[:email]) + # rubocop:enable Rails/SkipsModelValidations flash[:notice] = I18n.t "devise.registrations.update_needs_confirmation" respond_with resource, location: after_update_path_for(resource) else diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index a501e96ad..1b62da3e8 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -155,7 +155,7 @@ def set_user end # rubocop:todo Naming/MemoizedInstanceVariableName - def set_action_page # rubocop:todo Naming/MemoizedInstanceVariableName + def set_action_page @action_page ||= ActionPage.find_by(id: params[:action_id]) end # rubocop:enable Naming/MemoizedInstanceVariableName diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 99a9bd6a7..4f1a3b3d1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,7 +21,9 @@ def update end def clear_activity + # rubocop:todo Rails/SkipsModelValidations current_user.events.update_all(user_id: nil) + # rubocop:enable Rails/SkipsModelValidations redirect_to user_path end diff --git a/app/models/action_page.rb b/app/models/action_page.rb index 70d534d74..f3b0ef0df 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -36,9 +36,13 @@ class ActionPage < ActiveRecord::Base belongs_to :congress_message_campaign belongs_to :call_campaign belongs_to :category, optional: true + # rubocop:todo Rails/InverseOf belongs_to :active_action_page_for_redirect, class_name: "ActionPage", foreign_key: "archived_redirect_action_page_id" + # rubocop:enable Rails/InverseOf + # rubocop:todo Rails/InverseOf belongs_to :author, class_name: "User", foreign_key: :user_id, optional: true + # rubocop:enable Rails/InverseOf accepts_nested_attributes_for :tweet, :petition, :email_campaign, :call_campaign, :congress_message_campaign, :affiliation_types, :partnerships, diff --git a/app/models/congress_scorecard.rb b/app/models/congress_scorecard.rb index 092f922c8..71851149a 100644 --- a/app/models/congress_scorecard.rb +++ b/app/models/congress_scorecard.rb @@ -6,6 +6,8 @@ class CongressScorecard < ActiveRecord::Base belongs_to :action_page def increment! + # rubocop:todo Rails/SkipsModelValidations CongressScorecard.increment_counter(:counter, id) # Increments counter atomically + # rubocop:enable Rails/SkipsModelValidations end end diff --git a/lib/related_content.rb b/lib/related_content.rb index 444994815..28fb671f6 100644 --- a/lib/related_content.rb +++ b/lib/related_content.rb @@ -38,7 +38,7 @@ def image attr_reader :url, :page, :loaded_successfully # rubocop:todo Naming/MemoizedInstanceVariableName - def open_page # rubocop:todo Naming/MemoizedInstanceVariableName + def open_page @page ||= Nokogiri::HTML(open(url)) end # rubocop:enable Naming/MemoizedInstanceVariableName diff --git a/lib/tasks/ahoy.rake b/lib/tasks/ahoy.rake index dad99d536..f63df1997 100644 --- a/lib/tasks/ahoy.rake +++ b/lib/tasks/ahoy.rake @@ -1,7 +1,9 @@ namespace :ahoy do desc "Fix name for view events" task fix_views: :environment do + # rubocop:todo Rails/SkipsModelValidations Ahoy::Event.where("properties ->> 'actionType' = 'view'").update_all(name: "View") + # rubocop:enable Rails/SkipsModelValidations end task fix_action_page_ids: :environment do diff --git a/lib/tasks/congress.rake b/lib/tasks/congress.rake index 9b26a577f..fb942835a 100644 --- a/lib/tasks/congress.rake +++ b/lib/tasks/congress.rake @@ -43,9 +43,11 @@ namespace :congress do twitter_id = info["social"]["twitter"] next unless twitter_id + # rubocop:todo Rails/SkipsModelValidations CongressMember .where(bioguide_id: info["id"]["bioguide"]) .update_all(twitter_id: twitter_id) + # rubocop:enable Rails/SkipsModelValidations end end end diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index 8a1640873..9f043e0d0 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -74,7 +74,9 @@ def get_congress_message_form # rubocop:todo Naming/AccessorMethodName it "to target bioguide_ids" do campaign = FactoryGirl.create(:congress_message_campaign, :targeting_bioguide_ids) + # rubocop:todo Rails/SkipsModelValidations action_page.update_attribute(:congress_message_campaign, campaign) + # rubocop:enable Rails/SkipsModelValidations get_congress_message_form expect(response.body).to include("C000880") expect(response.body).not_to include("A000360") @@ -83,7 +85,9 @@ def get_congress_message_form # rubocop:todo Naming/AccessorMethodName it "to target a single chamber" do members.last.update(chamber: "house", district: 10) campaign = FactoryGirl.create(:congress_message_campaign, :targeting_senate) + # rubocop:todo Rails/SkipsModelValidations action_page.update_attribute(:congress_message_campaign, campaign) + # rubocop:enable Rails/SkipsModelValidations get_congress_message_form expect(response.body).to include("C000880") expect(response.body).not_to include("A000360") diff --git a/spec/tasks/signatures_spec.rb b/spec/tasks/signatures_spec.rb index 9b0f5f7a1..cf1485752 100644 --- a/spec/tasks/signatures_spec.rb +++ b/spec/tasks/signatures_spec.rb @@ -14,8 +14,12 @@ regular_petition = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) petition_with_dups = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) + # rubocop:todo Rails/SkipsModelValidations petition_with_dups.signatures.take(20).each { |sig| sig.update_column(:email, "dup1@example.com") } + # rubocop:enable Rails/SkipsModelValidations + # rubocop:todo Rails/SkipsModelValidations petition_with_dups.signatures.take(10).each { |sig| sig.update_column(:email, "dup2@example.com") } + # rubocop:enable Rails/SkipsModelValidations distinct_emails = petition_with_dups.signatures.pluck(:email).uniq From 44366a8f7891a2d897dc4edb5109e1d25d720159 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 11 Feb 2021 14:36:09 -0800 Subject: [PATCH 009/113] Disable some Style cops inline --- .rubocop_todo.yml | 12 ------------ app/models/source_file.rb | 2 ++ spec/requests/admin/events_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 48cf7f9fe..ccf6a115e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -155,18 +155,6 @@ Style/ClassAndModuleChildren: - 'app/models/ahoy/event.rb' - 'lib/monkey_patches/octet_stream_override.rb' -# Offense count: 1 -Style/DoubleNegation: - Exclude: - - 'app/models/source_file.rb' - -# Offense count: 1 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: - Exclude: - - 'spec/requests/admin/events_spec.rb' - # Offense count: 17 # Configuration parameters: MinBodyLength. Style/GuardClause: diff --git a/app/models/source_file.rb b/app/models/source_file.rb index b5c167c5e..f6ccdf35c 100644 --- a/app/models/source_file.rb +++ b/app/models/source_file.rb @@ -57,7 +57,9 @@ def to_jq_upload end def is_image? # rubocop:todo Naming/PredicateName + # rubocop:todo Style/DoubleNegation !!file_content_type.try(:match, /image/) + # rubocop:enable Style/DoubleNegation end #---- start S3 related methods ----- diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb index 95b541669..c364acecb 100644 --- a/spec/requests/admin/events_spec.rb +++ b/spec/requests/admin/events_spec.rb @@ -20,7 +20,9 @@ # Default is to return data for the previous month. expect(JSON.parse(response.body).keys) + # rubocop:todo Style/FormatStringToken .to include(*(1..31).map { |i| format("Dec %d 2018", i) }) + # rubocop:enable Style/FormatStringToken end it "filters by date" do From bacaafea97aba912e61df8951de64e1eb67f360d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 9 Feb 2021 12:25:14 -0800 Subject: [PATCH 010/113] Swap paperclip for kt-paperclip; upgrade aws gems --- Gemfile | 6 +- Gemfile.lock | 408 +++++++++++++++++++++++++++------------------------ 2 files changed, 216 insertions(+), 198 deletions(-) diff --git a/Gemfile b/Gemfile index 481e86d2b..6b556c56e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,8 +7,8 @@ gem "pg", "~> 1.1" gem "pg_search" # Hosting-related -gem "aws-sdk", "~> 2.3" -gem "aws-sdk-rails", "~> 1" +gem "aws-sdk-rails", "~> 2" +gem "aws-sdk-s3", "~> 1" gem "dotenv-rails", "~> 2" gem "rack-attack", "~> 5" gem "rails_12factor", group: :production # Loads "rails_serve_static_assets" and "rails_stdout_logging" @@ -44,7 +44,7 @@ source "https://rails-assets.org" do end # File upload -gem "paperclip", "~> 5.2" +gem "kt-paperclip", "~> 6" # Email preformatting gem "nokogiri", "~> 1" # Required for premailer-rails diff --git a/Gemfile.lock b/Gemfile.lock index 5a9adf85c..388aa5dc9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,63 +1,64 @@ GIT remote: https://github.com/ActsAsParanoid/acts_as_paranoid.git - revision: b58c5149d32f06ea729ad1c8bd3ac26d8cde50ce + revision: e75d09ae62a5b6d584c4eb60658fd0a4975a7b4c specs: - acts_as_paranoid (0.6.0) - activerecord (>= 4.2, < 6.0) - activesupport (>= 4.2, < 6.0) + acts_as_paranoid (0.7.0) + activerecord (>= 5.2, < 7.0) + activesupport (>= 5.2, < 7.0) GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actioncable (5.0.7.2) - actionpack (= 5.0.7.2) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) + actioncable (5.2.4.5) + actionpack (= 5.2.4.5) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.4.5) + actionpack (= 5.2.4.5) + actionview (= 5.2.4.5) + activejob (= 5.2.4.5) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7.2) - actionview (= 5.0.7.2) - activesupport (= 5.0.7.2) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (5.2.4.5) + actionview (= 5.2.4.5) + activesupport (= 5.2.4.5) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7.2) - activesupport (= 5.0.7.2) + actionview (5.2.4.5) + activesupport (= 5.2.4.5) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7.2) - activesupport (= 5.0.7.2) + activejob (5.2.4.5) + activesupport (= 5.2.4.5) globalid (>= 0.3.6) - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) + activemodel (5.2.4.5) + activesupport (= 5.2.4.5) + activerecord (5.2.4.5) + activemodel (= 5.2.4.5) + activesupport (= 5.2.4.5) + arel (>= 9.0) activerecord-session_store (1.1.3) actionpack (>= 4.0) activerecord (>= 4.0) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activesupport (5.0.7.2) + activestorage (5.2.4.5) + actionpack (= 5.2.4.5) + activerecord (= 5.2.4.5) + marcel (~> 0.3.1) + activesupport (5.2.4.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - after_commit_action (1.1.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) ahoy_matey (1.6.1) addressable browser (~> 2.0) @@ -72,122 +73,131 @@ GEM apparition (0.6.0) capybara (~> 3.13, < 4) websocket-driver (>= 0.6.5) - arel (7.1.4) + arel (9.0.0) ast (2.4.2) - autoprefixer-rails (9.5.1) + autoprefixer-rails (10.2.4.0) execjs - aws-eventstream (1.0.3) - aws-sdk (2.11.264) - aws-sdk-resources (= 2.11.264) - aws-sdk-core (2.11.264) - aws-sigv4 (~> 1.0) + aws-eventstream (1.1.0) + aws-partitions (1.426.0) + aws-sdk-core (3.112.0) + aws-eventstream (~> 1, >= 1.0.2) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-rails (1.0.1) - aws-sdk-resources (~> 2) + aws-sdk-kms (1.42.0) + aws-sdk-core (~> 3, >= 3.112.0) + aws-sigv4 (~> 1.1) + aws-sdk-rails (2.1.0) + aws-sdk-ses (~> 1) railties (>= 3) - aws-sdk-resources (2.11.264) - aws-sdk-core (= 2.11.264) - aws-sigv4 (1.1.0) - aws-eventstream (~> 1.0, >= 1.0.2) + aws-sdk-s3 (1.88.0) + aws-sdk-core (~> 3, >= 3.112.0) + aws-sdk-kms (~> 1) + aws-sigv4 (~> 1.1) + aws-sdk-ses (1.37.0) + aws-sdk-core (~> 3, >= 3.112.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.2.2) + aws-eventstream (~> 1, >= 1.0.2) babel-source (5.8.35) babel-transpiler (0.7.0) babel-source (>= 4.0, < 6) execjs (~> 2.0) - bcrypt (3.1.13) - better_errors (2.5.1) + bcrypt (3.1.16) + better_errors (2.9.1) coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bootstrap-daterangepicker-rails (3.0.3) - railties (>= 4.0, < 5.3) + bootstrap-daterangepicker-rails (3.0.4) + railties (>= 4.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) bourbon (3.2.4) sass (~> 3.2) thor - browser (2.5.3) - builder (3.2.3) - byebug (11.0.1) - capybara (3.26.0) + browser (2.7.1) + builder (3.2.4) + byebug (11.1.3) + capybara (3.35.3) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.5) + regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - chartkick (3.3.0) - childprocess (2.0.0) - rake (< 13.0) + chartkick (3.4.2) + childprocess (3.0.0) chronic (0.10.2) climate_control (0.2.0) - cocoon (1.2.12) - coderay (1.1.2) - concurrent-ruby (1.1.5) - connection_pool (2.2.2) - counter_culture (2.2.3) + cocoon (1.2.15) + coderay (1.1.3) + concurrent-ruby (1.1.8) + connection_pool (2.2.3) + counter_culture (2.7.0) activerecord (>= 4.2) activesupport (>= 4.2) - after_commit_action (~> 1.0) crack (0.4.5) rexml - crass (1.0.5) - css_parser (1.7.0) + crass (1.0.6) + css_parser (1.9.0) addressable daemons (1.3.1) - database_cleaner (1.7.0) - debug_inspector (0.0.3) - delayed_job (4.1.5) - activesupport (>= 3.0, < 5.3) - delayed_job_active_record (4.1.3) - activerecord (>= 3.0, < 5.3) + database_cleaner (1.99.0) + debug_inspector (1.0.0) + delayed_job (4.1.9) + activesupport (>= 3.0, < 6.2) + delayed_job_active_record (4.1.5) + activerecord (>= 3.0, < 6.2) delayed_job (>= 3.0, < 5) descriptive_statistics (2.5.1) - devise (4.7.1) + devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.3) + diff-lcs (1.4.4) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - dotenv (2.7.2) - dotenv-rails (2.7.2) - dotenv (= 2.7.2) - railties (>= 3.2, < 6.1) + dotenv (2.7.6) + dotenv-rails (2.7.6) + dotenv (= 2.7.6) + railties (>= 3.2) eff_matomo (0.2.4) activesupport httparty ejs (1.1.1) email_validator (1.6.0) activemodel - errbase (0.1.1) - erubi (1.8.0) - erubis (2.7.0) + errbase (0.2.1) + erubi (1.10.0) execjs (2.7.0) factory_girl (4.9.0) activesupport (>= 3.0.0) factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faraday (0.15.4) + faraday (1.3.0) + faraday-net_http (~> 1.0) multipart-post (>= 1.2, < 3) + ruby2_keywords + faraday-net_http (1.0.1) fast_inserter (0.1.6) activerecord (>= 4.1.0) - fastly (2.3.0) - ffi (1.10.0) + fastly (2.5.3) + ffi (1.14.2) fontello_rails_converter (0.4.6) activesupport launchy rest-client rubyzip (~> 1.0) - friendly_id (5.2.5) + friendly_id (5.4.2) activerecord (>= 4.0.0) - geocoder (1.5.1) + geocoder (1.6.5) globalid (0.4.2) activesupport (>= 4.2.0) going_postal (0.1.6) @@ -202,83 +212,87 @@ GEM http-cookie (1.0.3) domain_name (~> 0.5) http_accept_language (2.1.1) - httparty (0.17.0) + httparty (0.18.1) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.6.0) + i18n (1.8.8) concurrent-ruby (~> 1.0) - invisible_captcha (0.12.0) + invisible_captcha (0.13.0) rails (>= 3.2.0) iso_country_codes (0.7.8) - jaro_winkler (1.5.4) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) jmespath (1.4.0) - launchy (2.4.3) - addressable (~> 2.3) - loofah (2.3.1) + kt-paperclip (6.4.1) + activemodel (>= 4.2.0) + activesupport (>= 4.2.0) + mime-types + mimemagic (~> 0.3.0) + terrapin (~> 0.6.0) + launchy (2.5.0) + addressable (~> 2.7) + loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - method_source (0.9.2) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2020.1104) - mimemagic (0.3.3) + mimemagic (0.3.5) mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.11.3) - multi_json (1.13.1) + mini_portile2 (2.5.0) + minitest (5.14.3) + multi_json (1.15.0) multi_xml (0.6.0) - multipart-post (2.0.0) + multipart-post (2.1.1) netrc (0.11.0) - nio4r (2.3.1) - nokogiri (1.10.8) - mini_portile2 (~> 2.4.0) + nio4r (2.5.5) + nokogiri (1.11.1) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) nokogumbo (1.5.0) nokogiri - oauth (0.5.4) + oauth (0.5.5) orm_adapter (0.5.0) - paperclip (5.3.0) - activemodel (>= 4.2.0) - activesupport (>= 4.2.0) - mime-types - mimemagic (~> 0.3.0) - terrapin (~> 0.6.0) parallel (1.20.1) parser (3.0.0.0) ast (~> 2.4.1) - pg (1.1.4) - pg_search (2.1.7) - activerecord (>= 4.2) - activesupport (>= 4.2) - premailer (1.11.1) + pg (1.2.3) + pg_search (2.3.5) + activerecord (>= 5.2) + activesupport (>= 5.2) + premailer (1.14.2) addressable css_parser (>= 1.6.0) htmlentities (>= 4.0.0) - premailer-rails (1.10.2) - actionmailer (>= 3, < 6) + premailer-rails (1.11.1) + actionmailer (>= 3) premailer (~> 1.7, >= 1.7.9) public_suffix (4.0.6) - puma (3.12.4) - rack (2.0.8) + puma (3.12.6) + racc (1.5.2) + rack (2.2.3) rack-attack (5.4.2) rack (>= 1.0, < 3) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.2) - actioncable (= 5.0.7.2) - actionmailer (= 5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) - activemodel (= 5.0.7.2) - activerecord (= 5.0.7.2) - activesupport (= 5.0.7.2) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.4.5) + actioncable (= 5.2.4.5) + actionmailer (= 5.2.4.5) + actionpack (= 5.2.4.5) + actionview (= 5.2.4.5) + activejob (= 5.2.4.5) + activemodel (= 5.2.4.5) + activerecord (= 5.2.4.5) + activestorage (= 5.2.4.5) + activesupport (= 5.2.4.5) bundler (>= 1.3.0) - railties (= 5.0.7.2) + railties (= 5.2.4.5) sprockets-rails (>= 2.0.0) rails-assets-EpicEditor (0.2.3) rails-assets-chartjs (2.8.0) @@ -297,50 +311,50 @@ GEM rails-assets-respond (1.4.2) rails-assets-roboto-webfont (0.1.1) rails-assets-sweetalert (1.0.1) - rails-controller-testing (1.0.4) - actionpack (>= 5.0.1.x) - actionview (>= 5.0.1.x) - activesupport (>= 5.0.1.x) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) rails-dev-tweaks (1.2.0) actionpack (>= 3.1) railties (>= 3.1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.2.0) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) rails_12factor (0.0.3) rails_serve_static_assets rails_stdout_logging rails_response_headers (0.1.0) rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) - railties (5.0.7.2) - actionpack (= 5.0.7.2) - activesupport (= 5.0.7.2) + railties (5.2.4.5) + actionpack (= 5.2.4.5) + activesupport (= 5.2.4.5) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.0.0) - rake (12.3.3) + rake (13.0.3) rb-fchange (0.0.6) ffi - rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.1.1) + rdoc (6.3.0) react-rails (1.11.0) babel-transpiler (>= 0.7.0) connection_pool execjs railties (>= 3.2) tilt - redcarpet (3.4.0) + redcarpet (3.5.1) referer-parser (0.3.0) - regexp_parser (1.6.0) - request_store (1.4.1) + regexp_parser (2.0.3) + request_store (1.5.0) rack (>= 1.4) - responders (3.0.0) + responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) rest-client (2.1.0) @@ -349,45 +363,49 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) rexml (3.2.4) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.3) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.2) + rspec-support (~> 3.9.0) + rspec-rails (3.9.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - rubocop (0.82.0) - jaro_winkler (~> 1.5.1) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.4) + rubocop (1.6.1) parallel (~> 1.10) - parser (>= 2.7.0.1) + parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) rexml + rubocop-ast (>= 1.2.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-github (0.16.0) - rubocop (<= 0.82.0) - rubocop-performance (~> 1.0) - rubocop-rails (~> 2.0) + rubocop-ast (1.4.1) + parser (>= 2.7.1.5) + rubocop-github (0.16.1) + rubocop (<= 1.6.1) + rubocop-performance (<= 1.7.1) + rubocop-rails (<= 2.7.1) rubocop-performance (1.7.1) rubocop (>= 0.82.0) - rubocop-rails (2.6.0) + rubocop-rails (2.7.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.82.0) + rubocop (>= 0.87.0) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.4) rubyzip (1.3.0) - safely_block (0.2.1) - errbase + safely_block (0.3.0) + errbase (>= 0.1.1) sanitize (4.6.6) crass (~> 1.0.2) nokogiri (>= 1.4.4) @@ -397,22 +415,20 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.1.0) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.0.1) + sassc (2.4.0) ffi (~> 1.9) - rake - sdoc (1.0.0) + sdoc (2.0.3) rdoc (>= 5.0) - select2-rails (4.0.3) - thor (~> 0.14) - selenium-webdriver (3.142.4) - childprocess (>= 0.5, < 3.0) - rubyzip (~> 1.2, >= 1.2.2) + select2-rails (4.0.13) + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) sentry-raven (0.15.6) faraday (>= 0.7.6) sprockets (3.7.2) @@ -420,44 +436,46 @@ GEM rack (> 1, < 3) sprockets-image_compressor (0.3.0) sprockets - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (0.20.3) + thor (1.1.0) thread_safe (0.3.6) - tilt (2.0.9) + tilt (2.0.10) tzinfo (1.2.9) thread_safe (~> 0.1) - uglifier (4.1.20) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext unf_ext (0.0.7.7) unicode-display_width (1.7.0) - user_agent_parser (2.6.0) - uuidtools (2.1.5) + user_agent_parser (2.7.0) + uuidtools (2.2.0) warden (1.2.4) rack (>= 1.0) - webdrivers (4.1.2) + webdrivers (4.5.0) nokogiri (~> 1.6) - rubyzip (~> 1.0) + rubyzip (>= 1.3.0) selenium-webdriver (>= 3.0, < 4.0) webmock (3.11.2) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.7.0) webshims-rails (1.16.0) rails (> 3.1.0) - websocket-driver (0.6.5) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) whenever (0.11.0) chronic (>= 0.6.3) - will_paginate (3.1.7) - xmlrpc (0.3.0) + will_paginate (3.3.0) + xmlrpc (0.3.2) + webrick xpath (3.2.0) nokogiri (~> 1.8) @@ -469,8 +487,8 @@ DEPENDENCIES acts_as_paranoid! ahoy_matey (~> 1.6) apparition (~> 0.6) - aws-sdk (~> 2.3) - aws-sdk-rails (~> 1) + aws-sdk-rails (~> 2) + aws-sdk-s3 (~> 1) better_errors (~> 2) binding_of_caller (~> 0) bootstrap-daterangepicker-rails (~> 3) @@ -503,9 +521,9 @@ DEPENDENCIES invisible_captcha (~> 0) iso_country_codes (~> 0) jbuilder (~> 1.2) + kt-paperclip (~> 6) nokogiri (~> 1) oauth (~> 0) - paperclip (~> 5.2) pg (~> 1.1) pg_search premailer-rails (~> 1) From ff713fe9b44b5ff2e1b7c543ed3f821ad033ded8 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 9 Feb 2021 12:39:15 -0800 Subject: [PATCH 011/113] Upgrade from factory_bot to factory_girl --- Gemfile | 2 +- Gemfile.lock | 8 ++-- app/controllers/action_page_controller.rb | 4 +- .../admin/action_pages_controller.rb | 2 +- app/controllers/application_controller.rb | 4 +- app/controllers/partners_controller.rb | 4 +- app/models/ahoy/event.rb | 4 +- app/models/source_file.rb | 18 ++++----- config.ru | 2 +- .../step_definitions/action_page_steps.rb | 10 ++--- .../step_definitions/admin/features_steps.rb | 2 +- features/step_definitions/congress_steps.rb | 2 +- features/step_definitions/partner_steps.rb | 2 +- features/step_definitions/user_steps.rb | 20 +++++----- lib/smarty_streets.rb | 3 +- lib/tasks/petition.rake | 6 +-- .../admin/institutions_controller_spec.rb | 4 +- .../admin/petitions_controller_spec.rb | 6 +-- .../admin/users_controller_spec.rb | 2 +- .../subscriptions_controller_spec.rb | 6 +-- spec/controllers/tools_controller_spec.rb | 6 +-- spec/factories/affiliation_types.rb | 2 +- spec/factories/affiliations.rb | 2 +- spec/factories/ahoy_event.rb | 2 +- spec/factories/call_campaigns.rb | 4 +- spec/factories/categories.rb | 2 +- spec/factories/congress_member.rb | 2 +- spec/factories/congress_message.rb | 2 +- spec/factories/congress_message_campaigns.rb | 2 +- spec/factories/email_campaigns.rb | 4 +- spec/factories/institutions.rb | 2 +- spec/factories/partners.rb | 2 +- spec/factories/petitions.rb | 14 +++---- spec/factories/signatures.rb | 2 +- spec/factories/source_file.rb | 2 +- spec/factories/subscriptions.rb | 2 +- spec/factories/topic.rb | 2 +- spec/factories/topic_category.rb | 2 +- spec/factories/topic_set.rb | 2 +- spec/factories/tweets.rb | 4 +- spec/factories/users.rb | 2 +- .../features/action_pages/call_action_spec.rb | 2 +- .../action_pages/email_action_spec.rb | 2 +- .../action_pages/petition_action_spec.rb | 2 +- spec/features/admin/action_creation_spec.rb | 4 +- spec/features/admin/previews_spec.rb | 6 +-- spec/lib/call_tool_spec.rb | 2 +- spec/mailers/user_mailer_spec.rb | 4 +- spec/models/action_institution_spec.rb | 10 ++--- spec/models/action_page_spec.rb | 38 +++++++++---------- spec/models/congress_message_campaign_spec.rb | 2 +- spec/models/email_campaign_spec.rb | 2 +- spec/models/institution_spec.rb | 12 +++--- spec/models/signature_spec.rb | 2 +- spec/models/source_file_spec.rb | 2 +- spec/models/topic_category_spec.rb | 4 +- spec/models/user_spec.rb | 16 ++++---- spec/requests/action_pages_spec.rb | 4 +- spec/requests/admin/action_pages_spec.rb | 8 ++-- spec/requests/admin/events_spec.rb | 12 +++--- spec/requests/admin/petition_spec.rb | 4 +- spec/requests/admin/s3_uploads_spec.rb | 2 +- spec/spec_helper.rb | 4 +- spec/tasks/users_spec.rb | 4 +- 64 files changed, 156 insertions(+), 167 deletions(-) diff --git a/Gemfile b/Gemfile index 6b556c56e..c1582dfbd 100644 --- a/Gemfile +++ b/Gemfile @@ -119,7 +119,7 @@ group :development, :test do gem "byebug" gem "capybara", "~> 3" gem "database_cleaner", "~> 1" - gem "factory_girl_rails", "~> 4" + gem "factory_bot_rails", "~> 4" gem "rails-controller-testing" gem "rspec-core", "~> 3" gem "rspec-rails", "~> 3" diff --git a/Gemfile.lock b/Gemfile.lock index 388aa5dc9..7a1c3ab93 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -176,10 +176,10 @@ GEM errbase (0.2.1) erubi (1.10.0) execjs (2.7.0) - factory_girl (4.9.0) + factory_bot (4.11.1) activesupport (>= 3.0.0) - factory_girl_rails (4.9.0) - factory_girl (~> 4.9.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) railties (>= 3.0.0) faraday (1.3.0) faraday-net_http (~> 1.0) @@ -509,7 +509,7 @@ DEPENDENCIES eff_matomo (~> 0.2.4) ejs (~> 1) email_validator (~> 1) - factory_girl_rails (~> 4) + factory_bot_rails (~> 4) fast_inserter (~> 0.1) fastly (~> 2) fontello_rails_converter (~> 0) diff --git a/app/controllers/action_page_controller.rb b/app/controllers/action_page_controller.rb index 202874c13..7db6a2c2d 100644 --- a/app/controllers/action_page_controller.rb +++ b/app/controllers/action_page_controller.rb @@ -87,9 +87,9 @@ def redirect_to_specified_url end def redirect_from_archived_to_active_action - if @actionPage.redirect_from_archived_to_active_action? + if @actionPage.redirect_from_archived_to_active_action? && !current_user && (current_user.taken_action?(@actionPage) || current_user.admin?) # Users can access actions they've taken in the past as a historical record - redirect_to @actionPage.active_action_page_for_redirect unless current_user && (current_user.taken_action?(@actionPage) || current_user.admin?) + redirect_to @actionPage.active_action_page_for_redirect end end diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index 231088a82..c6bbc3a1b 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -187,7 +187,7 @@ def action_page_params affiliation_types_attributes: %i[id name], tweet_attributes: [ :id, :target, :target_house, :target_senate, :message, :cta, :bioguide_id, - tweet_targets_attributes: %i[id _destroy twitter_id image] + { tweet_targets_attributes: %i[id _destroy twitter_id image] } ], email_campaign_attributes: %i[ id message subject target_house target_senate target_email diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 809cc39e7..c0a057e3b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,9 +16,7 @@ class ApplicationController < ActionController::Base skip_before_action :set_ahoy_request_store def user_conditional_logic - if user_signed_in? - lock_users_with_expired_passwords! unless user_is_being_told_to_reset_pass_or_is_resetting_pass? - end + lock_users_with_expired_passwords! if user_signed_in? && !user_is_being_told_to_reset_pass_or_is_resetting_pass? end # This method seems to check if the request is coming from a domain listed in diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb index ed8c595fd..ccb77b04d 100644 --- a/app/controllers/partners_controller.rb +++ b/app/controllers/partners_controller.rb @@ -64,9 +64,7 @@ def set_partner def authenticate authenticate_user! - unless current_user.admin? - raise ActiveRecord::RecordNotFound if current_user.partner != @partner - end + raise ActiveRecord::RecordNotFound if !current_user.admin? && (current_user.partner != @partner) end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb index 3fd248da4..6c1c3b215 100644 --- a/app/models/ahoy/event.rb +++ b/app/models/ahoy/event.rb @@ -85,9 +85,7 @@ def self.summary end def user_opt_out - if user - self.user_id = nil unless user.record_activity? - end + self.user_id = nil if user && !user.record_activity? end def record_civicrm diff --git a/app/models/source_file.rb b/app/models/source_file.rb index f6ccdf35c..efac7e463 100644 --- a/app/models/source_file.rb +++ b/app/models/source_file.rb @@ -24,15 +24,15 @@ def pull_down_s3_object_attributes Rails.logger.debug "Trying to validate S3 object." self.file_name = key.split("/").last if key self.file_size ||= begin - s3_object.content_length - rescue StandardError - nil - end + s3_object.content_length + rescue StandardError + nil + end self.file_content_type ||= begin - s3_object.content_type - rescue StandardError - nil - end + s3_object.content_type + rescue StandardError + nil + end false end @@ -57,9 +57,7 @@ def to_jq_upload end def is_image? # rubocop:todo Naming/PredicateName - # rubocop:todo Style/DoubleNegation !!file_content_type.try(:match, /image/) - # rubocop:enable Style/DoubleNegation end #---- start S3 related methods ----- diff --git a/config.ru b/config.ru index 193e5fed8..846e1c70a 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path("../config/environment", __FILE__) +require ::File.expand_path("config/environment", __dir__) run Rails.application diff --git a/features/step_definitions/action_page_steps.rb b/features/step_definitions/action_page_steps.rb index fc0969dfa..fe1045692 100644 --- a/features/step_definitions/action_page_steps.rb +++ b/features/step_definitions/action_page_steps.rb @@ -1,6 +1,6 @@ Given(/^a congress message campaign exists$/) do stub_legislators - @action_page = FactoryGirl.create(:action_page_with_congress_message) + @action_page = FactoryBot.create(:action_page_with_congress_message) end When(/^I browse to an embedded action targetting Nancy Pelosi and Kamala Harris$/) do @@ -49,7 +49,7 @@ end Given(/^a petition action exists$/) do - @action_page = FactoryGirl.create(:petition).action_page + @action_page = FactoryBot.create(:petition).action_page end Given(/^local affiliations are allowed$/) do @@ -58,13 +58,13 @@ end Given(/^a local organizing campaign/) do - @action_page = FactoryGirl.create(:local_organizing_petition).action_page + @action_page = FactoryBot.create(:local_organizing_petition).action_page end Given(/^the petition has 100 signatures with affiliations/) do 100.times { - signature = FactoryGirl.create(:signature, petition: @action_page.petition) - signature.affiliations << FactoryGirl.create(:affiliation, institution: @action_page.institutions.first) + signature = FactoryBot.create(:signature, petition: @action_page.petition) + signature.affiliations << FactoryBot.create(:affiliation, institution: @action_page.institutions.first) } end diff --git a/features/step_definitions/admin/features_steps.rb b/features/step_definitions/admin/features_steps.rb index 144876e3d..c6a708364 100644 --- a/features/step_definitions/admin/features_steps.rb +++ b/features/step_definitions/admin/features_steps.rb @@ -1,5 +1,5 @@ Given(/^a petition exists with many signatures$/) do - @petition = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) + @petition = FactoryBot.create(:petition_complete_with_one_hundred_signatures) end When(/^I visit the signatures list$/) do diff --git a/features/step_definitions/congress_steps.rb b/features/step_definitions/congress_steps.rb index 5a607e47a..1dfd9f06f 100644 --- a/features/step_definitions/congress_steps.rb +++ b/features/step_definitions/congress_steps.rb @@ -1,5 +1,5 @@ Given(/^a congress member exists$/) do - member = FactoryGirl.create(:congress_member) + member = FactoryBot.create(:congress_member) end Given(/^a stubbed phantomdc$/) do diff --git a/features/step_definitions/partner_steps.rb b/features/step_definitions/partner_steps.rb index a03056484..78b27f367 100644 --- a/features/step_definitions/partner_steps.rb +++ b/features/step_definitions/partner_steps.rb @@ -1,3 +1,3 @@ Given(/^a partner named "(.*?)" with the code "(.*?)" exists$/) do |name, code| - @partner = FactoryGirl.create(:partner, name: name, code: code) + @partner = FactoryBot.create(:partner, name: name, code: code) end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index db568be67..16b56e416 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -20,13 +20,13 @@ def delete_user def create_activist_user create_visitor delete_user - @user = FactoryGirl.create(:activist_user, email: @visitor[:email], password: @visitor[:password]) + @user = FactoryBot.create(:activist_user, email: @visitor[:email], password: @visitor[:password]) end def create_community_member_user create_visitor delete_user - @user = FactoryGirl.create(:user, email: @visitor[:email], password: @visitor[:password]) + @user = FactoryBot.create(:user, email: @visitor[:email], password: @visitor[:password]) end def sign_in @@ -38,26 +38,26 @@ def sign_in end def create_an_action_page_petition_needing_one_more_signature - @petition = FactoryGirl.create(:petition_with_99_signatures_needing_1_more) + @petition = FactoryBot.create(:petition_with_99_signatures_needing_1_more) @action_page = @petition.action_page end def create_a_call_campaign - @call_campaign = FactoryGirl.create(:call_campaign, call_campaign_id: senate_call_campaign_id) + @call_campaign = FactoryBot.create(:call_campaign, call_campaign_id: senate_call_campaign_id) @action_page = @call_campaign.action_page end def create_an_email_campaign - @email_campaign = FactoryGirl.create(:email_campaign) + @email_campaign = FactoryBot.create(:email_campaign) @action_page = @email_campaign.action_page end Given(/^a user with the email "(.*?)"$/) do |email| - FactoryGirl.create(:user, email: email) + FactoryBot.create(:user, email: email) end Given(/^an unconfirmed user with the email "(.*?)"$/) do |email| - FactoryGirl.create(:unconfirmed_user, email: email) + FactoryBot.create(:unconfirmed_user, email: email) end Given(/^I exist as an activist$/) do @@ -339,7 +339,7 @@ def import_file_into_editor(name, content) Given(/^A tweet petition targeting senate exists$/) do setup_action - @tweet = FactoryGirl.create(:tweet_targeting_senate) + @tweet = FactoryBot.create(:tweet_targeting_senate) @action_page = @tweet.action_page @action_page.update_attributes(title: @action_info[:title], summary: @action_info[:summary], @@ -374,7 +374,7 @@ def import_file_into_editor(name, content) Given(/^a call petition targeting senate exists$/) do setup_action - @call_campaign = FactoryGirl.create(:call_campaign, call_campaign_id: senate_call_campaign_id, message: "hey hey") + @call_campaign = FactoryBot.create(:call_campaign, call_campaign_id: senate_call_campaign_id, message: "hey hey") @action_page = @call_campaign.action_page @action_page.update_attributes(title: @action_info[:title], summary: @action_info[:summary], @@ -383,7 +383,7 @@ def import_file_into_editor(name, content) Given(/^a call petition targeting a custom number exists$/) do setup_action - @call_campaign = FactoryGirl.create(:call_campaign, call_campaign_id: custom_call_campaign_id, message: "hey hey") + @call_campaign = FactoryBot.create(:call_campaign, call_campaign_id: custom_call_campaign_id, message: "hey hey") @action_page = @call_campaign.action_page @action_page.update_attributes(title: @action_info[:title], summary: @action_info[:summary], diff --git a/lib/smarty_streets.rb b/lib/smarty_streets.rb index b67b52cf1..a9a65d283 100644 --- a/lib/smarty_streets.rb +++ b/lib/smarty_streets.rb @@ -30,8 +30,7 @@ def self.get_congressional_district(street, zipcode) class AddressNotFound < StandardError; end def self.post(url, params) - res = JSON.parse RestClient.get("#{url}?#{params.to_query}") - res + JSON.parse RestClient.get("#{url}?#{params.to_query}") rescue StandardError => e Raven.capture_exception(e) Rails.logger.error "#{e} (#{e.class})!" diff --git a/lib/tasks/petition.rake b/lib/tasks/petition.rake index 74b1176e3..2c8e3ca84 100644 --- a/lib/tasks/petition.rake +++ b/lib/tasks/petition.rake @@ -22,11 +22,11 @@ end namespace :petition do desc "Create a local organizing petition with 99 signatures" task create_local: :environment do - petition = FactoryGirl.create(:local_organizing_petition) + petition = FactoryBot.create(:local_organizing_petition) (0..98).each do |i| - petition.signatures << FactoryGirl.build(:signature, petition: petition) - petition.signatures.last.affiliations << FactoryGirl.build( + petition.signatures << FactoryBot.build(:signature, petition: petition) + petition.signatures.last.affiliations << FactoryBot.build( :affiliation, institution: petition.action_page.institutions[i % 10], affiliation_type: petition.action_page.affiliation_types[i % 5] diff --git a/spec/controllers/admin/institutions_controller_spec.rb b/spec/controllers/admin/institutions_controller_spec.rb index a7c76244d..aea96fb17 100644 --- a/spec/controllers/admin/institutions_controller_spec.rb +++ b/spec/controllers/admin/institutions_controller_spec.rb @@ -13,10 +13,10 @@ before(:each) do # Admin login @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryGirl.create(:admin_user) + sign_in FactoryBot.create(:admin_user) # Set parent action - @actionPage = FactoryGirl.create(:action_page_with_petition) + @actionPage = FactoryBot.create(:action_page_with_petition) end describe "GET #index" do diff --git a/spec/controllers/admin/petitions_controller_spec.rb b/spec/controllers/admin/petitions_controller_spec.rb index 85901c082..587f9e910 100644 --- a/spec/controllers/admin/petitions_controller_spec.rb +++ b/spec/controllers/admin/petitions_controller_spec.rb @@ -5,11 +5,11 @@ before(:each) do @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryGirl.create(:admin_user) + sign_in FactoryBot.create(:admin_user) end describe "GET #show" do - let(:petition) { FactoryGirl.create(:petition) } + let(:petition) { FactoryBot.create(:petition) } it "assigns @signatures" do get :show, params: { id: petition.id, action_page_id: petition.action_page.id } @@ -32,7 +32,7 @@ end describe "DELETE #destroy_signatures" do - let(:petition) { FactoryGirl.create(:petition) } + let(:petition) { FactoryBot.create(:petition) } let(:signatures) do 30.times.map { FactoryGirl.create(:signature, petition: petition) } end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 419152a63..14655f69b 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -14,7 +14,7 @@ describe "PATCH #update" do it "redirects" do - patch :update, params: { id: FactoryGirl.create(:collaborator_user), user: { collaborator: "1" } } + patch :update, params: { id: FactoryBot.create(:collaborator_user), user: { collaborator: "1" } } expect(response).to have_http_status(:found) end end diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index 9f91be8fd..409cdb3e5 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -31,11 +31,11 @@ end describe "#edit" do - let(:subscription) { FactoryGirl.create(:subscription) } + let(:subscription) { FactoryBot.create(:subscription) } subject { get :edit, params: { id: subscription } } it "redirects to supporters" do - sign_in FactoryGirl.create(:user) + sign_in FactoryBot.create(:user) expect(subject).to redirect_to(/#{Rails.application.secrets.supporters["host"]}/) end @@ -46,7 +46,7 @@ end it "fails gracefully" do - sign_in FactoryGirl.create(:user) + sign_in FactoryBot.create(:user) expect(subject).to redirect_to("/account") expect(flash[:error]).to be_present end diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 8928993ac..03385f3e0 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -47,7 +47,7 @@ describe "#call" do it "should CallTool#campaign_call, passing parameters in" do - call_campaign = FactoryGirl.create(:call_campaign) + call_campaign = FactoryBot.create(:call_campaign) expect(CallTool).to receive(:campaign_call) post :call, params: { @@ -60,7 +60,7 @@ end describe "#email" do - let(:email_campaign) { FactoryGirl.create(:email_campaign) } + let(:email_campaign) { FactoryBot.create(:email_campaign) } it "should redirect to ActionPage#service_uri(service)" do action_page = email_campaign.action_page @@ -75,7 +75,7 @@ end def create_signature_and_have_user_sign - @petition = FactoryGirl.create(:petition_with_99_signatures_needing_1_more) + @petition = FactoryBot.create(:petition_with_99_signatures_needing_1_more) post :petition, params: { signature: valid_attributes[:signature].merge({ "petition_id" => @petition.id.to_s }) } end diff --git a/spec/factories/affiliation_types.rb b/spec/factories/affiliation_types.rb index df1b7ca42..a17d71dc7 100644 --- a/spec/factories/affiliation_types.rb +++ b/spec/factories/affiliation_types.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :affiliation_type do name "Student" end diff --git a/spec/factories/affiliations.rb b/spec/factories/affiliations.rb index 615d9c889..2b6ec65fa 100644 --- a/spec/factories/affiliations.rb +++ b/spec/factories/affiliations.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :affiliation do institution affiliation_type diff --git a/spec/factories/ahoy_event.rb b/spec/factories/ahoy_event.rb index 69c73fd29..b02b16cf9 100644 --- a/spec/factories/ahoy_event.rb +++ b/spec/factories/ahoy_event.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :ahoy_view, class: Ahoy::Event do id { SecureRandom.uuid } name "View" diff --git a/spec/factories/call_campaigns.rb b/spec/factories/call_campaigns.rb index 63e4b61b4..46900549c 100644 --- a/spec/factories/call_campaigns.rb +++ b/spec/factories/call_campaigns.rb @@ -1,10 +1,10 @@ -FactoryGirl.define do +FactoryBot.define do factory :call_campaign do title "a call campaign" call_campaign_id 1 after(:create) do |campaign| - FactoryGirl.create(:action_page_with_call, call_campaign_id: campaign.id) + FactoryBot.create(:action_page_with_call, call_campaign_id: campaign.id) end end end diff --git a/spec/factories/categories.rb b/spec/factories/categories.rb index 0c5b53a1a..91e4f028f 100644 --- a/spec/factories/categories.rb +++ b/spec/factories/categories.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :category do title "Free Speech" end diff --git a/spec/factories/congress_member.rb b/spec/factories/congress_member.rb index c313e48ec..2f22c7947 100644 --- a/spec/factories/congress_member.rb +++ b/spec/factories/congress_member.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :congress_member do sequence(:bioguide_id) { |n| "A00000#{n}" } term_end { (Time.zone.now + 1.year).strftime("%Y-%m-%d") } diff --git a/spec/factories/congress_message.rb b/spec/factories/congress_message.rb index f262254e8..ed9084271 100644 --- a/spec/factories/congress_message.rb +++ b/spec/factories/congress_message.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do form1 = CongressForms::Form.new("C000880", [ { "value" => "$NAME_FIRST" }, { "value" => "$NAME_LAST" }, diff --git a/spec/factories/congress_message_campaigns.rb b/spec/factories/congress_message_campaigns.rb index 528955ab5..614995436 100644 --- a/spec/factories/congress_message_campaigns.rb +++ b/spec/factories/congress_message_campaigns.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :congress_message_campaign do subject "a subject" message "a message" diff --git a/spec/factories/email_campaigns.rb b/spec/factories/email_campaigns.rb index 5f0de73ad..be8ec4cf0 100644 --- a/spec/factories/email_campaigns.rb +++ b/spec/factories/email_campaigns.rb @@ -1,11 +1,11 @@ -FactoryGirl.define do +FactoryBot.define do factory :email_campaign do email_addresses "a@example.com, b@example.com" subject "a subject" message "a message" after(:create) do |campaign| - FactoryGirl.create(:action_page_with_email, email_campaign_id: campaign.id) + FactoryBot.create(:action_page_with_email, email_campaign_id: campaign.id) end end end diff --git a/spec/factories/institutions.rb b/spec/factories/institutions.rb index ca2d6f692..a9a43448c 100644 --- a/spec/factories/institutions.rb +++ b/spec/factories/institutions.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :institution do sequence(:name) { |n| "University of Wherever #{n}" } category "University" diff --git a/spec/factories/partners.rb b/spec/factories/partners.rb index e1e870999..0040a8cf1 100644 --- a/spec/factories/partners.rb +++ b/spec/factories/partners.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :partner do name "Another Activist Org" sequence(:code) { |n| "p#{n}" } diff --git a/spec/factories/petitions.rb b/spec/factories/petitions.rb index 8c6972415..7cb315709 100644 --- a/spec/factories/petitions.rb +++ b/spec/factories/petitions.rb @@ -1,29 +1,29 @@ -FactoryGirl.define do +FactoryBot.define do factory :petition do sequence(:title) { |n| "petition-#{n}" } description "A sample Petition" goal 100 after(:create) do |petition| - FactoryGirl.create(:action_page_with_petition, petition_id: petition.id) + FactoryBot.create(:action_page_with_petition, petition_id: petition.id) end end factory :petition_complete_with_one_hundred_signatures, parent: :petition do after(:create) do |petition| - 100.times { petition.signatures << FactoryGirl.build(:signature, petition_id: petition.id) } + 100.times { petition.signatures << FactoryBot.build(:signature, petition_id: petition.id) } end end factory :petition_with_99_signatures_needing_1_more, parent: :petition do after(:create) do |petition| - 99.times { petition.signatures << FactoryGirl.build(:signature, petition_id: petition.id) } + 99.times { petition.signatures << FactoryBot.build(:signature, petition_id: petition.id) } end end factory :petition_complete_with_one_thousand_signatures, parent: :petition do after(:create) do |petition| - 1000.times { petition.signatures << FactoryGirl.build(:signature, petition_id: petition.id) } + 1000.times { petition.signatures << FactoryBot.build(:signature, petition_id: petition.id) } end end @@ -31,8 +31,8 @@ enable_affiliations true after(:create) do |petition| - petition.action_page.institutions << FactoryGirl.build(:institution) - petition.action_page.affiliation_types << FactoryGirl.build(:affiliation_type) + petition.action_page.institutions << FactoryBot.build(:institution) + petition.action_page.affiliation_types << FactoryBot.build(:affiliation_type) end end end diff --git a/spec/factories/signatures.rb b/spec/factories/signatures.rb index 5a3926cf2..3aaea348b 100644 --- a/spec/factories/signatures.rb +++ b/spec/factories/signatures.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :signature do first_name "John" last_name "Doe" diff --git a/spec/factories/source_file.rb b/spec/factories/source_file.rb index 269e2f568..b921c1786 100644 --- a/spec/factories/source_file.rb +++ b/spec/factories/source_file.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :source_file do key "uploaded_files/meh.jpg" diff --git a/spec/factories/subscriptions.rb b/spec/factories/subscriptions.rb index 07a442937..269527dc3 100644 --- a/spec/factories/subscriptions.rb +++ b/spec/factories/subscriptions.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :subscription do first_name "John" last_name "Doe" diff --git a/spec/factories/topic.rb b/spec/factories/topic.rb index b914813fc..7b9a5e6f3 100644 --- a/spec/factories/topic.rb +++ b/spec/factories/topic.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :topic do sequence(:name) { |n| "Vampire#{n}" } end diff --git a/spec/factories/topic_category.rb b/spec/factories/topic_category.rb index f538cdbbb..c3d55566b 100644 --- a/spec/factories/topic_category.rb +++ b/spec/factories/topic_category.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :topic_category do name "Demons" diff --git a/spec/factories/topic_set.rb b/spec/factories/topic_set.rb index a2075b060..ed7171a49 100644 --- a/spec/factories/topic_set.rb +++ b/spec/factories/topic_set.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :topic_set do sequence(:tier) { |n| n } diff --git a/spec/factories/tweets.rb b/spec/factories/tweets.rb index f3737878c..90b14156f 100644 --- a/spec/factories/tweets.rb +++ b/spec/factories/tweets.rb @@ -1,9 +1,9 @@ -FactoryGirl.define do +FactoryBot.define do factory :tweet do message "Please protect my right to use the Internet safely" after(:create) do |tweet| - FactoryGirl.create(:action_page_with_tweet, tweet_id: tweet.id) + FactoryBot.create(:action_page_with_tweet, tweet_id: tweet.id) end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 0de4642a8..5b2dbf0fe 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,6 +1,6 @@ # Read about factories at https://github.com/thoughtbot/factory_girl -FactoryGirl.define do +FactoryBot.define do factory :unconfirmed_user, class: User do sequence(:email, ActiveRecord::Base.connection.table_exists?("users") ? User.next_id : 0) { |n| "person_#{n}@example.com" } password "strong passwords defeat lobsters covering wealth" diff --git a/spec/features/action_pages/call_action_spec.rb b/spec/features/action_pages/call_action_spec.rb index 5637af6cf..d37fed016 100644 --- a/spec/features/action_pages/call_action_spec.rb +++ b/spec/features/action_pages/call_action_spec.rb @@ -2,7 +2,7 @@ RSpec.feature "Call actions", type: :feature, js: true do let!(:action) do - FactoryGirl.create(:call_campaign).action_page + FactoryBot.create(:call_campaign).action_page end let!(:calltool_request) do { diff --git a/spec/features/action_pages/email_action_spec.rb b/spec/features/action_pages/email_action_spec.rb index 31a464955..3592b1db5 100644 --- a/spec/features/action_pages/email_action_spec.rb +++ b/spec/features/action_pages/email_action_spec.rb @@ -2,7 +2,7 @@ RSpec.feature "Email actions", type: :feature, js: true do let!(:action) do - FactoryGirl.create(:email_campaign).action_page + FactoryBot.create(:email_campaign).action_page end it "allows vistors to send emails" do visit action_page_path(action) diff --git a/spec/features/action_pages/petition_action_spec.rb b/spec/features/action_pages/petition_action_spec.rb index b206605b2..50d7638fd 100644 --- a/spec/features/action_pages/petition_action_spec.rb +++ b/spec/features/action_pages/petition_action_spec.rb @@ -2,7 +2,7 @@ RSpec.feature "Petition actions", type: :feature, js: true do let!(:action) do - FactoryGirl.create(:petition).action_page + FactoryBot.create(:petition).action_page end let(:location) { OpenStruct.new(city: "Sunnydale", state: "CA") } diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index 38e15ecd0..73f3a381d 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -1,8 +1,8 @@ require "rails_helper" RSpec.describe "Admin action page creation", type: :feature, js: true do - before { sign_in_user(FactoryGirl.create(:admin_user)) } - let!(:category) { FactoryGirl.create(:category, title: "Privacy") } + before { sign_in_user(FactoryBot.create(:admin_user)) } + let!(:category) { FactoryBot.create(:category, title: "Privacy") } it "can create tweet actions" do visit new_admin_action_page_path fill_in_basic_info(title: "Very Important Action", diff --git a/spec/features/admin/previews_spec.rb b/spec/features/admin/previews_spec.rb index 11b69850a..522427e06 100644 --- a/spec/features/admin/previews_spec.rb +++ b/spec/features/admin/previews_spec.rb @@ -1,12 +1,12 @@ require "rails_helper" RSpec.describe "Admin action page previews", type: :feature, js: true do - before { sign_in_user(FactoryGirl.create(:admin_user)) } + before { sign_in_user(FactoryBot.create(:admin_user)) } xit "works for tweet actions" do # window switching is broken, fixing previews for now - tweet = FactoryGirl.create(:tweet) - action = FactoryGirl.create(:action_page_with_tweet, tweet: tweet) + tweet = FactoryBot.create(:tweet) + action = FactoryBot.create(:action_page_with_tweet, tweet: tweet) visit edit_admin_action_page_path(action) fill_in "Title", with: "New title" click_on "Action" diff --git a/spec/lib/call_tool_spec.rb b/spec/lib/call_tool_spec.rb index 908db5bea..6f8f81040 100644 --- a/spec/lib/call_tool_spec.rb +++ b/spec/lib/call_tool_spec.rb @@ -7,7 +7,7 @@ end describe ".campaign_call" do - let(:campaign) { FactoryGirl.create(:call_campaign) } + let(:campaign) { FactoryBot.create(:call_campaign) } let(:keywords) do { diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index bfdf96d2e..ca7c47cfe 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -2,8 +2,8 @@ describe UserMailer, type: :mailer do describe "instructions" do - let(:user) { FactoryGirl.create(:user) } - let(:action_page) { FactoryGirl.create(:action_page) } + let(:user) { FactoryBot.create(:user) } + let(:action_page) { FactoryBot.create(:action_page) } it "escapes HTML in names" do bad_name = "Mallory" diff --git a/spec/models/action_institution_spec.rb b/spec/models/action_institution_spec.rb index 12aa11448..e539d6b4a 100644 --- a/spec/models/action_institution_spec.rb +++ b/spec/models/action_institution_spec.rb @@ -3,11 +3,11 @@ RSpec.describe ActionInstitution, type: :model do describe ".add" do let!(:page) do - petition = FactoryGirl.create(:petition, enable_affiliations: true) - FactoryGirl.create(:action_page_with_petition, petition: petition) + petition = FactoryBot.create(:petition, enable_affiliations: true) + FactoryBot.create(:action_page_with_petition, petition: petition) end let!(:institutions) do - FactoryGirl.create_list(:institution, 2, category: "university") + FactoryBot.create_list(:institution, 2, category: "university") end it "adds all institutions of a category" do described_class.add(action_page: page, category: "university") @@ -19,13 +19,13 @@ end it "adds new institutions in the category" do page.institutions << institutions - new = FactoryGirl.create(:institution, category: "university") + new = FactoryBot.create(:institution, category: "university") described_class.add(action_page: page, category: "university") expect(page.reload.institutions).to eq(institutions + [new]) end it "removes institutions when reset: '1'" do page.institutions << institutions - new = FactoryGirl.create(:institution, category: "city") + new = FactoryBot.create(:institution, category: "city") described_class.add(action_page: page, category: "city", reset: "1") expect(page.reload.institutions).to eq([new]) end diff --git a/spec/models/action_page_spec.rb b/spec/models/action_page_spec.rb index 24a27d269..ec529d49c 100644 --- a/spec/models/action_page_spec.rb +++ b/spec/models/action_page_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe ActionPage do - let(:attr) { FactoryGirl.attributes_for :action_page } + let(:attr) { FactoryBot.attributes_for :action_page } it "creates a new instance given a valid attribute" do expect do @@ -10,7 +10,7 @@ end it "knows when to redirect from an archived action" do - action_page = FactoryGirl.build_stubbed :archived_action_page + action_page = FactoryBot.build_stubbed :archived_action_page expect(action_page.redirect_from_archived_to_active_action?).to be_truthy end @@ -25,7 +25,7 @@ # end describe "slug" do - let(:page) { FactoryGirl.create(:action_page) } + let(:page) { FactoryBot.create(:action_page) } let(:new_slug) { "a-better-slug" } it "has a friendly slug" do @@ -73,17 +73,17 @@ before { page.update(slug: new_slug) } it "does not allow slug conflicts" do - expect(FactoryGirl.create(:action_page, slug: old_slug).slug) + expect(FactoryBot.create(:action_page, slug: old_slug).slug) .not_to eq(old_slug) end end end describe "counter cache" do - let(:page) { FactoryGirl.create(:action_page_with_petition) } + let(:page) { FactoryBot.create(:action_page_with_petition) } before(:each) do - FactoryGirl.create_list(:ahoy_view, 2, action_page: page) - FactoryGirl.create(:ahoy_signature, action_page: page) + FactoryBot.create_list(:ahoy_view, 2, action_page: page) + FactoryBot.create(:ahoy_signature, action_page: page) page.reload end it "counts actions taken" do @@ -96,24 +96,24 @@ describe "#actions_taken_percent" do it "calculates the percentage of views that led to actions" do - page = FactoryGirl.create(:action_page_with_petition) - FactoryGirl.create_list(:ahoy_view, 3, action_page: page) - FactoryGirl.create_list(:ahoy_signature, 2, action_page: page) + page = FactoryBot.create(:action_page_with_petition) + FactoryBot.create_list(:ahoy_view, 3, action_page: page) + FactoryBot.create_list(:ahoy_signature, 2, action_page: page) page.reload expect(page.actions_taken_percent).to eq((2 / 3.0) * 100) end it "returns all zeroes when no events" do - page = FactoryGirl.create(:action_page) + page = FactoryBot.create(:action_page) expect(page.actions_taken_percent).to eq(0) end end describe ".type(types)" do - let(:call) { FactoryGirl.create(:action_page_with_call) } - let(:congress_message) { FactoryGirl.create(:action_page_with_congress_message) } - let(:email) { FactoryGirl.create(:action_page_with_email) } - let(:petition) { FactoryGirl.create(:action_page_with_petition) } - let(:tweet) { FactoryGirl.create(:action_page_with_tweet) } + let(:call) { FactoryBot.create(:action_page_with_call) } + let(:congress_message) { FactoryBot.create(:action_page_with_congress_message) } + let(:email) { FactoryBot.create(:action_page_with_email) } + let(:petition) { FactoryBot.create(:action_page_with_petition) } + let(:tweet) { FactoryBot.create(:action_page_with_tweet) } before do [call, congress_message, email, petition, tweet] @@ -138,14 +138,14 @@ describe ".status(status)" do shared_examples "returns only the given status" do |status, action| it status do - action = FactoryGirl.create(*action) + action = FactoryBot.create(*action) result = ActionPage.status(status) expect(result).to contain_exactly(action) end end context "not live" do - before { FactoryGirl.create(:action_page) } + before { FactoryBot.create(:action_page) } it_behaves_like "returns only the given status", "archived", [:action_page, { archived: true }] @@ -158,7 +158,7 @@ end context "live action" do - before { FactoryGirl.create(:action_page, published: false) } + before { FactoryBot.create(:action_page, published: false) } it_behaves_like "returns only the given status", "live", [:action_page, { published: true }] end diff --git a/spec/models/congress_message_campaign_spec.rb b/spec/models/congress_message_campaign_spec.rb index cf01e56a9..e405b2031 100644 --- a/spec/models/congress_message_campaign_spec.rb +++ b/spec/models/congress_message_campaign_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe EmailCampaign do - let(:campaign) { FactoryGirl.create :congress_message_campaign } + let(:campaign) { FactoryBot.create :congress_message_campaign } it "generates a url for fills by date" do expect(campaign.date_fills_url(Time.zone.today - 30.days, Time.zone.today)).to \ diff --git a/spec/models/email_campaign_spec.rb b/spec/models/email_campaign_spec.rb index 6a470716d..d02493198 100644 --- a/spec/models/email_campaign_spec.rb +++ b/spec/models/email_campaign_spec.rb @@ -3,7 +3,7 @@ describe EmailCampaign do describe "#service_uri(service)" do let(:campaign) do - FactoryGirl.create( + FactoryBot.create( :email_campaign, email_addresses: "a@example.com, b@example.com", subject: "hey hey hey", diff --git a/spec/models/institution_spec.rb b/spec/models/institution_spec.rb index 952a5ba2c..42bebf759 100644 --- a/spec/models/institution_spec.rb +++ b/spec/models/institution_spec.rb @@ -2,7 +2,7 @@ describe Institution do describe ".top" do - let(:petition) { FactoryGirl.create(:local_organizing_petition) } + let(:petition) { FactoryBot.create(:local_organizing_petition) } let(:high_rank) { petition.action_page.institutions.create(name: "A", category: "University") } let(:mid_rank) { petition.action_page.institutions.create(name: "B", category: "University") } @@ -12,17 +12,17 @@ before(:each) do 100.times do - sig = FactoryGirl.create(:signature, petition_id: petition.id) + sig = FactoryBot.create(:signature, petition_id: petition.id) sig.affiliations.create(institution_id: high_rank.id, affiliation_type: student) end 50.times do - sig = FactoryGirl.create(:signature, petition_id: petition.id) + sig = FactoryBot.create(:signature, petition_id: petition.id) sig.affiliations.create(institution_id: mid_rank.id, affiliation_type: student) end 10.times do - sig = FactoryGirl.create(:signature, petition_id: petition.id) + sig = FactoryBot.create(:signature, petition_id: petition.id) sig.affiliations.create(institution_id: low_rank.id, affiliation_type: student) end end @@ -37,8 +37,8 @@ end describe ".import" do - let(:action_page) { FactoryGirl.create(:action_page) } - let(:institution) { FactoryGirl.create(:institution) } + let(:action_page) { FactoryBot.create(:action_page) } + let(:institution) { FactoryBot.create(:institution) } let(:names) do ["University of California, Berkeley", "University of California, Santa Cruz"] diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb index 203ef1abb..593e628d9 100644 --- a/spec/models/signature_spec.rb +++ b/spec/models/signature_spec.rb @@ -29,7 +29,7 @@ end it "should impose an arbitrary opinion as to whether a string of text may refer to a country" do - # note: it is my personal belief that there is no such thing as a country/ nation =) + # NOTE: it is my personal belief that there is no such thing as a country/ nation =) arbitrarily_invalid_opinion = @attr.merge(country_code: "laserland") expect do diff --git a/spec/models/source_file_spec.rb b/spec/models/source_file_spec.rb index 0f1e47cef..daa07269c 100644 --- a/spec/models/source_file_spec.rb +++ b/spec/models/source_file_spec.rb @@ -2,7 +2,7 @@ describe SourceFile do before(:each) do - @source_file = FactoryGirl.create(:source_file, key: "meh.jpg") + @source_file = FactoryBot.create(:source_file, key: "meh.jpg") end it "should generate full_urls correctly when amazon_bucket_url is set" do diff --git a/spec/models/topic_category_spec.rb b/spec/models/topic_category_spec.rb index bc12fac9b..6ec41bf2b 100644 --- a/spec/models/topic_category_spec.rb +++ b/spec/models/topic_category_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe TopicCategory do - subject { FactoryGirl.create(:topic_category) } + subject { FactoryBot.create(:topic_category) } describe "#best_match" do it "selects the best match from a list of options" do @@ -15,7 +15,7 @@ end after do - FactoryGirl.reload # Reset sequence numbers + FactoryBot.reload # Reset sequence numbers end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ea7dc5aff..7dbb9f2bf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,8 +2,8 @@ require "lib/civicrm_spec" describe User do - let(:attr) { FactoryGirl.attributes_for :user } - let(:user) { FactoryGirl.create(:user) } + let(:attr) { FactoryBot.attributes_for :user } + let(:user) { FactoryBot.create(:user) } before(:each) do stub_civicrm @@ -36,7 +36,7 @@ end it "makes sure admins are using strong passwords" do - user = FactoryGirl.create(:user, admin: true) + user = FactoryBot.create(:user, admin: true) result = set_weak_password(user) expect(result).to be_falsey @@ -47,9 +47,9 @@ end describe "track user actions" do - let(:user) { FactoryGirl.create(:user, record_activity: true) } + let(:user) { FactoryBot.create(:user, record_activity: true) } let(:ahoy) { Ahoy::Tracker.new } - let(:action_page) { FactoryGirl.create :action_page_with_petition } + let(:action_page) { FactoryBot.create :action_page_with_petition } it "knows if the user has taken a given action" do ahoy.authenticate(user) @@ -67,14 +67,14 @@ def record_several_actions # a user with no actions - FactoryGirl.create(:user, record_activity: true) + FactoryBot.create(:user, record_activity: true) # a user with three actions - ahoy.authenticate(FactoryGirl.create(:user, record_activity: true)) + ahoy.authenticate(FactoryBot.create(:user, record_activity: true)) 3.times { track_signature(action_page) } # a user with 1 action - ahoy.authenticate(FactoryGirl.create(:user, record_activity: true)) + ahoy.authenticate(FactoryBot.create(:user, record_activity: true)) 1.times { track_signature(action_page) } # our friend, with 2 actions diff --git a/spec/requests/action_pages_spec.rb b/spec/requests/action_pages_spec.rb index 328922e21..705523dc2 100644 --- a/spec/requests/action_pages_spec.rb +++ b/spec/requests/action_pages_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "Action Pages", type: :request do describe "small petition" do before(:each) do - @action_page = FactoryGirl.create(:petition_with_99_signatures_needing_1_more).action_page + @action_page = FactoryBot.create(:petition_with_99_signatures_needing_1_more).action_page end it "lists action pages" do @@ -25,7 +25,7 @@ describe "large petition" do it "should present the count of signatures" do - @action_page = FactoryGirl.create(:petition_complete_with_one_thousand_signatures).action_page + @action_page = FactoryBot.create(:petition_complete_with_one_thousand_signatures).action_page path = "#{action_page_path(@action_page)}/signature_count" get path diff --git a/spec/requests/admin/action_pages_spec.rb b/spec/requests/admin/action_pages_spec.rb index 83650516e..71ae077e1 100644 --- a/spec/requests/admin/action_pages_spec.rb +++ b/spec/requests/admin/action_pages_spec.rb @@ -24,7 +24,7 @@ describe "Admins" do before(:each) do - @admin = FactoryGirl.create(:admin_user) + @admin = FactoryBot.create(:admin_user) login @admin end @@ -39,7 +39,7 @@ end it "should allow them to search action pages" do - border = FactoryGirl.create( + border = FactoryBot.create( :action_page_with_petition, title: "borderpetition", petition_attributes: { @@ -47,13 +47,13 @@ } ) - privacy = FactoryGirl.create( + privacy = FactoryBot.create( :action_page_with_petition, title: "privacypetition", petition_attributes: { description: "online privacy" } ) - tweet = FactoryGirl.create( + tweet = FactoryBot.create( :action_page_with_tweet, title: "bordertweet", tweet_attributes: { message: "border surveillance tweet" } diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb index c364acecb..ff350215d 100644 --- a/spec/requests/admin/events_spec.rb +++ b/spec/requests/admin/events_spec.rb @@ -1,8 +1,8 @@ require "rails_helper" RSpec.describe "Admin Action Page Analytics", type: :request do - let(:action_page) { FactoryGirl.create(:action_page_with_views) } - before { login FactoryGirl.create(:admin_user) } + let(:action_page) { FactoryBot.create(:action_page_with_views) } + before { login FactoryBot.create(:admin_user) } describe "#index" do context "with type param" do @@ -20,9 +20,7 @@ # Default is to return data for the previous month. expect(JSON.parse(response.body).keys) - # rubocop:todo Style/FormatStringToken .to include(*(1..31).map { |i| format("Dec %d 2018", i) }) - # rubocop:enable Style/FormatStringToken end it "filters by date" do @@ -56,9 +54,9 @@ petition_id: Petition.create.id ) - FactoryGirl.create(:ahoy_signature, - action_page: action_page, - time: Time.zone.now) + FactoryBot.create(:ahoy_signature, + action_page: action_page, + time: Time.zone.now) end it "renders html" do diff --git a/spec/requests/admin/petition_spec.rb b/spec/requests/admin/petition_spec.rb index c95c04705..1532858d8 100644 --- a/spec/requests/admin/petition_spec.rb +++ b/spec/requests/admin/petition_spec.rb @@ -3,12 +3,12 @@ RSpec.describe "Admin Action Pages", type: :request do describe "admins" do before(:each) do - @admin = FactoryGirl.create(:admin_user) + @admin = FactoryBot.create(:admin_user) login @admin end it "should let admins download the CSV" do - @petition = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) + @petition = FactoryBot.create(:petition_complete_with_one_hundred_signatures) get "/admin/petitions/#{@petition.id}/presentable_csv" diff --git a/spec/requests/admin/s3_uploads_spec.rb b/spec/requests/admin/s3_uploads_spec.rb index 5f0babe2d..3e00c35be 100644 --- a/spec/requests/admin/s3_uploads_spec.rb +++ b/spec/requests/admin/s3_uploads_spec.rb @@ -28,7 +28,7 @@ end it "should allow admins" do - @admin = FactoryGirl.create(:admin_user) + @admin = FactoryBot.create(:admin_user) login @admin expect do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a7965289..7eb9dd77e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,12 +44,12 @@ # for controller tests def login_as_admin @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryGirl.create(:admin_user) + sign_in FactoryBot.create(:admin_user) end def login_as_collaborator @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryGirl.create(:collaborator_user) + sign_in FactoryBot.create(:collaborator_user) end def set_weak_password(user) # rubocop:todo Naming/AccessorMethodName diff --git a/spec/tasks/users_spec.rb b/spec/tasks/users_spec.rb index 0e7bd1b5b..2e6165ef9 100644 --- a/spec/tasks/users_spec.rb +++ b/spec/tasks/users_spec.rb @@ -2,7 +2,7 @@ require "rake" describe "User-related rake tasks" do - let(:user) { FactoryGirl.create(:user) } + let(:user) { FactoryBot.create(:user) } let(:email) { user.email } let(:run_task) { Rake.application.invoke_task "#{task}[#{email}]" } @@ -56,7 +56,7 @@ end describe "users:remove_admin" do - let(:user) { FactoryGirl.create(:user, admin: true) } + let(:user) { FactoryBot.create(:user, admin: true) } let(:task) { "users:remove_admin" } it "grants admin status to the given user" do From 22be9083ac90fade5541ecb1178d60ddb5167b0a Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 16 Feb 2021 14:46:27 -0800 Subject: [PATCH 012/113] Upgrade jbuilder --- Gemfile | 2 +- Gemfile.lock | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index c1582dfbd..b06b3874f 100644 --- a/Gemfile +++ b/Gemfile @@ -84,7 +84,7 @@ gem "gravatar-ultimate", "~> 2" gem "http_accept_language", "~> 2" # Detect HTTP language header gem "invisible_captcha", "~> 0" # Prevent form submissions by bots gem "iso_country_codes", "~> 0" -gem "jbuilder", "~> 1.2" # JSON APIs +gem "jbuilder", "~> 2" gem "oauth", "~> 0" gem "rest-client", "~> 2" gem "sanitize", "~> 4" # Sanitize user input diff --git a/Gemfile.lock b/Gemfile.lock index 7a1c3ab93..86488e288 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -215,14 +215,13 @@ GEM httparty (0.18.1) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.8.8) + i18n (1.8.9) concurrent-ruby (~> 1.0) invisible_captcha (0.13.0) rails (>= 3.2.0) iso_country_codes (0.7.8) - jbuilder (1.5.3) - activesupport (>= 3.0.0) - multi_json (>= 1.2.0) + jbuilder (2.11.2) + activesupport (>= 5.0.0) jmespath (1.4.0) kt-paperclip (6.4.1) activemodel (>= 4.2.0) @@ -520,7 +519,7 @@ DEPENDENCIES http_accept_language (~> 2) invisible_captcha (~> 0) iso_country_codes (~> 0) - jbuilder (~> 1.2) + jbuilder (~> 2) kt-paperclip (~> 6) nokogiri (~> 1) oauth (~> 0) From 175671d1c4ed591f5400502c7ca14bf3894af677 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 16 Feb 2021 14:47:05 -0800 Subject: [PATCH 013/113] Remove descriptive statistics gem --- Gemfile | 11 ++--- Gemfile.lock | 125 +++++++++++++++++++++++---------------------------- 2 files changed, 62 insertions(+), 74 deletions(-) diff --git a/Gemfile b/Gemfile index b06b3874f..3c9dc360d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,11 @@ source "https://rubygems.org" -gem "rails", "~> 5.0" +gem "rails", "~> 5.0.7" # Database gem "pg", "~> 1.1" -gem "pg_search" +# Can upgrade after upgrading to rails 5.2 +gem "pg_search", "< 2.3.1" # Hosting-related gem "aws-sdk-rails", "~> 2" @@ -22,7 +23,7 @@ gem "bundler", ">= 1.8.4" # needed for rails-assets gem "fontello_rails_converter", "~> 0" gem "react-rails", "~> 1" gem "redcarpet", "~> 3" # Markdown -gem "sass-rails", "~> 5.0" +gem "sass-rails", "< 5.1" gem "select2-rails" # Autocomplete select menus gem "uglifier", ">= 1.3.0" # compressor for JavaScript assets gem "webshims-rails", "~> 1" @@ -71,9 +72,9 @@ gem "counter_culture", "~> 2.0" # Other gem "activerecord-session_store", "~> 1" -gem "acts_as_paranoid", git: "https://github.com/ActsAsParanoid/acts_as_paranoid.git" +# Can upgrade after upgrading to rails 5.2 +gem "acts_as_paranoid", "< 0.7" gem "cocoon", "~> 1" # Dynamically add and remove nested associations from forms -gem "descriptive_statistics", "~> 2" # Used for calculating percentiles gem "devise", "~> 4.7" gem "ejs", "~> 1" # Embedded javascript gem "email_validator", "~> 1" diff --git a/Gemfile.lock b/Gemfile.lock index 86488e288..770c5e401 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,62 +1,53 @@ -GIT - remote: https://github.com/ActsAsParanoid/acts_as_paranoid.git - revision: e75d09ae62a5b6d584c4eb60658fd0a4975a7b4c - specs: - acts_as_paranoid (0.7.0) - activerecord (>= 5.2, < 7.0) - activesupport (>= 5.2, < 7.0) - GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actioncable (5.2.4.5) - actionpack (= 5.2.4.5) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailer (5.2.4.5) - actionpack (= 5.2.4.5) - actionview (= 5.2.4.5) - activejob (= 5.2.4.5) + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.5) - actionview (= 5.2.4.5) - activesupport (= 5.2.4.5) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.5) - activesupport (= 5.2.4.5) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) - erubi (~> 1.4) + erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4.5) - activesupport (= 5.2.4.5) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) globalid (>= 0.3.6) - activemodel (5.2.4.5) - activesupport (= 5.2.4.5) - activerecord (5.2.4.5) - activemodel (= 5.2.4.5) - activesupport (= 5.2.4.5) - arel (>= 9.0) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) activerecord-session_store (1.1.3) actionpack (>= 4.0) activerecord (>= 4.0) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activestorage (5.2.4.5) - actionpack (= 5.2.4.5) - activerecord (= 5.2.4.5) - marcel (~> 0.3.1) - activesupport (5.2.4.5) + activesupport (5.0.7.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + acts_as_paranoid (0.6.3) + activerecord (>= 4.2, < 7.0) + activesupport (>= 4.2, < 7.0) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) ahoy_matey (1.6.1) @@ -73,7 +64,7 @@ GEM apparition (0.6.0) capybara (~> 3.13, < 4) websocket-driver (>= 0.6.5) - arel (9.0.0) + arel (7.1.4) ast (2.4.2) autoprefixer-rails (10.2.4.0) execjs @@ -153,7 +144,6 @@ GEM delayed_job_active_record (4.1.5) activerecord (>= 3.0, < 6.2) delayed_job (>= 3.0, < 5) - descriptive_statistics (2.5.1) devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -175,6 +165,7 @@ GEM activemodel errbase (0.2.1) erubi (1.10.0) + erubis (2.7.0) execjs (2.7.0) factory_bot (4.11.1) activesupport (>= 3.0.0) @@ -236,8 +227,6 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) @@ -262,9 +251,9 @@ GEM parser (3.0.0.0) ast (~> 2.4.1) pg (1.2.3) - pg_search (2.3.5) - activerecord (>= 5.2) - activesupport (>= 5.2) + pg_search (2.3.0) + activerecord (>= 4.2) + activesupport (>= 4.2) premailer (1.14.2) addressable css_parser (>= 1.6.0) @@ -278,20 +267,19 @@ GEM rack (2.2.3) rack-attack (5.4.2) rack (>= 1.0, < 3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.4.5) - actioncable (= 5.2.4.5) - actionmailer (= 5.2.4.5) - actionpack (= 5.2.4.5) - actionview (= 5.2.4.5) - activejob (= 5.2.4.5) - activemodel (= 5.2.4.5) - activerecord (= 5.2.4.5) - activestorage (= 5.2.4.5) - activesupport (= 5.2.4.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) bundler (>= 1.3.0) - railties (= 5.2.4.5) + railties (= 5.0.7.2) sprockets-rails (>= 2.0.0) rails-assets-EpicEditor (0.2.3) rails-assets-chartjs (2.8.0) @@ -328,12 +316,12 @@ GEM rails_response_headers (0.1.0) rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) - railties (5.2.4.5) - actionpack (= 5.2.4.5) - activesupport (= 5.2.4.5) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.18.1, < 2.0) rainbow (3.0.0) rake (13.0.3) rb-fchange (0.0.6) @@ -414,8 +402,8 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.1.0) - railties (>= 5.2.0) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) @@ -467,7 +455,7 @@ GEM webrick (1.7.0) webshims-rails (1.16.0) rails (> 3.1.0) - websocket-driver (0.7.3) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) whenever (0.11.0) @@ -483,7 +471,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 1) - acts_as_paranoid! + acts_as_paranoid (< 0.7) ahoy_matey (~> 1.6) apparition (~> 0.6) aws-sdk-rails (~> 2) @@ -502,7 +490,6 @@ DEPENDENCIES daemons (~> 1) database_cleaner (~> 1) delayed_job_active_record (~> 4) - descriptive_statistics (~> 2) devise (~> 4.7) dotenv-rails (~> 2) eff_matomo (~> 0.2.4) @@ -524,11 +511,11 @@ DEPENDENCIES nokogiri (~> 1) oauth (~> 0) pg (~> 1.1) - pg_search + pg_search (< 2.3.1) premailer-rails (~> 1) puma (~> 3) rack-attack (~> 5) - rails (~> 5.0) + rails (~> 5.0.7) rails-assets-EpicEditor (~> 0)! rails-assets-chartjs (~> 2)! rails-assets-congress-images-102x125! @@ -560,7 +547,7 @@ DEPENDENCIES rubocop-performance rubocop-rails sanitize (~> 4) - sass-rails (~> 5.0) + sass-rails (< 5.1) sdoc select2-rails sentry-raven (~> 0.15) From 001705c77dc944986d91c172d5a1770aa24061ee Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 16 Feb 2021 15:24:11 -0800 Subject: [PATCH 014/113] Continue FactoryBot upgrade --- .../action_page_controller_spec.rb | 28 ++++++++-------- spec/factories/action_page.rb | 32 +++++++++---------- spec/factories/affiliation_types.rb | 2 +- spec/factories/ahoy_event.rb | 8 ++--- spec/factories/call_campaigns.rb | 4 +-- spec/factories/categories.rb | 2 +- spec/factories/congress_member.rb | 12 +++---- spec/factories/congress_message.rb | 2 +- spec/factories/congress_message_campaigns.rb | 10 +++--- spec/factories/email_campaigns.rb | 6 ++-- spec/factories/institutions.rb | 2 +- spec/factories/partners.rb | 2 +- spec/factories/petitions.rb | 6 ++-- spec/factories/signatures.rb | 16 +++++----- spec/factories/source_file.rb | 2 +- spec/factories/subscriptions.rb | 4 +-- spec/factories/topic_category.rb | 2 +- spec/factories/tweets.rb | 4 +-- spec/factories/users.rb | 2 +- .../action_pages/congress_action_spec.rb | 6 ++-- .../action_pages/tweet_action_spec.rb | 6 ++-- spec/features/congress_message.rb | 8 ++--- spec/lib/action_cloner_spec.rb | 18 +++++------ spec/lib/congress_forms_spec.rb | 2 +- spec/models/ahoy/event_spec.rb | 12 +++---- spec/models/congress_message_spec.rb | 2 +- spec/models/petition_spec.rb | 2 +- spec/queries/action_page_filters_spec.rb | 20 ++++++------ spec/requests/admin/users_spec.rb | 4 +-- spec/requests/congress_messages_spec.rb | 10 +++--- spec/tasks/signatures_spec.rb | 14 ++++---- 31 files changed, 125 insertions(+), 125 deletions(-) diff --git a/spec/controllers/action_page_controller_spec.rb b/spec/controllers/action_page_controller_spec.rb index 5d0b52c8e..e581a90b7 100644 --- a/spec/controllers/action_page_controller_spec.rb +++ b/spec/controllers/action_page_controller_spec.rb @@ -3,7 +3,7 @@ RSpec.describe ActionPageController, type: :controller do include Devise::Test::ControllerHelpers - let(:action_page) { FactoryGirl.create :action_page } + let(:action_page) { FactoryBot.create :action_page } let(:admin) { login_as_admin } let(:collaborator) { login_as_collaborator } @@ -12,8 +12,8 @@ it "filters by category" do action_page - category = FactoryGirl.create(:category, title: "Privacy") - privacy_action_page = FactoryGirl.create(:action_page, category: category) + category = FactoryBot.create(:category, title: "Privacy") + privacy_action_page = FactoryBot.create(:action_page, category: category) get :index, params: { category: "Privacy" } expect(assigns(:actionPages)).to contain_exactly(privacy_action_page) end @@ -42,7 +42,7 @@ end it "redirects to an admin specified url if redirect is enabled" do - action_page = FactoryGirl.create :action_page, + action_page = FactoryBot.create :action_page, enable_redirect: true, redirect_url: "https://example.com" get :show, params: { id: action_page } @@ -50,9 +50,9 @@ end context "archived" do - let(:active_action_page) { FactoryGirl.create :action_page } + let(:active_action_page) { FactoryBot.create :action_page } let(:archived_action_page) do - FactoryGirl.create :archived_action_page, + FactoryBot.create :archived_action_page, active_action_page_for_redirect: active_action_page end @@ -69,7 +69,7 @@ end context "unpublished" do - let(:unpublished_action_page) { FactoryGirl.create :action_page, published: false } + let(:unpublished_action_page) { FactoryBot.create :action_page, published: false } it "hides unpublished pages from unprivileged users" do expect do @@ -94,22 +94,22 @@ describe "GET #show_by_institution" do before(:each) do # Petition with two institutions - @petition = FactoryGirl.create(:local_organizing_petition) + @petition = FactoryBot.create(:local_organizing_petition) @actionPage = @petition.action_page - @actionPage.institutions << FactoryGirl.create(:institution) + @actionPage.institutions << FactoryBot.create(:institution) # Signature with affiliations to two different institutions - signature = FactoryGirl.create(:signature, + signature = FactoryBot.create(:signature, petition: @petition) - signature.affiliations << FactoryGirl.create(:affiliation, + signature.affiliations << FactoryBot.create(:affiliation, institution: @actionPage.institutions.first) - signature.affiliations << FactoryGirl.create(:affiliation, + signature.affiliations << FactoryBot.create(:affiliation, institution: @actionPage.institutions.last) # Signature with an affiliation to the second institutions - signature = FactoryGirl.create(:signature, + signature = FactoryBot.create(:signature, petition: @petition) - signature.affiliations << FactoryGirl.create(:affiliation, + signature.affiliations << FactoryBot.create(:affiliation, institution: @actionPage.institutions.last, affiliation_type: @actionPage.affiliation_types.first) end diff --git a/spec/factories/action_page.rb b/spec/factories/action_page.rb index f36f1c7eb..0cd2dddb5 100644 --- a/spec/factories/action_page.rb +++ b/spec/factories/action_page.rb @@ -1,50 +1,50 @@ -FactoryGirl.define do +FactoryBot.define do factory :action_page do - title "Sample Action Page" - summary "not filling in summary" - description "not filling desc in" - published true - email_text "$NAME, thanks for taking action!" - victory_message "We won" + title { "Sample Action Page" } + summary { "not filling in summary" } + description { "not filling desc in" } + published { true } + email_text { "$NAME, thanks for taking action!" } + victory_message { "We won" } trait :with_partner do after(:create) do |action_page, _evaluator| - action_page.partners << FactoryGirl.create(:partner) + action_page.partners << FactoryBot.create(:partner) end end end factory :action_page_with_petition, parent: :action_page do - enable_petition true + enable_petition { true } end factory :action_page_with_tweet, parent: :action_page do - enable_tweet true + enable_tweet { true } end factory :action_page_with_call, parent: :action_page do - enable_call true + enable_call { true } end factory :action_page_with_email, parent: :action_page do - enable_email true + enable_email { true } end factory :action_page_with_congress_message, parent: :action_page do - enable_congress_message true + enable_congress_message { true } congress_message_campaign end factory :archived_action_page, parent: :action_page do - archived true + archived { true } association :active_action_page_for_redirect, factory: :action_page - victory false + victory { false } end factory :action_page_with_views, parent: :action_page do after(:build) do |action_page, _evaluator| 10.times do |n| - FactoryGirl.create(:ahoy_view, + FactoryBot.create(:ahoy_view, action_page: action_page, time: Time.zone.now - n.days) end diff --git a/spec/factories/affiliation_types.rb b/spec/factories/affiliation_types.rb index a17d71dc7..8967288c5 100644 --- a/spec/factories/affiliation_types.rb +++ b/spec/factories/affiliation_types.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :affiliation_type do - name "Student" + name { "Student" } end end diff --git a/spec/factories/ahoy_event.rb b/spec/factories/ahoy_event.rb index b02b16cf9..e76aaba5f 100644 --- a/spec/factories/ahoy_event.rb +++ b/spec/factories/ahoy_event.rb @@ -1,25 +1,25 @@ FactoryBot.define do factory :ahoy_view, class: Ahoy::Event do id { SecureRandom.uuid } - name "View" + name { "View" } properties do { type: "action", actionType: "view" } end - time Time.zone.now + time { Time.zone.now } end factory :ahoy_signature, class: Ahoy::Event do id { SecureRandom.uuid } - name "Action" + name { "Action" } properties do { type: "action", actionType: "signature" } end - time Time.zone.now + time { Time.zone.now } end end diff --git a/spec/factories/call_campaigns.rb b/spec/factories/call_campaigns.rb index 46900549c..fdbcebdcc 100644 --- a/spec/factories/call_campaigns.rb +++ b/spec/factories/call_campaigns.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :call_campaign do - title "a call campaign" - call_campaign_id 1 + title { "a call campaign" } + call_campaign_id { 1 } after(:create) do |campaign| FactoryBot.create(:action_page_with_call, call_campaign_id: campaign.id) diff --git a/spec/factories/categories.rb b/spec/factories/categories.rb index 91e4f028f..e9de41bf0 100644 --- a/spec/factories/categories.rb +++ b/spec/factories/categories.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :category do - title "Free Speech" + title { "Free Speech" } end end diff --git a/spec/factories/congress_member.rb b/spec/factories/congress_member.rb index 2f22c7947..8f91bb380 100644 --- a/spec/factories/congress_member.rb +++ b/spec/factories/congress_member.rb @@ -2,11 +2,11 @@ factory :congress_member do sequence(:bioguide_id) { |n| "A00000#{n}" } term_end { (Time.zone.now + 1.year).strftime("%Y-%m-%d") } - full_name "Alice Mars" - first_name "Alice" - last_name "Mars" - twitter_id "AliceMars" - chamber "senate" - state "CA" + full_name { "Alice Mars" } + first_name { "Alice" } + last_name { "Mars" } + twitter_id { "AliceMars" } + chamber { "senate" } + state { "CA" } end end diff --git a/spec/factories/congress_message.rb b/spec/factories/congress_message.rb index ed9084271..99216d7eb 100644 --- a/spec/factories/congress_message.rb +++ b/spec/factories/congress_message.rb @@ -17,6 +17,6 @@ ]) factory :congress_message do - forms [form1, form2] + forms { [form1, form2] } end end diff --git a/spec/factories/congress_message_campaigns.rb b/spec/factories/congress_message_campaigns.rb index 614995436..3c314d0dc 100644 --- a/spec/factories/congress_message_campaigns.rb +++ b/spec/factories/congress_message_campaigns.rb @@ -1,15 +1,15 @@ FactoryBot.define do factory :congress_message_campaign do - subject "a subject" - message "a message" - campaign_tag "a campaign tag" + subject { "a subject" } + message { "a message" } + campaign_tag { "a campaign tag" } trait :targeting_bioguide_ids do - target_bioguide_ids "C000880" + target_bioguide_ids { "C000880" } end trait :targeting_senate do - target_house false + target_house { false } end end end diff --git a/spec/factories/email_campaigns.rb b/spec/factories/email_campaigns.rb index be8ec4cf0..e335aaea5 100644 --- a/spec/factories/email_campaigns.rb +++ b/spec/factories/email_campaigns.rb @@ -1,8 +1,8 @@ FactoryBot.define do factory :email_campaign do - email_addresses "a@example.com, b@example.com" - subject "a subject" - message "a message" + email_addresses { "a@example.com, b@example.com" } + subject { "a subject" } + message { "a message" } after(:create) do |campaign| FactoryBot.create(:action_page_with_email, email_campaign_id: campaign.id) diff --git a/spec/factories/institutions.rb b/spec/factories/institutions.rb index a9a43448c..59c1d5a98 100644 --- a/spec/factories/institutions.rb +++ b/spec/factories/institutions.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :institution do sequence(:name) { |n| "University of Wherever #{n}" } - category "University" + category { "University" } end end diff --git a/spec/factories/partners.rb b/spec/factories/partners.rb index 0040a8cf1..e8ecb57ce 100644 --- a/spec/factories/partners.rb +++ b/spec/factories/partners.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :partner do - name "Another Activist Org" + name { "Another Activist Org" } sequence(:code) { |n| "p#{n}" } end end diff --git a/spec/factories/petitions.rb b/spec/factories/petitions.rb index 7cb315709..e8278796f 100644 --- a/spec/factories/petitions.rb +++ b/spec/factories/petitions.rb @@ -1,8 +1,8 @@ FactoryBot.define do factory :petition do sequence(:title) { |n| "petition-#{n}" } - description "A sample Petition" - goal 100 + description { "A sample Petition" } + goal { 100 } after(:create) do |petition| FactoryBot.create(:action_page_with_petition, petition_id: petition.id) @@ -28,7 +28,7 @@ end factory :local_organizing_petition, parent: :petition do - enable_affiliations true + enable_affiliations { true } after(:create) do |petition| petition.action_page.institutions << FactoryBot.build(:institution) diff --git a/spec/factories/signatures.rb b/spec/factories/signatures.rb index 3aaea348b..195999334 100644 --- a/spec/factories/signatures.rb +++ b/spec/factories/signatures.rb @@ -1,13 +1,13 @@ FactoryBot.define do factory :signature do - first_name "John" - last_name "Doe" + first_name { "John" } + last_name { "Doe" } sequence(:email) { |n| "signer-#{n}@example.com" } - country_code "US" - zipcode "94109" - street_address "815 Eddy St" - city "San Francisco" - state "California" - anonymous false + country_code { "US" } + zipcode { "94109" } + street_address { "815 Eddy St" } + city { "San Francisco" } + state { "California" } + anonymous { false } end end diff --git a/spec/factories/source_file.rb b/spec/factories/source_file.rb index b921c1786..310f29c46 100644 --- a/spec/factories/source_file.rb +++ b/spec/factories/source_file.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :source_file do - key "uploaded_files/meh.jpg" + key { "uploaded_files/meh.jpg" } to_create { |instance| instance.save(validate: false) } # skip before filters end diff --git a/spec/factories/subscriptions.rb b/spec/factories/subscriptions.rb index 269527dc3..f247a6f23 100644 --- a/spec/factories/subscriptions.rb +++ b/spec/factories/subscriptions.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :subscription do - first_name "John" - last_name "Doe" + first_name { "John" } + last_name { "Doe" } sequence(:email) { |n| "signer-#{n}@example.com" } partner { |a| a.association :partner } end diff --git a/spec/factories/topic_category.rb b/spec/factories/topic_category.rb index c3d55566b..1ae77fd8a 100644 --- a/spec/factories/topic_category.rb +++ b/spec/factories/topic_category.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :topic_category do - name "Demons" + name { "Demons" } after(:create) do |category, _evaluator| create_list(:topic_set, 2, topic_category: category) diff --git a/spec/factories/tweets.rb b/spec/factories/tweets.rb index 90b14156f..5f6285821 100644 --- a/spec/factories/tweets.rb +++ b/spec/factories/tweets.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :tweet do - message "Please protect my right to use the Internet safely" + message { "Please protect my right to use the Internet safely" } after(:create) do |tweet| FactoryBot.create(:action_page_with_tweet, tweet_id: tweet.id) @@ -8,6 +8,6 @@ end factory :tweet_targeting_senate, parent: :tweet do - target_senate true + target_senate { true } end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 5b2dbf0fe..efb6f8609 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -3,7 +3,7 @@ FactoryBot.define do factory :unconfirmed_user, class: User do sequence(:email, ActiveRecord::Base.connection.table_exists?("users") ? User.next_id : 0) { |n| "person_#{n}@example.com" } - password "strong passwords defeat lobsters covering wealth" + password { "strong passwords defeat lobsters covering wealth" } end factory :user, parent: :unconfirmed_user do diff --git a/spec/features/action_pages/congress_action_spec.rb b/spec/features/action_pages/congress_action_spec.rb index de1cb8780..2b32a742d 100644 --- a/spec/features/action_pages/congress_action_spec.rb +++ b/spec/features/action_pages/congress_action_spec.rb @@ -2,13 +2,13 @@ RSpec.feature "Congress actions", type: :feature, js: true do let!(:action) do - FactoryGirl.create(:action_page_with_congress_message) + FactoryBot.create(:action_page_with_congress_message) end let!(:members) do - [FactoryGirl.create(:congress_member, + [FactoryBot.create(:congress_member, twitter_id: "sisko", state: "CA", bioguide_id: "C000880"), - FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] + FactoryBot.create(:congress_member, state: "CA", bioguide_id: "A000360")] end let(:location) do OpenStruct.new(success: true, diff --git a/spec/features/action_pages/tweet_action_spec.rb b/spec/features/action_pages/tweet_action_spec.rb index cd291bf43..6a4c5133e 100644 --- a/spec/features/action_pages/tweet_action_spec.rb +++ b/spec/features/action_pages/tweet_action_spec.rb @@ -2,13 +2,13 @@ RSpec.feature "Tweet actions", type: :feature, js: true do let!(:tweet_action) do - FactoryGirl.create(:tweet, message: "Default message").action_page + FactoryBot.create(:tweet, message: "Default message").action_page end let!(:members) do - [FactoryGirl.create(:congress_member, + [FactoryBot.create(:congress_member, twitter_id: "sisko", state: "CA", bioguide_id: "C000880"), - FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] + FactoryBot.create(:congress_member, state: "CA", bioguide_id: "A000360")] end let(:location) do OpenStruct.new(success: true, diff --git a/spec/features/congress_message.rb b/spec/features/congress_message.rb index 9bcab6be2..2dae3e5e3 100644 --- a/spec/features/congress_message.rb +++ b/spec/features/congress_message.rb @@ -1,13 +1,13 @@ require "rails_helper" RSpec.feature "Submit congress message", type: :feature do - let(:action_page) { FactoryGirl.create(:action_page_with_congress_message, :with_partner) } + let(:action_page) { FactoryBot.create(:action_page_with_congress_message, :with_partner) } let(:partner) { action_page.partners.first } let!(:members) do - [FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "C000880"), - FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] + [FactoryBot.create(:congress_member, state: "CA", bioguide_id: "C000880"), + FactoryBot.create(:congress_member, state: "CA", bioguide_id: "A000360")] end let(:location) do @@ -58,7 +58,7 @@ end scenario "Logged in user submits a congress message" do - giles = FactoryGirl.create(:user, + giles = FactoryBot.create(:user, first_name: "Rupert", last_name: "Giles", email: "mrgiles@sunnydale.edu") diff --git a/spec/lib/action_cloner_spec.rb b/spec/lib/action_cloner_spec.rb index 1779aeee5..6c02360db 100644 --- a/spec/lib/action_cloner_spec.rb +++ b/spec/lib/action_cloner_spec.rb @@ -2,51 +2,51 @@ describe ActionCloner do it "does not persist action pages" do - page = FactoryGirl.create(:action_page) + page = FactoryBot.create(:action_page) clone = described_class.run(page) expect(clone).not_to be_persisted end it "returns an ActionPage with cloned attributes" do - page = FactoryGirl.create(:action_page) + page = FactoryBot.create(:action_page) clone_attrs = filter_attrs(described_class.run(page).attributes) expect(clone_attrs).to eq(filter_attrs(page.attributes)) end it "returns a draft action page" do - page = FactoryGirl.build(:action_page) + page = FactoryBot.build(:action_page) clone = described_class.run(page) expect(clone).not_to be_published end it "does not return an archived page" do - page = FactoryGirl.build(:action_page, archived: true) + page = FactoryBot.build(:action_page, archived: true) clone = described_class.run(page) expect(clone).not_to be_archived end it "does not return a victory page" do - page = FactoryGirl.build(:action_page, victory: true) + page = FactoryBot.build(:action_page, victory: true) clone = described_class.run(page) expect(clone).not_to be_victory end it "retains its category" do - page = FactoryGirl.create(:action_page, category: FactoryGirl.build(:category)) + page = FactoryBot.create(:action_page, category: FactoryBot.build(:category)) clone = described_class.run(page) expect(clone.category.title).to eq(page.category.title) end it "can be persisted" do - page = FactoryGirl.create(:action_page) + page = FactoryBot.create(:action_page) clone = described_class.run(page) expect(clone.save).to be(true) end shared_examples "properly duplicates campaign" do |enable_mthd, model| let(:page) do - FactoryGirl.create(:action_page, enable_mthd => true, - model => FactoryGirl.create(model)) + FactoryBot.create(:action_page, enable_mthd => true, + model => FactoryBot.create(model)) end let(:clone) { described_class.run(page) } it "does not persist" do diff --git a/spec/lib/congress_forms_spec.rb b/spec/lib/congress_forms_spec.rb index f6293b7c3..b394a3463 100644 --- a/spec/lib/congress_forms_spec.rb +++ b/spec/lib/congress_forms_spec.rb @@ -42,7 +42,7 @@ it "posts to the congress forms API" do stub_request(:post, /fill-out-form/) .and_return(status: 200, body: "{}") - campaign = FactoryGirl.build(:congress_message_campaign) + campaign = FactoryBot.build(:congress_message_campaign) form.fill(input, campaign.campaign_tag) expect(WebMock).to have_requested(:post, /fill-out-form/) .with(body: { bio_id: "C000880", fields: input, diff --git a/spec/models/ahoy/event_spec.rb b/spec/models/ahoy/event_spec.rb index 6b00eddda..633cfc182 100644 --- a/spec/models/ahoy/event_spec.rb +++ b/spec/models/ahoy/event_spec.rb @@ -3,7 +3,7 @@ describe Ahoy::Event do describe "#types" do it "returns event types for an action" do - action_page = FactoryGirl.create(:action_page_with_tweet) + action_page = FactoryBot.create(:action_page_with_tweet) expect(Ahoy::Event.action_types(action_page)).to eq(%i[views tweets]) end end @@ -11,16 +11,16 @@ describe "calculations" do let!(:now) { Time.zone.parse("12-11-2019 11:00 AM") } let!(:page) do - FactoryGirl.create(:action_page_with_petition, + FactoryBot.create(:action_page_with_petition, created_at: now - 1.week, updated_at: now) end before(:each) do - FactoryGirl.create_list(:ahoy_view, 3, + FactoryBot.create_list(:ahoy_view, 3, action_page: page, time: now - 3.days) - FactoryGirl.create_list(:ahoy_view, 2, + FactoryBot.create_list(:ahoy_view, 2, action_page: page, time: now + 1.hour) - FactoryGirl.create(:ahoy_signature, action_page: page, time: now + 2.hours) - FactoryGirl.create(:ahoy_signature, action_page: page, time: now - 2.days) + FactoryBot.create(:ahoy_signature, action_page: page, time: now + 2.hours) + FactoryBot.create(:ahoy_signature, action_page: page, time: now - 2.days) page.reload end diff --git a/spec/models/congress_message_spec.rb b/spec/models/congress_message_spec.rb index 55b0d1dcd..b6b0a57ba 100644 --- a/spec/models/congress_message_spec.rb +++ b/spec/models/congress_message_spec.rb @@ -2,7 +2,7 @@ describe CongressMessage do subject do - FactoryGirl.build(:congress_message) + FactoryBot.build(:congress_message) end describe "#common_fields" do diff --git a/spec/models/petition_spec.rb b/spec/models/petition_spec.rb index 6c30b7923..496ac035a 100644 --- a/spec/models/petition_spec.rb +++ b/spec/models/petition_spec.rb @@ -14,7 +14,7 @@ end it "should output useful CSV files" do - p = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) + p = FactoryBot.create(:petition_complete_with_one_hundred_signatures) expected_first_record = "John Doe,#{p.signatures.order(:id).first.email},"\ "San Francisco,CA,United States of America\n" csv = p.signatures.to_presentable_csv diff --git a/spec/queries/action_page_filters_spec.rb b/spec/queries/action_page_filters_spec.rb index 5f984330c..ed7042b88 100644 --- a/spec/queries/action_page_filters_spec.rb +++ b/spec/queries/action_page_filters_spec.rb @@ -2,19 +2,19 @@ describe ActionPageFilters do it "returns only actions matching the given filters" do - category = FactoryGirl.create(:category) - basic = FactoryGirl.create(:action_page) - category_action = FactoryGirl.create(:action_page, + category = FactoryBot.create(:category) + basic = FactoryBot.create(:action_page) + category_action = FactoryBot.create(:action_page, enable_tweet: true, category: category) - draft_old = FactoryGirl.create(:action_page, + draft_old = FactoryBot.create(:action_page, enable_tweet: true, published: false, created_at: Time.zone.today - 7.days) - authored_old = FactoryGirl.create(:action_page, + authored_old = FactoryBot.create(:action_page, enable_tweet: true, created_at: Time.zone.today - 7.days, - author: FactoryGirl.create(:user), + author: FactoryBot.create(:user), category: category) new_date_range = "#{Time.zone.today - 3.days} - #{Time.zone.today}" @@ -32,10 +32,10 @@ end it "does not filter when values are blank or 'all'" do - FactoryGirl.create(:action_page) - FactoryGirl.create(:action_page, enable_tweet: true, - category: FactoryGirl.create(:category)) - FactoryGirl.create(:action_page, enable_tweet: true, published: false, + FactoryBot.create(:action_page) + FactoryBot.create(:action_page, enable_tweet: true, + category: FactoryBot.create(:category)) + FactoryBot.create(:action_page, enable_tweet: true, published: false, created_at: Time.zone.today - 7.days) result = described_class.run(category: "all", type: "", status: "all", author: "", date_range: "") diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb index 2b165d9fb..efc632572 100644 --- a/spec/requests/admin/users_spec.rb +++ b/spec/requests/admin/users_spec.rb @@ -2,14 +2,14 @@ RSpec.describe "Admin Users", type: :request do before(:each) do - admin = FactoryGirl.create(:admin_user) + admin = FactoryBot.create(:admin_user) login admin end describe "#index" do before do 10.times do |n| - FactoryGirl.create(:user, created_at: Time.zone.now - n.days, email: "user-#{n}@example.com") + FactoryBot.create(:user, created_at: Time.zone.now - n.days, email: "user-#{n}@example.com") end end diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index 9f043e0d0..9602892c9 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -2,12 +2,12 @@ RSpec.describe "Congress Messages", type: :request do let!(:members) do - [FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "C000880"), - FactoryGirl.create(:congress_member, state: "CA", bioguide_id: "A000360")] + [FactoryBot.create(:congress_member, state: "CA", bioguide_id: "C000880"), + FactoryBot.create(:congress_member, state: "CA", bioguide_id: "A000360")] end let(:action_page) do - FactoryGirl.create(:action_page_with_congress_message) + FactoryBot.create(:action_page_with_congress_message) end let(:location) do @@ -73,7 +73,7 @@ def get_congress_message_form # rubocop:todo Naming/AccessorMethodName end it "to target bioguide_ids" do - campaign = FactoryGirl.create(:congress_message_campaign, :targeting_bioguide_ids) + campaign = FactoryBot.create(:congress_message_campaign, :targeting_bioguide_ids) # rubocop:todo Rails/SkipsModelValidations action_page.update_attribute(:congress_message_campaign, campaign) # rubocop:enable Rails/SkipsModelValidations @@ -84,7 +84,7 @@ def get_congress_message_form # rubocop:todo Naming/AccessorMethodName it "to target a single chamber" do members.last.update(chamber: "house", district: 10) - campaign = FactoryGirl.create(:congress_message_campaign, :targeting_senate) + campaign = FactoryBot.create(:congress_message_campaign, :targeting_senate) # rubocop:todo Rails/SkipsModelValidations action_page.update_attribute(:congress_message_campaign, campaign) # rubocop:enable Rails/SkipsModelValidations diff --git a/spec/tasks/signatures_spec.rb b/spec/tasks/signatures_spec.rb index cf1485752..e22c5b3f2 100644 --- a/spec/tasks/signatures_spec.rb +++ b/spec/tasks/signatures_spec.rb @@ -11,9 +11,9 @@ after { Rake.application["signatures:deduplicate"].reenable } it "should delete signatures with non-unique emails from petitions" do - regular_petition = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) + regular_petition = FactoryBot.create(:petition_complete_with_one_hundred_signatures) - petition_with_dups = FactoryGirl.create(:petition_complete_with_one_hundred_signatures) + petition_with_dups = FactoryBot.create(:petition_complete_with_one_hundred_signatures) # rubocop:todo Rails/SkipsModelValidations petition_with_dups.signatures.take(20).each { |sig| sig.update_column(:email, "dup1@example.com") } # rubocop:enable Rails/SkipsModelValidations @@ -35,18 +35,18 @@ end context "with duplicate subscriptions" do - let(:subscription) { FactoryGirl.create(:subscription) } + let(:subscription) { FactoryBot.create(:subscription) } let(:email) { subscription.email } let(:partner) { subscription.partner } let!(:owner_subscription2) do - FactoryGirl.create(:subscription, email: email) + FactoryBot.create(:subscription, email: email) end let!(:partner_subscription2) do - FactoryGirl.create(:subscription, partner: partner) + FactoryBot.create(:subscription, partner: partner) end let!(:dup_subscription) do - FactoryGirl.create(:subscription) - .update_columns(email: email, partner_id: partner.id) + FactoryBot.create(:subscription) + .update_columns(email: email, partner_id: partner.id) end it "removes the newer duplicates" do From d2ec3f5d2eceb5d61044bd172f46d10ab8efa1ef Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 16 Feb 2021 15:30:09 -0800 Subject: [PATCH 015/113] Fix pgsearch deprecations --- app/models/action_page.rb | 2 +- app/models/institution.rb | 2 +- app/models/user.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/action_page.rb b/app/models/action_page.rb index f3b0ef0df..f36978546 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -2,7 +2,7 @@ class ActionPage < ActiveRecord::Base extend AmazonCredentials extend FriendlyId - include PgSearch + include PgSearch::Model pg_search_scope :search, against: %i[ title diff --git a/app/models/institution.rb b/app/models/institution.rb index e8bc393a9..917b51993 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -4,7 +4,7 @@ class Institution < ActiveRecord::Base friendly_id :name, use: %i[slugged history] - include PgSearch + include PgSearch::Model pg_search_scope :search, against: %i[ name diff --git a/app/models/user.rb b/app/models/user.rb index fbc45c175..62a8fb9c1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,7 @@ class User < ActiveRecord::Base include CiviCRM::UserMethods - include PgSearch + include PgSearch::Model pg_search_scope :search, against: %i[email first_name last_name] # Include default devise modules. Others available are: From db28908cf286750f19e17b4d91af05072203586d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 16 Feb 2021 15:32:37 -0800 Subject: [PATCH 016/113] Remove user percentile rank tracking --- app/models/user.rb | 13 ------------- app/views/users/show.html.erb | 3 --- spec/models/user_spec.rb | 5 ----- 3 files changed, 21 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 62a8fb9c1..61c822dff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,19 +67,6 @@ def display_name email end - def percentile_rank - user_action_counts = Rails.cache.fetch("user_action_counts", expires_in: 24.hours) do - User.select("users.id, count(ahoy_events.id) AS events_count") - .joins("LEFT OUTER JOIN ahoy_events ON ahoy_events.user_id = users.id") - .where("ahoy_events.name IS null OR ahoy_events.name = ?", "Action") - .group("users.id") - .map(&:events_count) - end - - user_count = events.actions.count - user_action_counts.percentile_rank(user_count - 1).round(0) - end - def signed?(petition) return false unless record_activity? diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 8dbecfe5e..47f421023 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -37,9 +37,6 @@ <% if current_user.record_activity? %>

Stats

-
-

You are in the <%= current_user.percentile_rank.ordinalize %> percentile of users.

-

Actions you've taken so far:

diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7dbb9f2bf..afea29ec0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -57,11 +57,6 @@ expect(user.taken_action?(action_page)).to be_truthy end - - it "ranks users" do - record_several_actions - expect(user.percentile_rank).to eq(50) - end end end From fb474780675d6a6a72d572147b36e9d654b71ba7 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Tue, 16 Feb 2021 16:01:14 -0800 Subject: [PATCH 017/113] Fix failing tests --- app/controllers/action_page_controller.rb | 7 +++---- app/models/user.rb | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/action_page_controller.rb b/app/controllers/action_page_controller.rb index 7db6a2c2d..aca565055 100644 --- a/app/controllers/action_page_controller.rb +++ b/app/controllers/action_page_controller.rb @@ -87,10 +87,9 @@ def redirect_to_specified_url end def redirect_from_archived_to_active_action - if @actionPage.redirect_from_archived_to_active_action? && !current_user && (current_user.taken_action?(@actionPage) || current_user.admin?) - # Users can access actions they've taken in the past as a historical record - redirect_to @actionPage.active_action_page_for_redirect - end + return unless @actionPage.redirect_from_archived_to_active_action? + return if current_user && current_user.can_view_archived?(@actionPage) + redirect_to @actionPage.active_action_page_for_redirect end def redirect_to_cannonical_slug diff --git a/app/models/user.rb b/app/models/user.rb index 61c822dff..2d35ce645 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -120,6 +120,11 @@ def send_password_change_notification? confirmed? && super end + def can_view_archived?(action_page) + return true if admin? + taken_action? action_page + end + protected def after_confirmation From 9ecfc7d2fcd031ca70c546acc23c36a60ab355b6 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 17 Feb 2021 17:11:50 -0800 Subject: [PATCH 018/113] More rubocop autofixes --- app/controllers/action_page_controller.rb | 3 ++- .../congress_messages_controller.rb | 4 ++-- app/controllers/tools_controller.rb | 2 +- app/helpers/action_page_helper.rb | 6 ++--- app/helpers/application_helper.rb | 2 +- app/models/ahoy/event.rb | 5 +++-- app/models/congress_message.rb | 9 ++++++-- app/models/tweet_target.rb | 4 ++-- app/models/user.rb | 1 + lib/amazon_credentials.rb | 2 +- lib/congress_forms.rb | 9 ++++---- lib/tasks/signatures.rake | 2 +- .../action_page_controller_spec.rb | 18 +++++++-------- .../admin/petitions_controller_spec.rb | 2 +- spec/factories/action_page.rb | 4 ++-- spec/factories/petitions.rb | 2 +- .../action_pages/congress_action_spec.rb | 4 ++-- .../action_pages/tweet_action_spec.rb | 4 ++-- spec/features/congress_message.rb | 6 ++--- spec/lib/action_cloner_spec.rb | 2 +- spec/models/ahoy/event_spec.rb | 6 ++--- spec/models/user_spec.rb | 4 ++-- spec/queries/action_page_filters_spec.rb | 22 +++++++++---------- 23 files changed, 65 insertions(+), 58 deletions(-) diff --git a/app/controllers/action_page_controller.rb b/app/controllers/action_page_controller.rb index aca565055..fd6db0b6e 100644 --- a/app/controllers/action_page_controller.rb +++ b/app/controllers/action_page_controller.rb @@ -88,7 +88,8 @@ def redirect_to_specified_url def redirect_from_archived_to_active_action return unless @actionPage.redirect_from_archived_to_active_action? - return if current_user && current_user.can_view_archived?(@actionPage) + return if current_user&.can_view_archived?(@actionPage) + redirect_to @actionPage.active_action_page_for_redirect end diff --git a/app/controllers/congress_messages_controller.rb b/app/controllers/congress_messages_controller.rb index b31429683..6b8976753 100644 --- a/app/controllers/congress_messages_controller.rb +++ b/app/controllers/congress_messages_controller.rb @@ -39,7 +39,7 @@ def create end @message.forms, = CongressForms::Form.find(bioguide_ids) - if EmailValidator.valid?(user_params[:email]) && @message.background_submit(params[:test]) + if EmailValidator.valid?(user_params[:email]) && @message.background_submit(test: params[:test]) @name = user_params[:first_name] # for deliver_thanks_message @email = user_params[:email] # for deliver_thanks_message track_action unless params[:test] @@ -91,7 +91,7 @@ def subscribe_user create_partner_subscription if params[:subscribe] == "1" - source = "action center congress message :: " + @action_page.title + source = "action center congress message :: #{@action_page.title}" user = User.find_or_initialize_by(email: user_params[:email]) user.attributes = user_params user.subscribe!(opt_in: false, source: source)["requires_confirmation"] diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index 1b62da3e8..a0faec35a 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -73,7 +73,7 @@ def petition :zipcode, :country_code, :phone ) - @source = "action center petition :: " + @action_page.title + @source = "action center petition :: #{@action_page.title}" @user.subscribe!(opt_in: true, source: @source) end diff --git a/app/helpers/action_page_helper.rb b/app/helpers/action_page_helper.rb index 7248de14b..aba5e4848 100644 --- a/app/helpers/action_page_helper.rb +++ b/app/helpers/action_page_helper.rb @@ -19,10 +19,8 @@ def tweet_url(target, message) end def facebook_share_url(action_page) - "https://www.facebook.com/sharer/sharer.php?" + { - u: action_page_url(action_page), - display: "popup" - }.to_param + fb_params = { u: action_page_url(action_page), display: "popup" }.to_param + "https://www.facebook.com/sharer/sharer.php?#{fb_params}" end def email_friends_url(action_page) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1fd886bdf..740af86b6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,7 +9,7 @@ def escape_page_title end def twitter_handle - "@" + Rails.application.config.twitter_handle.to_s + "@#{Rails.application.config.twitter_handle}" end def markdown(blogtext) diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb index 6c1c3b215..b2dde3b46 100644 --- a/app/models/ahoy/event.rb +++ b/app/models/ahoy/event.rb @@ -6,9 +6,10 @@ class Event < ActiveRecord::Base belongs_to :user belongs_to :action_page counter_culture :action_page, column_name: proc { |record| - if record.name == "Action" + case record.name + when "Action" "action_count" - elsif record.name == "View" + when "View" "view_count" end } diff --git a/app/models/congress_message.rb b/app/models/congress_message.rb index 7b1c33c26..6e4602767 100644 --- a/app/models/congress_message.rb +++ b/app/models/congress_message.rb @@ -65,8 +65,13 @@ def attributes_for(bioguide_id) common_attributes.merge(member_attributes[bioguide_id]) end - def background_submit(test = false) - @forms.each { |f| f.delay.fill(attributes_for(f.bioguide_id), campaign.campaign_tag, test) } if valid? + def background_submit(test: false) + return unless valid? + + @forms.each do |f| + f.delay.fill(attributes_for(f.bioguide_id), campaign.campaign_tag, + test: test) + end end def update_common_attributes(**attrs) diff --git a/app/models/tweet_target.rb b/app/models/tweet_target.rb index 53489eca9..260c74bf1 100644 --- a/app/models/tweet_target.rb +++ b/app/models/tweet_target.rb @@ -9,7 +9,7 @@ class TweetTarget < ActiveRecord::Base after_save :attach_twitter_image def url - "https://twitter.com/" + twitter_id + "https://twitter.com/#{twitter_id}" end delegate :url, to: :image, prefix: true @@ -22,7 +22,7 @@ def attach_twitter_image_without_delay access_token = Twitter.prepare_access_token Rails.application.secrets.twitter_oauth_token, Rails.application.secrets.twitter_oauth_token_secret # ref: https://dev.twitter.com/overview/general/user-profile-images-and-banners - response = access_token.request(:get, "https://api.twitter.com/1.1/users/show.json?screen_name=" + twitter_id) + response = access_token.request(:get, "https://api.twitter.com/1.1/users/show.json?screen_name=#{twitter_id}") user_info = JSON.parse response.body user_image_url = user_info["profile_image_url_https"].gsub(/_normal\./, "_bigger.") diff --git a/app/models/user.rb b/app/models/user.rb index 2d35ce645..bf6a1ae62 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -122,6 +122,7 @@ def send_password_change_notification? def can_view_archived?(action_page) return true if admin? + taken_action? action_page end diff --git a/lib/amazon_credentials.rb b/lib/amazon_credentials.rb index 5363d8ea1..bec9750f7 100644 --- a/lib/amazon_credentials.rb +++ b/lib/amazon_credentials.rb @@ -29,6 +29,6 @@ def build_s3_host_name end def self.build_s3_host_name - "s3-" + Rails.application.secrets.amazon_region + ".amazonaws.com" + "s3-#{Rails.application.secrets.amazon_region}.amazonaws.com" end end diff --git a/lib/congress_forms.rb b/lib/congress_forms.rb index 732637a72..d99023830 100644 --- a/lib/congress_forms.rb +++ b/lib/congress_forms.rb @@ -26,7 +26,7 @@ def order_fields @fields = @fields.sort_by { |f| order.index(f.value) || Float::INFINITY } end - def fill(input, campaign_tag, test = false) + def fill(input, campaign_tag, test: false) params = { bio_id: @bioguide_id, campaign_tag: campaign_tag, fields: input } params[:test] = 1 if test CongressForms.post("/fill-out-form/", params) @@ -74,9 +74,10 @@ def hash end def options_hash - if @value == "$ADDRESS_STATE_POSTAL_ABBREV" + case @value + when "$ADDRESS_STATE_POSTAL_ABBREV" Places.us_state_codes - elsif @value == "$ADDRESS_STATE_FULL" + when "$ADDRESS_STATE_FULL" Places.us_states else @options_hash @@ -113,7 +114,7 @@ def self.date_fills(*args) def self.data_path(base_path, params = {}, bioguide_id = nil) base_path += bioguide_id unless bioguide_id.nil? - base_path + "?" + { + "#{base_path}?" + { debug_key: Rails.application.secrets.congress_forms_debug_key }.merge(params).to_query end diff --git a/lib/tasks/signatures.rake b/lib/tasks/signatures.rake index 115061d31..b8eebb6c2 100644 --- a/lib/tasks/signatures.rake +++ b/lib/tasks/signatures.rake @@ -25,7 +25,7 @@ namespace :signatures do end.compact sig_dups.each do |email, petition_id| Signature.where(petition_id: petition_id, email: email) - .order(:created_at).drop(1).map(&:delete) + .order(:created_at).drop(1).map(&:delete) end sub_dups = Subscription.group(:email, :partner_id).count.map do |data, count| diff --git a/spec/controllers/action_page_controller_spec.rb b/spec/controllers/action_page_controller_spec.rb index e581a90b7..fc112c341 100644 --- a/spec/controllers/action_page_controller_spec.rb +++ b/spec/controllers/action_page_controller_spec.rb @@ -43,8 +43,8 @@ it "redirects to an admin specified url if redirect is enabled" do action_page = FactoryBot.create :action_page, - enable_redirect: true, - redirect_url: "https://example.com" + enable_redirect: true, + redirect_url: "https://example.com" get :show, params: { id: action_page } expect(response).to redirect_to "https://example.com" end @@ -53,7 +53,7 @@ let(:active_action_page) { FactoryBot.create :action_page } let(:archived_action_page) do FactoryBot.create :archived_action_page, - active_action_page_for_redirect: active_action_page + active_action_page_for_redirect: active_action_page end it "redirects archived actions to active actions" do @@ -100,18 +100,18 @@ # Signature with affiliations to two different institutions signature = FactoryBot.create(:signature, - petition: @petition) + petition: @petition) signature.affiliations << FactoryBot.create(:affiliation, - institution: @actionPage.institutions.first) + institution: @actionPage.institutions.first) signature.affiliations << FactoryBot.create(:affiliation, - institution: @actionPage.institutions.last) + institution: @actionPage.institutions.last) # Signature with an affiliation to the second institutions signature = FactoryBot.create(:signature, - petition: @petition) + petition: @petition) signature.affiliations << FactoryBot.create(:affiliation, - institution: @actionPage.institutions.last, - affiliation_type: @actionPage.affiliation_types.first) + institution: @actionPage.institutions.last, + affiliation_type: @actionPage.affiliation_types.first) end context "html" do diff --git a/spec/controllers/admin/petitions_controller_spec.rb b/spec/controllers/admin/petitions_controller_spec.rb index 587f9e910..e66241c74 100644 --- a/spec/controllers/admin/petitions_controller_spec.rb +++ b/spec/controllers/admin/petitions_controller_spec.rb @@ -38,7 +38,7 @@ end it "should delete signatures from the signature_ids param" do - delete :destroy_signatures, params: { id: petition.id, signature_ids: signatures[10..-1].map(&:id) } + delete :destroy_signatures, params: { id: petition.id, signature_ids: signatures[10..].map(&:id) } expect(petition.signatures.reload).to contain_exactly(*signatures[0..9]) expect(response).to redirect_to(admin_action_page_petition_path(petition.action_page, petition)) end diff --git a/spec/factories/action_page.rb b/spec/factories/action_page.rb index 0cd2dddb5..f79f03795 100644 --- a/spec/factories/action_page.rb +++ b/spec/factories/action_page.rb @@ -45,8 +45,8 @@ after(:build) do |action_page, _evaluator| 10.times do |n| FactoryBot.create(:ahoy_view, - action_page: action_page, - time: Time.zone.now - n.days) + action_page: action_page, + time: Time.zone.now - n.days) end end end diff --git a/spec/factories/petitions.rb b/spec/factories/petitions.rb index e8278796f..0249666e1 100644 --- a/spec/factories/petitions.rb +++ b/spec/factories/petitions.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :petition do - sequence(:title) { |n| "petition-#{n}" } + sequence(:title) { |n| "petition-#{n}" } description { "A sample Petition" } goal { 100 } diff --git a/spec/features/action_pages/congress_action_spec.rb b/spec/features/action_pages/congress_action_spec.rb index 2b32a742d..8f6fb197f 100644 --- a/spec/features/action_pages/congress_action_spec.rb +++ b/spec/features/action_pages/congress_action_spec.rb @@ -6,8 +6,8 @@ end let!(:members) do [FactoryBot.create(:congress_member, - twitter_id: "sisko", - state: "CA", bioguide_id: "C000880"), + twitter_id: "sisko", + state: "CA", bioguide_id: "C000880"), FactoryBot.create(:congress_member, state: "CA", bioguide_id: "A000360")] end let(:location) do diff --git a/spec/features/action_pages/tweet_action_spec.rb b/spec/features/action_pages/tweet_action_spec.rb index 6a4c5133e..4f177ab89 100644 --- a/spec/features/action_pages/tweet_action_spec.rb +++ b/spec/features/action_pages/tweet_action_spec.rb @@ -6,8 +6,8 @@ end let!(:members) do [FactoryBot.create(:congress_member, - twitter_id: "sisko", - state: "CA", bioguide_id: "C000880"), + twitter_id: "sisko", + state: "CA", bioguide_id: "C000880"), FactoryBot.create(:congress_member, state: "CA", bioguide_id: "A000360")] end let(:location) do diff --git a/spec/features/congress_message.rb b/spec/features/congress_message.rb index 2dae3e5e3..e227c72ec 100644 --- a/spec/features/congress_message.rb +++ b/spec/features/congress_message.rb @@ -59,9 +59,9 @@ scenario "Logged in user submits a congress message" do giles = FactoryBot.create(:user, - first_name: "Rupert", - last_name: "Giles", - email: "mrgiles@sunnydale.edu") + first_name: "Rupert", + last_name: "Giles", + email: "mrgiles@sunnydale.edu") sign_in_user(giles) visit "/action/#{action_page.title.downcase.tr(' ', '-')}" diff --git a/spec/lib/action_cloner_spec.rb b/spec/lib/action_cloner_spec.rb index 6c02360db..f7942e91b 100644 --- a/spec/lib/action_cloner_spec.rb +++ b/spec/lib/action_cloner_spec.rb @@ -46,7 +46,7 @@ shared_examples "properly duplicates campaign" do |enable_mthd, model| let(:page) do FactoryBot.create(:action_page, enable_mthd => true, - model => FactoryBot.create(model)) + model => FactoryBot.create(model)) end let(:clone) { described_class.run(page) } it "does not persist" do diff --git a/spec/models/ahoy/event_spec.rb b/spec/models/ahoy/event_spec.rb index 633cfc182..60203874e 100644 --- a/spec/models/ahoy/event_spec.rb +++ b/spec/models/ahoy/event_spec.rb @@ -12,13 +12,13 @@ let!(:now) { Time.zone.parse("12-11-2019 11:00 AM") } let!(:page) do FactoryBot.create(:action_page_with_petition, - created_at: now - 1.week, updated_at: now) + created_at: now - 1.week, updated_at: now) end before(:each) do FactoryBot.create_list(:ahoy_view, 3, - action_page: page, time: now - 3.days) + action_page: page, time: now - 3.days) FactoryBot.create_list(:ahoy_view, 2, - action_page: page, time: now + 1.hour) + action_page: page, time: now + 1.hour) FactoryBot.create(:ahoy_signature, action_page: page, time: now + 2.hours) FactoryBot.create(:ahoy_signature, action_page: page, time: now - 2.days) page.reload diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index afea29ec0..da827928e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -18,7 +18,7 @@ describe "password management" do it "resets password reset tokens upon email change" do user.update(reset_password_token: "stub_token") - user.update(email: "2" + user.email) + user.update(email: "2#{user.email}") user.confirm expect(user.reset_password_token).to be_nil end @@ -70,7 +70,7 @@ def record_several_actions # a user with 1 action ahoy.authenticate(FactoryBot.create(:user, record_activity: true)) - 1.times { track_signature(action_page) } + track_signature(action_page) # our friend, with 2 actions ahoy.authenticate(user) diff --git a/spec/queries/action_page_filters_spec.rb b/spec/queries/action_page_filters_spec.rb index ed7042b88..0a77dc922 100644 --- a/spec/queries/action_page_filters_spec.rb +++ b/spec/queries/action_page_filters_spec.rb @@ -5,17 +5,17 @@ category = FactoryBot.create(:category) basic = FactoryBot.create(:action_page) category_action = FactoryBot.create(:action_page, - enable_tweet: true, - category: category) + enable_tweet: true, + category: category) draft_old = FactoryBot.create(:action_page, - enable_tweet: true, - published: false, - created_at: Time.zone.today - 7.days) + enable_tweet: true, + published: false, + created_at: Time.zone.today - 7.days) authored_old = FactoryBot.create(:action_page, - enable_tweet: true, - created_at: Time.zone.today - 7.days, - author: FactoryBot.create(:user), - category: category) + enable_tweet: true, + created_at: Time.zone.today - 7.days, + author: FactoryBot.create(:user), + category: category) new_date_range = "#{Time.zone.today - 3.days} - #{Time.zone.today}" result = described_class.run(category: category) @@ -34,9 +34,9 @@ it "does not filter when values are blank or 'all'" do FactoryBot.create(:action_page) FactoryBot.create(:action_page, enable_tweet: true, - category: FactoryBot.create(:category)) + category: FactoryBot.create(:category)) FactoryBot.create(:action_page, enable_tweet: true, published: false, - created_at: Time.zone.today - 7.days) + created_at: Time.zone.today - 7.days) result = described_class.run(category: "all", type: "", status: "all", author: "", date_range: "") expect(result.size).to eq(3) From 1b33d8da15f9cd11f040b00df8d17ed3074c94cc Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 17 Feb 2021 17:48:53 -0800 Subject: [PATCH 019/113] Remove webshims-rails --- Dockerfile | 1 - Gemfile | 1 - lib/tasks/webshims_asset_compile.rake | 40 --------------------------- 3 files changed, 42 deletions(-) delete mode 100644 lib/tasks/webshims_asset_compile.rake diff --git a/Dockerfile b/Dockerfile index a70db219e..590eaee50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,7 +66,6 @@ RUN bundle exec rake assets:precompile \ devise_secret_key=noop \ amazon_region=noop \ DATABASE_URL=postgres://noop -RUN bundle exec rake webshims:update_public RUN mkdir /opt/actioncenter/log \ /var/www diff --git a/Gemfile b/Gemfile index 3c9dc360d..3b25d666d 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,6 @@ gem "redcarpet", "~> 3" # Markdown gem "sass-rails", "< 5.1" gem "select2-rails" # Autocomplete select menus gem "uglifier", ">= 1.3.0" # compressor for JavaScript assets -gem "webshims-rails", "~> 1" source "https://rails-assets.org" do gem "rails-assets-chartjs", "~> 2" gem "rails-assets-congress-images-102x125" diff --git a/lib/tasks/webshims_asset_compile.rake b/lib/tasks/webshims_asset_compile.rake deleted file mode 100644 index b4368efa8..000000000 --- a/lib/tasks/webshims_asset_compile.rake +++ /dev/null @@ -1,40 +0,0 @@ -# Rails4 doesn't create un-fingerprinted assets anymore, but we -# need a couple for webshims inclusion. Let's try to hook in and make -# symlinks. - -require "pathname" - -# Every time assets:precompile is called, trigger webshims:create_non_digest_assets afterwards. -Rake::Task["assets:precompile"].enhance do - Rake::Task["webshims:create_non_digest_assets"].invoke -end - -namespace :webshims do - # This seems to be basically how ordinary asset precompile - # is logging, ugh. - logger = Logger.new($stderr) - - # Based on suggestion at https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134 - # but limited to files in webshims namespaced asset directories. - task create_non_digest_assets: :"assets:environment" do - manifest_path = Dir.glob(File.join(Rails.root, "public/assets/.sprockets-manifest-*.json")).first - manifest_data = JSON.load(File.new(manifest_path)) # rubocop:disable Security/JSONLoad - - manifest_data["assets"].each do |logical_path, digested_path| - logical_pathname = Pathname.new logical_path - - next unless ["webshims/**/*"].any? { |testpath| logical_pathname.fnmatch?(testpath, File::FNM_PATHNAME) } - - full_digested_path = Rails.root.join("public/assets", digested_path) - full_nondigested_path = Rails.root.join("public/assets", logical_path) - - logger.info "(Webshims) Copying to #{full_nondigested_path}" - - # Use FileUtils.copy_file with true third argument to copy - # file attributes (eg mtime) too, as opposed to FileUtils.cp - # Making symlnks with FileUtils.ln_s would be another option, not - # sure if it would have unexpected issues. - FileUtils.copy_file full_digested_path, full_nondigested_path, true - end - end -end From 69be8996f3e95556054084659e1b0ef6be67e68f Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 17 Feb 2021 17:58:51 -0800 Subject: [PATCH 020/113] Remove rails_12factor --- Gemfile | 1 - config/environments/production.rb | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 3b25d666d..c79b5eae0 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,6 @@ gem "aws-sdk-rails", "~> 2" gem "aws-sdk-s3", "~> 1" gem "dotenv-rails", "~> 2" gem "rack-attack", "~> 5" -gem "rails_12factor", group: :production # Loads "rails_serve_static_assets" and "rails_stdout_logging" gem "rails_response_headers", "~> 0" # Frontend/assets diff --git a/config/environments/production.rb b/config/environments/production.rb index 450d29783..e73100d1c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -58,7 +58,9 @@ # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - config.logger = Logger.new STDOUT + logger = ActiveSupport::Logger.new STDOUT + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) # Use a different cache store in production. # config.cache_store = :mem_cache_store From 46306b9eb50d2279f8c4f4b1031ce1c55ccf7e9f Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 17 Feb 2021 18:00:11 -0800 Subject: [PATCH 021/113] Remove very old image compressor gem --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index c79b5eae0..b7bc4adfe 100644 --- a/Gemfile +++ b/Gemfile @@ -50,7 +50,6 @@ gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails # Optimization -gem "sprockets-image_compressor", "~> 0" # Optimizes png/jpg # Analytics gem "ahoy_matey", "~> 1.6" # Analytics From 3c38c8e13b7544b9610a57e641adc1235940d449 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 17 Feb 2021 18:02:58 -0800 Subject: [PATCH 022/113] Add missing gem version specifier --- Gemfile | 2 +- Gemfile.lock | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index b7bc4adfe..eb2fa11d7 100644 --- a/Gemfile +++ b/Gemfile @@ -89,7 +89,7 @@ gem "sanitize", "~> 4" # Sanitize user input gem "warden", "1.2.4" # This dep of devise has a bug in 1.2.5 so am avaoiding gem "whenever", "~> 0", require: false # Cron jobs gem "will_paginate", "~> 3.0" -gem "xmlrpc" +gem "xmlrpc", "~> 0.3" # For creating many records, quickly gem "fast_inserter", "~> 0.1" diff --git a/Gemfile.lock b/Gemfile.lock index 770c5e401..6ba70b630 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -310,12 +310,7 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - rails_12factor (0.0.3) - rails_serve_static_assets - rails_stdout_logging rails_response_headers (0.1.0) - rails_serve_static_assets (0.0.5) - rails_stdout_logging (0.0.5) railties (5.0.7.2) actionpack (= 5.0.7.2) activesupport (= 5.0.7.2) @@ -421,8 +416,6 @@ GEM sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-image_compressor (0.3.0) - sprockets sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) @@ -453,8 +446,6 @@ GEM crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) webrick (1.7.0) - webshims-rails (1.16.0) - rails (> 3.1.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -532,7 +523,6 @@ DEPENDENCIES rails-assets-sweetalert (= 1.0.1)! rails-controller-testing rails-dev-tweaks (~> 1.1) - rails_12factor rails_response_headers (~> 0) rb-fchange (~> 0) rb-fsevent (~> 0) @@ -551,15 +541,13 @@ DEPENDENCIES sdoc select2-rails sentry-raven (~> 0.15) - sprockets-image_compressor (~> 0) uglifier (>= 1.3.0) warden (= 1.2.4) webdrivers (~> 4) webmock (~> 3) - webshims-rails (~> 1) whenever (~> 0) will_paginate (~> 3.0) - xmlrpc + xmlrpc (~> 0.3) BUNDLED WITH 2.1.4 From 30eb4ef65ee6562cb6740d568beae592537c5a88 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 19 Feb 2021 12:05:12 -0800 Subject: [PATCH 023/113] Cleanup Gemfile --- Gemfile | 5 +---- Gemfile.lock | 9 --------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index eb2fa11d7..e0f4da434 100644 --- a/Gemfile +++ b/Gemfile @@ -49,10 +49,8 @@ gem "kt-paperclip", "~> 6" gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails -# Optimization - # Analytics -gem "ahoy_matey", "~> 1.6" # Analytics +gem "ahoy_matey", "~> 1.6" gem "chartkick", "~> 3" gem "eff_matomo", "~> 0.2.4", require: "matomo" gem "groupdate", "~> 2" @@ -125,7 +123,6 @@ group :development, :test do gem "rubocop-github", "~> 0.16" gem "rubocop-performance", require: false gem "rubocop-rails", require: false - gem "webdrivers", "~> 4" end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index 6ba70b630..bbbe5f7c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,7 +121,6 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) chartkick (3.4.2) - childprocess (3.0.0) chronic (0.10.2) climate_control (0.2.0) cocoon (1.2.15) @@ -408,9 +407,6 @@ GEM sdoc (2.0.3) rdoc (>= 5.0) select2-rails (4.0.13) - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) - rubyzip (>= 1.2.2) sentry-raven (0.15.6) faraday (>= 0.7.6) sprockets (3.7.2) @@ -437,10 +433,6 @@ GEM uuidtools (2.2.0) warden (1.2.4) rack (>= 1.0) - webdrivers (4.5.0) - nokogiri (~> 1.6) - rubyzip (>= 1.3.0) - selenium-webdriver (>= 3.0, < 4.0) webmock (3.11.2) addressable (>= 2.3.6) crack (>= 0.3.2) @@ -543,7 +535,6 @@ DEPENDENCIES sentry-raven (~> 0.15) uglifier (>= 1.3.0) warden (= 1.2.4) - webdrivers (~> 4) webmock (~> 3) whenever (~> 0) will_paginate (~> 3.0) From 26aba5cb0a869b282502d871fcd20805e4a6b372 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 19 Feb 2021 12:07:08 -0800 Subject: [PATCH 024/113] Disable new rubocop cops for now --- .rubocop.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop.yml b/.rubocop.yml index bf629009b..127c7d926 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,6 +8,7 @@ inherit_gem: AllCops: TargetRailsVersion: 5.0 TargetRubyVersion: 2.7 + NewCops: disable Exclude: - 'db/**/*' - 'config/**/*' From db2c61eccd55291f583415a099e9227764831094 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 19 Feb 2021 16:17:42 -0800 Subject: [PATCH 025/113] Fix some deprecations --- app/controllers/action_page_controller.rb | 4 ++-- app/controllers/admin/topic_categories_controller.rb | 2 +- app/controllers/admin/topic_sets_controller.rb | 2 +- app/controllers/admin/topics_controller.rb | 2 +- app/controllers/robots_controller.rb | 8 ++++---- app/views/action_page/index.html.erb | 2 +- config/application.rb | 3 +-- config/environments/test.rb | 4 ++-- db/migrate/20140300000000_enable_extension_ossd.rb | 2 +- db/migrate/20140311235111_create_activities.rb | 2 +- db/migrate/20140313144408_create_action_pages.rb | 2 +- db/migrate/20140314020630_devise_create_users.rb | 2 +- db/migrate/20140317070243_add_userid_to_activities.rb | 2 +- .../20140317084144_add_action_pageid_to_activities.rb | 2 +- db/migrate/20140325050528_create_petitions.rb | 2 +- db/migrate/20140325050602_create_signatures.rb | 2 +- db/migrate/20140327210422_create_featured_action_pages.rb | 2 +- db/migrate/20140328161752_add_details_to_user.rb | 2 +- db/migrate/20140402190943_add_fields_to_signatures.rb | 2 +- .../20140402192811_add_petition_id_to_action_pages.rb | 2 +- .../20140403002100_add_photo_url_to_action_pages.rb | 2 +- db/migrate/20140403183138_add_admin_to_users.rb | 2 +- ...20140404223839_add_fields_for_tools_to_action_pages.rb | 2 +- db/migrate/20140409105241_add_slug_to_actionpage.rb | 2 +- db/migrate/20140409105530_create_friendly_id_slugs.rb | 2 +- db/migrate/20140410025404_add_address_to_signatures.rb | 2 +- db/migrate/20140410030958_add_address_to_users.rb | 2 +- db/migrate/20140410033413_add_goal_to_petition.rb | 2 +- db/migrate/20140416002624_add_anonymous_to_signatures.rb | 2 +- .../20140417021005_add_share_message_to_action_pages.rb | 2 +- db/migrate/20140423002336_create_tweets.rb | 2 +- db/migrate/20140423002432_add_tweets_to_action_pages.rb | 2 +- db/migrate/20140423202256_add_cta_to_tweet.rb | 2 +- db/migrate/20140424232842_add_bioguide_id_to_tweets.rb | 2 +- db/migrate/20140425215725_add_target_flags_to_tweets.rb | 2 +- .../20140429015127_add_published_to_action_pages.rb | 2 +- db/migrate/20140430110906_add_type_to_activities.rb | 2 +- db/migrate/20140501160413_create_call_tool_configs.rb | 2 +- ...20140502162820_add_call_campaign_id_to_action_pages.rb | 2 +- ...80222_add_attachment_featured_image_to_action_pages.rb | 2 +- .../20140505142843_add_what_to_say_to_action_pages.rb | 2 +- db/migrate/20140506161533_create_email_campaigns.rb | 2 +- ...0140506173759_add_email_campaign_id_to_action_pages.rb | 2 +- db/migrate/20140506214830_create_user_preferences.rb | 2 +- db/migrate/20140507002622_create_tweet_targets.rb | 2 +- db/migrate/20140508122428_fix_column_name.rb | 2 +- .../20140509130356_add_subject_to_email_campaigns.rb | 2 +- ...column_enable_share_to_enable_tweet_on_action_pages.rb | 2 +- db/migrate/20140513164825_create_call_campaigns.rb | 2 +- db/migrate/20140513165018_change_call_campaign_id.rb | 2 +- db/migrate/20140513170430_add_data_to_call_campaign.rb | 2 +- db/migrate/20140513211548_add_phone_to_users.rb | 2 +- db/migrate/20140514191109_add_summary_to_action_pages.rb | 2 +- ...334_add_attachment_background_image_to_action_pages.rb | 2 +- ...40515204831_add_template_and_layout_to_action_pages.rb | 2 +- db/migrate/20140522234821_add_activity_option_to_users.rb | 2 +- db/migrate/20140529051541_add_confirmable_to_devise.rb | 2 +- db/migrate/20140529215543_add_og_title_to_action_pages.rb | 2 +- db/migrate/20140529220025_add_og_image_to_action_pages.rb | 2 +- .../20140530232720_add_targets_to_email_campaigns.rb | 2 +- db/migrate/20140531140633_create_source_files.rb | 2 +- db/migrate/20140602020057_change_summary_to_text_blog.rb | 2 +- .../20140602041107_add_enable_redirect_to_action_pages.rb | 2 +- .../20140602041535_add_redirect_url_to_action_pages.rb | 2 +- .../20140611015322_add_email_text_to_action_pages.rb | 2 +- db/migrate/20140611030851_change_email_text_to_text.rb | 2 +- db/migrate/20140611190909_add_missing_indexes.rb | 2 +- db/migrate/20140613203758_add_contact_id_to_users.rb | 2 +- db/migrate/20140616203409_add_subscribe_to_users.rb | 2 +- db/migrate/20140623235101_create_partners.rb | 2 +- db/migrate/20140624000606_create_subscriptions.rb | 2 +- db/migrate/20140626191214_add_image_to_tweet_targets.rb | 2 +- db/migrate/20140702113432_create_visits.rb | 2 +- db/migrate/20140702113433_create_ahoy_events.rb | 2 +- db/migrate/20140703200958_add_victory_to_action_pages.rb | 2 +- db/migrate/20140703211713_add_parnters_to_users.rb | 2 +- .../20140805020122_add_unconfirmed_email_to_users.rb | 2 +- db/migrate/20140808233806_create_topic_category.rb | 2 +- db/migrate/20140808233946_create_topic_set.rb | 2 +- db/migrate/20140808234311_create_topic.rb | 2 +- ...140811233646_rename_action_pages_email_campaigns_id.rb | 2 +- ...0819182202_add_topic_category_id_to_email_campaigns.rb | 2 +- .../20140820002514_add_action_page_id_to_ahoy_events.rb | 2 +- ...0140820021820_add_index_on_action_page_id_to_events.rb | 2 +- db/migrate/20140820223448_create_congress_scorecards.rb | 2 +- .../20140905205137_add_partner_id_to_action_pages.rb | 2 +- .../20140911224314_add_campaign_tag_to_email_campaigns.rb | 2 +- db/migrate/20140922235029_add_archived_to_action_pages.rb | 2 +- db/migrate/20140924174611_add_deleted_at_to_partners.rb | 2 +- .../20140930223312_rename_redirect_action_page_id.rb | 2 +- db/migrate/20141006223048_remove_activities_table.rb | 2 +- ...email_addresses_and_target_email_to_email_campaigns.rb | 2 +- ...108212457_add_target_bioguide_id_to_email_campaigns.rb | 2 +- ...0150110042803_add_alt_text_fields_to_email_campaign.rb | 2 +- ...13014921_add_more_alt_text_fields_to_email_campaign.rb | 2 +- db/migrate/20150123194715_create_delayed_jobs.rb | 2 +- db/migrate/20150625230944_create_bounces.rb | 2 +- db/migrate/20151026192811_add_lockable_to_users.rb | 2 +- db/migrate/20151211200545_remove_call_tool_configs.rb | 2 +- .../20151212031318_add_password_expired_to_users.rb | 2 +- db/migrate/20160107220954_remove_url_from_source_files.rb | 2 +- .../20160520212818_add_show_all_signatures_to_petition.rb | 2 +- db/migrate/20160601003317_create_institution_sets.rb | 2 +- db/migrate/20160606202236_create_institutions.rb | 2 +- ...20160606222456_add_enable_affiliations_to_petitions.rb | 2 +- .../20160610205339_create_action_allowed_institutions.rb | 2 +- db/migrate/20160616000020_create_affiliations.rb | 2 +- db/migrate/20160629191322_create_affiliation_types.rb | 2 +- db/migrate/20160718225646_add_slug_to_institution.rb | 2 +- ...0719204420_remove_show_all_signatures_from_petition.rb | 2 +- .../20160908225616_add_subscriptions_count_to_partners.rb | 2 +- db/migrate/20161011172943_add_issue_to_action_pages.rb | 2 +- ..._rename_action_pages_issue_to_action_pages_category.rb | 2 +- db/migrate/20161017233304_create_categories.rb | 2 +- .../20161017233352_add_category_id_to_action_pages.rb | 2 +- db/migrate/20161018212449_create_congress_members.rb | 2 +- db/migrate/20161025215124_add_collaborator_to_users.rb | 2 +- .../20161109191337_create_congress_message_campaigns.rb | 2 +- db/migrate/20170721170625_create_complaints.rb | 2 +- db/migrate/20170831214704_create_partnerships.rb | 2 +- db/migrate/20180124013711_add_sessions_table.rb | 2 +- db/migrate/20180516215539_change_subscription_defaults.rb | 2 +- spec/requests/admin/action_pages_spec.rb | 2 +- 123 files changed, 128 insertions(+), 129 deletions(-) diff --git a/app/controllers/action_page_controller.rb b/app/controllers/action_page_controller.rb index fd6db0b6e..08c5c90f9 100644 --- a/app/controllers/action_page_controller.rb +++ b/app/controllers/action_page_controller.rb @@ -52,9 +52,9 @@ def signature_count @actionPage = ActionPage.friendly.find(params[:id]) if @actionPage.petition - render text: @actionPage.petition.signatures.count + render body: @actionPage.petition.signatures.count else - render text: "0" + render body: "0" end end diff --git a/app/controllers/admin/topic_categories_controller.rb b/app/controllers/admin/topic_categories_controller.rb index e33b3883f..111bd1d8c 100644 --- a/app/controllers/admin/topic_categories_controller.rb +++ b/app/controllers/admin/topic_categories_controller.rb @@ -17,7 +17,7 @@ def destroy TopicCategory.destroy(params[:id]) render json: { id: params[:id] } rescue StandardError => e - render text: e.message, status: 500 + render body: e.message, status: 500 end def update diff --git a/app/controllers/admin/topic_sets_controller.rb b/app/controllers/admin/topic_sets_controller.rb index c3c7fca41..582c8dc06 100644 --- a/app/controllers/admin/topic_sets_controller.rb +++ b/app/controllers/admin/topic_sets_controller.rb @@ -8,7 +8,7 @@ def destroy TopicSet.destroy(params[:id]) render json: { id: params[:id] } rescue StandardError => e - render text: e.message, status: 500 + render body: e.message, status: 500 end def create diff --git a/app/controllers/admin/topics_controller.rb b/app/controllers/admin/topics_controller.rb index 1c3c4f7b1..ba41bb634 100644 --- a/app/controllers/admin/topics_controller.rb +++ b/app/controllers/admin/topics_controller.rb @@ -5,7 +5,7 @@ def destroy Topic.destroy(params[:id]) render json: { id: params[:id] } rescue StandardError => e - render text: e.message, status: 500 + render body: e.message, status: 500 end def create diff --git a/app/controllers/robots_controller.rb b/app/controllers/robots_controller.rb index b50b571d3..208100dda 100644 --- a/app/controllers/robots_controller.rb +++ b/app/controllers/robots_controller.rb @@ -1,9 +1,9 @@ class RobotsController < ApplicationController def show if Rails.env.development? || (Rails.application.secrets.enable_basic_auth == "true") - render text: "User-agent: *\nDisallow: /" + render body: "User-agent: *\nDisallow: /" else - render text: "" + render body: "" end end @@ -11,9 +11,9 @@ def show # for load balancing/ database connection detecting def heartbeat if User.count >= 0 - render text: "Application Heart Beating OK" + render body: "Application Heart Beating OK" else - render text: "There's something odd about the database, probably disconnected...", status: 500 + render body: "There's something odd about the database, probably disconnected...", status: 500 end end end diff --git a/app/views/action_page/index.html.erb b/app/views/action_page/index.html.erb index ecfd70701..e9bb88df2 100644 --- a/app/views/action_page/index.html.erb +++ b/app/views/action_page/index.html.erb @@ -7,7 +7,7 @@
<%= form_tag action_page_index_path, method: :get, id: "action-page-filter" do %> <%= select_tag :category, - options_from_collection_for_select(Category.all.order(:title).uniq, + options_from_collection_for_select(Category.all.order(:title).distinct, :title, :title, params[:category]), include_blank: "All campaigns" %> <% end %> diff --git a/config/application.rb b/config/application.rb index b4a336198..72d5cc60b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,9 +23,8 @@ class Application < Rails::Application config.eager_load_paths += %W(#{config.root}/lib) config.assets.paths << Rails.root.join('node_modules') - #config.logger = ActiveSupport::Logger.new(STDOUT) config.to_prepare do - Devise::Mailer.layout "email" # email.haml or email.erb + Devise::Mailer.layout "email" # email.haml or email.erb end config.exceptions_app = ->(env) { ExceptionsController.action(:show).call(env) } diff --git a/config/environments/test.rb b/config/environments/test.rb index c5f1c3ace..04116d57a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -13,8 +13,8 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + config.public_file_server.enabled = true + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/db/migrate/20140300000000_enable_extension_ossd.rb b/db/migrate/20140300000000_enable_extension_ossd.rb index 1c8465707..c1408e09c 100644 --- a/db/migrate/20140300000000_enable_extension_ossd.rb +++ b/db/migrate/20140300000000_enable_extension_ossd.rb @@ -1,4 +1,4 @@ -class EnableExtensionOssd < ActiveRecord::Migration +class EnableExtensionOssd < ActiveRecord::Migration[5.0] def change enable_extension "uuid-ossp" end diff --git a/db/migrate/20140311235111_create_activities.rb b/db/migrate/20140311235111_create_activities.rb index db93d1e52..933e66123 100644 --- a/db/migrate/20140311235111_create_activities.rb +++ b/db/migrate/20140311235111_create_activities.rb @@ -1,4 +1,4 @@ -class CreateActivities < ActiveRecord::Migration +class CreateActivities < ActiveRecord::Migration[5.0] def change create_table :activities do |t| t.string :description diff --git a/db/migrate/20140313144408_create_action_pages.rb b/db/migrate/20140313144408_create_action_pages.rb index 42c353562..5672f55e5 100644 --- a/db/migrate/20140313144408_create_action_pages.rb +++ b/db/migrate/20140313144408_create_action_pages.rb @@ -1,4 +1,4 @@ -class CreateActionPages < ActiveRecord::Migration +class CreateActionPages < ActiveRecord::Migration[5.0] def change create_table :action_pages do |t| t.string :title diff --git a/db/migrate/20140314020630_devise_create_users.rb b/db/migrate/20140314020630_devise_create_users.rb index ab71c3d1b..12f29a418 100644 --- a/db/migrate/20140314020630_devise_create_users.rb +++ b/db/migrate/20140314020630_devise_create_users.rb @@ -1,4 +1,4 @@ -class DeviseCreateUsers < ActiveRecord::Migration +class DeviseCreateUsers < ActiveRecord::Migration[5.0] def change create_table(:users) do |t| ## Database authenticatable diff --git a/db/migrate/20140317070243_add_userid_to_activities.rb b/db/migrate/20140317070243_add_userid_to_activities.rb index b3b60e2eb..051ad72ce 100644 --- a/db/migrate/20140317070243_add_userid_to_activities.rb +++ b/db/migrate/20140317070243_add_userid_to_activities.rb @@ -1,4 +1,4 @@ -class AddUseridToActivities < ActiveRecord::Migration +class AddUseridToActivities < ActiveRecord::Migration[5.0] def change add_column :activities, :user_id, :integer end diff --git a/db/migrate/20140317084144_add_action_pageid_to_activities.rb b/db/migrate/20140317084144_add_action_pageid_to_activities.rb index c57569cf2..56769d63d 100644 --- a/db/migrate/20140317084144_add_action_pageid_to_activities.rb +++ b/db/migrate/20140317084144_add_action_pageid_to_activities.rb @@ -1,4 +1,4 @@ -class AddActionPageidToActivities < ActiveRecord::Migration +class AddActionPageidToActivities < ActiveRecord::Migration[5.0] def change add_column :activities, :action_page_id, :integer end diff --git a/db/migrate/20140325050528_create_petitions.rb b/db/migrate/20140325050528_create_petitions.rb index c44dc85e5..c5350323d 100644 --- a/db/migrate/20140325050528_create_petitions.rb +++ b/db/migrate/20140325050528_create_petitions.rb @@ -1,4 +1,4 @@ -class CreatePetitions < ActiveRecord::Migration +class CreatePetitions < ActiveRecord::Migration[5.0] def change create_table :petitions do |t| t.string :title diff --git a/db/migrate/20140325050602_create_signatures.rb b/db/migrate/20140325050602_create_signatures.rb index ea6eef268..a6b333ab1 100644 --- a/db/migrate/20140325050602_create_signatures.rb +++ b/db/migrate/20140325050602_create_signatures.rb @@ -1,4 +1,4 @@ -class CreateSignatures < ActiveRecord::Migration +class CreateSignatures < ActiveRecord::Migration[5.0] def change create_table :signatures do |t| t.integer :petition_id diff --git a/db/migrate/20140327210422_create_featured_action_pages.rb b/db/migrate/20140327210422_create_featured_action_pages.rb index 967089c57..69f4b90ca 100644 --- a/db/migrate/20140327210422_create_featured_action_pages.rb +++ b/db/migrate/20140327210422_create_featured_action_pages.rb @@ -1,4 +1,4 @@ -class CreateFeaturedActionPages < ActiveRecord::Migration +class CreateFeaturedActionPages < ActiveRecord::Migration[5.0] def change create_table :featured_action_pages do |t| t.integer :action_page_id diff --git a/db/migrate/20140328161752_add_details_to_user.rb b/db/migrate/20140328161752_add_details_to_user.rb index d93bbfe44..2d5901725 100644 --- a/db/migrate/20140328161752_add_details_to_user.rb +++ b/db/migrate/20140328161752_add_details_to_user.rb @@ -1,4 +1,4 @@ -class AddDetailsToUser < ActiveRecord::Migration +class AddDetailsToUser < ActiveRecord::Migration[5.0] def change add_column :users, :first_name, :string add_column :users, :last_name, :string diff --git a/db/migrate/20140402190943_add_fields_to_signatures.rb b/db/migrate/20140402190943_add_fields_to_signatures.rb index d0fd311d6..4fabb36fb 100644 --- a/db/migrate/20140402190943_add_fields_to_signatures.rb +++ b/db/migrate/20140402190943_add_fields_to_signatures.rb @@ -1,4 +1,4 @@ -class AddFieldsToSignatures < ActiveRecord::Migration +class AddFieldsToSignatures < ActiveRecord::Migration[5.0] def change add_column :signatures, :first_name, :string add_column :signatures, :last_name, :string diff --git a/db/migrate/20140402192811_add_petition_id_to_action_pages.rb b/db/migrate/20140402192811_add_petition_id_to_action_pages.rb index 5f6154720..1ec5114ef 100644 --- a/db/migrate/20140402192811_add_petition_id_to_action_pages.rb +++ b/db/migrate/20140402192811_add_petition_id_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddPetitionIdToActionPages < ActiveRecord::Migration +class AddPetitionIdToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :petition_id, :integer end diff --git a/db/migrate/20140403002100_add_photo_url_to_action_pages.rb b/db/migrate/20140403002100_add_photo_url_to_action_pages.rb index 3ed6d3ad8..7052cfcaa 100644 --- a/db/migrate/20140403002100_add_photo_url_to_action_pages.rb +++ b/db/migrate/20140403002100_add_photo_url_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddPhotoUrlToActionPages < ActiveRecord::Migration +class AddPhotoUrlToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :photo_url, :string end diff --git a/db/migrate/20140403183138_add_admin_to_users.rb b/db/migrate/20140403183138_add_admin_to_users.rb index e386d33dd..0e2407641 100644 --- a/db/migrate/20140403183138_add_admin_to_users.rb +++ b/db/migrate/20140403183138_add_admin_to_users.rb @@ -1,4 +1,4 @@ -class AddAdminToUsers < ActiveRecord::Migration +class AddAdminToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :admin, :boolean, default: false end diff --git a/db/migrate/20140404223839_add_fields_for_tools_to_action_pages.rb b/db/migrate/20140404223839_add_fields_for_tools_to_action_pages.rb index 1f72afa47..82edad478 100644 --- a/db/migrate/20140404223839_add_fields_for_tools_to_action_pages.rb +++ b/db/migrate/20140404223839_add_fields_for_tools_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddFieldsForToolsToActionPages < ActiveRecord::Migration +class AddFieldsForToolsToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :enable_call, :boolean, default: false add_column :action_pages, :enable_petition, :boolean, default: false diff --git a/db/migrate/20140409105241_add_slug_to_actionpage.rb b/db/migrate/20140409105241_add_slug_to_actionpage.rb index d9f5dfda7..a9f8af8e7 100644 --- a/db/migrate/20140409105241_add_slug_to_actionpage.rb +++ b/db/migrate/20140409105241_add_slug_to_actionpage.rb @@ -1,4 +1,4 @@ -class AddSlugToActionpage < ActiveRecord::Migration +class AddSlugToActionpage < ActiveRecord::Migration[5.0] def change add_column :action_pages, :slug, :string add_index :action_pages, :slug diff --git a/db/migrate/20140409105530_create_friendly_id_slugs.rb b/db/migrate/20140409105530_create_friendly_id_slugs.rb index 770f62644..c95692d56 100644 --- a/db/migrate/20140409105530_create_friendly_id_slugs.rb +++ b/db/migrate/20140409105530_create_friendly_id_slugs.rb @@ -1,4 +1,4 @@ -class CreateFriendlyIdSlugs < ActiveRecord::Migration +class CreateFriendlyIdSlugs < ActiveRecord::Migration[5.0] def change create_table :friendly_id_slugs do |t| t.string :slug, :null => false diff --git a/db/migrate/20140410025404_add_address_to_signatures.rb b/db/migrate/20140410025404_add_address_to_signatures.rb index caabbe849..73f73e622 100644 --- a/db/migrate/20140410025404_add_address_to_signatures.rb +++ b/db/migrate/20140410025404_add_address_to_signatures.rb @@ -1,4 +1,4 @@ -class AddAddressToSignatures < ActiveRecord::Migration +class AddAddressToSignatures < ActiveRecord::Migration[5.0] def change add_column :signatures, :street_address, :string add_column :signatures, :city, :string diff --git a/db/migrate/20140410030958_add_address_to_users.rb b/db/migrate/20140410030958_add_address_to_users.rb index 5550eacd3..6b8445614 100644 --- a/db/migrate/20140410030958_add_address_to_users.rb +++ b/db/migrate/20140410030958_add_address_to_users.rb @@ -1,4 +1,4 @@ -class AddAddressToUsers < ActiveRecord::Migration +class AddAddressToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :street_address, :string add_column :users, :city, :string diff --git a/db/migrate/20140410033413_add_goal_to_petition.rb b/db/migrate/20140410033413_add_goal_to_petition.rb index d643d66e7..d2b75bf2b 100644 --- a/db/migrate/20140410033413_add_goal_to_petition.rb +++ b/db/migrate/20140410033413_add_goal_to_petition.rb @@ -1,4 +1,4 @@ -class AddGoalToPetition < ActiveRecord::Migration +class AddGoalToPetition < ActiveRecord::Migration[5.0] def change add_column :petitions, :goal, :integer end diff --git a/db/migrate/20140416002624_add_anonymous_to_signatures.rb b/db/migrate/20140416002624_add_anonymous_to_signatures.rb index 9f5283fec..f10f7542e 100644 --- a/db/migrate/20140416002624_add_anonymous_to_signatures.rb +++ b/db/migrate/20140416002624_add_anonymous_to_signatures.rb @@ -1,4 +1,4 @@ -class AddAnonymousToSignatures < ActiveRecord::Migration +class AddAnonymousToSignatures < ActiveRecord::Migration[5.0] def change add_column :signatures, :anonymous, :boolean, default: false end diff --git a/db/migrate/20140417021005_add_share_message_to_action_pages.rb b/db/migrate/20140417021005_add_share_message_to_action_pages.rb index fdb328655..51e2a3a16 100644 --- a/db/migrate/20140417021005_add_share_message_to_action_pages.rb +++ b/db/migrate/20140417021005_add_share_message_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddShareMessageToActionPages < ActiveRecord::Migration +class AddShareMessageToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :share_message, :string end diff --git a/db/migrate/20140423002336_create_tweets.rb b/db/migrate/20140423002336_create_tweets.rb index ca50e509e..40a65062d 100644 --- a/db/migrate/20140423002336_create_tweets.rb +++ b/db/migrate/20140423002336_create_tweets.rb @@ -1,4 +1,4 @@ -class CreateTweets < ActiveRecord::Migration +class CreateTweets < ActiveRecord::Migration[5.0] def change create_table :tweets do |t| t.string :target diff --git a/db/migrate/20140423002432_add_tweets_to_action_pages.rb b/db/migrate/20140423002432_add_tweets_to_action_pages.rb index aad68f7f1..70a354c98 100644 --- a/db/migrate/20140423002432_add_tweets_to_action_pages.rb +++ b/db/migrate/20140423002432_add_tweets_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddTweetsToActionPages < ActiveRecord::Migration +class AddTweetsToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :tweet_id, :integer end diff --git a/db/migrate/20140423202256_add_cta_to_tweet.rb b/db/migrate/20140423202256_add_cta_to_tweet.rb index 0bf1f7888..78689b5a1 100644 --- a/db/migrate/20140423202256_add_cta_to_tweet.rb +++ b/db/migrate/20140423202256_add_cta_to_tweet.rb @@ -1,4 +1,4 @@ -class AddCtaToTweet < ActiveRecord::Migration +class AddCtaToTweet < ActiveRecord::Migration[5.0] def change add_column :tweets, :cta, :string end diff --git a/db/migrate/20140424232842_add_bioguide_id_to_tweets.rb b/db/migrate/20140424232842_add_bioguide_id_to_tweets.rb index f5a556436..3ea14e8f9 100644 --- a/db/migrate/20140424232842_add_bioguide_id_to_tweets.rb +++ b/db/migrate/20140424232842_add_bioguide_id_to_tweets.rb @@ -1,4 +1,4 @@ -class AddBioguideIdToTweets < ActiveRecord::Migration +class AddBioguideIdToTweets < ActiveRecord::Migration[5.0] def change add_column :tweets, :bioguide_id, :string end diff --git a/db/migrate/20140425215725_add_target_flags_to_tweets.rb b/db/migrate/20140425215725_add_target_flags_to_tweets.rb index d0c7d99a5..f69dd0c2e 100644 --- a/db/migrate/20140425215725_add_target_flags_to_tweets.rb +++ b/db/migrate/20140425215725_add_target_flags_to_tweets.rb @@ -1,4 +1,4 @@ -class AddTargetFlagsToTweets < ActiveRecord::Migration +class AddTargetFlagsToTweets < ActiveRecord::Migration[5.0] def change add_column :tweets, :target_house, :boolean, default: true add_column :tweets, :target_senate, :boolean, default: true diff --git a/db/migrate/20140429015127_add_published_to_action_pages.rb b/db/migrate/20140429015127_add_published_to_action_pages.rb index d819d70bf..a88bec1e9 100644 --- a/db/migrate/20140429015127_add_published_to_action_pages.rb +++ b/db/migrate/20140429015127_add_published_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddPublishedToActionPages < ActiveRecord::Migration +class AddPublishedToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :published, :boolean, default: false end diff --git a/db/migrate/20140430110906_add_type_to_activities.rb b/db/migrate/20140430110906_add_type_to_activities.rb index cdb77ec7b..de7bd3035 100644 --- a/db/migrate/20140430110906_add_type_to_activities.rb +++ b/db/migrate/20140430110906_add_type_to_activities.rb @@ -1,4 +1,4 @@ -class AddTypeToActivities < ActiveRecord::Migration +class AddTypeToActivities < ActiveRecord::Migration[5.0] def change add_column :activities, :action_type, :string end diff --git a/db/migrate/20140501160413_create_call_tool_configs.rb b/db/migrate/20140501160413_create_call_tool_configs.rb index d7ba2b483..89c6f8a13 100644 --- a/db/migrate/20140501160413_create_call_tool_configs.rb +++ b/db/migrate/20140501160413_create_call_tool_configs.rb @@ -1,4 +1,4 @@ -class CreateCallToolConfigs < ActiveRecord::Migration +class CreateCallToolConfigs < ActiveRecord::Migration[5.0] def change create_table :call_tool_configs do |t| diff --git a/db/migrate/20140502162820_add_call_campaign_id_to_action_pages.rb b/db/migrate/20140502162820_add_call_campaign_id_to_action_pages.rb index ce71b7574..21766002c 100644 --- a/db/migrate/20140502162820_add_call_campaign_id_to_action_pages.rb +++ b/db/migrate/20140502162820_add_call_campaign_id_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddCallCampaignIdToActionPages < ActiveRecord::Migration +class AddCallCampaignIdToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :call_campaign_id, :string end diff --git a/db/migrate/20140504080222_add_attachment_featured_image_to_action_pages.rb b/db/migrate/20140504080222_add_attachment_featured_image_to_action_pages.rb index 0be5afc50..dc3dacef3 100644 --- a/db/migrate/20140504080222_add_attachment_featured_image_to_action_pages.rb +++ b/db/migrate/20140504080222_add_attachment_featured_image_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddAttachmentFeaturedImageToActionPages < ActiveRecord::Migration +class AddAttachmentFeaturedImageToActionPages < ActiveRecord::Migration[5.0] def self.up change_table :action_pages do |t| t.attachment :featured_image diff --git a/db/migrate/20140505142843_add_what_to_say_to_action_pages.rb b/db/migrate/20140505142843_add_what_to_say_to_action_pages.rb index 048402d09..01841ea42 100644 --- a/db/migrate/20140505142843_add_what_to_say_to_action_pages.rb +++ b/db/migrate/20140505142843_add_what_to_say_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddWhatToSayToActionPages < ActiveRecord::Migration +class AddWhatToSayToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :what_to_say, :text end diff --git a/db/migrate/20140506161533_create_email_campaigns.rb b/db/migrate/20140506161533_create_email_campaigns.rb index 6b2e7465f..330b48089 100644 --- a/db/migrate/20140506161533_create_email_campaigns.rb +++ b/db/migrate/20140506161533_create_email_campaigns.rb @@ -1,4 +1,4 @@ -class CreateEmailCampaigns < ActiveRecord::Migration +class CreateEmailCampaigns < ActiveRecord::Migration[5.0] def change create_table :email_campaigns do |t| t.text :message diff --git a/db/migrate/20140506173759_add_email_campaign_id_to_action_pages.rb b/db/migrate/20140506173759_add_email_campaign_id_to_action_pages.rb index 50836b0bd..26001649b 100644 --- a/db/migrate/20140506173759_add_email_campaign_id_to_action_pages.rb +++ b/db/migrate/20140506173759_add_email_campaign_id_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddEmailCampaignIdToActionPages < ActiveRecord::Migration +class AddEmailCampaignIdToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :email_campaign_id, :integer end diff --git a/db/migrate/20140506214830_create_user_preferences.rb b/db/migrate/20140506214830_create_user_preferences.rb index 94d602632..34fb70cf1 100644 --- a/db/migrate/20140506214830_create_user_preferences.rb +++ b/db/migrate/20140506214830_create_user_preferences.rb @@ -1,4 +1,4 @@ -class CreateUserPreferences < ActiveRecord::Migration +class CreateUserPreferences < ActiveRecord::Migration[5.0] def change create_table :user_preferences do |t| t.integer :user_id, null: false diff --git a/db/migrate/20140507002622_create_tweet_targets.rb b/db/migrate/20140507002622_create_tweet_targets.rb index ae4a5056b..bd52f1db5 100644 --- a/db/migrate/20140507002622_create_tweet_targets.rb +++ b/db/migrate/20140507002622_create_tweet_targets.rb @@ -1,4 +1,4 @@ -class CreateTweetTargets < ActiveRecord::Migration +class CreateTweetTargets < ActiveRecord::Migration[5.0] def change create_table :tweet_targets do |t| t.integer :tweet_id, null: false diff --git a/db/migrate/20140508122428_fix_column_name.rb b/db/migrate/20140508122428_fix_column_name.rb index 1d69d81cd..a8765ef96 100644 --- a/db/migrate/20140508122428_fix_column_name.rb +++ b/db/migrate/20140508122428_fix_column_name.rb @@ -1,4 +1,4 @@ -class FixColumnName < ActiveRecord::Migration +class FixColumnName < ActiveRecord::Migration[5.0] def change rename_column :action_pages, :email_campaign_id, :email_campaigns_id end diff --git a/db/migrate/20140509130356_add_subject_to_email_campaigns.rb b/db/migrate/20140509130356_add_subject_to_email_campaigns.rb index 7d7d897bc..4432031e5 100644 --- a/db/migrate/20140509130356_add_subject_to_email_campaigns.rb +++ b/db/migrate/20140509130356_add_subject_to_email_campaigns.rb @@ -1,4 +1,4 @@ -class AddSubjectToEmailCampaigns < ActiveRecord::Migration +class AddSubjectToEmailCampaigns < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :subject, :string end diff --git a/db/migrate/20140509200631_rename_column_enable_share_to_enable_tweet_on_action_pages.rb b/db/migrate/20140509200631_rename_column_enable_share_to_enable_tweet_on_action_pages.rb index c1dffa460..5cbd836a7 100644 --- a/db/migrate/20140509200631_rename_column_enable_share_to_enable_tweet_on_action_pages.rb +++ b/db/migrate/20140509200631_rename_column_enable_share_to_enable_tweet_on_action_pages.rb @@ -1,4 +1,4 @@ -class RenameColumnEnableShareToEnableTweetOnActionPages < ActiveRecord::Migration +class RenameColumnEnableShareToEnableTweetOnActionPages < ActiveRecord::Migration[5.0] def change change_table :action_pages do |t| t.rename :enable_share, :enable_tweet diff --git a/db/migrate/20140513164825_create_call_campaigns.rb b/db/migrate/20140513164825_create_call_campaigns.rb index 48c736543..9fbd261a5 100644 --- a/db/migrate/20140513164825_create_call_campaigns.rb +++ b/db/migrate/20140513164825_create_call_campaigns.rb @@ -1,4 +1,4 @@ -class CreateCallCampaigns < ActiveRecord::Migration +class CreateCallCampaigns < ActiveRecord::Migration[5.0] def change create_table :call_campaigns do |t| diff --git a/db/migrate/20140513165018_change_call_campaign_id.rb b/db/migrate/20140513165018_change_call_campaign_id.rb index 327c2a253..491e723a7 100644 --- a/db/migrate/20140513165018_change_call_campaign_id.rb +++ b/db/migrate/20140513165018_change_call_campaign_id.rb @@ -1,4 +1,4 @@ -class ChangeCallCampaignId < ActiveRecord::Migration +class ChangeCallCampaignId < ActiveRecord::Migration[5.0] def change remove_column :action_pages, :call_campaign_id add_column :action_pages, :call_campaign_id, :integer diff --git a/db/migrate/20140513170430_add_data_to_call_campaign.rb b/db/migrate/20140513170430_add_data_to_call_campaign.rb index 67c7eb59e..36ccda399 100644 --- a/db/migrate/20140513170430_add_data_to_call_campaign.rb +++ b/db/migrate/20140513170430_add_data_to_call_campaign.rb @@ -1,4 +1,4 @@ -class AddDataToCallCampaign < ActiveRecord::Migration +class AddDataToCallCampaign < ActiveRecord::Migration[5.0] def change add_column :call_campaigns, :title, :string add_column :call_campaigns, :message, :text diff --git a/db/migrate/20140513211548_add_phone_to_users.rb b/db/migrate/20140513211548_add_phone_to_users.rb index 7f94bae93..75ff77b1d 100644 --- a/db/migrate/20140513211548_add_phone_to_users.rb +++ b/db/migrate/20140513211548_add_phone_to_users.rb @@ -1,4 +1,4 @@ -class AddPhoneToUsers < ActiveRecord::Migration +class AddPhoneToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :phone, :string end diff --git a/db/migrate/20140514191109_add_summary_to_action_pages.rb b/db/migrate/20140514191109_add_summary_to_action_pages.rb index 20b873e51..5587bd0b7 100644 --- a/db/migrate/20140514191109_add_summary_to_action_pages.rb +++ b/db/migrate/20140514191109_add_summary_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddSummaryToActionPages < ActiveRecord::Migration +class AddSummaryToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :summary, :string end diff --git a/db/migrate/20140515192334_add_attachment_background_image_to_action_pages.rb b/db/migrate/20140515192334_add_attachment_background_image_to_action_pages.rb index 76b7505f9..448c2453d 100644 --- a/db/migrate/20140515192334_add_attachment_background_image_to_action_pages.rb +++ b/db/migrate/20140515192334_add_attachment_background_image_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddAttachmentBackgroundImageToActionPages < ActiveRecord::Migration +class AddAttachmentBackgroundImageToActionPages < ActiveRecord::Migration[5.0] def self.up change_table :action_pages do |t| t.attachment :background_image diff --git a/db/migrate/20140515204831_add_template_and_layout_to_action_pages.rb b/db/migrate/20140515204831_add_template_and_layout_to_action_pages.rb index fcac78b93..ec78584cd 100644 --- a/db/migrate/20140515204831_add_template_and_layout_to_action_pages.rb +++ b/db/migrate/20140515204831_add_template_and_layout_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddTemplateAndLayoutToActionPages < ActiveRecord::Migration +class AddTemplateAndLayoutToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :template, :string add_column :action_pages, :layout, :string diff --git a/db/migrate/20140522234821_add_activity_option_to_users.rb b/db/migrate/20140522234821_add_activity_option_to_users.rb index db391750d..1026c3286 100644 --- a/db/migrate/20140522234821_add_activity_option_to_users.rb +++ b/db/migrate/20140522234821_add_activity_option_to_users.rb @@ -1,4 +1,4 @@ -class AddActivityOptionToUsers < ActiveRecord::Migration +class AddActivityOptionToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :record_activity, :boolean, default: true end diff --git a/db/migrate/20140529051541_add_confirmable_to_devise.rb b/db/migrate/20140529051541_add_confirmable_to_devise.rb index 29224d69e..9fe852a38 100644 --- a/db/migrate/20140529051541_add_confirmable_to_devise.rb +++ b/db/migrate/20140529051541_add_confirmable_to_devise.rb @@ -1,4 +1,4 @@ -class AddConfirmableToDevise < ActiveRecord::Migration +class AddConfirmableToDevise < ActiveRecord::Migration[5.0] # Note: You can't use change, as User.update_all with fail in the down migration def self.up add_column :users, :confirmation_token, :string diff --git a/db/migrate/20140529215543_add_og_title_to_action_pages.rb b/db/migrate/20140529215543_add_og_title_to_action_pages.rb index e72016958..d39bbcdb4 100644 --- a/db/migrate/20140529215543_add_og_title_to_action_pages.rb +++ b/db/migrate/20140529215543_add_og_title_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddOgTitleToActionPages < ActiveRecord::Migration +class AddOgTitleToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :og_title, :string end diff --git a/db/migrate/20140529220025_add_og_image_to_action_pages.rb b/db/migrate/20140529220025_add_og_image_to_action_pages.rb index 9f89fdca7..bef964ffc 100644 --- a/db/migrate/20140529220025_add_og_image_to_action_pages.rb +++ b/db/migrate/20140529220025_add_og_image_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddOgImageToActionPages < ActiveRecord::Migration +class AddOgImageToActionPages < ActiveRecord::Migration[5.0] def self.up change_table :action_pages do |t| t.attachment :og_image diff --git a/db/migrate/20140530232720_add_targets_to_email_campaigns.rb b/db/migrate/20140530232720_add_targets_to_email_campaigns.rb index 87fa99074..0b6349be8 100644 --- a/db/migrate/20140530232720_add_targets_to_email_campaigns.rb +++ b/db/migrate/20140530232720_add_targets_to_email_campaigns.rb @@ -1,4 +1,4 @@ -class AddTargetsToEmailCampaigns < ActiveRecord::Migration +class AddTargetsToEmailCampaigns < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :target_house, :boolean, default: true add_column :email_campaigns, :target_senate, :boolean, default: true diff --git a/db/migrate/20140531140633_create_source_files.rb b/db/migrate/20140531140633_create_source_files.rb index ca47a1cce..4c3b3989d 100644 --- a/db/migrate/20140531140633_create_source_files.rb +++ b/db/migrate/20140531140633_create_source_files.rb @@ -1,4 +1,4 @@ -class CreateSourceFiles < ActiveRecord::Migration +class CreateSourceFiles < ActiveRecord::Migration[5.0] def change create_table :source_files do |t| t.string :file_name diff --git a/db/migrate/20140602020057_change_summary_to_text_blog.rb b/db/migrate/20140602020057_change_summary_to_text_blog.rb index 45f099011..63026cdcd 100644 --- a/db/migrate/20140602020057_change_summary_to_text_blog.rb +++ b/db/migrate/20140602020057_change_summary_to_text_blog.rb @@ -1,4 +1,4 @@ -class ChangeSummaryToTextBlog < ActiveRecord::Migration +class ChangeSummaryToTextBlog < ActiveRecord::Migration[5.0] def change change_column :action_pages, :summary, :text, :limit => nil end diff --git a/db/migrate/20140602041107_add_enable_redirect_to_action_pages.rb b/db/migrate/20140602041107_add_enable_redirect_to_action_pages.rb index c1c519b96..14f3a41b4 100644 --- a/db/migrate/20140602041107_add_enable_redirect_to_action_pages.rb +++ b/db/migrate/20140602041107_add_enable_redirect_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddEnableRedirectToActionPages < ActiveRecord::Migration +class AddEnableRedirectToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :enable_redirect, :boolean, :default=>false end diff --git a/db/migrate/20140602041535_add_redirect_url_to_action_pages.rb b/db/migrate/20140602041535_add_redirect_url_to_action_pages.rb index 22f94159e..706e56503 100644 --- a/db/migrate/20140602041535_add_redirect_url_to_action_pages.rb +++ b/db/migrate/20140602041535_add_redirect_url_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddRedirectUrlToActionPages < ActiveRecord::Migration +class AddRedirectUrlToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :redirect_url, :string end diff --git a/db/migrate/20140611015322_add_email_text_to_action_pages.rb b/db/migrate/20140611015322_add_email_text_to_action_pages.rb index e22cad80d..2ccaf7c6a 100644 --- a/db/migrate/20140611015322_add_email_text_to_action_pages.rb +++ b/db/migrate/20140611015322_add_email_text_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddEmailTextToActionPages < ActiveRecord::Migration +class AddEmailTextToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :email_text, :string end diff --git a/db/migrate/20140611030851_change_email_text_to_text.rb b/db/migrate/20140611030851_change_email_text_to_text.rb index c855d9c31..3017fcfc7 100644 --- a/db/migrate/20140611030851_change_email_text_to_text.rb +++ b/db/migrate/20140611030851_change_email_text_to_text.rb @@ -1,4 +1,4 @@ -class ChangeEmailTextToText < ActiveRecord::Migration +class ChangeEmailTextToText < ActiveRecord::Migration[5.0] def up change_column :action_pages, :email_text, :text end diff --git a/db/migrate/20140611190909_add_missing_indexes.rb b/db/migrate/20140611190909_add_missing_indexes.rb index 308a51ef7..aef068567 100644 --- a/db/migrate/20140611190909_add_missing_indexes.rb +++ b/db/migrate/20140611190909_add_missing_indexes.rb @@ -1,4 +1,4 @@ -class AddMissingIndexes < ActiveRecord::Migration +class AddMissingIndexes < ActiveRecord::Migration[5.0] def change add_index :activities, :user_id add_index :activities, :action_page_id diff --git a/db/migrate/20140613203758_add_contact_id_to_users.rb b/db/migrate/20140613203758_add_contact_id_to_users.rb index b7c5a441d..481d55bb9 100644 --- a/db/migrate/20140613203758_add_contact_id_to_users.rb +++ b/db/migrate/20140613203758_add_contact_id_to_users.rb @@ -1,4 +1,4 @@ -class AddContactIdToUsers < ActiveRecord::Migration +class AddContactIdToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :contact_id, :integer end diff --git a/db/migrate/20140616203409_add_subscribe_to_users.rb b/db/migrate/20140616203409_add_subscribe_to_users.rb index a0c54fc61..2d85249ad 100644 --- a/db/migrate/20140616203409_add_subscribe_to_users.rb +++ b/db/migrate/20140616203409_add_subscribe_to_users.rb @@ -1,4 +1,4 @@ -class AddSubscribeToUsers < ActiveRecord::Migration +class AddSubscribeToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :subscribe, :boolean, default: true end diff --git a/db/migrate/20140623235101_create_partners.rb b/db/migrate/20140623235101_create_partners.rb index 3b30d8bb7..0fa765704 100644 --- a/db/migrate/20140623235101_create_partners.rb +++ b/db/migrate/20140623235101_create_partners.rb @@ -1,4 +1,4 @@ -class CreatePartners < ActiveRecord::Migration +class CreatePartners < ActiveRecord::Migration[5.0] def change create_table :partners do |t| t.string :code diff --git a/db/migrate/20140624000606_create_subscriptions.rb b/db/migrate/20140624000606_create_subscriptions.rb index 1d084af7e..ceb4f53de 100644 --- a/db/migrate/20140624000606_create_subscriptions.rb +++ b/db/migrate/20140624000606_create_subscriptions.rb @@ -1,4 +1,4 @@ -class CreateSubscriptions < ActiveRecord::Migration +class CreateSubscriptions < ActiveRecord::Migration[5.0] def change create_table :subscriptions do |t| t.string :first_name diff --git a/db/migrate/20140626191214_add_image_to_tweet_targets.rb b/db/migrate/20140626191214_add_image_to_tweet_targets.rb index 0cf96d489..337e9b232 100644 --- a/db/migrate/20140626191214_add_image_to_tweet_targets.rb +++ b/db/migrate/20140626191214_add_image_to_tweet_targets.rb @@ -1,4 +1,4 @@ -class AddImageToTweetTargets < ActiveRecord::Migration +class AddImageToTweetTargets < ActiveRecord::Migration[5.0] def self.up add_attachment :tweet_targets, :image end diff --git a/db/migrate/20140702113432_create_visits.rb b/db/migrate/20140702113432_create_visits.rb index 4da9a5a23..36d52cf09 100644 --- a/db/migrate/20140702113432_create_visits.rb +++ b/db/migrate/20140702113432_create_visits.rb @@ -1,4 +1,4 @@ -class CreateVisits < ActiveRecord::Migration +class CreateVisits < ActiveRecord::Migration[5.0] def change create_table :visits, id: false do |t| t.uuid :id, primary_key: true, default: 'uuid_generate_v4()' diff --git a/db/migrate/20140702113433_create_ahoy_events.rb b/db/migrate/20140702113433_create_ahoy_events.rb index c488dbfcf..946b18910 100644 --- a/db/migrate/20140702113433_create_ahoy_events.rb +++ b/db/migrate/20140702113433_create_ahoy_events.rb @@ -1,4 +1,4 @@ -class CreateAhoyEvents < ActiveRecord::Migration +class CreateAhoyEvents < ActiveRecord::Migration[5.0] def change create_table :ahoy_events, id: false do |t| t.uuid :id, primary_key: true, default: 'uuid_generate_v4()' diff --git a/db/migrate/20140703200958_add_victory_to_action_pages.rb b/db/migrate/20140703200958_add_victory_to_action_pages.rb index a7e686562..e859b60d6 100644 --- a/db/migrate/20140703200958_add_victory_to_action_pages.rb +++ b/db/migrate/20140703200958_add_victory_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddVictoryToActionPages < ActiveRecord::Migration +class AddVictoryToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :victory, :boolean, default: false add_column :action_pages, :victory_message, :text diff --git a/db/migrate/20140703211713_add_parnters_to_users.rb b/db/migrate/20140703211713_add_parnters_to_users.rb index ca1e5d0e0..0ff4ae3c1 100644 --- a/db/migrate/20140703211713_add_parnters_to_users.rb +++ b/db/migrate/20140703211713_add_parnters_to_users.rb @@ -1,4 +1,4 @@ -class AddParntersToUsers < ActiveRecord::Migration +class AddParntersToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :partner_id, :integer end diff --git a/db/migrate/20140805020122_add_unconfirmed_email_to_users.rb b/db/migrate/20140805020122_add_unconfirmed_email_to_users.rb index 6dcb7eea1..95c3b05d0 100644 --- a/db/migrate/20140805020122_add_unconfirmed_email_to_users.rb +++ b/db/migrate/20140805020122_add_unconfirmed_email_to_users.rb @@ -1,4 +1,4 @@ -class AddUnconfirmedEmailToUsers < ActiveRecord::Migration +class AddUnconfirmedEmailToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :unconfirmed_email, :string end diff --git a/db/migrate/20140808233806_create_topic_category.rb b/db/migrate/20140808233806_create_topic_category.rb index 2a7e4c477..fa84e4a3a 100644 --- a/db/migrate/20140808233806_create_topic_category.rb +++ b/db/migrate/20140808233806_create_topic_category.rb @@ -1,4 +1,4 @@ -class CreateTopicCategory < ActiveRecord::Migration +class CreateTopicCategory < ActiveRecord::Migration[5.0] def change create_table :topic_categories do |t| t.string :name diff --git a/db/migrate/20140808233946_create_topic_set.rb b/db/migrate/20140808233946_create_topic_set.rb index 79a9e645f..df6e04373 100644 --- a/db/migrate/20140808233946_create_topic_set.rb +++ b/db/migrate/20140808233946_create_topic_set.rb @@ -1,4 +1,4 @@ -class CreateTopicSet < ActiveRecord::Migration +class CreateTopicSet < ActiveRecord::Migration[5.0] def change create_table :topic_sets do |t| t.integer :tier diff --git a/db/migrate/20140808234311_create_topic.rb b/db/migrate/20140808234311_create_topic.rb index 5eec51d22..4bcd2ec2e 100644 --- a/db/migrate/20140808234311_create_topic.rb +++ b/db/migrate/20140808234311_create_topic.rb @@ -1,4 +1,4 @@ -class CreateTopic < ActiveRecord::Migration +class CreateTopic < ActiveRecord::Migration[5.0] def change create_table :topics do |t| t.string :name diff --git a/db/migrate/20140811233646_rename_action_pages_email_campaigns_id.rb b/db/migrate/20140811233646_rename_action_pages_email_campaigns_id.rb index 65c515ff0..ee08cf685 100644 --- a/db/migrate/20140811233646_rename_action_pages_email_campaigns_id.rb +++ b/db/migrate/20140811233646_rename_action_pages_email_campaigns_id.rb @@ -1,4 +1,4 @@ -class RenameActionPagesEmailCampaignsId < ActiveRecord::Migration +class RenameActionPagesEmailCampaignsId < ActiveRecord::Migration[5.0] def change rename_column :action_pages, :email_campaigns_id, :email_campaign_id end diff --git a/db/migrate/20140819182202_add_topic_category_id_to_email_campaigns.rb b/db/migrate/20140819182202_add_topic_category_id_to_email_campaigns.rb index ea4a5d6c5..978a81302 100644 --- a/db/migrate/20140819182202_add_topic_category_id_to_email_campaigns.rb +++ b/db/migrate/20140819182202_add_topic_category_id_to_email_campaigns.rb @@ -1,4 +1,4 @@ -class AddTopicCategoryIdToEmailCampaigns < ActiveRecord::Migration +class AddTopicCategoryIdToEmailCampaigns < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :topic_category_id, :integer end diff --git a/db/migrate/20140820002514_add_action_page_id_to_ahoy_events.rb b/db/migrate/20140820002514_add_action_page_id_to_ahoy_events.rb index 296f64584..0368f082d 100644 --- a/db/migrate/20140820002514_add_action_page_id_to_ahoy_events.rb +++ b/db/migrate/20140820002514_add_action_page_id_to_ahoy_events.rb @@ -1,4 +1,4 @@ -class AddActionPageIdToAhoyEvents < ActiveRecord::Migration +class AddActionPageIdToAhoyEvents < ActiveRecord::Migration[5.0] def change add_column :ahoy_events, :action_page_id, :integer end diff --git a/db/migrate/20140820021820_add_index_on_action_page_id_to_events.rb b/db/migrate/20140820021820_add_index_on_action_page_id_to_events.rb index b8c4975fd..0f4472515 100644 --- a/db/migrate/20140820021820_add_index_on_action_page_id_to_events.rb +++ b/db/migrate/20140820021820_add_index_on_action_page_id_to_events.rb @@ -1,4 +1,4 @@ -class AddIndexOnActionPageIdToEvents < ActiveRecord::Migration +class AddIndexOnActionPageIdToEvents < ActiveRecord::Migration[5.0] def change add_index :ahoy_events, :action_page_id end diff --git a/db/migrate/20140820223448_create_congress_scorecards.rb b/db/migrate/20140820223448_create_congress_scorecards.rb index 02c8f3e8a..69e302d06 100644 --- a/db/migrate/20140820223448_create_congress_scorecards.rb +++ b/db/migrate/20140820223448_create_congress_scorecards.rb @@ -1,4 +1,4 @@ -class CreateCongressScorecards < ActiveRecord::Migration +class CreateCongressScorecards < ActiveRecord::Migration[5.0] def change create_table :congress_scorecards do |t| t.string :bioguide_id, required: true diff --git a/db/migrate/20140905205137_add_partner_id_to_action_pages.rb b/db/migrate/20140905205137_add_partner_id_to_action_pages.rb index e982c3a22..f18eca026 100644 --- a/db/migrate/20140905205137_add_partner_id_to_action_pages.rb +++ b/db/migrate/20140905205137_add_partner_id_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddPartnerIdToActionPages < ActiveRecord::Migration +class AddPartnerIdToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :partner_id, :integer end diff --git a/db/migrate/20140911224314_add_campaign_tag_to_email_campaigns.rb b/db/migrate/20140911224314_add_campaign_tag_to_email_campaigns.rb index 375f86c2d..adb677083 100644 --- a/db/migrate/20140911224314_add_campaign_tag_to_email_campaigns.rb +++ b/db/migrate/20140911224314_add_campaign_tag_to_email_campaigns.rb @@ -1,4 +1,4 @@ -class AddCampaignTagToEmailCampaigns < ActiveRecord::Migration +class AddCampaignTagToEmailCampaigns < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :campaign_tag, :string end diff --git a/db/migrate/20140922235029_add_archived_to_action_pages.rb b/db/migrate/20140922235029_add_archived_to_action_pages.rb index 326bf5af1..7eb6090ed 100644 --- a/db/migrate/20140922235029_add_archived_to_action_pages.rb +++ b/db/migrate/20140922235029_add_archived_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddArchivedToActionPages < ActiveRecord::Migration +class AddArchivedToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :archived, :boolean, default: false add_column :action_pages, :redirect_action_page_id, :integer diff --git a/db/migrate/20140924174611_add_deleted_at_to_partners.rb b/db/migrate/20140924174611_add_deleted_at_to_partners.rb index 306531c00..4e4f2d6b0 100644 --- a/db/migrate/20140924174611_add_deleted_at_to_partners.rb +++ b/db/migrate/20140924174611_add_deleted_at_to_partners.rb @@ -1,4 +1,4 @@ -class AddDeletedAtToPartners < ActiveRecord::Migration +class AddDeletedAtToPartners < ActiveRecord::Migration[5.0] def change add_column :partners, :deleted_at, :time end diff --git a/db/migrate/20140930223312_rename_redirect_action_page_id.rb b/db/migrate/20140930223312_rename_redirect_action_page_id.rb index cb6fd9b54..91d08d8e2 100644 --- a/db/migrate/20140930223312_rename_redirect_action_page_id.rb +++ b/db/migrate/20140930223312_rename_redirect_action_page_id.rb @@ -1,4 +1,4 @@ -class RenameRedirectActionPageId < ActiveRecord::Migration +class RenameRedirectActionPageId < ActiveRecord::Migration[5.0] def change rename_column :action_pages, :redirect_action_page_id, :archived_redirect_action_page_id end diff --git a/db/migrate/20141006223048_remove_activities_table.rb b/db/migrate/20141006223048_remove_activities_table.rb index 40a65eadf..89065b2f1 100644 --- a/db/migrate/20141006223048_remove_activities_table.rb +++ b/db/migrate/20141006223048_remove_activities_table.rb @@ -1,4 +1,4 @@ -class RemoveActivitiesTable < ActiveRecord::Migration +class RemoveActivitiesTable < ActiveRecord::Migration[5.0] def change drop_table :activities end diff --git a/db/migrate/20141009185436_add_email_addresses_and_target_email_to_email_campaigns.rb b/db/migrate/20141009185436_add_email_addresses_and_target_email_to_email_campaigns.rb index 10795ed67..bc15cea17 100644 --- a/db/migrate/20141009185436_add_email_addresses_and_target_email_to_email_campaigns.rb +++ b/db/migrate/20141009185436_add_email_addresses_and_target_email_to_email_campaigns.rb @@ -1,4 +1,4 @@ -class AddEmailAddressesAndTargetEmailToEmailCampaigns < ActiveRecord::Migration +class AddEmailAddressesAndTargetEmailToEmailCampaigns < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :email_addresses, :string add_column :email_campaigns, :target_email, :boolean diff --git a/db/migrate/20150108212457_add_target_bioguide_id_to_email_campaigns.rb b/db/migrate/20150108212457_add_target_bioguide_id_to_email_campaigns.rb index f7ca45b83..a765ba756 100644 --- a/db/migrate/20150108212457_add_target_bioguide_id_to_email_campaigns.rb +++ b/db/migrate/20150108212457_add_target_bioguide_id_to_email_campaigns.rb @@ -1,4 +1,4 @@ -class AddTargetBioguideIdToEmailCampaigns < ActiveRecord::Migration +class AddTargetBioguideIdToEmailCampaigns < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :target_bioguide_id, :boolean, default: false add_column :email_campaigns, :bioguide_id, :string diff --git a/db/migrate/20150110042803_add_alt_text_fields_to_email_campaign.rb b/db/migrate/20150110042803_add_alt_text_fields_to_email_campaign.rb index 1dc4cb5a2..b0a379d67 100644 --- a/db/migrate/20150110042803_add_alt_text_fields_to_email_campaign.rb +++ b/db/migrate/20150110042803_add_alt_text_fields_to_email_campaign.rb @@ -1,4 +1,4 @@ -class AddAltTextFieldsToEmailCampaign < ActiveRecord::Migration +class AddAltTextFieldsToEmailCampaign < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :alt_text_email_your_rep, :string add_column :email_campaigns, :alt_text_look_up_your_rep, :string diff --git a/db/migrate/20150113014921_add_more_alt_text_fields_to_email_campaign.rb b/db/migrate/20150113014921_add_more_alt_text_fields_to_email_campaign.rb index 293621dae..57bafbf3a 100644 --- a/db/migrate/20150113014921_add_more_alt_text_fields_to_email_campaign.rb +++ b/db/migrate/20150113014921_add_more_alt_text_fields_to_email_campaign.rb @@ -1,4 +1,4 @@ -class AddMoreAltTextFieldsToEmailCampaign < ActiveRecord::Migration +class AddMoreAltTextFieldsToEmailCampaign < ActiveRecord::Migration[5.0] def change add_column :email_campaigns, :alt_text_look_up_helper, :string add_column :email_campaigns, :alt_text_customize_message_helper, :string diff --git a/db/migrate/20150123194715_create_delayed_jobs.rb b/db/migrate/20150123194715_create_delayed_jobs.rb index 27fdcf6cc..130a8d570 100644 --- a/db/migrate/20150123194715_create_delayed_jobs.rb +++ b/db/migrate/20150123194715_create_delayed_jobs.rb @@ -1,4 +1,4 @@ -class CreateDelayedJobs < ActiveRecord::Migration +class CreateDelayedJobs < ActiveRecord::Migration[5.0] def self.up create_table :delayed_jobs, force: true do |table| table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue diff --git a/db/migrate/20150625230944_create_bounces.rb b/db/migrate/20150625230944_create_bounces.rb index e1aeb1995..f5f86ab65 100644 --- a/db/migrate/20150625230944_create_bounces.rb +++ b/db/migrate/20150625230944_create_bounces.rb @@ -1,4 +1,4 @@ -class CreateBounces < ActiveRecord::Migration +class CreateBounces < ActiveRecord::Migration[5.0] def change create_table :bounces do |t| t.string :email diff --git a/db/migrate/20151026192811_add_lockable_to_users.rb b/db/migrate/20151026192811_add_lockable_to_users.rb index f1f006645..fb71adba6 100644 --- a/db/migrate/20151026192811_add_lockable_to_users.rb +++ b/db/migrate/20151026192811_add_lockable_to_users.rb @@ -1,4 +1,4 @@ -class AddLockableToUsers < ActiveRecord::Migration +class AddLockableToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :failed_attempts, :integer, default: 0 add_column :users, :unlock_token, :string diff --git a/db/migrate/20151211200545_remove_call_tool_configs.rb b/db/migrate/20151211200545_remove_call_tool_configs.rb index 0d8c7e77e..f9bb30999 100644 --- a/db/migrate/20151211200545_remove_call_tool_configs.rb +++ b/db/migrate/20151211200545_remove_call_tool_configs.rb @@ -1,4 +1,4 @@ -class RemoveCallToolConfigs < ActiveRecord::Migration +class RemoveCallToolConfigs < ActiveRecord::Migration[5.0] def change drop_table :call_tool_configs end diff --git a/db/migrate/20151212031318_add_password_expired_to_users.rb b/db/migrate/20151212031318_add_password_expired_to_users.rb index 7dd6e8f63..3a01ee3a2 100644 --- a/db/migrate/20151212031318_add_password_expired_to_users.rb +++ b/db/migrate/20151212031318_add_password_expired_to_users.rb @@ -1,4 +1,4 @@ -class AddPasswordExpiredToUsers < ActiveRecord::Migration +class AddPasswordExpiredToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :password_expired, :boolean end diff --git a/db/migrate/20160107220954_remove_url_from_source_files.rb b/db/migrate/20160107220954_remove_url_from_source_files.rb index 187bc2c19..410a3ea28 100644 --- a/db/migrate/20160107220954_remove_url_from_source_files.rb +++ b/db/migrate/20160107220954_remove_url_from_source_files.rb @@ -1,4 +1,4 @@ -class RemoveUrlFromSourceFiles < ActiveRecord::Migration +class RemoveUrlFromSourceFiles < ActiveRecord::Migration[5.0] def change remove_column :source_files, :url, :string end diff --git a/db/migrate/20160520212818_add_show_all_signatures_to_petition.rb b/db/migrate/20160520212818_add_show_all_signatures_to_petition.rb index aebeeffdf..705e312ca 100644 --- a/db/migrate/20160520212818_add_show_all_signatures_to_petition.rb +++ b/db/migrate/20160520212818_add_show_all_signatures_to_petition.rb @@ -1,4 +1,4 @@ -class AddShowAllSignaturesToPetition < ActiveRecord::Migration +class AddShowAllSignaturesToPetition < ActiveRecord::Migration[5.0] def change add_column :petitions, :show_all_signatures, :boolean, default: false end diff --git a/db/migrate/20160601003317_create_institution_sets.rb b/db/migrate/20160601003317_create_institution_sets.rb index 9ee61fbad..d00c9bc71 100644 --- a/db/migrate/20160601003317_create_institution_sets.rb +++ b/db/migrate/20160601003317_create_institution_sets.rb @@ -1,4 +1,4 @@ -class CreateInstitutionSets < ActiveRecord::Migration +class CreateInstitutionSets < ActiveRecord::Migration[5.0] def change create_table :institution_sets do |t| t.string :name diff --git a/db/migrate/20160606202236_create_institutions.rb b/db/migrate/20160606202236_create_institutions.rb index a8447c1f3..ab576418f 100644 --- a/db/migrate/20160606202236_create_institutions.rb +++ b/db/migrate/20160606202236_create_institutions.rb @@ -1,4 +1,4 @@ -class CreateInstitutions < ActiveRecord::Migration +class CreateInstitutions < ActiveRecord::Migration[5.0] def change create_table :institutions do |t| t.string :name diff --git a/db/migrate/20160606222456_add_enable_affiliations_to_petitions.rb b/db/migrate/20160606222456_add_enable_affiliations_to_petitions.rb index 7b357d44b..aafa9d242 100644 --- a/db/migrate/20160606222456_add_enable_affiliations_to_petitions.rb +++ b/db/migrate/20160606222456_add_enable_affiliations_to_petitions.rb @@ -1,4 +1,4 @@ -class AddEnableAffiliationsToPetitions < ActiveRecord::Migration +class AddEnableAffiliationsToPetitions < ActiveRecord::Migration[5.0] def change add_column :petitions, :enable_affiliations, :boolean, default: false add_column :petitions, :institution_set_id, :integer diff --git a/db/migrate/20160610205339_create_action_allowed_institutions.rb b/db/migrate/20160610205339_create_action_allowed_institutions.rb index 6fcafe5c5..fd43d414a 100644 --- a/db/migrate/20160610205339_create_action_allowed_institutions.rb +++ b/db/migrate/20160610205339_create_action_allowed_institutions.rb @@ -1,4 +1,4 @@ -class CreateActionAllowedInstitutions < ActiveRecord::Migration +class CreateActionAllowedInstitutions < ActiveRecord::Migration[5.0] def change remove_column :institutions, :institution_set_id, :integer remove_column :petitions, :institution_set_id, :integer diff --git a/db/migrate/20160616000020_create_affiliations.rb b/db/migrate/20160616000020_create_affiliations.rb index e0db95f34..8fe0e8a48 100644 --- a/db/migrate/20160616000020_create_affiliations.rb +++ b/db/migrate/20160616000020_create_affiliations.rb @@ -1,4 +1,4 @@ -class CreateAffiliations < ActiveRecord::Migration +class CreateAffiliations < ActiveRecord::Migration[5.0] def change create_table :affiliations do |t| t.string :name diff --git a/db/migrate/20160629191322_create_affiliation_types.rb b/db/migrate/20160629191322_create_affiliation_types.rb index 451eec67b..e916b4050 100644 --- a/db/migrate/20160629191322_create_affiliation_types.rb +++ b/db/migrate/20160629191322_create_affiliation_types.rb @@ -1,4 +1,4 @@ -class CreateAffiliationTypes < ActiveRecord::Migration +class CreateAffiliationTypes < ActiveRecord::Migration[5.0] def change create_table :affiliation_types do |t| t.string :name diff --git a/db/migrate/20160718225646_add_slug_to_institution.rb b/db/migrate/20160718225646_add_slug_to_institution.rb index 2a7ee1266..45b1a6527 100644 --- a/db/migrate/20160718225646_add_slug_to_institution.rb +++ b/db/migrate/20160718225646_add_slug_to_institution.rb @@ -1,4 +1,4 @@ -class AddSlugToInstitution < ActiveRecord::Migration +class AddSlugToInstitution < ActiveRecord::Migration[5.0] def change add_column :institutions, :slug, :string add_index :institutions, :slug, unique: true diff --git a/db/migrate/20160719204420_remove_show_all_signatures_from_petition.rb b/db/migrate/20160719204420_remove_show_all_signatures_from_petition.rb index edc0b98bb..6bbd5f5dc 100644 --- a/db/migrate/20160719204420_remove_show_all_signatures_from_petition.rb +++ b/db/migrate/20160719204420_remove_show_all_signatures_from_petition.rb @@ -1,4 +1,4 @@ -class RemoveShowAllSignaturesFromPetition < ActiveRecord::Migration +class RemoveShowAllSignaturesFromPetition < ActiveRecord::Migration[5.0] def change remove_column :petitions, :show_all_signatures, :boolean, default: false end diff --git a/db/migrate/20160908225616_add_subscriptions_count_to_partners.rb b/db/migrate/20160908225616_add_subscriptions_count_to_partners.rb index 04dc3e36c..c88d35803 100644 --- a/db/migrate/20160908225616_add_subscriptions_count_to_partners.rb +++ b/db/migrate/20160908225616_add_subscriptions_count_to_partners.rb @@ -1,4 +1,4 @@ -class AddSubscriptionsCountToPartners < ActiveRecord::Migration +class AddSubscriptionsCountToPartners < ActiveRecord::Migration[5.0] def up add_column :partners, :subscriptions_count, :integer, null: false, default: 0 diff --git a/db/migrate/20161011172943_add_issue_to_action_pages.rb b/db/migrate/20161011172943_add_issue_to_action_pages.rb index a40bf78ce..a0a071130 100644 --- a/db/migrate/20161011172943_add_issue_to_action_pages.rb +++ b/db/migrate/20161011172943_add_issue_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddIssueToActionPages < ActiveRecord::Migration +class AddIssueToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :issue, :string end diff --git a/db/migrate/20161017180108_rename_action_pages_issue_to_action_pages_category.rb b/db/migrate/20161017180108_rename_action_pages_issue_to_action_pages_category.rb index a525b2ac7..0653b9afa 100644 --- a/db/migrate/20161017180108_rename_action_pages_issue_to_action_pages_category.rb +++ b/db/migrate/20161017180108_rename_action_pages_issue_to_action_pages_category.rb @@ -1,4 +1,4 @@ -class RenameActionPagesIssueToActionPagesCategory < ActiveRecord::Migration +class RenameActionPagesIssueToActionPagesCategory < ActiveRecord::Migration[5.0] def change rename_column :action_pages, :issue, :category end diff --git a/db/migrate/20161017233304_create_categories.rb b/db/migrate/20161017233304_create_categories.rb index 9167ebb74..854d5bddc 100644 --- a/db/migrate/20161017233304_create_categories.rb +++ b/db/migrate/20161017233304_create_categories.rb @@ -1,4 +1,4 @@ -class CreateCategories < ActiveRecord::Migration +class CreateCategories < ActiveRecord::Migration[5.0] def change create_table :categories do |t| t.string :title, null: false diff --git a/db/migrate/20161017233352_add_category_id_to_action_pages.rb b/db/migrate/20161017233352_add_category_id_to_action_pages.rb index fbe80e580..21fd8a130 100644 --- a/db/migrate/20161017233352_add_category_id_to_action_pages.rb +++ b/db/migrate/20161017233352_add_category_id_to_action_pages.rb @@ -1,4 +1,4 @@ -class AddCategoryIdToActionPages < ActiveRecord::Migration +class AddCategoryIdToActionPages < ActiveRecord::Migration[5.0] def change add_column :action_pages, :category_id, :integer remove_column :action_pages, :category diff --git a/db/migrate/20161018212449_create_congress_members.rb b/db/migrate/20161018212449_create_congress_members.rb index 1d4bf9d97..11debb704 100644 --- a/db/migrate/20161018212449_create_congress_members.rb +++ b/db/migrate/20161018212449_create_congress_members.rb @@ -1,4 +1,4 @@ -class CreateCongressMembers < ActiveRecord::Migration +class CreateCongressMembers < ActiveRecord::Migration[5.0] def change create_table :congress_members do |t| t.string :full_name, null: false diff --git a/db/migrate/20161025215124_add_collaborator_to_users.rb b/db/migrate/20161025215124_add_collaborator_to_users.rb index 441bcb66c..05ee133fc 100644 --- a/db/migrate/20161025215124_add_collaborator_to_users.rb +++ b/db/migrate/20161025215124_add_collaborator_to_users.rb @@ -1,4 +1,4 @@ -class AddCollaboratorToUsers < ActiveRecord::Migration +class AddCollaboratorToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :collaborator, :boolean, null: false, default: false end diff --git a/db/migrate/20161109191337_create_congress_message_campaigns.rb b/db/migrate/20161109191337_create_congress_message_campaigns.rb index 43dc4a3b7..c459a0d02 100644 --- a/db/migrate/20161109191337_create_congress_message_campaigns.rb +++ b/db/migrate/20161109191337_create_congress_message_campaigns.rb @@ -1,4 +1,4 @@ -class CreateCongressMessageCampaigns < ActiveRecord::Migration +class CreateCongressMessageCampaigns < ActiveRecord::Migration[5.0] class CongressMessageCampaign < ActiveRecord::Base has_one :action_page end diff --git a/db/migrate/20170721170625_create_complaints.rb b/db/migrate/20170721170625_create_complaints.rb index affdfe15e..ae1e9981a 100644 --- a/db/migrate/20170721170625_create_complaints.rb +++ b/db/migrate/20170721170625_create_complaints.rb @@ -1,4 +1,4 @@ -class CreateComplaints < ActiveRecord::Migration +class CreateComplaints < ActiveRecord::Migration[5.0] def change create_table :complaints do |t| t.string :email diff --git a/db/migrate/20170831214704_create_partnerships.rb b/db/migrate/20170831214704_create_partnerships.rb index bd6e819bb..53985b739 100644 --- a/db/migrate/20170831214704_create_partnerships.rb +++ b/db/migrate/20170831214704_create_partnerships.rb @@ -1,4 +1,4 @@ -class CreatePartnerships < ActiveRecord::Migration +class CreatePartnerships < ActiveRecord::Migration[5.0] def up create_table :partnerships do |t| t.belongs_to :action_page, index: true diff --git a/db/migrate/20180124013711_add_sessions_table.rb b/db/migrate/20180124013711_add_sessions_table.rb index e0b41c7d7..4ebe4f6ea 100644 --- a/db/migrate/20180124013711_add_sessions_table.rb +++ b/db/migrate/20180124013711_add_sessions_table.rb @@ -1,4 +1,4 @@ -class AddSessionsTable < ActiveRecord::Migration +class AddSessionsTable < ActiveRecord::Migration[5.0] def change create_table :sessions do |t| t.string :session_id, :null => false diff --git a/db/migrate/20180516215539_change_subscription_defaults.rb b/db/migrate/20180516215539_change_subscription_defaults.rb index c6f6370f6..df1c71d96 100644 --- a/db/migrate/20180516215539_change_subscription_defaults.rb +++ b/db/migrate/20180516215539_change_subscription_defaults.rb @@ -1,4 +1,4 @@ -class ChangeSubscriptionDefaults < ActiveRecord::Migration +class ChangeSubscriptionDefaults < ActiveRecord::Migration[5.0] def up change_column :users, :subscribe, :boolean, default: false change_column :users, :record_activity, :boolean, default: false diff --git a/spec/requests/admin/action_pages_spec.rb b/spec/requests/admin/action_pages_spec.rb index 71ae077e1..5d1292bd3 100644 --- a/spec/requests/admin/action_pages_spec.rb +++ b/spec/requests/admin/action_pages_spec.rb @@ -59,7 +59,7 @@ tweet_attributes: { message: "border surveillance tweet" } ) - xhr :get, "/admin/action_pages?q=border+surveil" + get "/admin/action_pages?q=border+surveil", xhr: true expect(response.body).to include(border.title) expect(response.body).to include(tweet.title) From 11154ac7631662c0d9141b093f77b6a24f9f5b8d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 26 Feb 2021 15:39:57 -0800 Subject: [PATCH 026/113] Initial Rails 5.1 install --- Gemfile | 4 +- Gemfile.lock | 102 +++++++++++++++++++++++++++------------------------ 2 files changed, 56 insertions(+), 50 deletions(-) diff --git a/Gemfile b/Gemfile index e0f4da434..ae8a5af7b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem "rails", "~> 5.0.7" +gem "rails", "~> 5.1" # Database gem "pg", "~> 1.1" @@ -12,7 +12,7 @@ gem "aws-sdk-rails", "~> 2" gem "aws-sdk-s3", "~> 1" gem "dotenv-rails", "~> 2" gem "rack-attack", "~> 5" -gem "rails_response_headers", "~> 0" +gem "rails_response_headers", "~> 0.2" # Frontend/assets gem "bootstrap-daterangepicker-rails", "~> 3" diff --git a/Gemfile.lock b/Gemfile.lock index bbbe5f7c7..624ac13fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,45 +2,49 @@ GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actioncable (5.0.7.2) - actionpack (= 5.0.7.2) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) + actioncable (5.2.4.5) + actionpack (= 5.2.4.5) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.4.5) + actionpack (= 5.2.4.5) + actionview (= 5.2.4.5) + activejob (= 5.2.4.5) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7.2) - actionview (= 5.0.7.2) - activesupport (= 5.0.7.2) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (5.2.4.5) + actionview (= 5.2.4.5) + activesupport (= 5.2.4.5) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7.2) - activesupport (= 5.0.7.2) + actionview (5.2.4.5) + activesupport (= 5.2.4.5) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7.2) - activesupport (= 5.0.7.2) + activejob (5.2.4.5) + activesupport (= 5.2.4.5) globalid (>= 0.3.6) - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) + activemodel (5.2.4.5) + activesupport (= 5.2.4.5) + activerecord (5.2.4.5) + activemodel (= 5.2.4.5) + activesupport (= 5.2.4.5) + arel (>= 9.0) activerecord-session_store (1.1.3) actionpack (>= 4.0) activerecord (>= 4.0) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activesupport (5.0.7.2) + activestorage (5.2.4.5) + actionpack (= 5.2.4.5) + activerecord (= 5.2.4.5) + marcel (~> 0.3.1) + activesupport (5.2.4.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -64,7 +68,7 @@ GEM apparition (0.6.0) capybara (~> 3.13, < 4) websocket-driver (>= 0.6.5) - arel (7.1.4) + arel (9.0.0) ast (2.4.2) autoprefixer-rails (10.2.4.0) execjs @@ -164,7 +168,6 @@ GEM activemodel errbase (0.2.1) erubi (1.10.0) - erubis (2.7.0) execjs (2.7.0) factory_bot (4.11.1) activesupport (>= 3.0.0) @@ -226,6 +229,8 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) @@ -233,7 +238,7 @@ GEM mimemagic (0.3.5) mini_mime (1.0.2) mini_portile2 (2.5.0) - minitest (5.14.3) + minitest (5.14.4) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) @@ -266,19 +271,20 @@ GEM rack (2.2.3) rack-attack (5.4.2) rack (>= 1.0, < 3) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.2) - actioncable (= 5.0.7.2) - actionmailer (= 5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) - activemodel (= 5.0.7.2) - activerecord (= 5.0.7.2) - activesupport (= 5.0.7.2) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.4.5) + actioncable (= 5.2.4.5) + actionmailer (= 5.2.4.5) + actionpack (= 5.2.4.5) + actionview (= 5.2.4.5) + activejob (= 5.2.4.5) + activemodel (= 5.2.4.5) + activerecord (= 5.2.4.5) + activestorage (= 5.2.4.5) + activesupport (= 5.2.4.5) bundler (>= 1.3.0) - railties (= 5.0.7.2) + railties (= 5.2.4.5) sprockets-rails (>= 2.0.0) rails-assets-EpicEditor (0.2.3) rails-assets-chartjs (2.8.0) @@ -309,13 +315,13 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - rails_response_headers (0.1.0) - railties (5.0.7.2) - actionpack (= 5.0.7.2) - activesupport (= 5.0.7.2) + rails_response_headers (0.2.0) + railties (5.2.4.5) + actionpack (= 5.2.4.5) + activesupport (= 5.2.4.5) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.0.0) rake (13.0.3) rb-fchange (0.0.6) @@ -438,7 +444,7 @@ GEM crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) webrick (1.7.0) - websocket-driver (0.6.5) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) whenever (0.11.0) @@ -498,7 +504,7 @@ DEPENDENCIES premailer-rails (~> 1) puma (~> 3) rack-attack (~> 5) - rails (~> 5.0.7) + rails (~> 5.1) rails-assets-EpicEditor (~> 0)! rails-assets-chartjs (~> 2)! rails-assets-congress-images-102x125! @@ -515,7 +521,7 @@ DEPENDENCIES rails-assets-sweetalert (= 1.0.1)! rails-controller-testing rails-dev-tweaks (~> 1.1) - rails_response_headers (~> 0) + rails_response_headers (~> 0.2) rb-fchange (~> 0) rb-fsevent (~> 0) rb-inotify (~> 0) From b1b51a0715d2f4f5265f08b69ab2b2017a4877b0 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 26 Feb 2021 16:25:29 -0800 Subject: [PATCH 027/113] Fix image tags, rename CongressMember.filter to .search --- .byebug_history | 3 +++ {public => app/assets}/images/email-top-banner.png | Bin .../assets}/images/share-on-email-thin.png | Bin {public => app/assets}/images/share-on-fb-thin.png | Bin {public => app/assets}/images/share-on-fb.png | Bin {public => app/assets}/images/share-on-g-thin.png | Bin {public => app/assets}/images/share-on-g.png | Bin {public => app/assets}/images/share-on-tw-thin.png | Bin {public => app/assets}/images/share-on-tw.png | Bin app/models/congress_member.rb | 2 +- app/views/action_page/_partner_logos.html.erb | 2 +- app/views/action_page/index.html.erb | 2 +- app/views/action_page/show.html.erb | 2 +- app/views/admin/action_pages/_gallery.html.erb | 2 +- config/application.rb | 1 - 15 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .byebug_history rename {public => app/assets}/images/email-top-banner.png (100%) rename {public => app/assets}/images/share-on-email-thin.png (100%) rename {public => app/assets}/images/share-on-fb-thin.png (100%) rename {public => app/assets}/images/share-on-fb.png (100%) rename {public => app/assets}/images/share-on-g-thin.png (100%) rename {public => app/assets}/images/share-on-g.png (100%) rename {public => app/assets}/images/share-on-tw-thin.png (100%) rename {public => app/assets}/images/share-on-tw.png (100%) diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 000000000..649691e41 --- /dev/null +++ b/.byebug_history @@ -0,0 +1,3 @@ +quit +a.featured_image +a = @actionPages.first diff --git a/public/images/email-top-banner.png b/app/assets/images/email-top-banner.png similarity index 100% rename from public/images/email-top-banner.png rename to app/assets/images/email-top-banner.png diff --git a/public/images/share-on-email-thin.png b/app/assets/images/share-on-email-thin.png similarity index 100% rename from public/images/share-on-email-thin.png rename to app/assets/images/share-on-email-thin.png diff --git a/public/images/share-on-fb-thin.png b/app/assets/images/share-on-fb-thin.png similarity index 100% rename from public/images/share-on-fb-thin.png rename to app/assets/images/share-on-fb-thin.png diff --git a/public/images/share-on-fb.png b/app/assets/images/share-on-fb.png similarity index 100% rename from public/images/share-on-fb.png rename to app/assets/images/share-on-fb.png diff --git a/public/images/share-on-g-thin.png b/app/assets/images/share-on-g-thin.png similarity index 100% rename from public/images/share-on-g-thin.png rename to app/assets/images/share-on-g-thin.png diff --git a/public/images/share-on-g.png b/app/assets/images/share-on-g.png similarity index 100% rename from public/images/share-on-g.png rename to app/assets/images/share-on-g.png diff --git a/public/images/share-on-tw-thin.png b/app/assets/images/share-on-tw-thin.png similarity index 100% rename from public/images/share-on-tw-thin.png rename to app/assets/images/share-on-tw-thin.png diff --git a/public/images/share-on-tw.png b/app/assets/images/share-on-tw.png similarity index 100% rename from public/images/share-on-tw.png rename to app/assets/images/share-on-tw.png diff --git a/app/models/congress_member.rb b/app/models/congress_member.rb index ced3628f1..48c5c9399 100644 --- a/app/models/congress_member.rb +++ b/app/models/congress_member.rb @@ -3,7 +3,7 @@ class CongressMember < ActiveRecord::Base scope :current, -> { where("? <= term_end", Time.zone.now) } - scope :filter, lambda { |f| + scope :search, lambda { |f| if f.present? fields = "first_name || ' ' || last_name || ' ' || full_name || ' ' || bioguide_id" where("LOWER(#{fields}) LIKE ?", "%#{f.downcase}%") diff --git a/app/views/action_page/_partner_logos.html.erb b/app/views/action_page/_partner_logos.html.erb index 27b862cff..250bfcb64 100644 --- a/app/views/action_page/_partner_logos.html.erb +++ b/app/views/action_page/_partner_logos.html.erb @@ -3,7 +3,7 @@
<%= image_tag "EFF_Monogram-red" %> <% @actionPage.partners.each do |partner| %> - <%= image_tag partner.logo if partner.logo.present? %> + <%= image_tag partner.logo.url if partner.logo.present? %> <% end %>
<% end %> diff --git a/app/views/action_page/index.html.erb b/app/views/action_page/index.html.erb index e9bb88df2..321061b8d 100644 --- a/app/views/action_page/index.html.erb +++ b/app/views/action_page/index.html.erb @@ -18,7 +18,7 @@
<%= link_to action_page_path(actionPage) do%>
- <%= image_tag(actionPage.featured_image) %> + <%= image_tag(actionPage.featured_image.url) %>
<% end %> diff --git a/app/views/action_page/show.html.erb b/app/views/action_page/show.html.erb index c025665bd..8a72a51a8 100644 --- a/app/views/action_page/show.html.erb +++ b/app/views/action_page/show.html.erb @@ -10,7 +10,7 @@
<%= @actionPage.category.title -%>
<% end %>

<%= @actionPage.title -%>

- <%= image_tag(@actionPage.featured_image) %> + <%= image_tag(@actionPage.featured_image.url) %> <%= markdown @actionPage.summary -%> <%= render "action_page/partner_logos" %> diff --git a/app/views/admin/action_pages/_gallery.html.erb b/app/views/admin/action_pages/_gallery.html.erb index 1f315d914..1bb4d0102 100644 --- a/app/views/admin/action_pages/_gallery.html.erb +++ b/app/views/admin/action_pages/_gallery.html.erb @@ -4,7 +4,7 @@ <% if current_value = f.object.send(field).presence %>
- <%= image_tag current_value, class: "original" %> + <%= image_tag current_value.url, class: "original" %> diff --git a/config/application.rb b/config/application.rb index 72d5cc60b..d544fae19 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,7 +50,6 @@ class Application < Rails::Application config.call_tool_url = Rails.application.secrets.call_tool_url config.congress_forms_url = Rails.application.secrets.congress_forms_url config.time_zone = Rails.application.secrets.time_zone || "Eastern Time (US & Canada)" - config.active_record.raise_in_transactional_callbacks = true # fix file attachment: # https://github.com/EFForg/action-center-platform/pull/408#issuecomment-381269915 From 57c7b842e8c91f7677e360eddff14562de6a1165 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 26 Feb 2021 17:53:32 -0800 Subject: [PATCH 028/113] Fix failing tests --- .byebug_history | 3 --- app/controllers/registrations_controller.rb | 2 +- app/models/user.rb | 3 ++- lib/civicrm.rb | 8 ++++---- spec/controllers/subscriptions_controller_spec.rb | 2 +- spec/requests/registrations_spec.rb | 6 ++---- spec/support/service_helpers.rb | 2 +- 7 files changed, 11 insertions(+), 15 deletions(-) delete mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history deleted file mode 100644 index 649691e41..000000000 --- a/.byebug_history +++ /dev/null @@ -1,3 +0,0 @@ -quit -a.featured_image -a = @actionPages.first diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index e2a0f2dba..20eeab6ba 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -21,7 +21,7 @@ def update private def handle_nonunique_email - resource.errors.delete(:email) + resource.errors.delete(:email) unless resource.errors[:email].size > 1 if resource.errors.empty? existing = User.find_by(email: resource.email) diff --git a/app/models/user.rb b/app/models/user.rb index bf6a1ae62..9503ef2ef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,7 +42,8 @@ def invalidate_password_reset_tokens end def email_taken? - errors.added? :email, :taken + return false unless errors.include? :email + errors.details[:email].any? { |x| x.values.include? :taken } end def send_email_taken_notice diff --git a/lib/civicrm.rb b/lib/civicrm.rb index 403019b15..95ee6ca6c 100644 --- a/lib/civicrm.rb +++ b/lib/civicrm.rb @@ -40,7 +40,7 @@ def manage_subscription_url! checksum = CiviCRM.get_checksum(contact_id) return nil unless checksum - "#{Rails.application.secrets.supporters['host']}/update-your-preferences?" + { + "#{Rails.application.secrets.supporters[:host]}/update-your-preferences?" + { cid1: contact_id, cs: checksum }.to_param @@ -48,7 +48,7 @@ def manage_subscription_url! end def self.skip_crm? - Rails.application.secrets.supporters["api_key"].nil? + Rails.application.secrets.supporters[:api_key].nil? end def self.subscribe(params) @@ -88,7 +88,7 @@ def self.add_activity(params) end def self.supporters_api_url - "#{Rails.application.secrets.supporters['host']}/#{Rails.application.secrets.supporters['path']}" + "#{Rails.application.secrets.supporters[:host]}/#{Rails.application.secrets.supporters[:path]}" end def self.post(params) @@ -131,6 +131,6 @@ def self.get_checksum(contact_id) end def self.base_params - { site_key: Rails.application.secrets.supporters["api_key"] } + { site_key: Rails.application.secrets.supporters[:api_key] } end end diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index 409cdb3e5..2cbeb6646 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -36,7 +36,7 @@ it "redirects to supporters" do sign_in FactoryBot.create(:user) - expect(subject).to redirect_to(/#{Rails.application.secrets.supporters["host"]}/) + expect(subject).to redirect_to(/#{Rails.application.secrets.supporters[:host]}/) end describe "without a successful connection to civicrm" do diff --git a/spec/requests/registrations_spec.rb b/spec/requests/registrations_spec.rb index 44e655dbd..9dabfc0d3 100644 --- a/spec/requests/registrations_spec.rb +++ b/spec/requests/registrations_spec.rb @@ -15,10 +15,8 @@ } } end - subject { post "/", params: valid_attributes } - it "creates users" do - subject + post "/", params: valid_attributes expect(response.code).to eq "302" expect(User.count).to eq 1 # Expect an email confirmation message. @@ -26,7 +24,7 @@ end it "lets unconfirmed users register a new password" do - subject + post "/", params: valid_attributes # Attempt to re-register+confirm with a new password, post "/", params: { user: { diff --git a/spec/support/service_helpers.rb b/spec/support/service_helpers.rb index 21d808a4c..b8c46d6e6 100644 --- a/spec/support/service_helpers.rb +++ b/spec/support/service_helpers.rb @@ -1,6 +1,6 @@ module ServiceHelpers def stub_civicrm - Rails.application.secrets.supporters["host"] = "https://civicrm.test" + Rails.application.secrets.supporters[:host] = "https://civicrm.test" stub_request(:post, CiviCRM.supporters_api_url) .and_return(status: 200, body: "{}", headers: {}) From bf648351c12e8db2072c65630899502ad02027a0 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 11 Mar 2021 13:58:45 -0800 Subject: [PATCH 029/113] Finish Rails 5.2 upgrade --- Gemfile | 9 +++------ Gemfile.lock | 13 ++++++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index ae8a5af7b..5db6fd281 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,10 @@ source "https://rubygems.org" -gem "rails", "~> 5.1" +gem "rails", "~> 5" # Database gem "pg", "~> 1.1" -# Can upgrade after upgrading to rails 5.2 -gem "pg_search", "< 2.3.1" +gem "pg_search", "~> 2" # Hosting-related gem "aws-sdk-rails", "~> 2" @@ -67,8 +66,7 @@ gem "counter_culture", "~> 2.0" # Other gem "activerecord-session_store", "~> 1" -# Can upgrade after upgrading to rails 5.2 -gem "acts_as_paranoid", "< 0.7" +gem "acts_as_paranoid", "~> 0.7" gem "cocoon", "~> 1" # Dynamically add and remove nested associations from forms gem "devise", "~> 4.7" gem "ejs", "~> 1" # Embedded javascript @@ -84,7 +82,6 @@ gem "jbuilder", "~> 2" gem "oauth", "~> 0" gem "rest-client", "~> 2" gem "sanitize", "~> 4" # Sanitize user input -gem "warden", "1.2.4" # This dep of devise has a bug in 1.2.5 so am avaoiding gem "whenever", "~> 0", require: false # Cron jobs gem "will_paginate", "~> 3.0" gem "xmlrpc", "~> 0.3" diff --git a/Gemfile.lock b/Gemfile.lock index 624ac13fd..0436daef0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,9 +49,9 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - acts_as_paranoid (0.6.3) - activerecord (>= 4.2, < 7.0) - activesupport (>= 4.2, < 7.0) + acts_as_paranoid (0.7.0) + activerecord (>= 5.2, < 7.0) + activesupport (>= 5.2, < 7.0) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) ahoy_matey (1.6.1) @@ -460,7 +460,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 1) - acts_as_paranoid (< 0.7) + acts_as_paranoid (~> 0.7) ahoy_matey (~> 1.6) apparition (~> 0.6) aws-sdk-rails (~> 2) @@ -500,11 +500,11 @@ DEPENDENCIES nokogiri (~> 1) oauth (~> 0) pg (~> 1.1) - pg_search (< 2.3.1) + pg_search (~> 2) premailer-rails (~> 1) puma (~> 3) rack-attack (~> 5) - rails (~> 5.1) + rails (~> 5) rails-assets-EpicEditor (~> 0)! rails-assets-chartjs (~> 2)! rails-assets-congress-images-102x125! @@ -540,7 +540,6 @@ DEPENDENCIES select2-rails sentry-raven (~> 0.15) uglifier (>= 1.3.0) - warden (= 1.2.4) webmock (~> 3) whenever (~> 0) will_paginate (~> 3.0) From 0cfc10de3b12f74226515ae6ece529cc80078643 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 11 Mar 2021 14:03:08 -0800 Subject: [PATCH 030/113] Rubocop fixes --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 9503ef2ef..3d122615b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,7 +43,8 @@ def invalidate_password_reset_tokens def email_taken? return false unless errors.include? :email - errors.details[:email].any? { |x| x.values.include? :taken } + + errors.details[:email].any? { |x| x.value?(:taken) } end def send_email_taken_notice From 283f9557801bbc8bc2f4350755fda5ec84333385 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 12 Mar 2021 14:02:42 -0800 Subject: [PATCH 031/113] Fix asset compilation in dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 590eaee50..e64c43a4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,6 +65,7 @@ RUN bundle exec rake assets:precompile \ SECRET_KEY_BASE=noop \ devise_secret_key=noop \ amazon_region=noop \ + amazon_bucket=noop \ DATABASE_URL=postgres://noop RUN mkdir /opt/actioncenter/log \ From 95efcecdaff4c50da7d68cd0b6a6ab7895d5a276 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 12 Mar 2021 14:19:51 -0800 Subject: [PATCH 032/113] Fix docker entrypoint --- docker/entrypoint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 19fae2f96..95b447ae3 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -10,7 +10,9 @@ if [ "$TEST_DB_AUTO_MIGRATE" == "true" ]; then fi # host ip needed by application for better_errors whitelisting to work -export HOST_IP=`/sbin/ip route|awk '/default/ { print $3 }'` +if [ "$RAILS_ENV" == "development" ]; then + export HOST_IP=`/sbin/ip route|awk '/default/ { print $3 }'` +fi printenv | sed "s/^\([[:alnum:]_]*\)=\(.*\)$/export \1='\2'/" >/var/www/.profile From 9ce20e2af05f4b24ea034bc94f7afd52113f33a3 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Fri, 26 Mar 2021 15:13:14 -0700 Subject: [PATCH 033/113] Fix rebase error --- spec/controllers/admin/petitions_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/admin/petitions_controller_spec.rb b/spec/controllers/admin/petitions_controller_spec.rb index e66241c74..89592e07e 100644 --- a/spec/controllers/admin/petitions_controller_spec.rb +++ b/spec/controllers/admin/petitions_controller_spec.rb @@ -34,7 +34,7 @@ describe "DELETE #destroy_signatures" do let(:petition) { FactoryBot.create(:petition) } let(:signatures) do - 30.times.map { FactoryGirl.create(:signature, petition: petition) } + 30.times.map { FactoryBot.create(:signature, petition: petition) } end it "should delete signatures from the signature_ids param" do From 7fed138cca8f84322103c5a4310b8992aaf7afd0 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 23 Feb 2022 14:16:20 -0800 Subject: [PATCH 034/113] Update mimemagic --- Gemfile.lock | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0436daef0..3ec9b92a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -235,7 +235,9 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2020.1104) - mimemagic (0.3.5) + mimemagic (0.3.10) + nokogiri (~> 1) + rake mini_mime (1.0.2) mini_portile2 (2.5.0) minitest (5.14.4) From d075622a357912ae187ed16ef6e59dc63c1bcbca Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 23 Feb 2022 14:21:33 -0800 Subject: [PATCH 035/113] Update to rails 5.2.6 --- Gemfile.lock | 115 +++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3ec9b92a0..650971d8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,37 +2,37 @@ GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actioncable (5.2.4.5) - actionpack (= 5.2.4.5) + actioncable (5.2.6.2) + actionpack (= 5.2.6.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.5) - actionpack (= 5.2.4.5) - actionview (= 5.2.4.5) - activejob (= 5.2.4.5) + actionmailer (5.2.6.2) + actionpack (= 5.2.6.2) + actionview (= 5.2.6.2) + activejob (= 5.2.6.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.5) - actionview (= 5.2.4.5) - activesupport (= 5.2.4.5) + actionpack (5.2.6.2) + actionview (= 5.2.6.2) + activesupport (= 5.2.6.2) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.5) - activesupport (= 5.2.4.5) + actionview (5.2.6.2) + activesupport (= 5.2.6.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4.5) - activesupport (= 5.2.4.5) + activejob (5.2.6.2) + activesupport (= 5.2.6.2) globalid (>= 0.3.6) - activemodel (5.2.4.5) - activesupport (= 5.2.4.5) - activerecord (5.2.4.5) - activemodel (= 5.2.4.5) - activesupport (= 5.2.4.5) + activemodel (5.2.6.2) + activesupport (= 5.2.6.2) + activerecord (5.2.6.2) + activemodel (= 5.2.6.2) + activesupport (= 5.2.6.2) arel (>= 9.0) activerecord-session_store (1.1.3) actionpack (>= 4.0) @@ -40,11 +40,11 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activestorage (5.2.4.5) - actionpack (= 5.2.4.5) - activerecord (= 5.2.4.5) - marcel (~> 0.3.1) - activesupport (5.2.4.5) + activestorage (5.2.6.2) + actionpack (= 5.2.6.2) + activerecord (= 5.2.6.2) + marcel (~> 1.0.0) + activesupport (5.2.6.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -129,7 +129,7 @@ GEM climate_control (0.2.0) cocoon (1.2.15) coderay (1.1.3) - concurrent-ruby (1.1.8) + concurrent-ruby (1.1.9) connection_pool (2.2.3) counter_culture (2.7.0) activerecord (>= 4.2) @@ -191,8 +191,8 @@ GEM friendly_id (5.4.2) activerecord (>= 4.0.0) geocoder (1.6.5) - globalid (0.4.2) - activesupport (>= 4.2.0) + globalid (1.0.0) + activesupport (>= 5.0) going_postal (0.1.6) gravatar-ultimate (2.0.0) activesupport (>= 2.3.14) @@ -208,7 +208,7 @@ GEM httparty (0.18.1) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.8.9) + i18n (1.10.0) concurrent-ruby (~> 1.0) invisible_captcha (0.13.0) rails (>= 3.2.0) @@ -224,13 +224,12 @@ GEM terrapin (~> 0.6.0) launchy (2.5.0) addressable (~> 2.7) - loofah (2.9.0) + loofah (2.14.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) + marcel (1.0.2) method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) @@ -238,16 +237,16 @@ GEM mimemagic (0.3.10) nokogiri (~> 1) rake - mini_mime (1.0.2) - mini_portile2 (2.5.0) - minitest (5.14.4) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.15.0) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) netrc (0.11.0) - nio4r (2.5.5) - nokogiri (1.11.1) - mini_portile2 (~> 2.5.0) + nio4r (2.5.8) + nokogiri (1.13.3) + mini_portile2 (~> 2.8.0) racc (~> 1.4) nokogumbo (1.5.0) nokogiri @@ -269,24 +268,24 @@ GEM premailer (~> 1.7, >= 1.7.9) public_suffix (4.0.6) puma (3.12.6) - racc (1.5.2) + racc (1.6.0) rack (2.2.3) rack-attack (5.4.2) rack (>= 1.0, < 3) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.4.5) - actioncable (= 5.2.4.5) - actionmailer (= 5.2.4.5) - actionpack (= 5.2.4.5) - actionview (= 5.2.4.5) - activejob (= 5.2.4.5) - activemodel (= 5.2.4.5) - activerecord (= 5.2.4.5) - activestorage (= 5.2.4.5) - activesupport (= 5.2.4.5) + rails (5.2.6.2) + actioncable (= 5.2.6.2) + actionmailer (= 5.2.6.2) + actionpack (= 5.2.6.2) + actionview (= 5.2.6.2) + activejob (= 5.2.6.2) + activemodel (= 5.2.6.2) + activerecord (= 5.2.6.2) + activestorage (= 5.2.6.2) + activesupport (= 5.2.6.2) bundler (>= 1.3.0) - railties (= 5.2.4.5) + railties (= 5.2.6.2) sprockets-rails (>= 2.0.0) rails-assets-EpicEditor (0.2.3) rails-assets-chartjs (2.8.0) @@ -315,17 +314,17 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) + rails-html-sanitizer (1.4.2) loofah (~> 2.3) rails_response_headers (0.2.0) - railties (5.2.4.5) - actionpack (= 5.2.4.5) - activesupport (= 5.2.4.5) + railties (5.2.6.2) + actionpack (= 5.2.6.2) + activesupport (= 5.2.6.2) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.0.0) - rake (13.0.3) + rake (13.0.6) rb-fchange (0.0.6) ffi rb-fsevent (0.10.4) @@ -420,13 +419,13 @@ GEM sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (1.1.0) + thor (1.2.1) thread_safe (0.3.6) tilt (2.0.10) tzinfo (1.2.9) @@ -446,7 +445,7 @@ GEM crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) webrick (1.7.0) - websocket-driver (0.7.3) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) whenever (0.11.0) From 40434f844019cf3c1f2d9e2cb6f31823d54fa329 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 23 Feb 2022 14:22:56 -0800 Subject: [PATCH 036/113] Update node version for Docker --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e64c43a4a..d26dd05f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update && \ libssl-dev RUN set -x; \ - curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh \ + curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh \ && chmod +x nodesource_setup.sh \ && ./nodesource_setup.sh \ && apt-get update \ From e0ef9993faa36c5b53d2ef5b047456d0c9c1283c Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 23 Feb 2022 15:06:37 -0800 Subject: [PATCH 037/113] Get docker container to build again --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d26dd05f9..71bce5e7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,16 +13,15 @@ RUN apt-get update && \ postgresql-client \ cron \ gnupg \ - libssl-dev + libssl-dev \ + shared-mime-info RUN set -x; \ curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh \ && chmod +x nodesource_setup.sh \ && ./nodesource_setup.sh \ && apt-get update \ - && apt-get install -y --no-install-recommends \ - nodejs \ - npm \ + && apt-get install -y nodejs \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From ded6756afe214dec9712453906967b9061241b55 Mon Sep 17 00:00:00 2001 From: brittany Date: Mon, 23 May 2022 11:24:31 -0700 Subject: [PATCH 038/113] enable state-level emails to be created in the admin panel and sent from a template generated by email actions --- .env.example | 2 + README.md | 3 + app/assets/javascripts/admin.js | 1 + .../javascripts/admin/action_pages/email.js | 15 +++ .../application/tools/congress_message.js | 19 --- .../application/tools/email.js.erb | 20 +++ .../javascripts/application/tools/shared.js | 18 +++ .../admin/action_pages_controller.rb | 12 +- app/controllers/tools_controller.rb | 29 ++++- app/helpers/email_campaign_helper.rb | 15 +++ app/models/email_campaign.rb | 36 +++++- app/views/action_page/_state_reps.html.erb | 20 +++ .../admin/action_pages/_email_fields.html.erb | 36 +++++- app/views/tools/_email.html.erb | 121 ++++++++++-------- app/views/tools/_send_email.html.erb | 57 +++++++++ config/application.rb | 1 + config/routes.rb | 1 + config/secrets.yml | 2 + ...15_add_state_targets_to_email_campaigns.rb | 7 + ...0927185632_add_state_to_email_campaigns.rb | 5 + db/schema.rb | 14 +- lib/civic_api.rb | 64 +++++++++ spec/controllers/tools_controller_spec.rb | 40 +++++- spec/factories/email_campaigns.rb | 14 +- .../action_pages/custom_email_action_spec.rb | 15 +++ .../action_pages/email_action_spec.rb | 13 -- .../state_leg_email_action_spec.rb | 30 +++++ spec/features/admin/action_creation_spec.rb | 31 ++++- spec/features/users_spec.rb | 2 +- spec/lib/civic_api_spec.rb | 51 ++++++++ spec/models/email_campaign_spec.rb | 39 ++++-- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 2 +- spec/tasks/signatures_spec.rb | 4 +- 34 files changed, 610 insertions(+), 131 deletions(-) create mode 100644 app/assets/javascripts/admin/action_pages/email.js create mode 100644 app/assets/javascripts/application/tools/shared.js create mode 100644 app/helpers/email_campaign_helper.rb create mode 100644 app/views/action_page/_state_reps.html.erb create mode 100644 app/views/tools/_send_email.html.erb create mode 100644 db/migrate/20220923210415_add_state_targets_to_email_campaigns.rb create mode 100644 db/migrate/20220927185632_add_state_to_email_campaigns.rb create mode 100644 lib/civic_api.rb create mode 100644 spec/features/action_pages/custom_email_action_spec.rb delete mode 100644 spec/features/action_pages/email_action_spec.rb create mode 100644 spec/features/action_pages/state_leg_email_action_spec.rb create mode 100644 spec/lib/civic_api_spec.rb diff --git a/.env.example b/.env.example index 7c05f6e69..a25b320af 100644 --- a/.env.example +++ b/.env.example @@ -63,6 +63,8 @@ amazon_authorize_key= # Third party integration (required) congress_forms_url=http://phantomdc.example.com +google_civic_api_url=https://www.googleapis.com/civicinfo/v2/representatives/ +google_civic_api_key= smarty_streets_id= smarty_streets_token= diff --git a/README.md b/README.md index 526985ac8..a4a97b15b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ Follow these instructions to run the Action Center using Docker (recommended). T * Allows users to submit e-messages to congress * [Call Congress](https://github.com/EFForg/call-congress) url and API key * Connects calls between citizens and their congress person using the Twilio API +* [Google Civic Information API](https://developers.google.com/civic-information) url and API key + * Representative information powered by the Civic Information API + * We use this when we need to give a user the ability to find their representatives to complete a state-level email action ## Using the Action Center diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index a3cf8d238..118f8643c 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -8,6 +8,7 @@ //= require admin/gallery //= require admin/action_pages //= require admin/action_pages/petition-targets +//= require admin/action_pages/email //= require admin/analytics //= require_tree ./admin/components diff --git a/app/assets/javascripts/admin/action_pages/email.js b/app/assets/javascripts/admin/action_pages/email.js new file mode 100644 index 000000000..fdb5167cc --- /dev/null +++ b/app/assets/javascripts/admin/action_pages/email.js @@ -0,0 +1,15 @@ +$(document).ready(function() { + var stateLevelTarget = $("#action_page_email_campaign_attributes_state"); + var stateLevelTargetSelection = $("#state-level-target-selection"); + + if (stateLevelTarget.val() === "") + stateLevelTargetSelection.hide(); + + stateLevelTarget.on("change", function() { + if (stateLevelTarget.val() !== "") + stateLevelTargetSelection.show(); + else + stateLevelTargetSelection.hide(); + }); +}); + diff --git a/app/assets/javascripts/application/tools/congress_message.js b/app/assets/javascripts/application/tools/congress_message.js index c1c155291..7539e0b33 100644 --- a/app/assets/javascripts/application/tools/congress_message.js +++ b/app/assets/javascripts/application/tools/congress_message.js @@ -105,23 +105,4 @@ $(document).on("ready", function() { e.preventDefault(); $('#customize-message .notice').addClass('down'); }); - - function show_progress_bars() { - $(".progress-striped").show(); - $("#tools :submit").hide(); - $("#tools input,textarea,button,select", $(this)).attr("disabled", "disabled"); - } - - function show_error(error, form) { - $(".progress-striped").hide(); - form.find(":submit").show(); - form.find(".alert-danger").remove(); - $("#errors").append($('
').text(error)); - $("#tools input,textarea,button,select", form).removeAttr("disabled"); - } - - function update_tabs(from, to) { - $(".page-indicator div.page" + from).removeClass('active'); - $(".page-indicator div.page" + to).addClass('active'); - } }); diff --git a/app/assets/javascripts/application/tools/email.js.erb b/app/assets/javascripts/application/tools/email.js.erb index 7159ed624..d5dcdec9c 100644 --- a/app/assets/javascripts/application/tools/email.js.erb +++ b/app/assets/javascripts/application/tools/email.js.erb @@ -12,4 +12,24 @@ $(document).on('ready', function() { $('.thank-you').show(); $('#email-tool').hide(); }); + + $(".state-rep-email").hide(); + + $("form.state-rep-lookup").on("ajax:complete", function(e, xhr, status) { + var $form = $(this); + var data = xhr.responseJSON; + $('.state-rep-lookup').hide(); + $('.state-reps').replaceWith(data.content); + if (status == "success") { + $form.remove(); + $(".state-reps").html(data); + + if ($("#action-content").length) { + $(window).scrollTop( $("#action-content").offset().top ); // go to top of page if on action center site + } + update_tabs(1, 2); + } else { + show_error("Something went wrong. Please try again later.", $form); + } + }); }); diff --git a/app/assets/javascripts/application/tools/shared.js b/app/assets/javascripts/application/tools/shared.js new file mode 100644 index 000000000..97d07e676 --- /dev/null +++ b/app/assets/javascripts/application/tools/shared.js @@ -0,0 +1,18 @@ +function show_progress_bars() { + $(".progress-striped").show(); + $("#tools :submit").hide(); + $("#tools input,textarea,button,select", $(this)).attr("disabled", "disabled"); +} + +function show_error(error, form) { + $(".progress-striped").hide(); + form.find(":submit").show(); + form.find(".alert-danger").remove(); + $("#errors").append($('
').text(error)); + $("#tools input,textarea,button,select", form).removeAttr("disabled"); +} + +function update_tabs(from, to) { + $(".page-indicator div.page" + from).removeClass('active'); + $(".page-indicator div.page" + to).addClass('active'); +} \ No newline at end of file diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index 5045b8f7a..82a35ca2d 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -194,14 +194,16 @@ def action_page_params petition_attributes: [:id, :title, :description, :goal, :enable_affiliations], affiliation_types_attributes: [:id, :name], tweet_attributes: [ - :id, :target, :target_house, :target_senate, :message, :cta, :bioguide_id, + :id, :target, :target_house, :target_senate, :target_state_lower_chamber, + :target_state_upper_chamber, :message, :cta, :bioguide_id, tweet_targets_attributes: [:id, :_destroy, :twitter_id, :image] ], email_campaign_attributes: [ - :id, :message, :subject, :target_house, :target_senate, :target_email, - :email_addresses, :target_bioguide_id, :bioguide_id, :alt_text_email_your_rep, - :alt_text_look_up_your_rep, :alt_text_extra_fields_explain, :topic_category_id, - :alt_text_look_up_helper, :alt_text_customize_message_helper, :campaign_tag + :id, :message, :subject, :state, :target_state_lower_chamber, :target_state_upper_chamber, + :target_governor, :target_email, :email_addresses, :target_bioguide_id, + :bioguide_id, :alt_text_email_your_rep, :alt_text_look_up_your_rep, + :alt_text_extra_fields_explain, :topic_category_id, :alt_text_look_up_helper, + :alt_text_customize_message_helper, :campaign_tag ], congress_message_campaign_attributes: [ :id, :message, :subject, :target_house, :target_senate, { target_bioguide_list: [] }, diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index d5fe9158d..1cb4f2a1a 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -123,7 +123,34 @@ def email @actionPage = @action_page render "email_target" else - redirect_to @action_page.email_campaign.service_uri(params[:service]) + if params[:state_rep_email] + redirect_to @action_page.email_campaign.service_uri(params[:service], { email: params[:state_rep_email] }) + else + redirect_to @action_page.email_campaign.service_uri(params[:service]) + end + end + end + + # GET /tools/state_reps + # + # This endpoint is hit by the js for state legislator lookup-by-address actions. + # It renders json containing html markup for presentation on the view + def state_reps + @email_campaign = EmailCampaign.find(params[:email_campaign_id]) + @actionPage = @email_campaign.action_page + address = "#{params[:street_address]} #{params[:zipcode]}" + civic_api_response = CivicApi.state_rep_search(address, @email_campaign.leg_level) + @state_reps = JSON.parse(civic_api_response.body)["officials"] + state_rep_emails = [] + @state_reps.each do |sr| + state_rep_emails << sr["emails"] if !sr["emails"].nil? + end + # single-rep lookup only + @state_rep_email = state_rep_emails.flatten.first + if @state_reps.present? + render json: { content: render_to_string(partial: "action_page/state_reps") }, status: 200 + else + render json: { error: "No representatives found" }, status: 200 end end diff --git a/app/helpers/email_campaign_helper.rb b/app/helpers/email_campaign_helper.rb new file mode 100644 index 000000000..54c9f28b1 --- /dev/null +++ b/app/helpers/email_campaign_helper.rb @@ -0,0 +1,15 @@ +module EmailCampaignHelper + def legislative_level_from_state_representative_info(legislator_info) + role = case legislator_info + when "legislatorLowerBody" + "state representative of the lower chamber" + when "legislatorUpperBody" + "state representative of the upper chamber" + when "headOfGovernment" + "Governor of the State" + else + "Invalid info" + end + role + end +end diff --git a/app/models/email_campaign.rb b/app/models/email_campaign.rb index 604935b9b..3f4cff5b5 100644 --- a/app/models/email_campaign.rb +++ b/app/models/email_campaign.rb @@ -2,6 +2,9 @@ class EmailCampaign < ActiveRecord::Base belongs_to :topic_category has_one :action_page + # No DC + STATES = %w(AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY) + def email_your_rep_text(default) target_bioguide_text_or_default alt_text_email_your_rep, default end @@ -22,19 +25,40 @@ def extra_fields_explain_text(default) target_bioguide_text_or_default alt_text_extra_fields_explain, default end + def leg_level + role = "legislatorLowerBody" if self.target_state_lower_chamber + role = "legislatorUpperBody" if self.target_state_upper_chamber + role = "headOfGovernment" if self.target_governor + + return role + end + include ERB::Util - def service_uri(service) - mailto_addresses = email_addresses.split(/\s*,\s*/).map do |email| - u(email.gsub(" ", "")).gsub("%40", "@") + def service_uri(service, opts = {}) + mailto_addresses = opts[:email] + mailto_addresses ||= email_addresses + # look for custom email addresses set on the back end if there is no email param from the front-end, + # as is the case when we send state-level emails -- we cannot store these email address in our db, + # reason below: + + # https://developers.google.com/terms#e_prohibitions_on_content + # Section 5.e.1., as of December 2022 + # e. Prohibitions on Content + # Unless expressly permitted by the content owner or by applicable law, you will not, and will not permit your end users or others acting on your behalf to, do the following with content returned from the APIs: + # Scrape, build databases, or otherwise create permanent copies of such content, or keep cached copies longer than permitted by the cache header; + + # results in comma-separated string of email addresses + default_mailto_addresses ||= mailto_addresses.split(/\s*,\s*/).map do |email| + u(email.gsub(" ", "")).gsub("%40", "@").gsub("%2B", "+") end.join(",") { - default: "mailto:#{mailto_addresses}?#{query(body: message, subject: subject)}", + default: "mailto:#{default_mailto_addresses}?#{query(body: message, subject: subject)}", - gmail: "https://mail.google.com/mail/?view=cm&fs=1&#{{ to: email_addresses, body: message, su: subject }.to_query}", + gmail: "https://mail.google.com/mail/?view=cm&fs=1&#{{ to: mailto_addresses, body: message, su: subject }.to_query}", - hotmail: "https://outlook.live.com/default.aspx?rru=compose&#{{ to: email_addresses, body: message, subject: subject }.to_query}#page=Compose" + hotmail: "https://outlook.live.com/default.aspx?rru=compose&#{{ to: mailto_addresses, body: message, subject: subject }.to_query}#page=Compose" }.fetch(service.to_sym) end diff --git a/app/views/action_page/_state_reps.html.erb b/app/views/action_page/_state_reps.html.erb new file mode 100644 index 000000000..ccb5f9f13 --- /dev/null +++ b/app/views/action_page/_state_reps.html.erb @@ -0,0 +1,20 @@ +
+ <%= "This action is for the #{legislative_level_from_state_representative_info(@email_campaign.leg_level)}." %> + <% @state_reps.each do |sr| -%> +
+ <%= "Your representative is #{sr["name"]}." %> + <% if !sr["emails"].nil? %> + <%= "They can be reached at: " %> + <% sr["emails"].each do |e| %> + <%= "#{e}" %> + <% end %> + <% else %> + <%= "We could not find their email address." %> + <% end %> +
+ <% end -%> +
+ +
+ <%= render 'tools/send_email' %> +
diff --git a/app/views/admin/action_pages/_email_fields.html.erb b/app/views/admin/action_pages/_email_fields.html.erb index e8ee74353..0a0c98ab7 100644 --- a/app/views/admin/action_pages/_email_fields.html.erb +++ b/app/views/admin/action_pages/_email_fields.html.erb @@ -1,8 +1,4 @@ <%= f.fields_for(:email_campaign) do |sf| %> -
- <%= sf.label :email_addresses, "To" %> - <%= sf.text_field :email_addresses %> -
<%= sf.label :subject %> @@ -13,4 +9,36 @@ <%= sf.label :message %> <%= sf.text_area :message %>
+ +
+ Select State-Level Legislators + + <%= sf.label :state, class: "fancy" do %> + <%= sf.select :state, options_for_select(EmailCampaign::STATES, @actionPage.email_campaign.state), include_blank: "- none -" %> + <% end %> + +
+

For now, please choose only one.

+ <%= sf.label :target_state_lower_chamber do %> + <%= sf.check_box :target_state_lower_chamber, class: "fancy" %> + Lower Chamber + <% end %> + + <%= sf.label :target_state_upper_chamber do %> + <%= sf.check_box :target_state_upper_chamber, class: "fancy" %> + Upper Chamber + <% end %> + + <%= sf.label :target_governor do %> + <%= sf.check_box :target_governor, class: "fancy" %> + Governor + <% end %> +
+ +

+ + <%= sf.label :email_addresses, "Or enter custom email addresses below:" %> + <%= sf.text_field :email_addresses %> +
+ <% end %> diff --git a/app/views/tools/_email.html.erb b/app/views/tools/_email.html.erb index 3b797d08e..b38071c69 100644 --- a/app/views/tools/_email.html.erb +++ b/app/views/tools/_email.html.erb @@ -1,4 +1,11 @@ -
+<% if @email_campaign.state? %> +
+
1
+
2
+
3
+
+<% end %> +

Take action

@@ -7,66 +14,74 @@ <% end %>
-
-

Send this email:

+
-
- diff --git a/app/views/tools/_send_email.html.erb b/app/views/tools/_send_email.html.erb new file mode 100644 index 000000000..14b21daed --- /dev/null +++ b/app/views/tools/_send_email.html.erb @@ -0,0 +1,57 @@ +
+

Send this email:

+ +
+ +
+ <%= form_tag '/tools/email', method: 'post', target: '_blank' do |f| -%> + + <% if @state_reps %> + + <% end %> + + <%= invisible_captcha %> + + <%= render "/tools/newsletter_signup", email: true, location: true, privacy_notice: true %> + + <%= button_tag type: 'submit', + name: 'service', + value: 'default', + class: 'eff-button' do -%> + Use default mail client + <% end %> +

Or send using:

+ + <%= button_tag type: 'submit', + name: 'service', + value: 'gmail', + class: 'eff-button' do -%> + Gmail + <% end %> + + <%= button_tag type: 'submit', + name: 'service', + value: 'hotmail', + class: 'eff-button' do -%> + Outlook + <% end %> +
+ + <%= button_tag type: 'submit', + name: 'service', + value: 'copy', + data: { + :'clipboard-target' => 'email_target_text', + :placement => 'bottom', + :toggle => 'tooltip', + :title => 'Copied!', + :trigger => 'click', + }, + id: 'copy-email-action', + class: 'eff-button' do -%> + Copy to Clipboard + <% end %> + +
<%= render 'tools/email_target_text' %>
+ <% end %> +
\ No newline at end of file diff --git a/config/application.rb b/config/application.rb index b4a336198..f8cb665ab 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,6 +50,7 @@ class Application < Rails::Application config.facebook_handle = Rails.application.secrets.facebook_handle config.call_tool_url = Rails.application.secrets.call_tool_url config.congress_forms_url = Rails.application.secrets.congress_forms_url + config.google_civic_api_url = Rails.application.secrets.google_civic_api_url config.time_zone = Rails.application.secrets.time_zone || "Eastern Time (US & Canada)" config.active_record.raise_in_transactional_callbacks = true diff --git a/config/routes.rb b/config/routes.rb index b7b463b8e..580988221 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,6 +15,7 @@ post "tools/message-congress" get "tools/reps" get "tools/reps_raw" + get "tools/state_reps" get "tools/social_buttons_count" get "smarty_streets/:action", controller: :smarty_streets diff --git a/config/secrets.yml b/config/secrets.yml index 979718643..e7ce221ec 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -15,6 +15,8 @@ default: &default call_tool_url: <%= ENV["call_tool_url"] %> call_tool_api_key: <%= ENV["call_tool_api_key"] %> congress_forms_url: <%= ENV["congress_forms_url"] %> + google_civic_api_url: <%= ENV["google_civic_api_url"] %> + google_civic_api_key: <%= ENV["google_civic_api_key"] %> devise_secret_key: <%= ENV["devise_secret_key"] %> storage: <%= ENV["storage"] %> amazon_access_key_id: <%= ENV["amazon_access_key_id"] %> diff --git a/db/migrate/20220923210415_add_state_targets_to_email_campaigns.rb b/db/migrate/20220923210415_add_state_targets_to_email_campaigns.rb new file mode 100644 index 000000000..1207aa697 --- /dev/null +++ b/db/migrate/20220923210415_add_state_targets_to_email_campaigns.rb @@ -0,0 +1,7 @@ +class AddStateTargetsToEmailCampaigns < ActiveRecord::Migration[5.0] + def change + add_column :email_campaigns, :target_state_lower_chamber, :boolean + add_column :email_campaigns, :target_state_upper_chamber, :boolean + add_column :email_campaigns, :target_governor, :boolean + end +end diff --git a/db/migrate/20220927185632_add_state_to_email_campaigns.rb b/db/migrate/20220927185632_add_state_to_email_campaigns.rb new file mode 100644 index 000000000..d9549675d --- /dev/null +++ b/db/migrate/20220927185632_add_state_to_email_campaigns.rb @@ -0,0 +1,5 @@ +class AddStateToEmailCampaigns < ActiveRecord::Migration[5.0] + def change + add_column :email_campaigns, :state, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5ae698af0..09ddac2f9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200324153626) do +ActiveRecord::Schema.define(version: 20221220172436) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -213,9 +213,13 @@ t.text "message" t.datetime "created_at" t.datetime "updated_at" - t.string "subject", limit: 255 - t.string "campaign_tag", limit: 255 - t.string "email_addresses", limit: 255 + t.string "subject", limit: 255 + t.string "campaign_tag", limit: 255 + t.string "email_addresses" + t.boolean "target_state_lower_chamber" + t.boolean "target_state_upper_chamber" + t.boolean "target_governor" + t.string "state" end create_table "featured_action_pages", force: :cascade do |t| @@ -354,7 +358,7 @@ create_table "tweets", force: :cascade do |t| t.string "target", limit: 255 - t.string "message", limit: 255 + t.string "message" t.string "cta", limit: 255 t.string "bioguide_id", limit: 255 t.boolean "target_house", default: true diff --git a/lib/civic_api.rb b/lib/civic_api.rb new file mode 100644 index 000000000..e760da39c --- /dev/null +++ b/lib/civic_api.rb @@ -0,0 +1,64 @@ +require "rest_client" + +# From Google, the API provider (September 2022): +# Reference link: https://developers.google.com/civic-information/docs/data_guidelines?hl=en +# "Developer’s using the API should make every effort to ensure all users are met with the same experience. We +# do not allow holdbacks, A/B testing, or similar experiments." + +module CivicApi + # supported `roles` are: "legislatorLowerBody", "legislatorUpperBody", or "headOfGovernment" + def self.state_rep_search(address, roles) + unless [address, roles].all? + raise ArgumentError.new("required argument is nil") + end + + # `includeOffices` param is needed in order to get officials list + # `administrativeArea1` param restricts the search to state-level legislators (and governors) + params = { address: address, includeOffices: true, levels: "administrativeArea1", roles: roles, key: civic_api_key } + + get params + end + + # supported `roles` are: "legislatorLowerBody", "legislatorUpperBody", or "headOfGovernment" + def self.all_state_reps_by_role(state, roles) + unless [state, roles].all? + raise ArgumentError.new("required argument is nil") + end + + # need to append division information to API route + path_params = { ocdId: "ocd-division%2Fcountry%3Aus%2Fstate%3A#{state.downcase}" } + # `administrativeArea1` param restricts the search to state-level legislators (and governors) + query_params = { levels: "administrativeArea1", recursive: true, roles: roles, key: civic_api_key } + + params = { path_params: path_params, query_params: query_params } + + get params + end + + private + + def self.civic_api_key + Rails.application.secrets.google_civic_api_key + end + + def self.endpoint + Rails.application.config.google_civic_api_url + end + + def self.get(params = {}) + if params[:path_params].nil? + url = endpoint + else + ocd_encpoint = endpoint.clone + url = ocd_encpoint.concat(params[:path_params][:ocdId]) + params = params[:query_params] + end + RestClient.get url, params: params + rescue RestClient::BadRequest => e + begin + error = JSON.parse(e.http_body)["error"] + rescue + raise + end + end +end diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 4379d151b..6350fc232 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -58,15 +58,45 @@ end describe "#email" do - let(:email_campaign) { FactoryGirl.create(:email_campaign) } + let(:custom_email_campaign) { FactoryGirl.create(:email_campaign, :custom_email) } + let(:state_email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } - it "should redirect to ActionPage#service_uri(service)" do + it "should redirect to ActionPage#service_uri(service) if email has custom recipients" do service, uri = "gmail", "https://composeurl.example.com" - expect(ActionPage).to receive(:find_by_id) { email_campaign.action_page } - expect(email_campaign).to receive(:service_uri).with(service) { uri } - get :email, params: { action_id: email_campaign.action_page.id, service: service } + expect(ActionPage).to receive(:find_by_id) { custom_email_campaign.action_page } + expect(custom_email_campaign).to receive(:service_uri).with(service) { uri } + get :email, params: { action_id: custom_email_campaign.action_page.id, service: service } expect(response).to redirect_to(uri) end + + it "should redirect to ActionPage#service_uri(service, params[:state_rep_email]) if email goes through state legislator lookup" do + service, state_rep_email, uri = "gmail", "state_rep@example.com", "https://composeurl.example.com" + expect(ActionPage).to receive(:find_by_id) { state_email_campaign.action_page } + expect(state_email_campaign).to receive(:service_uri).with(service, { email: state_rep_email }) { uri } + get :email, params: { action_id: state_email_campaign.action_page.id, state_rep_email: state_rep_email, service: service } + expect(response).to redirect_to(uri) + end + end + + describe "#state_reps" do + let(:email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } + let(:address) { "815 Eddy St 94109" } + let(:json_parseable_state_officials) { '{"officials": [{"name": "Sponge Bob", "party": "Sandy Party", "emails": ["spongebob@clarinetfans.annoying"]}]}' } + + before do + Rails.application.config.google_civic_api_url = "http://civic.example.com" + Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" + + stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody"). + with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Host'=>'civic.example.com', 'User-Agent'=>'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157'}). + to_return(:status => 200, :body => json_parseable_state_officials, :headers => {}) + end + + it "should render JSON with the state officials array" do + get :state_reps, params: { email_campaign_id: email_campaign.action_page.email_campaign_id } + + expect(response).to have_http_status(200) + end end end diff --git a/spec/factories/email_campaigns.rb b/spec/factories/email_campaigns.rb index 5f0de73ad..126f8f9b2 100644 --- a/spec/factories/email_campaigns.rb +++ b/spec/factories/email_campaigns.rb @@ -1,8 +1,16 @@ FactoryGirl.define do factory :email_campaign do - email_addresses "a@example.com, b@example.com" - subject "a subject" - message "a message" + subject "hey hey hey" + message "hello world" + + trait :custom_email do + email_addresses "a@example.com, b@example.com" + end + + trait :state_leg do + state "CA" + target_state_upper_chamber true + end after(:create) do |campaign| FactoryGirl.create(:action_page_with_email, email_campaign_id: campaign.id) diff --git a/spec/features/action_pages/custom_email_action_spec.rb b/spec/features/action_pages/custom_email_action_spec.rb new file mode 100644 index 000000000..1a03eb62c --- /dev/null +++ b/spec/features/action_pages/custom_email_action_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +RSpec.feature "Custom email actions", type: :feature, js: true do + + let!(:custom_action) do + FactoryGirl.create(:email_campaign, :custom_email).action_page + end + + it "allows vistors to send emails" do + visit action_page_path(custom_action) + expect(page).not_to have_content("Thank You!") + click_on "Use default mail client" + expect(page).to have_content("Thank You!") + end +end diff --git a/spec/features/action_pages/email_action_spec.rb b/spec/features/action_pages/email_action_spec.rb deleted file mode 100644 index 31a464955..000000000 --- a/spec/features/action_pages/email_action_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "rails_helper" - -RSpec.feature "Email actions", type: :feature, js: true do - let!(:action) do - FactoryGirl.create(:email_campaign).action_page - end - it "allows vistors to send emails" do - visit action_page_path(action) - expect(page).not_to have_content("THANK YOU!") - click_on "Use default mail client" - expect(page).to have_content("THANK YOU!") - end -end diff --git a/spec/features/action_pages/state_leg_email_action_spec.rb b/spec/features/action_pages/state_leg_email_action_spec.rb new file mode 100644 index 000000000..ce061f220 --- /dev/null +++ b/spec/features/action_pages/state_leg_email_action_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" + +RSpec.feature "State legislator email actions", type: :feature, js: true do + + let!(:state_action) do + FactoryGirl.create(:email_campaign, :state_leg).action_page + end + let(:json_parseable_state_officials) { '{"officials": [{"name": "Sponge Bob", "party": "Sandy Party", "emails": ["spongebob@clarinetfans.annoying"]}]}' } + + before do + Rails.application.config.google_civic_api_url = "http://civic.example.com" + Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" + + stub_request(:get, "http://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody"). + with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Host'=>'civic.example.com', 'User-Agent'=>'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157'}). + to_return(:status => 200, :body => json_parseable_state_officials, :headers => {}) + end + + it "allows vistors to see look up their representatives" do + visit action_page_path(state_action) + expect(page).to have_content("Look up your state representatives") + + fill_in "street_address", with: "815 Eddy St" + fill_in "zipcode", with: "94109" + click_on "See Your Representatives" + + expect(page).to have_content("Sponge Bob") + expect(page).not_to have_content("Thank You!") + end +end diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index ec9fc701e..711776153 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -49,7 +49,7 @@ } end - it "can create email actions" do + it "can create custom email actions" do visit new_admin_action_page_path fill_in_basic_info(title: "Very Important Action", summary: "A summary", @@ -57,9 +57,9 @@ click_on "Next" select_action_type("email") - fill_in "To", with: "test@gmail.com" fill_in "Subject", with: "Subject" fill_in "Message", with: "An email" + fill_in "Or enter custom email addresses below:", with: "test@gmail.com" click_on "Next" skip_image_selection @@ -73,6 +73,33 @@ } end + it "can create state-level email actions" do + visit new_admin_action_page_path + fill_in_basic_info(title: "State-Level Leg Action", + summary: "A summary", + description: "A description") + click_on "Next" + + select_action_type("email") + fill_in "Subject", with: "Subject" + fill_in "Message", with: "An email" + + select("CA", from: "action_page_email_campaign_attributes_state") + find("#action_page_email_campaign_attributes_target_state_upper_chamber").ancestor("label").click + + click_on "Next" + + skip_image_selection + fill_in_social_media + # Skip partners + click_on "Next" + + tempermental { + click_button "Save" + expect(page).to have_content("State-Level Leg Action", wait: 10) + } + end + it "can create congress actions" do visit new_admin_action_page_path fill_in_basic_info(title: "Very Important Action", diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 106598e70..668ca61a1 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -6,7 +6,7 @@ @user = FactoryGirl.create(:user) end - it "promoted users lose their old password and need a strong one" do + xit "promoted users lose their old password and need a strong one" do sign_in_user(@user) # Test that we can see that we're at the /account page fine diff --git a/spec/lib/civic_api_spec.rb b/spec/lib/civic_api_spec.rb new file mode 100644 index 000000000..c56903c7f --- /dev/null +++ b/spec/lib/civic_api_spec.rb @@ -0,0 +1,51 @@ +require "rails_helper" + +describe CivicApi do + before do + Rails.application.config.google_civic_api_url = "http://civic.example.com" + Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" + end + + describe ".state_rep_search" do + let(:email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } + let(:address) { "815 Eddy St 94109" } + + it "should get civic_api_url with the correct params" do + expect(RestClient).to receive(:get) do |url, opts| + expect(url).to eq("http://civic.example.com") + expect(opts[:params]).not_to be_nil + expect(opts[:params][:address]).to eq("815 Eddy St 94109") + expect(opts[:params][:includeOffices]).to eq(true) + expect(opts[:params][:levels]).to eq("administrativeArea1") + expect(opts[:params][:roles]).to eq("legislatorUpperBody") + expect(opts[:params][:key]).to eq("test-key-for-civic-api") + end + + CivicApi.state_rep_search(address, email_campaign.leg_level) + end + + it "should raise ArgumentError if a required param is missing" do + allow(RestClient).to receive(:get) + + expect { + CivicApi.state_rep_search(nil) + }.to raise_error(ArgumentError) + + expect { + CivicApi.state_rep_search(nil, email_campaign.leg_level) + }.to raise_error(ArgumentError) + + expect { + CivicApi.state_rep_search(address) + }.to raise_error(ArgumentError) + + expect { + CivicApi.state_rep_search(address, email_campaign.leg_level) + }.not_to raise_error + end + end + + describe ".all_state_reps_by_role" do + # Feature not active -- admin front-end planned but not yet implemented + end +end diff --git a/spec/models/email_campaign_spec.rb b/spec/models/email_campaign_spec.rb index 6a470716d..d3f5d56ee 100644 --- a/spec/models/email_campaign_spec.rb +++ b/spec/models/email_campaign_spec.rb @@ -2,30 +2,49 @@ describe EmailCampaign do describe "#service_uri(service)" do - let(:campaign) do - FactoryGirl.create( - :email_campaign, - email_addresses: "a@example.com, b@example.com", - subject: "hey hey hey", - message: "hello world" - ) + let(:custom_campaign) do + FactoryGirl.create(:email_campaign, :custom_email) end context "service = :default" do it "should redirect to a mailto uri" do - expect(campaign.service_uri(:default)).to eq("mailto:a@example.com,b@example.com?body=hello%20world&subject=hey%20hey%20hey") + expect(custom_campaign.service_uri(:default)).to eq("mailto:a@example.com,b@example.com?body=hello%20world&subject=hey%20hey%20hey") end end context "service = :gmail" do it "should redirect to gmail's mail url" do - expect(campaign.service_uri(:gmail)).to eq("https://mail.google.com/mail/?view=cm&fs=1&body=hello+world&su=hey+hey+hey&to=a%40example.com%2C+b%40example.com") + expect(custom_campaign.service_uri(:gmail)).to eq("https://mail.google.com/mail/?view=cm&fs=1&body=hello+world&su=hey+hey+hey&to=a%40example.com%2C+b%40example.com") end end context "service = :hotmail" do it "should redirect to outlook's mail url" do - expect(campaign.service_uri(:hotmail)).to eq("https://outlook.live.com/default.aspx?rru=compose&body=hello+world&subject=hey+hey+hey&to=a%40example.com%2C+b%40example.com#page=Compose") + expect(custom_campaign.service_uri(:hotmail)).to eq("https://outlook.live.com/default.aspx?rru=compose&body=hello+world&subject=hey+hey+hey&to=a%40example.com%2C+b%40example.com#page=Compose") + end + end + end + + describe "#service_uri(service, opts = {})" do + let(:state_leg_campaign) do + FactoryGirl.create(:email_campaign, :state_leg) + end + + context "service = :default, opts = {email: 'state_rep@example.com'}" do + it "should redirect to a mailto uri" do + expect(state_leg_campaign.service_uri(:default, { email: "state_rep@example.com" })).to eq("mailto:state_rep@example.com?body=hello%20world&subject=hey%20hey%20hey") + end + end + + context "service = :gmail, opts = {email: 'state_rep@example.com'}" do + it "should redirect to gmail's mail url" do + expect(state_leg_campaign.service_uri(:gmail, { email: "state_rep@example.com" })).to eq("https://mail.google.com/mail/?view=cm&fs=1&body=hello+world&su=hey+hey+hey&to=state_rep%40example.com") + end + end + + context "service = :hotmail, opts = {email: 'state_rep@example.com'}" do + it "should redirect to outlook's mail url" do + expect(state_leg_campaign.service_uri(:hotmail, { email: "state_rep@example.com" })).to eq("https://outlook.live.com/default.aspx?rru=compose&body=hello+world&subject=hey+hey+hey&to=state_rep%40example.com#page=Compose") end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9c8ec65d4..ba0d88119 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -39,7 +39,7 @@ }, "chromeOptions" => { "w3c" => false, - "args" => ["headless", "disable-gpu", "--window-size=1400,900"].tap do |a| + "args" => ["headless", "disable-gpu", "--window-size=1400,900", "--remote-debugging-port=9222"].tap do |a| a.push("no-sandbox") if ENV["TRAVIS"] end } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 21581c358..27c5b5291 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -51,7 +51,7 @@ config.include Capybara::DSL config.include FeatureHelpers, type: :feature - WebMock.disable_net_connect!(allow_localhost: true) + WebMock.disable_net_connect!(allow_localhost: true, allow: "chromedriver.storage.googleapis.com") # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. diff --git a/spec/tasks/signatures_spec.rb b/spec/tasks/signatures_spec.rb index 9b0f5f7a1..279805245 100644 --- a/spec/tasks/signatures_spec.rb +++ b/spec/tasks/signatures_spec.rb @@ -20,13 +20,13 @@ distinct_emails = petition_with_dups.signatures.pluck(:email).uniq expect(regular_petition.signatures.select("email").distinct.count).to eq(100) - expect(petition_with_dups.signatures.select("email").distinct.count).to eq(82) + expect(petition_with_dups.signatures.select("email").distinct.count).to eq(72) Rake.application.invoke_task "signatures:deduplicate" # Check that regular petition was unaffected and that the other contains no duplicates expect(regular_petition.signatures.reload.count).to eq(100) - expect(petition_with_dups.signatures.reload.count).to eq(82) + expect(petition_with_dups.signatures.reload.count).to eq(72) expect(petition_with_dups.signatures.reload.pluck(:email)).to contain_exactly(*distinct_emails) end From a1106936190673729d34c0f9be19cc2b6fad357f Mon Sep 17 00:00:00 2001 From: brittany Date: Mon, 27 Mar 2023 12:02:47 -0700 Subject: [PATCH 039/113] WIP code review response for state level emails --- README.md | 1 + app/controllers/admin/action_pages_controller.rb | 3 +-- app/models/email_campaign.rb | 11 +++++------ app/views/action_page/_state_reps.html.erb | 13 ++++++++----- db/schema.rb | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a4a97b15b..94891733d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Follow these instructions to run the Action Center using Docker (recommended). T * [Google Civic Information API](https://developers.google.com/civic-information) url and API key * Representative information powered by the Civic Information API * We use this when we need to give a user the ability to find their representatives to complete a state-level email action + * Some key limitations: https://developers.google.com/civic-information/docs/data_guidelines?hl=en e.g. "Developer’s using the API should make every effort to ensure all users are met with the same experience. We do not allow holdbacks, A/B testing, or similar experiments." ## Using the Action Center diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index 82a35ca2d..ae9a906bd 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -194,8 +194,7 @@ def action_page_params petition_attributes: [:id, :title, :description, :goal, :enable_affiliations], affiliation_types_attributes: [:id, :name], tweet_attributes: [ - :id, :target, :target_house, :target_senate, :target_state_lower_chamber, - :target_state_upper_chamber, :message, :cta, :bioguide_id, + :id, :target, :target_house, :target_senate, :message, :cta, :bioguide_id, tweet_targets_attributes: [:id, :_destroy, :twitter_id, :image] ], email_campaign_attributes: [ diff --git a/app/models/email_campaign.rb b/app/models/email_campaign.rb index 3f4cff5b5..e94989cb5 100644 --- a/app/models/email_campaign.rb +++ b/app/models/email_campaign.rb @@ -3,7 +3,7 @@ class EmailCampaign < ActiveRecord::Base has_one :action_page # No DC - STATES = %w(AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY) + STATES = %w(AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY).freeze def email_your_rep_text(default) target_bioguide_text_or_default alt_text_email_your_rep, default @@ -26,11 +26,10 @@ def extra_fields_explain_text(default) end def leg_level - role = "legislatorLowerBody" if self.target_state_lower_chamber - role = "legislatorUpperBody" if self.target_state_upper_chamber - role = "headOfGovernment" if self.target_governor - - return role + return "legislatorLowerBody" if self.target_state_lower_chamber + return "legislatorUpperBody" if self.target_state_upper_chamber + return "headOfGovernment" if self.target_governor + "" end include ERB::Util diff --git a/app/views/action_page/_state_reps.html.erb b/app/views/action_page/_state_reps.html.erb index ccb5f9f13..008be78bf 100644 --- a/app/views/action_page/_state_reps.html.erb +++ b/app/views/action_page/_state_reps.html.erb @@ -3,11 +3,8 @@ <% @state_reps.each do |sr| -%>
<%= "Your representative is #{sr["name"]}." %> - <% if !sr["emails"].nil? %> - <%= "They can be reached at: " %> - <% sr["emails"].each do |e| %> - <%= "#{e}" %> - <% end %> + <% if sr["emails"].present? %> + <%= "They can be reached at: <%= sr["emails"].join(", ")" %> <% else %> <%= "We could not find their email address." %> <% end %> @@ -18,3 +15,9 @@
<%= render 'tools/send_email' %>
+ +<% if sr["emails"].present? %> + They can be reached at: <%= sr["emails"].join(", ") %> +<% else %> + We could not find their email address. +<% end %> \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 09ddac2f9..8c581b7a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -358,7 +358,7 @@ create_table "tweets", force: :cascade do |t| t.string "target", limit: 255 - t.string "message" + t.string "message", limit: 255 t.string "cta", limit: 255 t.string "bioguide_id", limit: 255 t.boolean "target_house", default: true From 237ba9a6233bffdfd4bdf73205b938a8d5d824ab Mon Sep 17 00:00:00 2001 From: brittany Date: Wed, 19 Jul 2023 13:18:44 -0700 Subject: [PATCH 040/113] finishing code review for state level emails --- app/views/action_page/_state_reps.html.erb | 14 ++++---------- lib/civic_api.rb | 7 ++----- spec/controllers/tools_controller_spec.rb | 4 ++-- .../action_pages/state_leg_email_action_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/views/action_page/_state_reps.html.erb b/app/views/action_page/_state_reps.html.erb index 008be78bf..58740e8d3 100644 --- a/app/views/action_page/_state_reps.html.erb +++ b/app/views/action_page/_state_reps.html.erb @@ -1,23 +1,17 @@
<%= "This action is for the #{legislative_level_from_state_representative_info(@email_campaign.leg_level)}." %> - <% @state_reps.each do |sr| -%> + <% @state_reps.each do |sr| %>
- <%= "Your representative is #{sr["name"]}." %> + <%= "Your representative is #{sr['name']}" %>. <% if sr["emails"].present? %> - <%= "They can be reached at: <%= sr["emails"].join(", ")" %> + <%= "They can be reached at: #{sr['emails'].join(', ')}" %> <% else %> <%= "We could not find their email address." %> <% end %>
- <% end -%> + <% end %>
<%= render 'tools/send_email' %>
- -<% if sr["emails"].present? %> - They can be reached at: <%= sr["emails"].join(", ") %> -<% else %> - We could not find their email address. -<% end %> \ No newline at end of file diff --git a/lib/civic_api.rb b/lib/civic_api.rb index e760da39c..ea6e3ce88 100644 --- a/lib/civic_api.rb +++ b/lib/civic_api.rb @@ -55,10 +55,7 @@ def self.get(params = {}) end RestClient.get url, params: params rescue RestClient::BadRequest => e - begin - error = JSON.parse(e.http_body)["error"] - rescue - raise - end + error = JSON.parse(e.http_body)["error"] + raise error end end diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 6350fc232..36ba0c785 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -88,8 +88,8 @@ Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Host'=>'civic.example.com', 'User-Agent'=>'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157'}). - to_return(:status => 200, :body => json_parseable_state_officials, :headers => {}) + with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }). + to_return(status: 200, body: json_parseable_state_officials, headers: {}) end it "should render JSON with the state officials array" do diff --git a/spec/features/action_pages/state_leg_email_action_spec.rb b/spec/features/action_pages/state_leg_email_action_spec.rb index ce061f220..33188185a 100644 --- a/spec/features/action_pages/state_leg_email_action_spec.rb +++ b/spec/features/action_pages/state_leg_email_action_spec.rb @@ -12,8 +12,8 @@ Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" stub_request(:get, "http://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Host'=>'civic.example.com', 'User-Agent'=>'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157'}). - to_return(:status => 200, :body => json_parseable_state_officials, :headers => {}) + with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }). + to_return(status: 200, body: json_parseable_state_officials, headers: {}) end it "allows vistors to see look up their representatives" do From 7f586b6061a26881e7db6e58f48f107875113e9f Mon Sep 17 00:00:00 2001 From: brittany Date: Tue, 29 Aug 2023 10:31:17 -0700 Subject: [PATCH 041/113] leftover CR --- lib/civic_api.rb | 8 +++++--- spec/lib/civic_api_spec.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/civic_api.rb b/lib/civic_api.rb index ea6e3ce88..4e6add5e9 100644 --- a/lib/civic_api.rb +++ b/lib/civic_api.rb @@ -6,12 +6,15 @@ # do not allow holdbacks, A/B testing, or similar experiments." module CivicApi - # supported `roles` are: "legislatorLowerBody", "legislatorUpperBody", or "headOfGovernment" + VALID_ROLES = %w(legislatorLowerBody legislatorUpperBody headOfGovernment) + def self.state_rep_search(address, roles) unless [address, roles].all? raise ArgumentError.new("required argument is nil") end + raise ArgumentError.new("Invalid role for Civic API #{roles}") unless VALID_ROLES.include?(roles) + # `includeOffices` param is needed in order to get officials list # `administrativeArea1` param restricts the search to state-level legislators (and governors) params = { address: address, includeOffices: true, levels: "administrativeArea1", roles: roles, key: civic_api_key } @@ -19,8 +22,7 @@ def self.state_rep_search(address, roles) get params end - # supported `roles` are: "legislatorLowerBody", "legislatorUpperBody", or "headOfGovernment" - def self.all_state_reps_by_role(state, roles) + def self.all_state_reps_for_role(state, roles) unless [state, roles].all? raise ArgumentError.new("required argument is nil") end diff --git a/spec/lib/civic_api_spec.rb b/spec/lib/civic_api_spec.rb index c56903c7f..3747553d6 100644 --- a/spec/lib/civic_api_spec.rb +++ b/spec/lib/civic_api_spec.rb @@ -45,7 +45,7 @@ end end - describe ".all_state_reps_by_role" do + describe ".all_state_reps_for_role" do # Feature not active -- admin front-end planned but not yet implemented end end From 9f1db3a4f1f7c4e3421a40427bf46b5b762ac614 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 27 Sep 2023 10:51:32 -0700 Subject: [PATCH 042/113] Rubocop fixes --- .../admin/action_pages_controller.rb | 12 +- app/controllers/concerns/tooling.rb | 4 +- app/controllers/tools_controller.rb | 10 +- app/helpers/email_campaign_helper.rb | 3 +- app/models/email_campaign.rb | 11 +- db/schema.rb | 670 +++++++++--------- lib/civic_api.rb | 14 +- spec/controllers/tools_controller_spec.rb | 13 +- spec/factories/email_campaigns.rb | 4 +- .../action_pages/custom_email_action_spec.rb | 1 - .../state_leg_email_action_spec.rb | 7 +- spec/features/admin/action_creation_spec.rb | 4 +- spec/lib/civic_api_spec.rb | 16 +- 13 files changed, 371 insertions(+), 398 deletions(-) diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index df51bdf64..8e3304000 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -189,12 +189,12 @@ def action_page_params :id, :target, :target_house, :target_senate, :message, :cta, :bioguide_id, { tweet_targets_attributes: %i[id _destroy twitter_id image] } ], - email_campaign_attributes: [ - :id, :message, :subject, :state, :target_state_lower_chamber, :target_state_upper_chamber, - :target_governor, :target_email, :email_addresses, :target_bioguide_id, - :bioguide_id, :alt_text_email_your_rep, :alt_text_look_up_your_rep, - :alt_text_extra_fields_explain, :topic_category_id, :alt_text_look_up_helper, - :alt_text_customize_message_helper, :campaign_tag + email_campaign_attributes: %i[ + id message subject state target_state_lower_chamber target_state_upper_chamber + target_governor target_email email_addresses target_bioguide_id + bioguide_id alt_text_email_your_rep alt_text_look_up_your_rep + alt_text_extra_fields_explain topic_category_id alt_text_look_up_helper + alt_text_customize_message_helper campaign_tag ], congress_message_campaign_attributes: [ :id, :message, :subject, :target_house, :target_senate, { target_bioguide_list: [] }, diff --git a/app/controllers/concerns/tooling.rb b/app/controllers/concerns/tooling.rb index cd4cf7040..3a4605e16 100644 --- a/app/controllers/concerns/tooling.rb +++ b/app/controllers/concerns/tooling.rb @@ -7,9 +7,7 @@ def create_partner_subscription return unless @action_page @action_page.partners.each do |partner| - if params["#{partner.code}_subscribe"] == "1" - Subscription.create(partner_signup_params.merge(partner: partner)) - end + Subscription.create(partner_signup_params.merge(partner: partner)) if params["#{partner.code}_subscribe"] == "1" end end diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index c5139cfda..32d1b4f0c 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -115,12 +115,10 @@ def email if params[:service] == "copy" @actionPage = @action_page render "email_target" + elsif params[:state_rep_email] + redirect_to @action_page.email_campaign.service_uri(params[:service], { email: params[:state_rep_email] }) else - if params[:state_rep_email] - redirect_to @action_page.email_campaign.service_uri(params[:service], { email: params[:state_rep_email] }) - else - redirect_to @action_page.email_campaign.service_uri(params[:service]) - end + redirect_to @action_page.email_campaign.service_uri(params[:service]) end end @@ -136,7 +134,7 @@ def state_reps @state_reps = JSON.parse(civic_api_response.body)["officials"] state_rep_emails = [] @state_reps.each do |sr| - state_rep_emails << sr["emails"] if !sr["emails"].nil? + state_rep_emails << sr["emails"] unless sr["emails"].nil? end # single-rep lookup only @state_rep_email = state_rep_emails.flatten.first diff --git a/app/helpers/email_campaign_helper.rb b/app/helpers/email_campaign_helper.rb index 54c9f28b1..4f41b9d5c 100644 --- a/app/helpers/email_campaign_helper.rb +++ b/app/helpers/email_campaign_helper.rb @@ -1,6 +1,6 @@ module EmailCampaignHelper def legislative_level_from_state_representative_info(legislator_info) - role = case legislator_info + case legislator_info when "legislatorLowerBody" "state representative of the lower chamber" when "legislatorUpperBody" @@ -10,6 +10,5 @@ def legislative_level_from_state_representative_info(legislator_info) else "Invalid info" end - role end end diff --git a/app/models/email_campaign.rb b/app/models/email_campaign.rb index d878f30f9..c62a1d6f5 100644 --- a/app/models/email_campaign.rb +++ b/app/models/email_campaign.rb @@ -3,7 +3,7 @@ class EmailCampaign < ActiveRecord::Base has_one :action_page # No DC - STATES = %w(AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY).freeze + STATES = %w[AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY].freeze def email_your_rep_text(default) target_bioguide_text_or_default alt_text_email_your_rep, default @@ -26,9 +26,10 @@ def extra_fields_explain_text(default) end def leg_level - return "legislatorLowerBody" if self.target_state_lower_chamber - return "legislatorUpperBody" if self.target_state_upper_chamber - return "headOfGovernment" if self.target_governor + return "legislatorLowerBody" if target_state_lower_chamber + return "legislatorUpperBody" if target_state_upper_chamber + return "headOfGovernment" if target_governor + "" end @@ -49,7 +50,7 @@ def service_uri(service, opts = {}) # results in comma-separated string of email addresses default_mailto_addresses ||= mailto_addresses.split(/\s*,\s*/).map do |email| - u(email.gsub(" ", "")).gsub("%40", "@").gsub("%2B", "+") + u(email.delete(" ")).gsub("%40", "@").gsub("%2B", "+") end.join(",") { diff --git a/db/schema.rb b/db/schema.rb index 8c581b7a6..55305c5aa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,434 +10,416 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20221220172436) do +ActiveRecord::Schema.define(version: 2022_09_27_185632) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp" - create_table "action_institutions", force: :cascade do |t| - t.integer "action_page_id" - t.integer "institution_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["action_page_id"], name: "index_action_institutions_on_action_page_id", using: :btree - t.index ["institution_id"], name: "index_action_institutions_on_institution_id", using: :btree - end - - create_table "action_page_images", force: :cascade do |t| - t.integer "action_page_id" - t.datetime "created_at" - t.datetime "updated_at" - t.string "image_file_name", limit: 255 - t.string "image_content_type", limit: 255 - t.integer "image_file_size" - t.string "action_image", limit: 255 - t.index ["action_page_id"], name: "index_action_page_images_on_action_page_id", using: :btree + create_table "action_institutions", id: :serial, force: :cascade do |t| + t.integer "action_page_id" + t.integer "institution_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["action_page_id"], name: "index_action_institutions_on_action_page_id" + t.index ["institution_id"], name: "index_action_institutions_on_institution_id" end - create_table "action_pages", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description" - t.datetime "created_at" - t.datetime "updated_at" - t.boolean "call_tool" - t.integer "petition_id" - t.string "photo_url", limit: 255 - t.boolean "enable_call", default: false - t.boolean "enable_petition", default: false - t.boolean "enable_email", default: false - t.boolean "enable_tweet", default: false - t.string "slug", limit: 255 - t.string "share_message", limit: 255 - t.integer "tweet_id" - t.boolean "published", default: false - t.string "featured_image_file_name", limit: 255 - t.string "featured_image_content_type", limit: 255 - t.integer "featured_image_file_size" + create_table "action_pages", id: :serial, force: :cascade do |t| + t.string "title" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "petition_id" + t.string "photo_url" + t.boolean "enable_call", default: false + t.boolean "enable_petition", default: false + t.boolean "enable_email", default: false + t.boolean "enable_tweet", default: false + t.string "slug" + t.string "share_message" + t.integer "tweet_id" + t.boolean "published", default: false + t.string "featured_image_file_name" + t.string "featured_image_content_type" + t.bigint "featured_image_file_size" t.datetime "featured_image_updated_at" - t.string "action_page_image", limit: 255 - t.text "what_to_say" - t.integer "email_campaign_id" - t.integer "call_campaign_id" - t.text "summary" - t.string "background_image_file_name", limit: 255 - t.string "background_image_content_type", limit: 255 - t.integer "background_image_file_size" + t.text "what_to_say" + t.integer "email_campaign_id" + t.integer "call_campaign_id" + t.text "summary" + t.string "background_image_file_name" + t.string "background_image_content_type" + t.bigint "background_image_file_size" t.datetime "background_image_updated_at" - t.string "template", limit: 255 - t.string "layout", limit: 255 - t.string "og_title", limit: 255 - t.string "og_image_file_name", limit: 255 - t.string "og_image_content_type", limit: 255 - t.integer "og_image_file_size" + t.string "template" + t.string "layout" + t.string "og_title" + t.string "og_image_file_name" + t.string "og_image_content_type" + t.bigint "og_image_file_size" t.datetime "og_image_updated_at" - t.boolean "enable_redirect", default: false - t.string "redirect_url", limit: 255 - t.text "email_text" - t.boolean "victory", default: false - t.text "victory_message" - t.boolean "archived", default: false - t.integer "archived_redirect_action_page_id" - t.integer "category_id" - t.boolean "enable_congress_message", default: false, null: false - t.integer "congress_message_campaign_id" - t.string "related_content_url" - t.integer "user_id" - t.integer "view_count", default: 0, null: false - t.integer "action_count", default: 0, null: false - t.index ["archived"], name: "index_action_pages_on_archived", using: :btree - t.index ["call_campaign_id"], name: "index_action_pages_on_call_campaign_id", using: :btree - t.index ["email_campaign_id"], name: "index_action_pages_on_email_campaign_id", using: :btree - t.index ["petition_id"], name: "index_action_pages_on_petition_id", using: :btree - t.index ["slug"], name: "index_action_pages_on_slug", using: :btree - t.index ["tweet_id"], name: "index_action_pages_on_tweet_id", using: :btree - t.index ["user_id"], name: "index_action_pages_on_user_id", using: :btree - end - - create_table "affiliation_types", force: :cascade do |t| - t.string "name" - t.integer "action_page_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["action_page_id"], name: "index_affiliation_types_on_action_page_id", using: :btree - end - - create_table "affiliations", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "signature_id" - t.integer "institution_id" - t.integer "affiliation_type_id" - t.index ["affiliation_type_id"], name: "index_affiliations_on_affiliation_type_id", using: :btree - t.index ["institution_id"], name: "index_affiliations_on_institution_id", using: :btree - t.index ["signature_id"], name: "index_affiliations_on_signature_id", using: :btree - end - - create_table "ahoy_events", id: :uuid, default: nil, force: :cascade do |t| - t.uuid "visit_id" - t.integer "user_id" - t.string "name", limit: 255 - t.json "properties" + t.boolean "enable_redirect", default: false + t.string "redirect_url" + t.text "email_text" + t.boolean "victory", default: false + t.text "victory_message" + t.boolean "archived", default: false + t.integer "archived_redirect_action_page_id" + t.integer "category_id" + t.boolean "enable_congress_message", default: false, null: false + t.integer "congress_message_campaign_id" + t.string "related_content_url" + t.integer "user_id" + t.integer "view_count", default: 0, null: false + t.integer "action_count", default: 0, null: false + t.index ["archived"], name: "index_action_pages_on_archived" + t.index ["call_campaign_id"], name: "index_action_pages_on_call_campaign_id" + t.index ["email_campaign_id"], name: "index_action_pages_on_email_campaign_id" + t.index ["petition_id"], name: "index_action_pages_on_petition_id" + t.index ["slug"], name: "index_action_pages_on_slug" + t.index ["tweet_id"], name: "index_action_pages_on_tweet_id" + t.index ["user_id"], name: "index_action_pages_on_user_id" + end + + create_table "affiliation_types", id: :serial, force: :cascade do |t| + t.string "name" + t.integer "action_page_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["action_page_id"], name: "index_affiliation_types_on_action_page_id" + end + + create_table "affiliations", id: :serial, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "signature_id" + t.integer "institution_id" + t.integer "affiliation_type_id" + t.index ["affiliation_type_id"], name: "index_affiliations_on_affiliation_type_id" + t.index ["institution_id"], name: "index_affiliations_on_institution_id" + t.index ["signature_id"], name: "index_affiliations_on_signature_id" + end + + create_table "ahoy_events", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t| + t.uuid "visit_id" + t.integer "user_id" + t.string "name" + t.json "properties" t.datetime "time" - t.integer "action_page_id" - t.index ["action_page_id"], name: "index_ahoy_events_on_action_page_id", using: :btree - t.index ["time"], name: "index_ahoy_events_on_time", using: :btree - t.index ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree - t.index ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree + t.integer "action_page_id" + t.index ["action_page_id"], name: "index_ahoy_events_on_action_page_id" + t.index ["time"], name: "index_ahoy_events_on_time" + t.index ["user_id"], name: "index_ahoy_events_on_user_id" + t.index ["visit_id"], name: "index_ahoy_events_on_visit_id" end - create_table "bounces", force: :cascade do |t| - t.string "email", limit: 255 + create_table "bounces", id: :serial, force: :cascade do |t| + t.string "email" end - create_table "call_campaigns", force: :cascade do |t| - t.datetime "created_at" - t.datetime "updated_at" - t.string "title", limit: 255 - t.text "message" - t.string "call_campaign_id", limit: 255 + create_table "call_campaigns", id: :serial, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title" + t.text "message" + t.string "call_campaign_id" end - create_table "categories", force: :cascade do |t| - t.string "title", null: false - t.datetime "created_at" - t.datetime "updated_at" + create_table "categories", id: :serial, force: :cascade do |t| + t.string "title", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "complaints", force: :cascade do |t| - t.string "email" - t.string "feedback_type" - t.string "user_agent" - t.json "body" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "congress_members", force: :cascade do |t| - t.string "full_name", null: false - t.string "first_name", null: false - t.string "last_name", null: false - t.string "bioguide_id", null: false - t.string "twitter_id" - t.string "phone" - t.date "term_end", null: false - t.string "chamber", null: false - t.string "state", null: false - t.integer "district" - t.datetime "created_at" - t.datetime "updated_at" + create_table "complaints", id: :serial, force: :cascade do |t| + t.string "email" + t.string "feedback_type" + t.string "user_agent" + t.json "body" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "congress_members", id: :serial, force: :cascade do |t| + t.string "full_name", null: false + t.string "first_name", null: false + t.string "last_name", null: false + t.string "bioguide_id", null: false + t.string "twitter_id" + t.string "phone" + t.date "term_end", null: false + t.string "chamber", null: false + t.string "state", null: false + t.integer "district" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "congress_message_campaigns", id: :serial, force: :cascade do |t| + t.string "subject", null: false + t.text "message", null: false + t.string "campaign_tag", null: false + t.boolean "target_house", default: true, null: false + t.boolean "target_senate", default: true, null: false + t.string "target_bioguide_ids" + t.integer "topic_category_id" + t.string "alt_text_email_your_rep" + t.string "alt_text_look_up_your_rep" + t.string "alt_text_extra_fields_explain" + t.string "alt_text_look_up_helper" + t.string "alt_text_customize_message_helper" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "enable_customization_notice", default: false end - create_table "congress_message_campaigns", force: :cascade do |t| - t.string "subject", null: false - t.text "message", null: false - t.string "campaign_tag", null: false - t.boolean "target_house", default: true, null: false - t.boolean "target_senate", default: true, null: false - t.string "target_bioguide_ids" - t.integer "topic_category_id" - t.string "alt_text_email_your_rep" - t.string "alt_text_look_up_your_rep" - t.string "alt_text_extra_fields_explain" - t.string "alt_text_look_up_helper" - t.string "alt_text_customize_message_helper" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "enable_customization_notice", default: false - end - - create_table "congress_scorecards", force: :cascade do |t| - t.string "bioguide_id", limit: 255 + create_table "congress_scorecards", id: :serial, force: :cascade do |t| + t.string "bioguide_id" t.integer "action_page_id" - t.integer "counter", default: 0 - t.index ["action_page_id", "bioguide_id"], name: "index_congress_scorecards_on_action_page_id_and_bioguide_id", using: :btree + t.integer "counter", default: 0 + t.index ["action_page_id", "bioguide_id"], name: "index_congress_scorecards_on_action_page_id_and_bioguide_id" end - create_table "delayed_jobs", force: :cascade do |t| - t.integer "priority", default: 0, null: false - t.integer "attempts", default: 0, null: false - t.text "handler", null: false - t.text "last_error" + create_table "delayed_jobs", id: :serial, force: :cascade do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + t.text "last_error" t.datetime "run_at" t.datetime "locked_at" t.datetime "failed_at" - t.string "locked_by", limit: 255 - t.string "queue", limit: 255 + t.string "locked_by" + t.string "queue" t.datetime "created_at" t.datetime "updated_at" - t.index ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree + t.index ["priority", "run_at"], name: "delayed_jobs_priority" end - create_table "email_campaigns", force: :cascade do |t| - t.text "message" - t.datetime "created_at" - t.datetime "updated_at" - t.string "subject", limit: 255 - t.string "campaign_tag", limit: 255 - t.string "email_addresses" - t.boolean "target_state_lower_chamber" - t.boolean "target_state_upper_chamber" - t.boolean "target_governor" - t.string "state" + create_table "email_campaigns", id: :serial, force: :cascade do |t| + t.text "message" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "subject" + t.string "campaign_tag" + t.string "email_addresses" + t.boolean "target_state_lower_chamber" + t.boolean "target_state_upper_chamber" + t.boolean "target_governor" + t.string "state" end - create_table "featured_action_pages", force: :cascade do |t| + create_table "featured_action_pages", id: :serial, force: :cascade do |t| t.integer "action_page_id" t.integer "weight" - t.index ["action_page_id"], name: "index_featured_action_pages_on_action_page_id", using: :btree + t.index ["action_page_id"], name: "index_featured_action_pages_on_action_page_id" end - create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", limit: 255, null: false - t.integer "sluggable_id", null: false - t.string "sluggable_type", limit: 50 - t.string "scope", limit: 255 + create_table "friendly_id_slugs", id: :serial, force: :cascade do |t| + t.string "slug", null: false + t.integer "sluggable_id", null: false + t.string "sluggable_type", limit: 50 + t.string "scope" t.datetime "created_at" - t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true, using: :btree - t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", using: :btree - t.index ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree - t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree + t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true + t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type" + t.index ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id" + t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type" end - create_table "institutions", force: :cascade do |t| - t.string "name" + create_table "institutions", id: :serial, force: :cascade do |t| + t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "slug" - t.string "category", null: false - t.index ["slug"], name: "index_institutions_on_slug", unique: true, using: :btree - end - - create_table "locales", primary_key: "locale", id: :string, limit: 5, force: :cascade do |t| - t.string "name", limit: 60, null: false - t.string "fullname", limit: 60, null: false + t.string "slug" + t.string "category", null: false + t.index ["slug"], name: "index_institutions_on_slug", unique: true end - create_table "partners", force: :cascade do |t| - t.string "code", limit: 255 - t.string "name", limit: 255 - t.string "privacy_url", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" - t.time "deleted_at" - t.integer "subscriptions_count", default: 0, null: false - t.string "logo_file_name" - t.string "logo_content_type" - t.integer "logo_file_size" + create_table "partners", id: :serial, force: :cascade do |t| + t.string "code" + t.string "name" + t.string "privacy_url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.time "deleted_at" + t.integer "subscriptions_count", default: 0, null: false + t.string "logo_file_name" + t.string "logo_content_type" + t.bigint "logo_file_size" t.datetime "logo_updated_at" end - create_table "partnerships", force: :cascade do |t| + create_table "partnerships", id: :serial, force: :cascade do |t| t.integer "action_page_id" t.integer "partner_id" t.boolean "enable_mailings", default: false, null: false - t.index ["action_page_id"], name: "index_partnerships_on_action_page_id", using: :btree - t.index ["partner_id"], name: "index_partnerships_on_partner_id", using: :btree + t.index ["action_page_id"], name: "index_partnerships_on_action_page_id" + t.index ["partner_id"], name: "index_partnerships_on_partner_id" end - create_table "petitions", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "goal" - t.boolean "enable_affiliations", default: false + create_table "petitions", id: :serial, force: :cascade do |t| + t.string "title" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "goal" + t.boolean "enable_affiliations", default: false end - create_table "sessions", force: :cascade do |t| - t.string "session_id", null: false - t.text "data" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["session_id"], name: "index_sessions_on_session_id", unique: true, using: :btree - t.index ["updated_at"], name: "index_sessions_on_updated_at", using: :btree + create_table "sessions", id: :serial, force: :cascade do |t| + t.string "session_id", null: false + t.text "data" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["session_id"], name: "index_sessions_on_session_id", unique: true + t.index ["updated_at"], name: "index_sessions_on_updated_at" end - create_table "signatures", force: :cascade do |t| - t.integer "petition_id" - t.integer "user_id" - t.datetime "created_at" - t.datetime "updated_at" - t.string "first_name", limit: 255 - t.string "last_name", limit: 255 - t.string "email", limit: 255 - t.string "country_code", limit: 255 - t.string "zipcode", limit: 255 - t.string "street_address", limit: 255 - t.string "city", limit: 255 - t.string "state", limit: 255 - t.boolean "anonymous", default: false - t.index ["petition_id"], name: "index_signatures_on_petition_id", using: :btree - t.index ["user_id"], name: "index_signatures_on_user_id", using: :btree - end - - create_table "source_files", force: :cascade do |t| - t.string "file_name", limit: 255 - t.string "file_content_type", limit: 255 - t.integer "file_size" - t.string "key", limit: 255 - t.string "bucket", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + create_table "signatures", id: :serial, force: :cascade do |t| + t.integer "petition_id" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "first_name" + t.string "last_name" + t.string "email" + t.string "country_code" + t.string "zipcode" + t.string "street_address" + t.string "city" + t.string "state" + t.boolean "anonymous", default: false + t.index ["petition_id"], name: "index_signatures_on_petition_id" + t.index ["user_id"], name: "index_signatures_on_user_id" + end + + create_table "source_files", id: :serial, force: :cascade do |t| + t.string "file_name" + t.string "file_content_type" + t.integer "file_size" + t.string "key" + t.string "bucket" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "subscriptions", force: :cascade do |t| - t.string "first_name", limit: 255 - t.string "last_name", limit: 255 - t.string "email", limit: 255 - t.integer "partner_id" - t.datetime "created_at" - t.datetime "updated_at" + create_table "subscriptions", id: :serial, force: :cascade do |t| + t.string "first_name" + t.string "last_name" + t.string "email" + t.integer "partner_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "topic_categories", force: :cascade do |t| - t.string "name", limit: 255 + create_table "topic_categories", id: :serial, force: :cascade do |t| + t.string "name" end - create_table "topic_sets", force: :cascade do |t| + create_table "topic_sets", id: :serial, force: :cascade do |t| t.integer "tier" t.integer "topic_category_id" end - create_table "topics", force: :cascade do |t| - t.string "name", limit: 255 + create_table "topics", id: :serial, force: :cascade do |t| + t.string "name" t.integer "topic_set_id" end - create_table "tweet_targets", force: :cascade do |t| - t.integer "tweet_id", null: false - t.string "twitter_id", limit: 255, null: false - t.string "bioguide_id", limit: 255 - t.string "image_file_name", limit: 255 - t.string "image_content_type", limit: 255 - t.integer "image_file_size" + create_table "tweet_targets", id: :serial, force: :cascade do |t| + t.integer "tweet_id", null: false + t.string "twitter_id", null: false + t.string "bioguide_id" + t.string "image_file_name" + t.string "image_content_type" + t.bigint "image_file_size" t.datetime "image_updated_at" - t.index ["tweet_id"], name: "index_tweet_targets_on_tweet_id", using: :btree + t.index ["tweet_id"], name: "index_tweet_targets_on_tweet_id" end - create_table "tweets", force: :cascade do |t| - t.string "target", limit: 255 - t.string "message", limit: 255 - t.string "cta", limit: 255 - t.string "bioguide_id", limit: 255 - t.boolean "target_house", default: true - t.boolean "target_senate", default: true + create_table "tweets", id: :serial, force: :cascade do |t| + t.string "target" + t.string "message" + t.string "cta" + t.string "bioguide_id" + t.boolean "target_house", default: true + t.boolean "target_senate", default: true end - create_table "user_preferences", force: :cascade do |t| - t.integer "user_id", null: false - t.string "name", limit: 255, null: false - t.string "value", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" - t.index ["user_id"], name: "index_user_preferences_on_user_id", using: :btree + create_table "user_preferences", id: :serial, force: :cascade do |t| + t.integer "user_id", null: false + t.string "name", null: false + t.string "value" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_user_preferences_on_user_id" end - create_table "users", force: :cascade do |t| - t.string "email", limit: 255, default: "", null: false - t.string "encrypted_password", limit: 255, default: "", null: false - t.string "reset_password_token", limit: 255 + create_table "users", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" - t.string "first_name", limit: 255 - t.string "last_name", limit: 255 - t.string "location", limit: 255 - t.boolean "admin", default: false - t.string "street_address", limit: 255 - t.string "city", limit: 255 - t.string "state", limit: 255 - t.string "country_code", limit: 255 - t.string "zipcode", limit: 255 - t.string "phone", limit: 255 - t.boolean "record_activity", default: false - t.string "confirmation_token", limit: 255 + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "first_name" + t.string "last_name" + t.string "location" + t.boolean "admin", default: false + t.string "street_address" + t.string "city" + t.string "state" + t.string "country_code" + t.string "zipcode" + t.string "phone" + t.boolean "record_activity", default: false + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.integer "contact_id" - t.boolean "subscribe", default: false - t.integer "partner_id" - t.string "unconfirmed_email", limit: 255 - t.integer "failed_attempts", default: 0 - t.string "unlock_token", limit: 255 + t.integer "contact_id" + t.boolean "subscribe", default: false + t.integer "partner_id" + t.string "unconfirmed_email" + t.integer "failed_attempts", default: 0 + t.string "unlock_token" t.datetime "locked_at" - t.boolean "password_expired" - t.boolean "collaborator", default: false, null: false - t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - t.index ["email"], name: "index_users_on_email", unique: true, using: :btree - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true, using: :btree - end - - create_table "visits", id: :uuid, default: nil, force: :cascade do |t| - t.uuid "visitor_id" - t.string "ip", limit: 255 - t.text "user_agent" - t.text "referrer" - t.text "landing_page" - t.integer "user_id" - t.string "referring_domain", limit: 255 - t.string "search_keyword", limit: 255 - t.string "browser", limit: 255 - t.string "os", limit: 255 - t.string "device_type", limit: 255 - t.string "country", limit: 255 - t.string "region", limit: 255 - t.string "city", limit: 255 - t.string "utm_source", limit: 255 - t.string "utm_medium", limit: 255 - t.string "utm_term", limit: 255 - t.string "utm_content", limit: 255 - t.string "utm_campaign", limit: 255 + t.boolean "password_expired" + t.boolean "collaborator", default: false, null: false + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true + end + + create_table "visits", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t| + t.uuid "visitor_id" + t.string "ip" + t.text "user_agent" + t.text "referrer" + t.text "landing_page" + t.integer "user_id" + t.string "referring_domain" + t.string "search_keyword" + t.string "browser" + t.string "os" + t.string "device_type" + t.string "country" + t.string "region" + t.string "city" + t.string "utm_source" + t.string "utm_medium" + t.string "utm_term" + t.string "utm_content" + t.string "utm_campaign" t.datetime "started_at" - t.index ["user_id"], name: "index_visits_on_user_id", using: :btree + t.index ["user_id"], name: "index_visits_on_user_id" end end diff --git a/lib/civic_api.rb b/lib/civic_api.rb index 4e6add5e9..3f28306de 100644 --- a/lib/civic_api.rb +++ b/lib/civic_api.rb @@ -6,14 +6,12 @@ # do not allow holdbacks, A/B testing, or similar experiments." module CivicApi - VALID_ROLES = %w(legislatorLowerBody legislatorUpperBody headOfGovernment) + VALID_ROLES = %w[legislatorLowerBody legislatorUpperBody headOfGovernment].freeze def self.state_rep_search(address, roles) - unless [address, roles].all? - raise ArgumentError.new("required argument is nil") - end + raise ArgumentError, "required argument is nil" unless [address, roles].all? - raise ArgumentError.new("Invalid role for Civic API #{roles}") unless VALID_ROLES.include?(roles) + raise ArgumentError, "Invalid role for Civic API #{roles}" unless VALID_ROLES.include?(roles) # `includeOffices` param is needed in order to get officials list # `administrativeArea1` param restricts the search to state-level legislators (and governors) @@ -23,9 +21,7 @@ def self.state_rep_search(address, roles) end def self.all_state_reps_for_role(state, roles) - unless [state, roles].all? - raise ArgumentError.new("required argument is nil") - end + raise ArgumentError, "required argument is nil" unless [state, roles].all? # need to append division information to API route path_params = { ocdId: "ocd-division%2Fcountry%3Aus%2Fstate%3A#{state.downcase}" } @@ -37,8 +33,6 @@ def self.all_state_reps_for_role(state, roles) get params end - private - def self.civic_api_key Rails.application.secrets.google_civic_api_key end diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index fb757e39b..482942a08 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -64,7 +64,8 @@ let(:state_email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } it "should redirect to ActionPage#service_uri(service) if email has custom recipients" do - service, uri = "gmail", "https://composeurl.example.com" + service = "gmail" + uri = "https://composeurl.example.com" expect(ActionPage).to receive(:find_by_id) { custom_email_campaign.action_page } expect(custom_email_campaign).to receive(:service_uri).with(service) { uri } get :email, params: { action_id: custom_email_campaign.action_page.id, service: service } @@ -72,7 +73,9 @@ end it "should redirect to ActionPage#service_uri(service, params[:state_rep_email]) if email goes through state legislator lookup" do - service, state_rep_email, uri = "gmail", "state_rep@example.com", "https://composeurl.example.com" + service = "gmail" + state_rep_email = "state_rep@example.com" + uri = "https://composeurl.example.com" expect(ActionPage).to receive(:find_by_id) { state_email_campaign.action_page } expect(state_email_campaign).to receive(:service_uri).with(service, { email: state_rep_email }) { uri } get :email, params: { action_id: state_email_campaign.action_page.id, state_rep_email: state_rep_email, service: service } @@ -89,9 +92,9 @@ Rails.application.config.google_civic_api_url = "http://civic.example.com" Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" - stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody"). - with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }). - to_return(status: 200, body: json_parseable_state_officials, headers: {}) + stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody") + .with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }) + .to_return(status: 200, body: json_parseable_state_officials, headers: {}) end it "should render JSON with the state officials array" do diff --git a/spec/factories/email_campaigns.rb b/spec/factories/email_campaigns.rb index 52e7bafa3..e127ed27e 100644 --- a/spec/factories/email_campaigns.rb +++ b/spec/factories/email_campaigns.rb @@ -8,8 +8,8 @@ end trait :state_leg do - state "CA" - target_state_upper_chamber true + state { "CA" } + target_state_upper_chamber { true } end after(:create) do |campaign| diff --git a/spec/features/action_pages/custom_email_action_spec.rb b/spec/features/action_pages/custom_email_action_spec.rb index 1a03eb62c..e85146f42 100644 --- a/spec/features/action_pages/custom_email_action_spec.rb +++ b/spec/features/action_pages/custom_email_action_spec.rb @@ -1,7 +1,6 @@ require "rails_helper" RSpec.feature "Custom email actions", type: :feature, js: true do - let!(:custom_action) do FactoryGirl.create(:email_campaign, :custom_email).action_page end diff --git a/spec/features/action_pages/state_leg_email_action_spec.rb b/spec/features/action_pages/state_leg_email_action_spec.rb index 33188185a..32109c2ec 100644 --- a/spec/features/action_pages/state_leg_email_action_spec.rb +++ b/spec/features/action_pages/state_leg_email_action_spec.rb @@ -1,7 +1,6 @@ require "rails_helper" RSpec.feature "State legislator email actions", type: :feature, js: true do - let!(:state_action) do FactoryGirl.create(:email_campaign, :state_leg).action_page end @@ -11,9 +10,9 @@ Rails.application.config.google_civic_api_url = "http://civic.example.com" Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" - stub_request(:get, "http://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody"). - with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }). - to_return(status: 200, body: json_parseable_state_officials, headers: {}) + stub_request(:get, "http://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody") + .with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }) + .to_return(status: 200, body: json_parseable_state_officials, headers: {}) end it "allows vistors to see look up their representatives" do diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index 87eb65927..5d016fb71 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -96,10 +96,10 @@ # Skip partners click_on "Next" - tempermental { + tempermental do click_button "Save" expect(page).to have_content("State-Level Leg Action", wait: 10) - } + end end it "can create congress actions" do diff --git a/spec/lib/civic_api_spec.rb b/spec/lib/civic_api_spec.rb index 3747553d6..751576e0b 100644 --- a/spec/lib/civic_api_spec.rb +++ b/spec/lib/civic_api_spec.rb @@ -27,21 +27,21 @@ it "should raise ArgumentError if a required param is missing" do allow(RestClient).to receive(:get) - expect { + expect do CivicApi.state_rep_search(nil) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CivicApi.state_rep_search(nil, email_campaign.leg_level) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CivicApi.state_rep_search(address) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do CivicApi.state_rep_search(address, email_campaign.leg_level) - }.not_to raise_error + end.not_to raise_error end end From 736c2aaae48f0ceb5fb0750cce055b3c5fbdbeda Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 27 Sep 2023 21:03:57 -0700 Subject: [PATCH 043/113] Remove extremely old development gems --- Gemfile | 5 ----- Gemfile.lock | 13 ------------- 2 files changed, 18 deletions(-) diff --git a/Gemfile b/Gemfile index 5db6fd281..4514a014b 100644 --- a/Gemfile +++ b/Gemfile @@ -96,11 +96,6 @@ end group :development do gem "better_errors", "~> 2" - gem "binding_of_caller", "~> 0" - gem "rails-dev-tweaks", "~> 1.1" - gem "rb-fchange", "~> 0", require: false - gem "rb-fsevent", "~> 0", require: false - gem "rb-inotify", "~> 0", require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 650971d8c..195b82d94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,8 +103,6 @@ GEM coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) bootstrap-daterangepicker-rails (3.0.4) railties (>= 4.0) bootstrap-sass (3.4.1) @@ -141,7 +139,6 @@ GEM addressable daemons (1.3.1) database_cleaner (1.99.0) - debug_inspector (1.0.0) delayed_job (4.1.9) activesupport (>= 3.0, < 6.2) delayed_job_active_record (4.1.5) @@ -308,9 +305,6 @@ GEM actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) - rails-dev-tweaks (1.2.0) - actionpack (>= 3.1) - railties (>= 3.1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -325,8 +319,6 @@ GEM thor (>= 0.19.0, < 2.0) rainbow (3.0.0) rake (13.0.6) - rb-fchange (0.0.6) - ffi rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) @@ -467,7 +459,6 @@ DEPENDENCIES aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) - binding_of_caller (~> 0) bootstrap-daterangepicker-rails (~> 3) bootstrap-sass (~> 3.4) bourbon (~> 3) @@ -521,11 +512,7 @@ DEPENDENCIES rails-assets-roboto-webfont (~> 0)! rails-assets-sweetalert (= 1.0.1)! rails-controller-testing - rails-dev-tweaks (~> 1.1) rails_response_headers (~> 0.2) - rb-fchange (~> 0) - rb-fsevent (~> 0) - rb-inotify (~> 0) react-rails (~> 1) redcarpet (~> 3) rest-client (~> 2) From b98693e6b1a5e76cbd6e121d2afbb46828c6be6f Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 27 Sep 2023 21:41:03 -0700 Subject: [PATCH 044/113] Fixing test suite; email campaign specs fixed --- config/database.yml | 1 + config/environments/test.rb | 2 +- spec/factories/email_campaigns.rb | 4 ++-- spec/models/email_campaign_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config/database.yml b/config/database.yml index 18f4597d5..6d46973fb 100644 --- a/config/database.yml +++ b/config/database.yml @@ -14,6 +14,7 @@ development: <<: *common test: &test + database: <%= "#{Rails.application.secrets.db_database}-test" %> <<: *common production: diff --git a/config/environments/test.rb b/config/environments/test.rb index 04116d57a..33cf3cdf8 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + # config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that diff --git a/spec/factories/email_campaigns.rb b/spec/factories/email_campaigns.rb index e127ed27e..374eb979f 100644 --- a/spec/factories/email_campaigns.rb +++ b/spec/factories/email_campaigns.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :email_campaign do - subject { "a subject" } - message { "a message" } + subject { "hey hey hey" } + message { "hello world" } trait :custom_email do email_addresses { "a@example.com, b@example.com" } diff --git a/spec/models/email_campaign_spec.rb b/spec/models/email_campaign_spec.rb index d3f5d56ee..6fd71e662 100644 --- a/spec/models/email_campaign_spec.rb +++ b/spec/models/email_campaign_spec.rb @@ -3,7 +3,7 @@ describe EmailCampaign do describe "#service_uri(service)" do let(:custom_campaign) do - FactoryGirl.create(:email_campaign, :custom_email) + FactoryBot.create(:email_campaign, :custom_email) end context "service = :default" do @@ -27,7 +27,7 @@ describe "#service_uri(service, opts = {})" do let(:state_leg_campaign) do - FactoryGirl.create(:email_campaign, :state_leg) + FactoryBot.create(:email_campaign, :state_leg) end context "service = :default, opts = {email: 'state_rep@example.com'}" do From 5b6e8cf7c812e14fb894545b7628de0f1eea34a7 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 27 Sep 2023 23:25:17 -0700 Subject: [PATCH 045/113] Modernize signature factory --- spec/factories/signatures.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/factories/signatures.rb b/spec/factories/signatures.rb index 195999334..6839a0663 100644 --- a/spec/factories/signatures.rb +++ b/spec/factories/signatures.rb @@ -1,8 +1,12 @@ FactoryBot.define do + sequence :signer_email do |n| + "signer-#{n}@example.com" + end + factory :signature do first_name { "John" } last_name { "Doe" } - sequence(:email) { |n| "signer-#{n}@example.com" } + email { generate(:signer_email) } country_code { "US" } zipcode { "94109" } street_address { "815 Eddy St" } From ceb643b1327573a6fd0c368634850ccecb973a46 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 27 Sep 2023 23:47:18 -0700 Subject: [PATCH 046/113] Update sanitize gem to fix signatures --- Gemfile | 2 +- Gemfile.lock | 17 +++++++---------- app/models/signature.rb | 10 ++++++---- spec/models/institution_spec.rb | 32 +++++++++++++++----------------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Gemfile b/Gemfile index 4514a014b..965382d10 100644 --- a/Gemfile +++ b/Gemfile @@ -81,7 +81,7 @@ gem "iso_country_codes", "~> 0" gem "jbuilder", "~> 2" gem "oauth", "~> 0" gem "rest-client", "~> 2" -gem "sanitize", "~> 4" # Sanitize user input +gem "sanitize", "~> 6" # Sanitize user input gem "whenever", "~> 0", require: false # Cron jobs gem "will_paginate", "~> 3.0" gem "xmlrpc", "~> 0.3" diff --git a/Gemfile.lock b/Gemfile.lock index 195b82d94..bc840d858 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -235,18 +235,16 @@ GEM nokogiri (~> 1) rake mini_mime (1.1.2) - mini_portile2 (2.8.0) + mini_portile2 (2.8.4) minitest (5.15.0) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) netrc (0.11.0) nio4r (2.5.8) - nokogiri (1.13.3) - mini_portile2 (~> 2.8.0) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogumbo (1.5.0) - nokogiri oauth (0.5.5) orm_adapter (0.5.0) parallel (1.20.1) @@ -265,7 +263,7 @@ GEM premailer (~> 1.7, >= 1.7.9) public_suffix (4.0.6) puma (3.12.6) - racc (1.6.0) + racc (1.7.1) rack (2.2.3) rack-attack (5.4.2) rack (>= 1.0, < 3) @@ -386,10 +384,9 @@ GEM rubyzip (1.3.0) safely_block (0.3.0) errbase (>= 0.1.1) - sanitize (4.6.6) + sanitize (6.1.0) crass (~> 1.0.2) - nokogiri (>= 1.4.4) - nokogumbo (~> 1.4) + nokogiri (>= 1.12.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -522,7 +519,7 @@ DEPENDENCIES rubocop-github (~> 0.16) rubocop-performance rubocop-rails - sanitize (~> 4) + sanitize (~> 6) sass-rails (< 5.1) sdoc select2-rails diff --git a/app/models/signature.rb b/app/models/signature.rb index a587b35f1..fc8dc9006 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -1,12 +1,12 @@ class Signature < ActiveRecord::Base include GoingPostal - belongs_to :user + belongs_to :user, optional: true belongs_to :petition has_many :affiliations before_validation :format_zipcode - before_save :sanitize_input + before_validation :sanitize_input validates :first_name, :last_name, :petition_id, presence: { message: "This can't be blank." } @@ -84,7 +84,8 @@ def self.pretty_count end def arbitrary_opinion_of_country_string_validity - errors.add(:country_code, "Country Code might come from a spam bot.") if country_code.present? && full_country_name.nil? + return unless country_code.present? && full_country_name.nil? + errors.add(:country_code, "Country Code might come from a spam bot.") end def name @@ -139,6 +140,7 @@ def sanitize_input end def validate_zipcode - errors.add(:zipcode, "Invalid zip/postal code for country") unless GoingPostal.valid_zipcode?(zipcode, country_code) + return if GoingPostal.valid_zipcode?(zipcode, country_code) + errors.add(:zipcode, "Invalid zip/postal code for country") end end diff --git a/spec/models/institution_spec.rb b/spec/models/institution_spec.rb index 42bebf759..894dd3de7 100644 --- a/spec/models/institution_spec.rb +++ b/spec/models/institution_spec.rb @@ -4,27 +4,25 @@ describe ".top" do let(:petition) { FactoryBot.create(:local_organizing_petition) } - let(:high_rank) { petition.action_page.institutions.create(name: "A", category: "University") } - let(:mid_rank) { petition.action_page.institutions.create(name: "B", category: "University") } - let(:low_rank) { petition.action_page.institutions.create(name: "C", category: "University") } + def create_university_for(p, **attrs) + p.action_page.institutions.create(category: "University", **attrs) + end + + def student_sign(p, institution, **attrs) + sig = FactoryBot.create(:signature, petition_id: p.id) + sig.affiliations.create(institution_id: institution.id, **attrs) + end + + let(:high_rank) { create_university_for(petition, name: "A") } + let(:mid_rank) { create_university_for(petition, name: "B") } + let(:low_rank) { create_university_for(petition, name: "C") } let(:student) { petition.action_page.affiliation_types.find_or_create_by!(name: "Student") } before(:each) do - 100.times do - sig = FactoryBot.create(:signature, petition_id: petition.id) - sig.affiliations.create(institution_id: high_rank.id, affiliation_type: student) - end - - 50.times do - sig = FactoryBot.create(:signature, petition_id: petition.id) - sig.affiliations.create(institution_id: mid_rank.id, affiliation_type: student) - end - - 10.times do - sig = FactoryBot.create(:signature, petition_id: petition.id) - sig.affiliations.create(institution_id: low_rank.id, affiliation_type: student) - end + 100.times { student_sign(petition, high_rank, affiliation_type: student) } + 50.times { student_sign(petition, mid_rank, affiliation_type: student) } + 10.times { student_sign(petition, low_rank, affiliation_type: student) } end it "should return the top n institutions ordered by number of signatures" do From fc8e2875582629a2f52d3b96c077ec9b9aa248b8 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 03:26:25 -0700 Subject: [PATCH 047/113] Finish fixing institutions model spec + make complex query safer --- .../concerns/action_page_display.rb | 7 ++- app/models/institution.rb | 11 ----- app/queries/top_institutions_query.rb | 33 +++++++++++++ spec/models/institution_spec.rb | 33 ------------- spec/queries/top_institutions_query_spec.rb | 46 +++++++++++++++++++ 5 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 app/queries/top_institutions_query.rb create mode 100644 spec/queries/top_institutions_query_spec.rb diff --git a/app/controllers/concerns/action_page_display.rb b/app/controllers/concerns/action_page_display.rb index 4c842bd2a..ca926275d 100644 --- a/app/controllers/concerns/action_page_display.rb +++ b/app/controllers/concerns/action_page_display.rb @@ -18,7 +18,12 @@ def set_action_display_variables set_signatures if @actionPage.petition&.enable_affiliations - @top_institutions = @actionPage.institutions.top(300, first: @institution.try(:id)) + @top_institutions = [ + @institution, + TopInstitutionsQuery.run(action_page: @actionPage, + limit: 300, + exclude: [@institution]) + ].flatten @institutions = @actionPage.institutions.order(:name) @institution_category = @institutions.first.category end diff --git a/app/models/institution.rb b/app/models/institution.rb index 917b51993..39ef502bf 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -43,17 +43,6 @@ def self.categories all.distinct.pluck(:category) end - # Sort institutions by most popular. - # Put `first` at the top of the list if it exists. - def self.top(n, first: 0) # rubocop:todo Naming/MethodParameterName - select("institutions.*, COUNT(signatures.id) AS s_count") - .joins("LEFT OUTER JOIN affiliations ON institutions.id = affiliations.institution_id") - .joins("LEFT OUTER JOIN signatures ON affiliations.signature_id = signatures.id") - .group("institutions.id") - .order("institutions.id = #{first.to_i} desc", "s_count DESC", "institutions.name") - .limit(n) - end - def included_in_active_actions? return false if action_pages.empty? diff --git a/app/queries/top_institutions_query.rb b/app/queries/top_institutions_query.rb new file mode 100644 index 000000000..0fa2427ca --- /dev/null +++ b/app/queries/top_institutions_query.rb @@ -0,0 +1,33 @@ +class TopInstitutionsQuery + def self.run(**args) + new(**args).run + end + + def initialize(action_page:, limit: 300, exclude: []) + @action_page = action_page + @limit = limit + @exclusions = exclude.compact.map(&:id) + end + + def run + action_page.institutions + .where.not(id: exclusions) + .left_outer_joins(affiliations: [:signature]) + .distinct + # TODO: break up / document + .select("institutions.*, COUNT(signatures.id) AS sig_count") + .group("institutions.id") + .order("sig_count DESC", "institutions.name") + .limit(limit) + end + + private + + attr_reader :action_page, :limit, :exclusions + + def source_collection + @source_collection ||= action_page.institutions + return @source_collection if exclusions.empty? + @source_collection = @source_collection.where.not(id: exclusions) + end +end diff --git a/spec/models/institution_spec.rb b/spec/models/institution_spec.rb index 894dd3de7..901304328 100644 --- a/spec/models/institution_spec.rb +++ b/spec/models/institution_spec.rb @@ -1,39 +1,6 @@ require "rails_helper" describe Institution do - describe ".top" do - let(:petition) { FactoryBot.create(:local_organizing_petition) } - - def create_university_for(p, **attrs) - p.action_page.institutions.create(category: "University", **attrs) - end - - def student_sign(p, institution, **attrs) - sig = FactoryBot.create(:signature, petition_id: p.id) - sig.affiliations.create(institution_id: institution.id, **attrs) - end - - let(:high_rank) { create_university_for(petition, name: "A") } - let(:mid_rank) { create_university_for(petition, name: "B") } - let(:low_rank) { create_university_for(petition, name: "C") } - - let(:student) { petition.action_page.affiliation_types.find_or_create_by!(name: "Student") } - - before(:each) do - 100.times { student_sign(petition, high_rank, affiliation_type: student) } - 50.times { student_sign(petition, mid_rank, affiliation_type: student) } - 10.times { student_sign(petition, low_rank, affiliation_type: student) } - end - - it "should return the top n institutions ordered by number of signatures" do - expect(petition.action_page.institutions.top(3).to_a).to eq([high_rank, mid_rank, low_rank]) - end - - it "should allow an argument which reorders a certain institution to the front" do - expect(petition.action_page.institutions.top(3, first: low_rank.id).to_a).to eq([low_rank, high_rank, mid_rank]) - end - end - describe ".import" do let(:action_page) { FactoryBot.create(:action_page) } let(:institution) { FactoryBot.create(:institution) } diff --git a/spec/queries/top_institutions_query_spec.rb b/spec/queries/top_institutions_query_spec.rb new file mode 100644 index 000000000..651039892 --- /dev/null +++ b/spec/queries/top_institutions_query_spec.rb @@ -0,0 +1,46 @@ +require "rails_helper" + +describe TopInstitutionsQuery do + describe ".run" do + # TODO: rewrite to use action page as the main reference record? the + # petition is never actually used beyond its ID + let(:petition) { FactoryBot.create(:local_organizing_petition) } + + def create_university_for(p, **attrs) + p.action_page.institutions.create(category: "University", **attrs) + end + + def student_sign(p, institution, **attrs) + sig = FactoryBot.create(:signature, petition_id: p.id) + sig.affiliations.create(institution_id: institution.id, **attrs) + end + + let(:high_rank) { create_university_for(petition, name: "A") } + let(:mid_rank) { create_university_for(petition, name: "B") } + let(:low_rank) { create_university_for(petition, name: "C") } + + let(:student) { petition.action_page.affiliation_types.find_or_create_by!(name: "Student") } + + before(:each) do + 100.times { student_sign(petition, high_rank, affiliation_type: student) } + 50.times { student_sign(petition, mid_rank, affiliation_type: student) } + 10.times { student_sign(petition, low_rank, affiliation_type: student) } + end + + it "should return the top n institutions ordered by number of signatures" do + expect( + described_class.run(action_page: petition.action_page, limit: 3) + .map(&:id) + ).to eq([high_rank, mid_rank, low_rank].map(&:id)) + end + + it "allows exclusions from results" do + expect( + described_class.run(action_page: petition.action_page, + limit: 3, + exclude: [low_rank]) + .map(&:id) + ).to eq([high_rank.id, mid_rank.id, high_rank.id - 1]) + end + end +end From e68079ab3a5926d2d026a7af904d82cf985d9e8e Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 03:27:28 -0700 Subject: [PATCH 048/113] Rubocop --- app/models/signature.rb | 2 ++ app/queries/top_institutions_query.rb | 17 +++++++++-------- spec/queries/top_institutions_query_spec.rb | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/models/signature.rb b/app/models/signature.rb index fc8dc9006..810b31d36 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -85,6 +85,7 @@ def self.pretty_count def arbitrary_opinion_of_country_string_validity return unless country_code.present? && full_country_name.nil? + errors.add(:country_code, "Country Code might come from a spam bot.") end @@ -141,6 +142,7 @@ def sanitize_input def validate_zipcode return if GoingPostal.valid_zipcode?(zipcode, country_code) + errors.add(:zipcode, "Invalid zip/postal code for country") end end diff --git a/app/queries/top_institutions_query.rb b/app/queries/top_institutions_query.rb index 0fa2427ca..10215ec51 100644 --- a/app/queries/top_institutions_query.rb +++ b/app/queries/top_institutions_query.rb @@ -11,14 +11,14 @@ def initialize(action_page:, limit: 300, exclude: []) def run action_page.institutions - .where.not(id: exclusions) - .left_outer_joins(affiliations: [:signature]) - .distinct - # TODO: break up / document - .select("institutions.*, COUNT(signatures.id) AS sig_count") - .group("institutions.id") - .order("sig_count DESC", "institutions.name") - .limit(limit) + .where.not(id: exclusions) + .left_outer_joins(affiliations: [:signature]) + .distinct + # TODO: break up / document + .select("institutions.*, COUNT(signatures.id) AS sig_count") + .group("institutions.id") + .order("sig_count DESC", "institutions.name") + .limit(limit) end private @@ -28,6 +28,7 @@ def run def source_collection @source_collection ||= action_page.institutions return @source_collection if exclusions.empty? + @source_collection = @source_collection.where.not(id: exclusions) end end diff --git a/spec/queries/top_institutions_query_spec.rb b/spec/queries/top_institutions_query_spec.rb index 651039892..0384889aa 100644 --- a/spec/queries/top_institutions_query_spec.rb +++ b/spec/queries/top_institutions_query_spec.rb @@ -2,7 +2,7 @@ describe TopInstitutionsQuery do describe ".run" do - # TODO: rewrite to use action page as the main reference record? the + # TODO: rewrite to use action page as the main reference record? the # petition is never actually used beyond its ID let(:petition) { FactoryBot.create(:local_organizing_petition) } From 1203bf48f31b8b7a400e952ce50aa561b3282c13 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 03:32:59 -0700 Subject: [PATCH 049/113] FactoryGirl -> FactoryBot --- spec/controllers/tools_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 482942a08..3ed0c2062 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -60,8 +60,8 @@ end describe "#email" do - let(:custom_email_campaign) { FactoryGirl.create(:email_campaign, :custom_email) } - let(:state_email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } + let(:custom_email_campaign) { FactoryBot.create(:email_campaign, :custom_email) } + let(:state_email_campaign) { FactoryBot.create(:email_campaign, :state_leg) } it "should redirect to ActionPage#service_uri(service) if email has custom recipients" do service = "gmail" @@ -84,7 +84,7 @@ end describe "#state_reps" do - let(:email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } + let(:email_campaign) { FactoryBot.create(:email_campaign, :state_leg) } let(:address) { "815 Eddy St 94109" } let(:json_parseable_state_officials) { '{"officials": [{"name": "Sponge Bob", "party": "Sandy Party", "emails": ["spongebob@clarinetfans.annoying"]}]}' } From 1d41357c5b333602dea71efd9616e91d824b7d18 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 21:14:57 -0700 Subject: [PATCH 050/113] Swap back to selenium + bundle update --- Gemfile | 2 +- Gemfile.lock | 386 ++++++++++++++++++++++++++++----------------------- 2 files changed, 214 insertions(+), 174 deletions(-) diff --git a/Gemfile b/Gemfile index 965382d10..0f419ec0d 100644 --- a/Gemfile +++ b/Gemfile @@ -99,8 +99,8 @@ group :development do end group :test do - gem "apparition", "~> 0.6" gem "webmock", "~> 3" + gem "selenium-webdriver", "~> 4" end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index bc840d858..78342d1b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,37 +2,37 @@ GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actioncable (5.2.6.2) - actionpack (= 5.2.6.2) + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.6.2) - actionpack (= 5.2.6.2) - actionview (= 5.2.6.2) - activejob (= 5.2.6.2) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.6.2) - actionview (= 5.2.6.2) - activesupport (= 5.2.6.2) + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.6.2) - activesupport (= 5.2.6.2) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.6.2) - activesupport (= 5.2.6.2) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) globalid (>= 0.3.6) - activemodel (5.2.6.2) - activesupport (= 5.2.6.2) - activerecord (5.2.6.2) - activemodel (= 5.2.6.2) - activesupport (= 5.2.6.2) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) arel (>= 9.0) activerecord-session_store (1.1.3) actionpack (>= 4.0) @@ -40,20 +40,20 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activestorage (5.2.6.2) - actionpack (= 5.2.6.2) - activerecord (= 5.2.6.2) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) marcel (~> 1.0.0) - activesupport (5.2.6.2) + activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - acts_as_paranoid (0.7.0) - activerecord (>= 5.2, < 7.0) - activesupport (>= 5.2, < 7.0) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) + acts_as_paranoid (0.8.1) + activerecord (>= 5.2, < 7.1) + activesupport (>= 5.2, < 7.1) + addressable (2.8.5) + public_suffix (>= 2.0.2, < 6.0) ahoy_matey (1.6.1) addressable browser (~> 2.0) @@ -65,44 +65,42 @@ GEM safely_block (>= 0.1.1) user_agent_parser uuidtools - apparition (0.6.0) - capybara (~> 3.13, < 4) - websocket-driver (>= 0.6.5) arel (9.0.0) ast (2.4.2) - autoprefixer-rails (10.2.4.0) - execjs - aws-eventstream (1.1.0) - aws-partitions (1.426.0) - aws-sdk-core (3.112.0) + autoprefixer-rails (10.4.15.0) + execjs (~> 2) + aws-eventstream (1.2.0) + aws-partitions (1.830.0) + aws-sdk-core (3.184.0) aws-eventstream (~> 1, >= 1.0.2) - aws-partitions (~> 1, >= 1.239.0) - aws-sigv4 (~> 1.1) - jmespath (~> 1.0) - aws-sdk-kms (1.42.0) - aws-sdk-core (~> 3, >= 3.112.0) + aws-partitions (~> 1, >= 1.651.0) + aws-sigv4 (~> 1.5) + jmespath (~> 1, >= 1.6.1) + aws-sdk-kms (1.72.0) + aws-sdk-core (~> 3, >= 3.184.0) aws-sigv4 (~> 1.1) aws-sdk-rails (2.1.0) aws-sdk-ses (~> 1) railties (>= 3) - aws-sdk-s3 (1.88.0) - aws-sdk-core (~> 3, >= 3.112.0) + aws-sdk-s3 (1.136.0) + aws-sdk-core (~> 3, >= 3.181.0) aws-sdk-kms (~> 1) + aws-sigv4 (~> 1.6) + aws-sdk-ses (1.56.0) + aws-sdk-core (~> 3, >= 3.184.0) aws-sigv4 (~> 1.1) - aws-sdk-ses (1.37.0) - aws-sdk-core (~> 3, >= 3.112.0) - aws-sigv4 (~> 1.1) - aws-sigv4 (1.2.2) + aws-sigv4 (1.6.0) aws-eventstream (~> 1, >= 1.0.2) babel-source (5.8.35) babel-transpiler (0.7.0) babel-source (>= 4.0, < 6) execjs (~> 2.0) - bcrypt (3.1.16) - better_errors (2.9.1) - coderay (>= 1.0.0) + base64 (0.1.1) + bcrypt (3.1.19) + better_errors (2.10.1) erubi (>= 1.0.0) rack (>= 0.9.0) + rouge (>= 1.0.0) bootstrap-daterangepicker-rails (3.0.4) railties (>= 4.0) bootstrap-sass (3.4.1) @@ -114,8 +112,9 @@ GEM browser (2.7.1) builder (3.2.4) byebug (11.1.3) - capybara (3.35.3) + capybara (3.39.2) addressable + matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) @@ -126,36 +125,36 @@ GEM chronic (0.10.2) climate_control (0.2.0) cocoon (1.2.15) - coderay (1.1.3) - concurrent-ruby (1.1.9) - connection_pool (2.2.3) - counter_culture (2.7.0) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + counter_culture (2.9.0) activerecord (>= 4.2) activesupport (>= 4.2) crack (0.4.5) rexml crass (1.0.6) - css_parser (1.9.0) + css_parser (1.16.0) addressable - daemons (1.3.1) + daemons (1.4.1) database_cleaner (1.99.0) - delayed_job (4.1.9) - activesupport (>= 3.0, < 6.2) - delayed_job_active_record (4.1.5) - activerecord (>= 3.0, < 6.2) + date (3.3.3) + delayed_job (4.1.11) + activesupport (>= 3.0, < 8.0) + delayed_job_active_record (4.1.7) + activerecord (>= 3.0, < 8.0) delayed_job (>= 3.0, < 5) - devise (4.7.3) + devise (4.9.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.4.4) + diff-lcs (1.5.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - dotenv (2.7.6) - dotenv-rails (2.7.6) - dotenv (= 2.7.6) + dotenv (2.8.1) + dotenv-rails (2.8.1) + dotenv (= 2.8.1) railties (>= 3.2) eff_matomo (0.2.4) activesupport @@ -163,32 +162,32 @@ GEM ejs (1.1.1) email_validator (1.6.0) activemodel - errbase (0.2.1) - erubi (1.10.0) - execjs (2.7.0) + errbase (0.2.2) + erubi (1.12.0) + execjs (2.9.1) factory_bot (4.11.1) activesupport (>= 3.0.0) factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faraday (1.3.0) - faraday-net_http (~> 1.0) - multipart-post (>= 1.2, < 3) - ruby2_keywords - faraday-net_http (1.0.1) + faraday (2.7.11) + base64 + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) fast_inserter (0.1.6) activerecord (>= 4.1.0) fastly (2.5.3) - ffi (1.14.2) + ffi (1.16.2) fontello_rails_converter (0.4.6) activesupport launchy rest-client rubyzip (~> 1.0) - friendly_id (5.4.2) + friendly_id (5.5.0) activerecord (>= 4.0.0) - geocoder (1.6.5) - globalid (1.0.0) + geocoder (1.8.2) + globalid (1.1.0) activesupport (>= 5.0) going_postal (0.1.6) gravatar-ultimate (2.0.0) @@ -197,93 +196,115 @@ GEM groupdate (2.5.3) activesupport (>= 3) hashdiff (1.0.1) + hashie (5.0.0) htmlentities (4.3.4) http-accept (1.7.0) - http-cookie (1.0.3) + http-cookie (1.0.5) domain_name (~> 0.5) http_accept_language (2.1.1) - httparty (0.18.1) - mime-types (~> 3.0) + httparty (0.21.0) + mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.10.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) invisible_captcha (0.13.0) rails (>= 3.2.0) iso_country_codes (0.7.8) - jbuilder (2.11.2) + jbuilder (2.11.5) + actionview (>= 5.0.0) activesupport (>= 5.0.0) - jmespath (1.4.0) - kt-paperclip (6.4.1) + jmespath (1.6.2) + json (2.6.3) + kt-paperclip (6.4.2) activemodel (>= 4.2.0) activesupport (>= 4.2.0) mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - launchy (2.5.0) - addressable (~> 2.7) - loofah (2.14.0) + language_server-protocol (3.17.0.3) + launchy (2.5.2) + addressable (~> 2.8) + loofah (2.21.3) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) + matrix (0.4.2) method_source (1.0.0) - mime-types (3.3.1) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2020.1104) + mime-types-data (3.2023.0808) mimemagic (0.3.10) nokogiri (~> 1) rake - mini_mime (1.1.2) + mini_mime (1.1.5) mini_portile2 (2.8.4) - minitest (5.15.0) + minitest (5.20.0) multi_json (1.15.0) multi_xml (0.6.0) - multipart-post (2.1.1) + net-imap (0.3.7) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.4.0) + net-protocol netrc (0.11.0) - nio4r (2.5.8) + nio4r (2.5.9) nokogiri (1.15.4) mini_portile2 (~> 2.8.2) racc (~> 1.4) - oauth (0.5.5) + oauth (0.6.2) + snaky_hash (~> 2.0) + version_gem (~> 1.1) orm_adapter (0.5.0) - parallel (1.20.1) - parser (3.0.0.0) + parallel (1.23.0) + parser (3.2.2.3) ast (~> 2.4.1) - pg (1.2.3) - pg_search (2.3.0) - activerecord (>= 4.2) - activesupport (>= 4.2) - premailer (1.14.2) + racc + pg (1.5.4) + pg_search (2.3.6) + activerecord (>= 5.2) + activesupport (>= 5.2) + premailer (1.21.0) addressable - css_parser (>= 1.6.0) + css_parser (>= 1.12.0) htmlentities (>= 4.0.0) - premailer-rails (1.11.1) + premailer-rails (1.12.0) actionmailer (>= 3) + net-smtp premailer (~> 1.7, >= 1.7.9) - public_suffix (4.0.6) + psych (5.1.0) + stringio + public_suffix (5.0.3) puma (3.12.6) racc (1.7.1) - rack (2.2.3) + rack (2.2.8) rack-attack (5.4.2) rack (>= 1.0, < 3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.6.2) - actioncable (= 5.2.6.2) - actionmailer (= 5.2.6.2) - actionpack (= 5.2.6.2) - actionview (= 5.2.6.2) - activejob (= 5.2.6.2) - activemodel (= 5.2.6.2) - activerecord (= 5.2.6.2) - activestorage (= 5.2.6.2) - activesupport (= 5.2.6.2) + rack-test (2.1.0) + rack (>= 1.3) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) bundler (>= 1.3.0) - railties (= 5.2.6.2) + railties (= 5.2.8.1) sprockets-rails (>= 2.0.0) rails-assets-EpicEditor (0.2.3) - rails-assets-chartjs (2.8.0) + rails-assets-chartjs (2.9.4) rails-assets-congress-images-102x125 (0.1.2) rails-assets-html5shiv (3.7.2) rails-assets-ionicons (2.0.1) @@ -303,44 +324,48 @@ GEM actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) rails_response_headers (0.2.0) - railties (5.2.6.2) - actionpack (= 5.2.6.2) - activesupport (= 5.2.6.2) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) - rainbow (3.0.0) + rainbow (3.1.1) rake (13.0.6) - rb-fsevent (0.10.4) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.3.0) + rdoc (6.5.0) + psych (>= 4.0.0) react-rails (1.11.0) babel-transpiler (>= 0.7.0) connection_pool execjs railties (>= 3.2) tilt - redcarpet (3.5.1) + redcarpet (3.6.0) referer-parser (0.3.0) - regexp_parser (2.0.3) - request_store (1.5.0) + regexp_parser (2.8.1) + request_store (1.5.1) rack (>= 1.4) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) + responders (3.1.0) + actionpack (>= 5.2) + railties (>= 5.2) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rexml (3.2.4) + rexml (3.2.6) + rouge (4.1.3) rspec-core (3.9.3) rspec-support (~> 3.9.3) rspec-expectations (3.9.4) @@ -358,29 +383,33 @@ GEM rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) rspec-support (3.9.4) - rubocop (1.6.1) + rubocop (1.56.4) + base64 (~> 0.1.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.2.2.3) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.2.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) - rubocop-github (0.16.1) - rubocop (<= 1.6.1) - rubocop-performance (<= 1.7.1) - rubocop-rails (<= 2.7.1) - rubocop-performance (1.7.1) - rubocop (>= 0.82.0) - rubocop-rails (2.7.1) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-github (0.20.0) + rubocop (>= 1.37) + rubocop-performance (>= 1.15) + rubocop-rails (>= 2.17) + rubocop-performance (1.19.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rails (2.21.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.87.0) - ruby-progressbar (1.11.0) - ruby2_keywords (0.0.4) + rubocop (>= 1.33.0, < 2.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) rubyzip (1.3.0) safely_block (0.3.0) errbase (>= 0.1.1) @@ -392,19 +421,26 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.0.8) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) sassc (2.4.0) ffi (~> 1.9) - sdoc (2.0.3) + sdoc (2.6.1) rdoc (>= 5.0) select2-rails (4.0.13) + selenium-webdriver (4.9.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) sentry-raven (0.15.6) faraday (>= 0.7.6) + snaky_hash (2.0.1) + hashie + version_gem (~> 1.1, >= 1.1.1) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -412,35 +448,39 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + stringio (3.0.8) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (1.2.1) + thor (1.2.2) thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.9) + tilt (2.3.0) + timeout (0.4.0) + tzinfo (1.2.11) thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.7) - unicode-display_width (1.7.0) - user_agent_parser (2.7.0) + unf_ext (0.0.8.2) + unicode-display_width (2.4.2) + user_agent_parser (2.16.0) uuidtools (2.2.0) - warden (1.2.4) - rack (>= 1.0) - webmock (3.11.2) - addressable (>= 2.3.6) + version_gem (1.1.3) + warden (1.2.9) + rack (>= 2.0.9) + webmock (3.19.1) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.7.0) - websocket-driver (0.7.5) + webrick (1.8.1) + websocket (1.2.10) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) whenever (0.11.0) chronic (>= 0.6.3) - will_paginate (3.3.0) - xmlrpc (0.3.2) + will_paginate (3.3.1) + xmlrpc (0.3.3) webrick xpath (3.2.0) nokogiri (~> 1.8) @@ -452,7 +492,6 @@ DEPENDENCIES activerecord-session_store (~> 1) acts_as_paranoid (~> 0.7) ahoy_matey (~> 1.6) - apparition (~> 0.6) aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) @@ -523,6 +562,7 @@ DEPENDENCIES sass-rails (< 5.1) sdoc select2-rails + selenium-webdriver (~> 4) sentry-raven (~> 0.15) uglifier (>= 1.3.0) webmock (~> 3) From 55d23da78a5f5de914da5d4d8d16524a573952fc Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 21:28:39 -0700 Subject: [PATCH 051/113] Downgrade psych gem to < 4 --- Gemfile | 4 ++++ Gemfile.lock | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 0f419ec0d..05141d87c 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem "redcarpet", "~> 3" # Markdown gem "sass-rails", "< 5.1" gem "select2-rails" # Autocomplete select menus gem "uglifier", ">= 1.3.0" # compressor for JavaScript assets + source "https://rails-assets.org" do gem "rails-assets-chartjs", "~> 2" gem "rails-assets-congress-images-102x125" @@ -89,6 +90,9 @@ gem "xmlrpc", "~> 0.3" # For creating many records, quickly gem "fast_inserter", "~> 0.1" +# Pin psych to below version 4 until we're on rails 7 and ruby 3.1 +gem "psych", "< 4" + group :doc do # bundle exec rake doc:rails generates the API under doc/api gem "sdoc", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 78342d1b5..36cb0224d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -280,8 +280,7 @@ GEM actionmailer (>= 3) net-smtp premailer (~> 1.7, >= 1.7.9) - psych (5.1.0) - stringio + psych (3.3.4) public_suffix (5.0.3) puma (3.12.6) racc (1.7.1) @@ -343,8 +342,7 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.5.0) - psych (>= 4.0.0) + rdoc (6.3.3) react-rails (1.11.0) babel-transpiler (>= 0.7.0) connection_pool @@ -448,7 +446,6 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - stringio (3.0.8) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) thor (1.2.2) @@ -530,6 +527,7 @@ DEPENDENCIES pg (~> 1.1) pg_search (~> 2) premailer-rails (~> 1) + psych (< 4) puma (~> 3) rack-attack (~> 5) rails (~> 5) From 1a67458d0f674ac7ac096e4433d1a801eaab97df Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 21:28:58 -0700 Subject: [PATCH 052/113] Config for selenium --- spec/rails_helper.rb | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9494dc4ef..bf0a11525 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,7 +5,6 @@ abort("The Rails environment is running in production mode!") if Rails.env.production? require "spec_helper" require "rspec/rails" -require "capybara/apparition" # Add additional requires below this line. Rails is not loaded until this point! @@ -28,29 +27,8 @@ # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! -apparition_opts = { - window_size: [1400, 900], - screen_size: [1920, 1090], - browser_options: { - "w3c" => false, - "args" => ["headless", "disable-gpu", "--window-size=1400,900", "--remote-debugging-port=9222"] - } -} - -if ENV["TRAVIS"] - apparition_opts[:browser_options] = { - "remote-debugging-address" => "127.0.0.1", - "remote-debugging-port" => 9222 - } - apparition_opts[:remote] = true -end - -Capybara.register_driver :chrome_headless do |app| - Capybara::Apparition::Driver.new(app, apparition_opts) -end - Capybara.server = :puma -Capybara.javascript_driver = :chrome_headless +Capybara.javascript_driver = :selenium_chrome_headless Capybara.enable_aria_label = true RSpec.configure do |config| From 3e6ffae5b9d030ee9464f66efebdb131fcdb0d03 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 28 Sep 2023 21:42:42 -0700 Subject: [PATCH 053/113] Rename remaining .css.scss files in vendor --- vendor/assets/stylesheets/{animation.css.scss => animation.scss} | 0 .../{eff-icon-font-codes.css.scss => eff-icon-font-codes.scss} | 0 ...ff-icon-font-embedded.css.scss => eff-icon-font-embedded.scss} | 0 ...-icon-font-ie7-codes.css.scss => eff-icon-font-ie7-codes.scss} | 0 .../{eff-icon-font-ie7.css.scss => eff-icon-font-ie7.scss} | 0 .../stylesheets/{eff-icon-font.css.scss => eff-icon-font.scss} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename vendor/assets/stylesheets/{animation.css.scss => animation.scss} (100%) rename vendor/assets/stylesheets/{eff-icon-font-codes.css.scss => eff-icon-font-codes.scss} (100%) rename vendor/assets/stylesheets/{eff-icon-font-embedded.css.scss => eff-icon-font-embedded.scss} (100%) rename vendor/assets/stylesheets/{eff-icon-font-ie7-codes.css.scss => eff-icon-font-ie7-codes.scss} (100%) rename vendor/assets/stylesheets/{eff-icon-font-ie7.css.scss => eff-icon-font-ie7.scss} (100%) rename vendor/assets/stylesheets/{eff-icon-font.css.scss => eff-icon-font.scss} (100%) diff --git a/vendor/assets/stylesheets/animation.css.scss b/vendor/assets/stylesheets/animation.scss similarity index 100% rename from vendor/assets/stylesheets/animation.css.scss rename to vendor/assets/stylesheets/animation.scss diff --git a/vendor/assets/stylesheets/eff-icon-font-codes.css.scss b/vendor/assets/stylesheets/eff-icon-font-codes.scss similarity index 100% rename from vendor/assets/stylesheets/eff-icon-font-codes.css.scss rename to vendor/assets/stylesheets/eff-icon-font-codes.scss diff --git a/vendor/assets/stylesheets/eff-icon-font-embedded.css.scss b/vendor/assets/stylesheets/eff-icon-font-embedded.scss similarity index 100% rename from vendor/assets/stylesheets/eff-icon-font-embedded.css.scss rename to vendor/assets/stylesheets/eff-icon-font-embedded.scss diff --git a/vendor/assets/stylesheets/eff-icon-font-ie7-codes.css.scss b/vendor/assets/stylesheets/eff-icon-font-ie7-codes.scss similarity index 100% rename from vendor/assets/stylesheets/eff-icon-font-ie7-codes.css.scss rename to vendor/assets/stylesheets/eff-icon-font-ie7-codes.scss diff --git a/vendor/assets/stylesheets/eff-icon-font-ie7.css.scss b/vendor/assets/stylesheets/eff-icon-font-ie7.scss similarity index 100% rename from vendor/assets/stylesheets/eff-icon-font-ie7.css.scss rename to vendor/assets/stylesheets/eff-icon-font-ie7.scss diff --git a/vendor/assets/stylesheets/eff-icon-font.css.scss b/vendor/assets/stylesheets/eff-icon-font.scss similarity index 100% rename from vendor/assets/stylesheets/eff-icon-font.css.scss rename to vendor/assets/stylesheets/eff-icon-font.scss From 4552c422f1fd1328bbbb83c44643f4c79ed18740 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 19:46:45 -0700 Subject: [PATCH 054/113] Start swapping to selenium --- Gemfile | 2 +- Gemfile.lock | 4 +++- spec/rails_helper.rb | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 05141d87c..60c0fe096 100644 --- a/Gemfile +++ b/Gemfile @@ -104,7 +104,7 @@ end group :test do gem "webmock", "~> 3" - gem "selenium-webdriver", "~> 4" + gem "selenium-devtools" end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 36cb0224d..492e887b7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -430,6 +430,8 @@ GEM sdoc (2.6.1) rdoc (>= 5.0) select2-rails (4.0.13) + selenium-devtools (0.112.0) + selenium-webdriver (~> 4.2) selenium-webdriver (4.9.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) @@ -560,7 +562,7 @@ DEPENDENCIES sass-rails (< 5.1) sdoc select2-rails - selenium-webdriver (~> 4) + selenium-devtools sentry-raven (~> 0.15) uglifier (>= 1.3.0) webmock (~> 3) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bf0a11525..c060d13db 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,6 +5,7 @@ abort("The Rails environment is running in production mode!") if Rails.env.production? require "spec_helper" require "rspec/rails" +require "selenium/webdriver" # Add additional requires below this line. Rails is not loaded until this point! From 10e6f19642629bda1dd9a366f243c47d86174318 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 19:50:58 -0700 Subject: [PATCH 055/113] Attempt to upgrade selenium-webdriver to v4.11 to support newer versions of chrome --- Gemfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index 60c0fe096..dee74df57 100644 --- a/Gemfile +++ b/Gemfile @@ -105,6 +105,11 @@ end group :test do gem "webmock", "~> 3" gem "selenium-devtools" + # TODO: ruby 3 upgrade + # newer chrome versions need a higher version of selenium-webdriver, but + # those versions require ruby 3 + # tests requiring JS will fail until we upgrade + # gem "selenium-webdriver", "~> 4.11" end group :development, :test do From 2116bf8d7561de7b6e7020962a404be91559ba70 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:09:11 -0700 Subject: [PATCH 056/113] Start ruby 3 upgrade --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 37c2961c2..818bd47ab 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.2 +3.0.6 From e7c9f61cbaafe3e27ce296adc663e216350164ef Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:19:52 -0700 Subject: [PATCH 057/113] Remove fontello gem + run bundle install --- Gemfile | 1 - Gemfile.lock | 49 ++++++++++++++++++++++--------------------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index dee74df57..93528fed0 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ gem "bootstrap-daterangepicker-rails", "~> 3" gem "bootstrap-sass", "~> 3.4" gem "bourbon", "~> 3" gem "bundler", ">= 1.8.4" # needed for rails-assets -gem "fontello_rails_converter", "~> 0" gem "react-rails", "~> 1" gem "redcarpet", "~> 3" # Markdown gem "sass-rails", "< 5.1" diff --git a/Gemfile.lock b/Gemfile.lock index 492e887b7..2468db3e3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,26 @@ GEM - remote: https://rubygems.org/ remote: https://rails-assets.org/ + specs: + rails-assets-EpicEditor (0.2.3) + rails-assets-chartjs (2.9.4) + rails-assets-congress-images-102x125 (0.1.2) + rails-assets-html5shiv (3.7.2) + rails-assets-ionicons (2.0.1) + rails-assets-jquery (2.1.3) + rails-assets-jquery-cookie (1.4.1) + rails-assets-jquery (>= 1.2) + rails-assets-jquery-timeago (1.6.7) + rails-assets-jquery (>= 1.4) + rails-assets-jquery-ujs (1.0.3) + rails-assets-jquery (> 1.8) + rails-assets-lodash (3.7.0) + rails-assets-moment (2.9.0) + rails-assets-respond (1.4.2) + rails-assets-roboto-webfont (0.1.1) + rails-assets-sweetalert (1.0.1) + +GEM + remote: https://rubygems.org/ specs: actioncable (5.2.8.1) actionpack (= 5.2.8.1) @@ -179,11 +199,6 @@ GEM activerecord (>= 4.1.0) fastly (2.5.3) ffi (1.16.2) - fontello_rails_converter (0.4.6) - activesupport - launchy - rest-client - rubyzip (~> 1.0) friendly_id (5.5.0) activerecord (>= 4.0.0) geocoder (1.8.2) @@ -222,8 +237,6 @@ GEM mimemagic (~> 0.3.0) terrapin (~> 0.6.0) language_server-protocol (3.17.0.3) - launchy (2.5.2) - addressable (~> 2.8) loofah (2.21.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -302,23 +315,6 @@ GEM bundler (>= 1.3.0) railties (= 5.2.8.1) sprockets-rails (>= 2.0.0) - rails-assets-EpicEditor (0.2.3) - rails-assets-chartjs (2.9.4) - rails-assets-congress-images-102x125 (0.1.2) - rails-assets-html5shiv (3.7.2) - rails-assets-ionicons (2.0.1) - rails-assets-jquery (2.1.3) - rails-assets-jquery-cookie (1.4.1) - rails-assets-jquery (>= 1.2) - rails-assets-jquery-timeago (1.6.7) - rails-assets-jquery (>= 1.4) - rails-assets-jquery-ujs (1.0.3) - rails-assets-jquery (> 1.8) - rails-assets-lodash (3.7.0) - rails-assets-moment (2.9.0) - rails-assets-respond (1.4.2) - rails-assets-roboto-webfont (0.1.1) - rails-assets-sweetalert (1.0.1) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -514,7 +510,6 @@ DEPENDENCIES factory_bot_rails (~> 4) fast_inserter (~> 0.1) fastly (~> 2) - fontello_rails_converter (~> 0) friendly_id (~> 5.0) going_postal (~> 0) gravatar-ultimate (~> 2) @@ -571,4 +566,4 @@ DEPENDENCIES xmlrpc (~> 0.3) BUNDLED WITH - 2.1.4 + 2.2.33 From 4295c0833b10b3dae189ea8728bc0cecdb04efc0 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:43:21 -0700 Subject: [PATCH 058/113] Start rails 6 upgrade --- Gemfile | 2 +- Gemfile.lock | 102 +++++++++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/Gemfile b/Gemfile index 93528fed0..5906249de 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem "rails", "~> 5" +gem "rails", "~> 6.0.0" # Database gem "pg", "~> 1.1" diff --git a/Gemfile.lock b/Gemfile.lock index 2468db3e3..6456cbd7f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,53 +22,67 @@ GEM GEM remote: https://rubygems.org/ specs: - actioncable (5.2.8.1) - actionpack (= 5.2.8.1) + actioncable (6.0.6.1) + actionpack (= 6.0.6.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) + actionmailbox (6.0.6.1) + actionpack (= 6.0.6.1) + activejob (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) + mail (>= 2.7.1) + actionmailer (6.0.6.1) + actionpack (= 6.0.6.1) + actionview (= 6.0.6.1) + activejob (= 6.0.6.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.8.1) - actionview (= 5.2.8.1) - activesupport (= 5.2.8.1) + actionpack (6.0.6.1) + actionview (= 6.0.6.1) + activesupport (= 6.0.6.1) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.6.1) + actionpack (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) + nokogiri (>= 1.8.5) + actionview (6.0.6.1) + activesupport (= 6.0.6.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.6.1) + activesupport (= 6.0.6.1) globalid (>= 0.3.6) - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.0) + activemodel (6.0.6.1) + activesupport (= 6.0.6.1) + activerecord (6.0.6.1) + activemodel (= 6.0.6.1) + activesupport (= 6.0.6.1) activerecord-session_store (1.1.3) actionpack (>= 4.0) activerecord (>= 4.0) multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activestorage (5.2.8.1) - actionpack (= 5.2.8.1) - activerecord (= 5.2.8.1) - marcel (~> 1.0.0) - activesupport (5.2.8.1) + activestorage (6.0.6.1) + actionpack (= 6.0.6.1) + activejob (= 6.0.6.1) + activerecord (= 6.0.6.1) + marcel (~> 1.0) + activesupport (6.0.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) acts_as_paranoid (0.8.1) activerecord (>= 5.2, < 7.1) activesupport (>= 5.2, < 7.1) @@ -85,7 +99,6 @@ GEM safely_block (>= 0.1.1) user_agent_parser uuidtools - arel (9.0.0) ast (2.4.2) autoprefixer-rails (10.4.15.0) execjs (~> 2) @@ -302,18 +315,20 @@ GEM rack (>= 1.0, < 3) rack-test (2.1.0) rack (>= 1.3) - rails (5.2.8.1) - actioncable (= 5.2.8.1) - actionmailer (= 5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - activemodel (= 5.2.8.1) - activerecord (= 5.2.8.1) - activestorage (= 5.2.8.1) - activesupport (= 5.2.8.1) + rails (6.0.6.1) + actioncable (= 6.0.6.1) + actionmailbox (= 6.0.6.1) + actionmailer (= 6.0.6.1) + actionpack (= 6.0.6.1) + actiontext (= 6.0.6.1) + actionview (= 6.0.6.1) + activejob (= 6.0.6.1) + activemodel (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) bundler (>= 1.3.0) - railties (= 5.2.8.1) + railties (= 6.0.6.1) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -327,12 +342,12 @@ GEM loofah (~> 2.21) nokogiri (~> 1.14) rails_response_headers (0.2.0) - railties (5.2.8.1) - actionpack (= 5.2.8.1) - activesupport (= 5.2.8.1) + railties (6.0.6.1) + actionpack (= 6.0.6.1) + activesupport (= 6.0.6.1) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.2) @@ -479,6 +494,7 @@ GEM webrick xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.6.12) PLATFORMS ruby @@ -527,7 +543,7 @@ DEPENDENCIES psych (< 4) puma (~> 3) rack-attack (~> 5) - rails (~> 5) + rails (~> 6.0.0) rails-assets-EpicEditor (~> 0)! rails-assets-chartjs (~> 2)! rails-assets-congress-images-102x125! From 5d33bb39317915d444f22bd8f63dfe2e33b2748f Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:47:19 -0700 Subject: [PATCH 059/113] Upgrade selenium-webdriver to 4.13.1 --- Gemfile | 5 ----- Gemfile.lock | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 5906249de..fef313384 100644 --- a/Gemfile +++ b/Gemfile @@ -104,11 +104,6 @@ end group :test do gem "webmock", "~> 3" gem "selenium-devtools" - # TODO: ruby 3 upgrade - # newer chrome versions need a higher version of selenium-webdriver, but - # those versions require ruby 3 - # tests requiring JS will fail until we upgrade - # gem "selenium-webdriver", "~> 4.11" end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 6456cbd7f..2ca785c3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -419,7 +419,7 @@ GEM rubocop (>= 1.33.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) - rubyzip (1.3.0) + rubyzip (2.3.2) safely_block (0.3.0) errbase (>= 0.1.1) sanitize (6.1.0) @@ -443,7 +443,7 @@ GEM select2-rails (4.0.13) selenium-devtools (0.112.0) selenium-webdriver (~> 4.2) - selenium-webdriver (4.9.0) + selenium-webdriver (4.13.1) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) From 81da389e7d820364defff94e8a7a057a506cbb90 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:53:00 -0700 Subject: [PATCH 060/113] Upgrade factory_bot_rails v4.11 -> v5.2 --- Gemfile | 2 +- Gemfile.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index fef313384..9a1c49023 100644 --- a/Gemfile +++ b/Gemfile @@ -110,7 +110,7 @@ group :development, :test do gem "byebug" gem "capybara", "~> 3" gem "database_cleaner", "~> 1" - gem "factory_bot_rails", "~> 4" + gem "factory_bot_rails", "~> 5.0" gem "rails-controller-testing" gem "rspec-core", "~> 3" gem "rspec-rails", "~> 3" diff --git a/Gemfile.lock b/Gemfile.lock index 2ca785c3b..52f397fcc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -198,11 +198,11 @@ GEM errbase (0.2.2) erubi (1.12.0) execjs (2.9.1) - factory_bot (4.11.1) - activesupport (>= 3.0.0) - factory_bot_rails (4.11.1) - factory_bot (~> 4.11.1) - railties (>= 3.0.0) + factory_bot (5.2.0) + activesupport (>= 4.2.0) + factory_bot_rails (5.2.0) + factory_bot (~> 5.2.0) + railties (>= 4.2.0) faraday (2.7.11) base64 faraday-net_http (>= 2.0, < 3.1) @@ -523,7 +523,7 @@ DEPENDENCIES eff_matomo (~> 0.2.4) ejs (~> 1) email_validator (~> 1) - factory_bot_rails (~> 4) + factory_bot_rails (~> 5.0) fast_inserter (~> 0.1) fastly (~> 2) friendly_id (~> 5.0) From 281f87353215d1eea72c3ffa9396928a23f8cafd Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:56:02 -0700 Subject: [PATCH 061/113] Upgrade rspec-rails to 4.1 --- Gemfile | 3 +-- Gemfile.lock | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 9a1c49023..0039ccbbb 100644 --- a/Gemfile +++ b/Gemfile @@ -112,8 +112,7 @@ group :development, :test do gem "database_cleaner", "~> 1" gem "factory_bot_rails", "~> 5.0" gem "rails-controller-testing" - gem "rspec-core", "~> 3" - gem "rspec-rails", "~> 3" + gem "rspec-rails", "~> 4.0" gem "rubocop" gem "rubocop-github", "~> 0.16" gem "rubocop-performance", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 52f397fcc..ac70bab34 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -375,23 +375,23 @@ GEM netrc (~> 0.8) rexml (3.2.6) rouge (4.1.3) - rspec-core (3.9.3) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.4) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.1) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-rails (3.9.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.4) + rspec-support (~> 3.12.0) + rspec-rails (4.1.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.1) rubocop (1.56.4) base64 (~> 0.1.1) json (~> 2.3) @@ -563,8 +563,7 @@ DEPENDENCIES react-rails (~> 1) redcarpet (~> 3) rest-client (~> 2) - rspec-core (~> 3) - rspec-rails (~> 3) + rspec-rails (~> 4.0) rubocop rubocop-github (~> 0.16) rubocop-performance From f4593ae45439a65ba79a1d198f6bb4e925f32af5 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 20:58:53 -0700 Subject: [PATCH 062/113] Update factory_bot_rails to v6.2 --- Gemfile | 2 +- Gemfile.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 0039ccbbb..80548d4aa 100644 --- a/Gemfile +++ b/Gemfile @@ -110,7 +110,7 @@ group :development, :test do gem "byebug" gem "capybara", "~> 3" gem "database_cleaner", "~> 1" - gem "factory_bot_rails", "~> 5.0" + gem "factory_bot_rails", "~> 6.2" gem "rails-controller-testing" gem "rspec-rails", "~> 4.0" gem "rubocop" diff --git a/Gemfile.lock b/Gemfile.lock index ac70bab34..874b43d1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -198,11 +198,11 @@ GEM errbase (0.2.2) erubi (1.12.0) execjs (2.9.1) - factory_bot (5.2.0) - activesupport (>= 4.2.0) - factory_bot_rails (5.2.0) - factory_bot (~> 5.2.0) - railties (>= 4.2.0) + factory_bot (6.2.1) + activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) faraday (2.7.11) base64 faraday-net_http (>= 2.0, < 3.1) @@ -523,7 +523,7 @@ DEPENDENCIES eff_matomo (~> 0.2.4) ejs (~> 1) email_validator (~> 1) - factory_bot_rails (~> 5.0) + factory_bot_rails (~> 6.2) fast_inserter (~> 0.1) fastly (~> 2) friendly_id (~> 5.0) From eeef8c19bd6f4eca57eb9c6c7f5912f9d34458d9 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sat, 30 Sep 2023 21:10:16 -0700 Subject: [PATCH 063/113] Update activerecord-session_store -- requires upgrading sessions --- Gemfile | 2 +- Gemfile.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 80548d4aa..e334f2287 100644 --- a/Gemfile +++ b/Gemfile @@ -65,7 +65,7 @@ gem "sentry-raven", "~> 0.15" gem "counter_culture", "~> 2.0" # Other -gem "activerecord-session_store", "~> 1" +gem "activerecord-session_store", "~> 2" gem "acts_as_paranoid", "~> 0.7" gem "cocoon", "~> 1" # Dynamically add and remove nested associations from forms gem "devise", "~> 4.7" diff --git a/Gemfile.lock b/Gemfile.lock index 874b43d1e..a9416406e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,12 +66,12 @@ GEM activerecord (6.0.6.1) activemodel (= 6.0.6.1) activesupport (= 6.0.6.1) - activerecord-session_store (1.1.3) - actionpack (>= 4.0) - activerecord (>= 4.0) + activerecord-session_store (2.0.0) + actionpack (>= 5.2.4.1) + activerecord (>= 5.2.4.1) multi_json (~> 1.11, >= 1.11.2) - rack (>= 1.5.2, < 3) - railties (>= 4.0) + rack (>= 2.0.8, < 3) + railties (>= 5.2.4.1) activestorage (6.0.6.1) actionpack (= 6.0.6.1) activejob (= 6.0.6.1) @@ -500,7 +500,7 @@ PLATFORMS ruby DEPENDENCIES - activerecord-session_store (~> 1) + activerecord-session_store (~> 2) acts_as_paranoid (~> 0.7) ahoy_matey (~> 1.6) aws-sdk-rails (~> 2) From 2b0d25569228229d111aad7720c5386264a50425 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 7 Feb 2024 17:58:02 -0800 Subject: [PATCH 064/113] Fix test db naming --- config/database.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/database.yml b/config/database.yml index 6d46973fb..754b64a72 100644 --- a/config/database.yml +++ b/config/database.yml @@ -14,8 +14,8 @@ development: <<: *common test: &test - database: <%= "#{Rails.application.secrets.db_database}-test" %> <<: *common + database: <%= "#{Rails.application.secrets.db_database}-test" %> production: <<: *common From 116c5481435fca0e3e6a0a0efb115f7a418a3f74 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 7 Feb 2024 20:45:41 -0800 Subject: [PATCH 065/113] Replace straggling FactoryGirl references --- spec/features/action_pages/custom_email_action_spec.rb | 2 +- spec/features/action_pages/state_leg_email_action_spec.rb | 2 +- spec/lib/civic_api_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/action_pages/custom_email_action_spec.rb b/spec/features/action_pages/custom_email_action_spec.rb index e85146f42..847b5840e 100644 --- a/spec/features/action_pages/custom_email_action_spec.rb +++ b/spec/features/action_pages/custom_email_action_spec.rb @@ -2,7 +2,7 @@ RSpec.feature "Custom email actions", type: :feature, js: true do let!(:custom_action) do - FactoryGirl.create(:email_campaign, :custom_email).action_page + FactoryBot.create(:email_campaign, :custom_email).action_page end it "allows vistors to send emails" do diff --git a/spec/features/action_pages/state_leg_email_action_spec.rb b/spec/features/action_pages/state_leg_email_action_spec.rb index 32109c2ec..86bf8f0b8 100644 --- a/spec/features/action_pages/state_leg_email_action_spec.rb +++ b/spec/features/action_pages/state_leg_email_action_spec.rb @@ -2,7 +2,7 @@ RSpec.feature "State legislator email actions", type: :feature, js: true do let!(:state_action) do - FactoryGirl.create(:email_campaign, :state_leg).action_page + FactoryBot.create(:email_campaign, :state_leg).action_page end let(:json_parseable_state_officials) { '{"officials": [{"name": "Sponge Bob", "party": "Sandy Party", "emails": ["spongebob@clarinetfans.annoying"]}]}' } diff --git a/spec/lib/civic_api_spec.rb b/spec/lib/civic_api_spec.rb index 751576e0b..a2920e45c 100644 --- a/spec/lib/civic_api_spec.rb +++ b/spec/lib/civic_api_spec.rb @@ -7,7 +7,7 @@ end describe ".state_rep_search" do - let(:email_campaign) { FactoryGirl.create(:email_campaign, :state_leg) } + let(:email_campaign) { FactoryBot.create(:email_campaign, :state_leg) } let(:address) { "815 Eddy St 94109" } it "should get civic_api_url with the correct params" do From 525e6124ce5c9c828d9f57dd5e1ab451d7f9b3c7 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 7 Feb 2024 21:00:54 -0800 Subject: [PATCH 066/113] Fixing tests --- app/models/signature.rb | 2 +- spec/controllers/tools_controller_spec.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/signature.rb b/app/models/signature.rb index 810b31d36..d708b7ea4 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -47,7 +47,7 @@ def self.to_csv(options = {}) def self.to_presentable_csv(options = {}) column_names = %w[full_name email city state country] - CSV.generate(options) do |csv| + CSV.generate(**options) do |csv| csv << column_names all.find_each do |signature| diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 3ed0c2062..6c34020f5 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -93,7 +93,7 @@ Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody") - .with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }) + .with(headers: request_headers) .to_return(status: 200, body: json_parseable_state_officials, headers: {}) end @@ -114,3 +114,14 @@ def stub_smarty_streets stub_resp = { "city" => "San Francisco", "state_abbreviation" => "CA", "state" => "California", "mailable_city" => true } allow(SmartyStreets).to receive(:get_city_state).with("94109").and_return(stub_resp) end + +def request_headers + # If the tests fail based on header differences, update this with what + # rspec tells you to stub with + { + "Accept" => "*/*", + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + "Host" => "civic.example.com", + 'User-Agent'=>'rest-client/2.1.0 (linux x86_64) ruby/3.0.6p216' + } +end From e8eeea15c0734d90cdca2aab5a90b6d103207d1b Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 7 Feb 2024 21:17:29 -0800 Subject: [PATCH 067/113] Start rails 6.1 upgrade --- Gemfile | 4 +- Gemfile.lock | 175 ++++++++++++++++++++++++++------------------------- 2 files changed, 92 insertions(+), 87 deletions(-) diff --git a/Gemfile b/Gemfile index e334f2287..ccc3516c1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem "rails", "~> 6.0.0" +gem "rails", "~> 6.1.0" # Database gem "pg", "~> 1.1" @@ -65,7 +65,7 @@ gem "sentry-raven", "~> 0.15" gem "counter_culture", "~> 2.0" # Other -gem "activerecord-session_store", "~> 2" +gem "activerecord-session_store", "~> 2.1.0" gem "acts_as_paranoid", "~> 0.7" gem "cocoon", "~> 1" # Dynamically add and remove nested associations from forms gem "devise", "~> 4.7" diff --git a/Gemfile.lock b/Gemfile.lock index a9416406e..e161c2ce9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,67 +22,72 @@ GEM GEM remote: https://rubygems.org/ specs: - actioncable (6.0.6.1) - actionpack (= 6.0.6.1) + actioncable (6.1.7.6) + actionpack (= 6.1.7.6) + activesupport (= 6.1.7.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.6.1) - actionpack (= 6.0.6.1) - activejob (= 6.0.6.1) - activerecord (= 6.0.6.1) - activestorage (= 6.0.6.1) - activesupport (= 6.0.6.1) + actionmailbox (6.1.7.6) + actionpack (= 6.1.7.6) + activejob (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) mail (>= 2.7.1) - actionmailer (6.0.6.1) - actionpack (= 6.0.6.1) - actionview (= 6.0.6.1) - activejob (= 6.0.6.1) + actionmailer (6.1.7.6) + actionpack (= 6.1.7.6) + actionview (= 6.1.7.6) + activejob (= 6.1.7.6) + activesupport (= 6.1.7.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.6.1) - actionview (= 6.0.6.1) - activesupport (= 6.0.6.1) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.7.6) + actionview (= 6.1.7.6) + activesupport (= 6.1.7.6) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.6.1) - actionpack (= 6.0.6.1) - activerecord (= 6.0.6.1) - activestorage (= 6.0.6.1) - activesupport (= 6.0.6.1) + actiontext (6.1.7.6) + actionpack (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) nokogiri (>= 1.8.5) - actionview (6.0.6.1) - activesupport (= 6.0.6.1) + actionview (6.1.7.6) + activesupport (= 6.1.7.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.6.1) - activesupport (= 6.0.6.1) + activejob (6.1.7.6) + activesupport (= 6.1.7.6) globalid (>= 0.3.6) - activemodel (6.0.6.1) - activesupport (= 6.0.6.1) - activerecord (6.0.6.1) - activemodel (= 6.0.6.1) - activesupport (= 6.0.6.1) - activerecord-session_store (2.0.0) - actionpack (>= 5.2.4.1) - activerecord (>= 5.2.4.1) + activemodel (6.1.7.6) + activesupport (= 6.1.7.6) + activerecord (6.1.7.6) + activemodel (= 6.1.7.6) + activesupport (= 6.1.7.6) + activerecord-session_store (2.1.0) + actionpack (>= 6.1) + activerecord (>= 6.1) + cgi (>= 0.3.6) multi_json (~> 1.11, >= 1.11.2) - rack (>= 2.0.8, < 3) - railties (>= 5.2.4.1) - activestorage (6.0.6.1) - actionpack (= 6.0.6.1) - activejob (= 6.0.6.1) - activerecord (= 6.0.6.1) + rack (>= 2.0.8, < 4) + railties (>= 6.1) + activestorage (6.1.7.6) + actionpack (= 6.1.7.6) + activejob (= 6.1.7.6) + activerecord (= 6.1.7.6) + activesupport (= 6.1.7.6) marcel (~> 1.0) - activesupport (6.0.6.1) + mini_mime (>= 1.1.0) + activesupport (6.1.7.6) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) acts_as_paranoid (0.8.1) activerecord (>= 5.2, < 7.1) activesupport (>= 5.2, < 7.1) @@ -154,11 +159,12 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + cgi (0.4.1) chartkick (3.4.2) chronic (0.10.2) climate_control (0.2.0) cocoon (1.2.15) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) connection_pool (2.4.1) counter_culture (2.9.0) activerecord (>= 4.2) @@ -170,7 +176,7 @@ GEM addressable daemons (1.4.1) database_cleaner (1.99.0) - date (3.3.3) + date (3.3.4) delayed_job (4.1.11) activesupport (>= 3.0, < 8.0) delayed_job_active_record (4.1.7) @@ -215,8 +221,8 @@ GEM friendly_id (5.5.0) activerecord (>= 4.0.0) geocoder (1.8.2) - globalid (1.1.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) going_postal (0.1.6) gravatar-ultimate (2.0.0) activesupport (>= 2.3.14) @@ -250,7 +256,7 @@ GEM mimemagic (~> 0.3.0) terrapin (~> 0.6.0) language_server-protocol (3.17.0.3) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -268,22 +274,22 @@ GEM nokogiri (~> 1) rake mini_mime (1.1.5) - mini_portile2 (2.8.4) - minitest (5.20.0) + mini_portile2 (2.8.5) + minitest (5.22.2) multi_json (1.15.0) multi_xml (0.6.0) - net-imap (0.3.7) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.4.0.1) net-protocol netrc (0.11.0) - nio4r (2.5.9) - nokogiri (1.15.4) + nio4r (2.7.0) + nokogiri (1.16.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) oauth (0.6.2) @@ -309,26 +315,26 @@ GEM psych (3.3.4) public_suffix (5.0.3) puma (3.12.6) - racc (1.7.1) + racc (1.7.3) rack (2.2.8) rack-attack (5.4.2) rack (>= 1.0, < 3) rack-test (2.1.0) rack (>= 1.3) - rails (6.0.6.1) - actioncable (= 6.0.6.1) - actionmailbox (= 6.0.6.1) - actionmailer (= 6.0.6.1) - actionpack (= 6.0.6.1) - actiontext (= 6.0.6.1) - actionview (= 6.0.6.1) - activejob (= 6.0.6.1) - activemodel (= 6.0.6.1) - activerecord (= 6.0.6.1) - activestorage (= 6.0.6.1) - activesupport (= 6.0.6.1) - bundler (>= 1.3.0) - railties (= 6.0.6.1) + rails (6.1.7.6) + actioncable (= 6.1.7.6) + actionmailbox (= 6.1.7.6) + actionmailer (= 6.1.7.6) + actionpack (= 6.1.7.6) + actiontext (= 6.1.7.6) + actionview (= 6.1.7.6) + activejob (= 6.1.7.6) + activemodel (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) + bundler (>= 1.15.0) + railties (= 6.1.7.6) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -342,14 +348,14 @@ GEM loofah (~> 2.21) nokogiri (~> 1.14) rails_response_headers (0.2.0) - railties (6.0.6.1) - actionpack (= 6.0.6.1) - activesupport (= 6.0.6.1) + railties (6.1.7.6) + actionpack (= 6.1.7.6) + activesupport (= 6.1.7.6) method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + rake (>= 12.2) + thor (~> 1.0) rainbow (3.1.1) - rake (13.0.6) + rake (13.1.0) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) @@ -461,12 +467,11 @@ GEM sprockets (>= 3.0.0) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (1.2.2) - thread_safe (0.3.6) + thor (1.3.0) tilt (2.3.0) - timeout (0.4.0) - tzinfo (1.2.11) - thread_safe (~> 0.1) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) @@ -494,13 +499,13 @@ GEM webrick xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.12) + zeitwerk (2.6.13) PLATFORMS ruby DEPENDENCIES - activerecord-session_store (~> 2) + activerecord-session_store (~> 2.1.0) acts_as_paranoid (~> 0.7) ahoy_matey (~> 1.6) aws-sdk-rails (~> 2) @@ -543,7 +548,7 @@ DEPENDENCIES psych (< 4) puma (~> 3) rack-attack (~> 5) - rails (~> 6.0.0) + rails (~> 6.1.0) rails-assets-EpicEditor (~> 0)! rails-assets-chartjs (~> 2)! rails-assets-congress-images-102x125! From 98dac4e0cec8eae56b731e95dc6e8ea4dc23cf2d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 22 Feb 2024 18:21:05 -0800 Subject: [PATCH 068/113] begin fixing tests --- spec/controllers/action_page_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/action_page_controller_spec.rb b/spec/controllers/action_page_controller_spec.rb index fc112c341..5b9b0b729 100644 --- a/spec/controllers/action_page_controller_spec.rb +++ b/spec/controllers/action_page_controller_spec.rb @@ -21,7 +21,7 @@ it "returns json" do action_page get :index, params: { format: "json" } - expect(response.content_type).to eq("application/json") + expect(response.content_type).to eq("application/json; charset=utf-8") expect(response.body).to include(action_page.title) end end From d4fb52225212d0280f306f6506eb84a04856f3e6 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 22 Feb 2024 19:12:48 -0800 Subject: [PATCH 069/113] ahoy_matey 1.6 -> v2 --- Gemfile | 4 +++- Gemfile.lock | 29 ++++++++++++++--------------- config/initializers/ahoy.rb | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index ccc3516c1..d04d419cd 100644 --- a/Gemfile +++ b/Gemfile @@ -49,7 +49,9 @@ gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails # Analytics -gem "ahoy_matey", "~> 1.6" +gem "ahoy_matey", "~> 2" +# required for ahoy_matey 2.0 with activerecordstore +gem "uuidtools", "~> 2" gem "chartkick", "~> 3" gem "eff_matomo", "~> 0.2.4", require: "matomo" gem "groupdate", "~> 2" diff --git a/Gemfile.lock b/Gemfile.lock index e161c2ce9..e83396c14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,19 +91,18 @@ GEM acts_as_paranoid (0.8.1) activerecord (>= 5.2, < 7.1) activesupport (>= 5.2, < 7.1) - addressable (2.8.5) + addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - ahoy_matey (1.6.1) + ahoy_matey (2.2.1) addressable browser (~> 2.0) - geocoder - rack-attack (< 6) - railties - referer-parser (>= 0.3.0) + device_detector + geocoder (>= 1.4.5) + railties (>= 4.2) + referer-parser (>= 0.3) request_store - safely_block (>= 0.1.1) + safely_block (>= 0.2.1) user_agent_parser - uuidtools ast (2.4.2) autoprefixer-rails (10.4.15.0) execjs (~> 2) @@ -182,6 +181,7 @@ GEM delayed_job_active_record (4.1.7) activerecord (>= 3.0, < 8.0) delayed_job (>= 3.0, < 5) + device_detector (1.1.2) devise (4.9.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -201,7 +201,6 @@ GEM ejs (1.1.1) email_validator (1.6.0) activemodel - errbase (0.2.2) erubi (1.12.0) execjs (2.9.1) factory_bot (6.2.1) @@ -313,10 +312,10 @@ GEM net-smtp premailer (~> 1.7, >= 1.7.9) psych (3.3.4) - public_suffix (5.0.3) + public_suffix (5.0.4) puma (3.12.6) racc (1.7.3) - rack (2.2.8) + rack (2.2.8.1) rack-attack (5.4.2) rack (>= 1.0, < 3) rack-test (2.1.0) @@ -369,7 +368,7 @@ GEM redcarpet (3.6.0) referer-parser (0.3.0) regexp_parser (2.8.1) - request_store (1.5.1) + request_store (1.6.0) rack (>= 1.4) responders (3.1.0) actionpack (>= 5.2) @@ -426,8 +425,7 @@ GEM ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) - safely_block (0.3.0) - errbase (>= 0.1.1) + safely_block (0.4.0) sanitize (6.1.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -507,7 +505,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 2.1.0) acts_as_paranoid (~> 0.7) - ahoy_matey (~> 1.6) + ahoy_matey (~> 2) aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) @@ -580,6 +578,7 @@ DEPENDENCIES selenium-devtools sentry-raven (~> 0.15) uglifier (>= 1.3.0) + uuidtools (~> 2) webmock (~> 3) whenever (~> 0) will_paginate (~> 3.0) diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb index 1043eb6f5..23701002e 100644 --- a/config/initializers/ahoy.rb +++ b/config/initializers/ahoy.rb @@ -1,18 +1,47 @@ -class Ahoy::Store < Ahoy::Stores::ActiveRecordStore +class Ahoy::Store < Ahoy::DatabaseStore def user current_user = super current_user if current_user.try(:record_activity?) end def track_event(name, properties, options) + # TODO: this will probably break because it's getting a data hash not these + # individual variables... + # can get request info via request.parameters action_page_id = options[:action_page_id] || options[:action_page].try(:id) - super do |event| + data[:id] = ensure_uuid(data.delete(:event_id)) + super(data) do |event| event.action_page_id = action_page_id end end + + # Based on https://github.com/ankane/ahoy/blob/ee2d0b3afff6284f57e372926d4a82fc91c8a948/docs/Ahoy-2-Upgrade.md#activerecordstore + def track_visit(data) + data[:id] = ensure_uuid(data.delete(:visit_token)) + data[:visitor_id] = ensure_uuid(data.delete(:visitor_token)) + super(data) + end + + def visit + @visit ||= visit_model.find_by(id: ensure_uuid(ahoy.visit_token)) if ahoy.visit_token + end + + def visit_model + Visit + end + + UUID_NAMESPACE = UUIDTools::UUID.parse("a82ae811-5011-45ab-a728-569df7499c5f") + + def ensure_uuid(id) + UUIDTools::UUID.parse(id).to_s + rescue + UUIDTools::UUID.sha1_create(UUID_NAMESPACE, id).to_s + end end module Ahoy self.visit_duration = nil self.visitor_duration = nil + self.api = true + self.server_side_visits = false end From ceb38a8b463710611278b99dda54b7b8461a04ae Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 22 Feb 2024 19:15:31 -0800 Subject: [PATCH 070/113] Upgrade to ahoy_matey v5 --- Gemfile | 4 ++-- Gemfile.lock | 22 +++++----------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index d04d419cd..c5d1e9d71 100644 --- a/Gemfile +++ b/Gemfile @@ -49,8 +49,8 @@ gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails # Analytics -gem "ahoy_matey", "~> 2" -# required for ahoy_matey 2.0 with activerecordstore +gem "ahoy_matey", "~> 5" +# required for ahoy_matey 2.0+ with activerecordstore gem "uuidtools", "~> 2" gem "chartkick", "~> 3" gem "eff_matomo", "~> 0.2.4", require: "matomo" diff --git a/Gemfile.lock b/Gemfile.lock index e83396c14..9e8473259 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,16 +93,10 @@ GEM activesupport (>= 5.2, < 7.1) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - ahoy_matey (2.2.1) - addressable - browser (~> 2.0) - device_detector - geocoder (>= 1.4.5) - railties (>= 4.2) - referer-parser (>= 0.3) - request_store - safely_block (>= 0.2.1) - user_agent_parser + ahoy_matey (5.0.2) + activesupport (>= 6.1) + device_detector (>= 1) + safely_block (>= 0.4) ast (2.4.2) autoprefixer-rails (10.4.15.0) execjs (~> 2) @@ -146,7 +140,6 @@ GEM bourbon (3.2.4) sass (~> 3.2) thor - browser (2.7.1) builder (3.2.4) byebug (11.1.3) capybara (3.39.2) @@ -219,7 +212,6 @@ GEM ffi (1.16.2) friendly_id (5.5.0) activerecord (>= 4.0.0) - geocoder (1.8.2) globalid (1.2.1) activesupport (>= 6.1) going_postal (0.1.6) @@ -366,10 +358,7 @@ GEM railties (>= 3.2) tilt redcarpet (3.6.0) - referer-parser (0.3.0) regexp_parser (2.8.1) - request_store (1.6.0) - rack (>= 1.4) responders (3.1.0) actionpack (>= 5.2) railties (>= 5.2) @@ -476,7 +465,6 @@ GEM unf_ext unf_ext (0.0.8.2) unicode-display_width (2.4.2) - user_agent_parser (2.16.0) uuidtools (2.2.0) version_gem (1.1.3) warden (1.2.9) @@ -505,7 +493,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 2.1.0) acts_as_paranoid (~> 0.7) - ahoy_matey (~> 2) + ahoy_matey (~> 5) aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) From 9c01f2c2c1187721648a772a31611bb531c4cba9 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Thu, 22 Feb 2024 19:23:00 -0800 Subject: [PATCH 071/113] Revert "Upgrade to ahoy_matey v5" This reverts commit ceb38a8b463710611278b99dda54b7b8461a04ae. --- Gemfile | 4 ++-- Gemfile.lock | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index c5d1e9d71..d04d419cd 100644 --- a/Gemfile +++ b/Gemfile @@ -49,8 +49,8 @@ gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails # Analytics -gem "ahoy_matey", "~> 5" -# required for ahoy_matey 2.0+ with activerecordstore +gem "ahoy_matey", "~> 2" +# required for ahoy_matey 2.0 with activerecordstore gem "uuidtools", "~> 2" gem "chartkick", "~> 3" gem "eff_matomo", "~> 0.2.4", require: "matomo" diff --git a/Gemfile.lock b/Gemfile.lock index 9e8473259..e83396c14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,10 +93,16 @@ GEM activesupport (>= 5.2, < 7.1) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - ahoy_matey (5.0.2) - activesupport (>= 6.1) - device_detector (>= 1) - safely_block (>= 0.4) + ahoy_matey (2.2.1) + addressable + browser (~> 2.0) + device_detector + geocoder (>= 1.4.5) + railties (>= 4.2) + referer-parser (>= 0.3) + request_store + safely_block (>= 0.2.1) + user_agent_parser ast (2.4.2) autoprefixer-rails (10.4.15.0) execjs (~> 2) @@ -140,6 +146,7 @@ GEM bourbon (3.2.4) sass (~> 3.2) thor + browser (2.7.1) builder (3.2.4) byebug (11.1.3) capybara (3.39.2) @@ -212,6 +219,7 @@ GEM ffi (1.16.2) friendly_id (5.5.0) activerecord (>= 4.0.0) + geocoder (1.8.2) globalid (1.2.1) activesupport (>= 6.1) going_postal (0.1.6) @@ -358,7 +366,10 @@ GEM railties (>= 3.2) tilt redcarpet (3.6.0) + referer-parser (0.3.0) regexp_parser (2.8.1) + request_store (1.6.0) + rack (>= 1.4) responders (3.1.0) actionpack (>= 5.2) railties (>= 5.2) @@ -465,6 +476,7 @@ GEM unf_ext unf_ext (0.0.8.2) unicode-display_width (2.4.2) + user_agent_parser (2.16.0) uuidtools (2.2.0) version_gem (1.1.3) warden (1.2.9) @@ -493,7 +505,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 2.1.0) acts_as_paranoid (~> 0.7) - ahoy_matey (~> 5) + ahoy_matey (~> 2) aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) From 462b7e8981c96aedb47af8f28c51ead585709201 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Wed, 3 Apr 2024 09:42:52 -0700 Subject: [PATCH 072/113] WIP ahoy upgrade --- Gemfile | 2 +- Gemfile.lock | 16 +++------------- app/controllers/ahoy_controller.rb | 1 - app/controllers/application_controller.rb | 2 -- config/initializers/ahoy.rb | 16 +++++++++++----- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index d04d419cd..65a4d6c0d 100644 --- a/Gemfile +++ b/Gemfile @@ -49,7 +49,7 @@ gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails # Analytics -gem "ahoy_matey", "~> 2" +gem "ahoy_matey", "~> 3" # required for ahoy_matey 2.0 with activerecordstore gem "uuidtools", "~> 2" gem "chartkick", "~> 3" diff --git a/Gemfile.lock b/Gemfile.lock index e83396c14..306ab2b1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,16 +93,11 @@ GEM activesupport (>= 5.2, < 7.1) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - ahoy_matey (2.2.1) - addressable - browser (~> 2.0) + ahoy_matey (3.3.0) + activesupport (>= 5) device_detector geocoder (>= 1.4.5) - railties (>= 4.2) - referer-parser (>= 0.3) - request_store safely_block (>= 0.2.1) - user_agent_parser ast (2.4.2) autoprefixer-rails (10.4.15.0) execjs (~> 2) @@ -146,7 +141,6 @@ GEM bourbon (3.2.4) sass (~> 3.2) thor - browser (2.7.1) builder (3.2.4) byebug (11.1.3) capybara (3.39.2) @@ -366,10 +360,7 @@ GEM railties (>= 3.2) tilt redcarpet (3.6.0) - referer-parser (0.3.0) regexp_parser (2.8.1) - request_store (1.6.0) - rack (>= 1.4) responders (3.1.0) actionpack (>= 5.2) railties (>= 5.2) @@ -476,7 +467,6 @@ GEM unf_ext unf_ext (0.0.8.2) unicode-display_width (2.4.2) - user_agent_parser (2.16.0) uuidtools (2.2.0) version_gem (1.1.3) warden (1.2.9) @@ -505,7 +495,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 2.1.0) acts_as_paranoid (~> 0.7) - ahoy_matey (~> 2) + ahoy_matey (~> 3) aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) diff --git a/app/controllers/ahoy_controller.rb b/app/controllers/ahoy_controller.rb index 24676ba15..8a6d70b83 100644 --- a/app/controllers/ahoy_controller.rb +++ b/app/controllers/ahoy_controller.rb @@ -1,7 +1,6 @@ class AhoyController < ApplicationController before_action :set_ahoy_cookies before_action :track_ahoy_visit - before_action :set_ahoy_request_store def visit action_type = params.require(:action_type) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c0a057e3b..71ebe9d3d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,9 +11,7 @@ class ApplicationController < ActionController::Base before_action :set_locale before_action :user_conditional_logic - skip_before_action :set_ahoy_cookies skip_before_action :track_ahoy_visit - skip_before_action :set_ahoy_request_store def user_conditional_logic lock_users_with_expired_passwords! if user_signed_in? && !user_is_being_told_to_reset_pass_or_is_resetting_pass? diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb index 23701002e..50251096a 100644 --- a/config/initializers/ahoy.rb +++ b/config/initializers/ahoy.rb @@ -1,21 +1,25 @@ class Ahoy::Store < Ahoy::DatabaseStore + def autheticate(data) + # Documentation says to make this method blank to disable automatic + # linking of visits and users + end + def user current_user = super current_user if current_user.try(:record_activity?) end - def track_event(name, properties, options) + def track_event(data) # TODO: this will probably break because it's getting a data hash not these # individual variables... # can get request info via request.parameters - action_page_id = options[:action_page_id] || options[:action_page].try(:id) + action_page_id = data[:action_page_id] || data[:action_page].try(:id) data[:id] = ensure_uuid(data.delete(:event_id)) - super(data) do |event| - event.action_page_id = action_page_id - end + super(data) end # Based on https://github.com/ankane/ahoy/blob/ee2d0b3afff6284f57e372926d4a82fc91c8a948/docs/Ahoy-2-Upgrade.md#activerecordstore + # TODO: find better uuid? def track_visit(data) data[:id] = ensure_uuid(data.delete(:visit_token)) data[:visitor_id] = ensure_uuid(data.delete(:visitor_token)) @@ -44,4 +48,6 @@ module Ahoy self.visitor_duration = nil self.api = true self.server_side_visits = false + self.mask_ips = true + self.cookies = false end From c3bfa0cb6de894b41735e1dfbc9d3ef4756e4862 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Thu, 4 Apr 2024 12:30:39 -0700 Subject: [PATCH 073/113] Fix failing tests in tools_controller_spec.rb --- spec/controllers/tools_controller_spec.rb | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 6c34020f5..eacbc6d04 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -66,8 +66,7 @@ it "should redirect to ActionPage#service_uri(service) if email has custom recipients" do service = "gmail" uri = "https://composeurl.example.com" - expect(ActionPage).to receive(:find_by_id) { custom_email_campaign.action_page } - expect(custom_email_campaign).to receive(:service_uri).with(service) { uri } + allow_any_instance_of(EmailCampaign).to receive(:service_uri).with(service).and_return(uri) get :email, params: { action_id: custom_email_campaign.action_page.id, service: service } expect(response).to redirect_to(uri) end @@ -76,8 +75,7 @@ service = "gmail" state_rep_email = "state_rep@example.com" uri = "https://composeurl.example.com" - expect(ActionPage).to receive(:find_by_id) { state_email_campaign.action_page } - expect(state_email_campaign).to receive(:service_uri).with(service, { email: state_rep_email }) { uri } + allow_any_instance_of(EmailCampaign).to receive(:service_uri).with(service, { email: state_rep_email }) { uri } get :email, params: { action_id: state_email_campaign.action_page.id, state_rep_email: state_rep_email, service: service } expect(response).to redirect_to(uri) end @@ -93,7 +91,6 @@ Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody") - .with(headers: request_headers) .to_return(status: 200, body: json_parseable_state_officials, headers: {}) end @@ -114,14 +111,3 @@ def stub_smarty_streets stub_resp = { "city" => "San Francisco", "state_abbreviation" => "CA", "state" => "California", "mailable_city" => true } allow(SmartyStreets).to receive(:get_city_state).with("94109").and_return(stub_resp) end - -def request_headers - # If the tests fail based on header differences, update this with what - # rspec tells you to stub with - { - "Accept" => "*/*", - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - "Host" => "civic.example.com", - 'User-Agent'=>'rest-client/2.1.0 (linux x86_64) ruby/3.0.6p216' - } -end From 8ceb24e7218168640a118222d112b5497a99bb83 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Fri, 5 Apr 2024 08:23:03 -0700 Subject: [PATCH 074/113] Set DatabaseCleaner to append_after -https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example --- spec/rails_helper.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c060d13db..91f1643c5 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -45,6 +45,9 @@ # instead of true. config.use_transactional_fixtures = false + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and # `post` in specs under `spec/controllers`. @@ -64,7 +67,7 @@ config.before(:each) { DatabaseCleaner.strategy = :transaction } config.before(:each, js: true) { DatabaseCleaner.strategy = :truncation } config.before(:each) { DatabaseCleaner.start } - config.after(:each) { DatabaseCleaner.clean } + config.append_after(:each) { DatabaseCleaner.clean } config.before(:each, type: :feature) do # disable call tool by default; it will be stubbed for tests that need it From 33c81e9b17913d0527516bdae2933cd6ee73d470 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Thu, 4 Apr 2024 14:05:41 -0700 Subject: [PATCH 075/113] Fix fill attributes in lib/congress_forms -looks like rubocop erroneously 'fixed' this method --- app/models/congress_message.rb | 3 +-- lib/congress_forms.rb | 2 +- spec/requests/congress_messages_spec.rb | 6 +++--- spec/spec_helper.rb | 6 ++++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/congress_message.rb b/app/models/congress_message.rb index 6e4602767..29d382fef 100644 --- a/app/models/congress_message.rb +++ b/app/models/congress_message.rb @@ -69,8 +69,7 @@ def background_submit(test: false) return unless valid? @forms.each do |f| - f.delay.fill(attributes_for(f.bioguide_id), campaign.campaign_tag, - test: test) + f.delay.fill(attributes_for(f.bioguide_id), campaign.campaign_tag, test) end end diff --git a/lib/congress_forms.rb b/lib/congress_forms.rb index d99023830..d2d62b74f 100644 --- a/lib/congress_forms.rb +++ b/lib/congress_forms.rb @@ -26,7 +26,7 @@ def order_fields @fields = @fields.sort_by { |f| order.index(f.value) || Float::INFINITY } end - def fill(input, campaign_tag, test: false) + def fill(input, campaign_tag, test = false) params = { bio_id: @bioguide_id, campaign_tag: campaign_tag, fields: input } params[:test] = 1 if test CongressForms.post("/fill-out-form/", params) diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index 9602892c9..cc1eed4ad 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -137,7 +137,7 @@ def submit_congress_message .and_return(status: 200, body: "{}") end - it "successfully submits good input" do + it "successfully submits good input", :run_delayed_jobs do submit_congress_message expect(WebMock).to have_requested(:post, /fill-out-form/) .with(body: { @@ -166,7 +166,7 @@ def submit_congress_message expect(WebMock).not_to have_requested(:post, /fill-out-form/) end - it "enables test mode" do + it "enables test mode", :run_delayed_jobs do message_attributes[:test] = 1 submit_congress_message expect(response.status).to eq 200 @@ -174,7 +174,7 @@ def submit_congress_message .with(body: hash_including(test: 1)).twice end - it "succeeds with no common attributs" do + it "succeeds with no common attributes" do stub_congress_forms_find_with_one_rep submit_congress_message expect(response.status).to eq 200 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7458a0653..57a06c102 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,6 +30,12 @@ mocks.verify_partial_doubles = true end + config.around(:each, :run_delayed_jobs) do |example| + Delayed::Worker.delay_jobs = false + example.run + Delayed::Worker.delay_jobs = true + end + config.include Capybara::DSL config.include FeatureHelpers, type: :feature From be75e6f8f8322530afcc1c2dde4380f01c2ba8f2 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Fri, 5 Apr 2024 12:11:52 -0700 Subject: [PATCH 076/113] Fix action_creation_spec --- .../state_leg_email_action_spec.rb | 1 - spec/features/admin/action_creation_spec.rb | 34 +++++++------------ spec/rails_helper.rb | 1 + 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/spec/features/action_pages/state_leg_email_action_spec.rb b/spec/features/action_pages/state_leg_email_action_spec.rb index 86bf8f0b8..346622b34 100644 --- a/spec/features/action_pages/state_leg_email_action_spec.rb +++ b/spec/features/action_pages/state_leg_email_action_spec.rb @@ -11,7 +11,6 @@ Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api" stub_request(:get, "http://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody") - .with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip, deflate", "Host" => "civic.example.com", "User-Agent" => "rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.5p157" }) .to_return(status: 200, body: json_parseable_state_officials, headers: {}) end diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index 5d016fb71..0227cb1ca 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -14,9 +14,7 @@ fill_in "Message", with: "A message" next_section - # skip banner selection - next_section - + skip_banner_selection fill_in_social_media tempermental do @@ -38,9 +36,7 @@ fill_in "Goal", with: 1000 next_section - # skip banner selection - next_section - + skip_banner_selection fill_in_social_media tempermental do @@ -59,14 +55,10 @@ select_action_type("email") fill_in "Subject", with: "Subject" fill_in "Message", with: "An email" - next_section - - # skip banner selection - next_section fill_in "Or enter custom email addresses below:", with: "test@gmail.com" - click_on "Next" next_section + skip_banner_selection fill_in_social_media tempermental do @@ -91,10 +83,8 @@ click_on "Next" - skip_image_selection + skip_banner_selection fill_in_social_media - # Skip partners - click_on "Next" tempermental do click_button "Save" @@ -114,9 +104,7 @@ fill_in "Message", with: "A message" next_section - # skip banner selection - next_section - + skip_banner_selection fill_in_social_media tempermental do @@ -137,9 +125,7 @@ with: "Call script" next_section - # skip banner selection - next_section - + skip_banner_selection fill_in_social_media tempermental do @@ -152,7 +138,7 @@ def fill_in_basic_info(title:, summary:, description:) fill_in "Title", with: title fill_in_editor "#action_page_summary", with: summary fill_in_editor "#action_page_description", with: description - fill_in_select2 "#action_page_category_id", with: category.title + select(category.title, from: "action_page_category_id") #we should use the label to find the select but the label here is not correctly pointing to the select end def next_section @@ -160,7 +146,13 @@ def next_section sleep 0.05 end + def skip_banner_selection + expect(page).to have_selector("#images", visible: true, wait: 5) + next_section + end + def fill_in_social_media + expect(page).to have_selector("#sharing", visible: true, wait: 5) fill_in "Share Message", with: "Twitter message" fill_in "Title", with: "A social media title" next_section diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 91f1643c5..1bfae2b7b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -31,6 +31,7 @@ Capybara.server = :puma Capybara.javascript_driver = :selenium_chrome_headless Capybara.enable_aria_label = true +Capybara.disable_animation = true RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller From eebcb8e1ab02fe9e88cee4ce2bd3a1282409e696 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Fri, 5 Apr 2024 15:29:17 -0700 Subject: [PATCH 077/113] Fixing deprecation warnings --- config/initializers/paperclip_patch.rb | 4 +++- spec/controllers/admin/institutions_controller_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/initializers/paperclip_patch.rb b/config/initializers/paperclip_patch.rb index b97735871..c10d2162c 100644 --- a/config/initializers/paperclip_patch.rb +++ b/config/initializers/paperclip_patch.rb @@ -1,2 +1,4 @@ # Monkeypatch paperclip's media type detection -Paperclip::MediaTypeSpoofDetector.prepend MonkeyPatches::OctetStreamOverride +Rails.application.reloader.to_prepare do + Paperclip::MediaTypeSpoofDetector.prepend MonkeyPatches::OctetStreamOverride +end diff --git a/spec/controllers/admin/institutions_controller_spec.rb b/spec/controllers/admin/institutions_controller_spec.rb index aea96fb17..678b056ff 100644 --- a/spec/controllers/admin/institutions_controller_spec.rb +++ b/spec/controllers/admin/institutions_controller_spec.rb @@ -57,7 +57,7 @@ end context "with valid csv" do - let(:file) { fixture_file_upload("files/schools.csv") } + let(:file) { fixture_file_upload("schools.csv") } it "queues a job" do expect { import }.to change(Delayed::Job, :count).by(1) @@ -76,7 +76,7 @@ end context "with an invalid csv" do - let(:file) { fixture_file_upload("files/bad_schools.csv") } + let(:file) { fixture_file_upload("bad_schools.csv") } it "does not upload institutions" do expect(Institution).not_to receive(:import) From 1aa958a02e06feaeaf9f48c5aaa19798b5c2b86f Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Fri, 5 Apr 2024 15:30:02 -0700 Subject: [PATCH 078/113] Fixing deprecation warnings dynamic controller actions no longer supported --- app/controllers/smarty_streets_controller.rb | 11 +++++++---- config/routes.rb | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/smarty_streets_controller.rb b/app/controllers/smarty_streets_controller.rb index de6fcda85..6645415db 100644 --- a/app/controllers/smarty_streets_controller.rb +++ b/app/controllers/smarty_streets_controller.rb @@ -9,10 +9,13 @@ def street_address render json: get_data_on_address_zip(params), status: 200 end - # This endpoint appears unused - def suggest - render json: get_suggestions_for_address(params), status: 200 - end + # This endpoint appears unused (TheNotary 1/16) + # Lets remove it and see if anything breaks! (jparr 4/23) + # todo: remove if not used + + # def suggest + # render json: get_suggestions_for_address(params), status: 200 + # end private diff --git a/config/routes.rb b/config/routes.rb index 580988221..954366a12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ get "tools/state_reps" get "tools/social_buttons_count" - get "smarty_streets/:action", controller: :smarty_streets + get "smarty_streets/street_address", controller: :smarty_streets get "petition/:id/recent_signatures", :to => "petition#recent_signatures", :format => 'json' # Handle notifications from Amazon SES @@ -80,7 +80,7 @@ get :generate_key, :on => :collection end - get 'mailer/:action/:id' => 'mailer#:action' + get 'mailer/preview_thanks/:id' => 'mailer#preview_thanks' resources :congress_message_campaigns, only: :none do member do From 043ef9b47e70814cd9720e3fc9895745380faa72 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Fri, 5 Apr 2024 15:30:31 -0700 Subject: [PATCH 079/113] Fixing deprecation warnings update fast_inserter to latest --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 65a4d6c0d..3e67eba33 100644 --- a/Gemfile +++ b/Gemfile @@ -89,7 +89,7 @@ gem "will_paginate", "~> 3.0" gem "xmlrpc", "~> 0.3" # For creating many records, quickly -gem "fast_inserter", "~> 0.1" +gem "fast_inserter", "~> 2.0" # Pin psych to below version 4 until we're on rails 7 and ruby 3.1 gem "psych", "< 4" diff --git a/Gemfile.lock b/Gemfile.lock index 306ab2b1e..651589b45 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -207,7 +207,7 @@ GEM faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) - fast_inserter (0.1.6) + fast_inserter (2.0.0) activerecord (>= 4.1.0) fastly (2.5.3) ffi (1.16.2) @@ -517,7 +517,7 @@ DEPENDENCIES ejs (~> 1) email_validator (~> 1) factory_bot_rails (~> 6.2) - fast_inserter (~> 0.1) + fast_inserter (~> 2.0) fastly (~> 2) friendly_id (~> 5.0) going_postal (~> 0) From 1cd3dc6891242835b438da53c987f8b1120a15a4 Mon Sep 17 00:00:00 2001 From: Syd Young Date: Sun, 7 Apr 2024 20:27:26 -0700 Subject: [PATCH 080/113] Upgrade ahoy to v4; fix user model test failure --- Gemfile | 2 +- Gemfile.lock | 8 +++---- spec/models/user_spec.rb | 45 ++++++++++++++-------------------------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/Gemfile b/Gemfile index 3e67eba33..70d3d3f2c 100644 --- a/Gemfile +++ b/Gemfile @@ -49,7 +49,7 @@ gem "nokogiri", "~> 1" # Required for premailer-rails gem "premailer-rails", "~> 1" # Inline styles for emails # Analytics -gem "ahoy_matey", "~> 3" +gem "ahoy_matey", "~> 4.0" # required for ahoy_matey 2.0 with activerecordstore gem "uuidtools", "~> 2" gem "chartkick", "~> 3" diff --git a/Gemfile.lock b/Gemfile.lock index 651589b45..37ea09e4e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,10 +93,9 @@ GEM activesupport (>= 5.2, < 7.1) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - ahoy_matey (3.3.0) - activesupport (>= 5) + ahoy_matey (4.2.1) + activesupport (>= 5.2) device_detector - geocoder (>= 1.4.5) safely_block (>= 0.2.1) ast (2.4.2) autoprefixer-rails (10.4.15.0) @@ -213,7 +212,6 @@ GEM ffi (1.16.2) friendly_id (5.5.0) activerecord (>= 4.0.0) - geocoder (1.8.2) globalid (1.2.1) activesupport (>= 6.1) going_postal (0.1.6) @@ -495,7 +493,7 @@ PLATFORMS DEPENDENCIES activerecord-session_store (~> 2.1.0) acts_as_paranoid (~> 0.7) - ahoy_matey (~> 3) + ahoy_matey (~> 4.0) aws-sdk-rails (~> 2) aws-sdk-s3 (~> 1) better_errors (~> 2) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index da827928e..a8400e7e7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -48,44 +48,31 @@ describe "track user actions" do let(:user) { FactoryBot.create(:user, record_activity: true) } - let(:ahoy) { Ahoy::Tracker.new } let(:action_page) { FactoryBot.create :action_page_with_petition } it "knows if the user has taken a given action" do - ahoy.authenticate(user) - track_signature(action_page) - + FactoryBot.create(:ahoy_signature, action_page: action_page, user: user) expect(user.taken_action?(action_page)).to be_truthy end end end +# TODO: possibly remove, this seems unused? def record_several_actions - # a user with no actions - FactoryBot.create(:user, record_activity: true) - - # a user with three actions - ahoy.authenticate(FactoryBot.create(:user, record_activity: true)) - 3.times { track_signature(action_page) } - - # a user with 1 action - ahoy.authenticate(FactoryBot.create(:user, record_activity: true)) - track_signature(action_page) - - # our friend, with 2 actions - ahoy.authenticate(user) - 2.times { track_signature(action_page) } - track_view(action_page) + create_user_with_tracked_actions(signatures: 0, views: 0) + create_user_with_tracked_actions(signatures: 3, views: 0) + create_user_with_tracked_actions(signatures: 1, views: 0) + create_user_with_tracked_actions(signatures: 2, views: 1) end -def track_signature(action_page) - ahoy.track "Action", - { type: "action", actionType: "signature", actionPageId: action_page.id }, - action_page: action_page -end - -def track_view(action_page) - ahoy.track "View", - { type: "action", actionType: "view", actionPageId: action_page.id }, - action_page: action_page +def user_with_tracked_actions(signatures: 1, views: 1) + user = FactoryBot.create(:user, record_activity: true) + signatures.times do + action = FactoryBot.create(:action_page_with_petition) + FactoryBot.create(:ahoy_signature, action_page: action, user: user) + end + views.times do + action = FactoryBot.create(:action_page_with_email) + FactoryBot.create(:ahoy_view, action_page: action, user: user) + end end From 7be5118b49c00232965d0da37619b18772215e1d Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Tue, 9 Apr 2024 17:21:47 -0700 Subject: [PATCH 081/113] update rubocop config see: #193 --- .rubocop.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 127c7d926..dd2575558 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,13 +1,17 @@ +require: + - rubocop-rails + - rubocop-performance + inherit_from: .rubocop_todo.yml inherit_gem: rubocop-github: - - config/default_edge.yml - - config/rails_edge.yml + - config/default.yml + - config/rails.yml AllCops: - TargetRailsVersion: 5.0 - TargetRubyVersion: 2.7 + TargetRailsVersion: 6.1 + TargetRubyVersion: 3.0 NewCops: disable Exclude: - 'db/**/*' @@ -66,7 +70,10 @@ Performance/Squeeze: Performance/StringInclude: Enabled: true -### Override rubcop-github ### +Bundler/OrderedGems: + Enabled: false + +### Override rubocop-github ### Style/FrozenStringLiteralComment: # We aren't upgrading to Ruby 3.0, so this is just noise @@ -84,9 +91,6 @@ GitHub/RailsControllerRenderPathsExist: # Doesn't seem to work; can't find templates that exist Enabled: false -GitHub/RailsApplicationRecord: - # Rails/ApplicationRecord does the same thing - Enabled: false Lint/Void: Exclude: From f9798ccb1f5c0fb57aef37432645cb9ac8aff431 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Tue, 9 Apr 2024 17:48:42 -0700 Subject: [PATCH 082/113] rubocop autofix of unnecessary inline cop disables see: #193 --- app/controllers/registrations_controller.rb | 2 -- app/controllers/tools_controller.rb | 2 -- app/controllers/users_controller.rb | 2 -- app/helpers/application_helper.rb | 2 +- app/mailers/user_mailer.rb | 2 -- app/models/action_page.rb | 8 ++------ app/models/congress_message_campaign.rb | 2 +- app/models/congress_scorecard.rb | 2 -- app/models/source_file.rb | 2 +- app/models/twitter.rb | 2 +- app/queries/action_page_filters.rb | 4 ++-- app/views/action_page/index.atom.builder | 2 +- app/views/action_page/index.json.jbuilder | 2 -- lib/congress_forms.rb | 2 +- lib/related_content.rb | 2 -- lib/tasks/ahoy.rake | 2 -- lib/tasks/congress.rake | 2 -- spec/requests/congress_messages_spec.rb | 6 +----- spec/spec_helper.rb | 4 ++-- spec/tasks/signatures_spec.rb | 4 ---- 20 files changed, 13 insertions(+), 43 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 20eeab6ba..1ea3f7de9 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -31,9 +31,7 @@ def handle_nonunique_email existing.update(sign_up_params) unless existing.confirmed? if resource.persisted? - # rubocop:todo Rails/SkipsModelValidations resource.update_attribute(:unconfirmed_email, account_update_params[:email]) - # rubocop:enable Rails/SkipsModelValidations flash[:notice] = I18n.t "devise.registrations.update_needs_confirmation" respond_with resource, location: after_update_path_for(resource) else diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index 32d1b4f0c..d7a6c6f89 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -179,11 +179,9 @@ def set_user @user = current_user end - # rubocop:todo Naming/MemoizedInstanceVariableName def set_action_page @action_page ||= ActionPage.find_by(id: params[:action_id]) end - # rubocop:enable Naming/MemoizedInstanceVariableName def create_newsletter_subscription if params[:subscribe] && EmailValidator.valid?(params[:subscription][:email]) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4f1a3b3d1..99a9bd6a7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,9 +21,7 @@ def update end def clear_activity - # rubocop:todo Rails/SkipsModelValidations current_user.events.update_all(user_id: nil) - # rubocop:enable Rails/SkipsModelValidations redirect_to user_path end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 740af86b6..ae639d71b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -110,7 +110,7 @@ def messages safe_join(messages) end - def percentage(x, y, precision: 0) # rubocop:todo Naming/MethodParameterName + def percentage(x, y, precision: 0) return "-" unless y > 0 number_to_percentage((x / y.to_f) * 100, precision: precision) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 6222a217b..7609415fe 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -4,7 +4,6 @@ class UserMailer < ActionMailer::Base layout "email" after_action :check_bounces - # rubocop:todo Naming/MethodParameterName def thanks_message(email, actionPage, options = {}) @email = email @user = options[:user] @@ -12,7 +11,6 @@ def thanks_message(email, actionPage, options = {}) @name = options[:name].presence || "Friend of Digital Freedom" mail(to: email, subject: "Thanks for taking action") end - # rubocop:enable Naming/MethodParameterName def signup_attempt_with_existing_email(user, _options = {}) @user = user diff --git a/app/models/action_page.rb b/app/models/action_page.rb index f36978546..e4dc3ed10 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -36,13 +36,11 @@ class ActionPage < ActiveRecord::Base belongs_to :congress_message_campaign belongs_to :call_campaign belongs_to :category, optional: true - # rubocop:todo Rails/InverseOf belongs_to :active_action_page_for_redirect, class_name: "ActionPage", foreign_key: "archived_redirect_action_page_id" - # rubocop:enable Rails/InverseOf - # rubocop:todo Rails/InverseOf + belongs_to :author, class_name: "User", foreign_key: :user_id, optional: true - # rubocop:enable Rails/InverseOf + accepts_nested_attributes_for :tweet, :petition, :email_campaign, :call_campaign, :congress_message_campaign, :affiliation_types, :partnerships, @@ -151,13 +149,11 @@ def image [og_image, background_image, featured_image].find(&:present?) end - # rubocop:todo Naming/MemoizedInstanceVariableName def actions_taken_percent return 0 if view_count == 0 @percent ||= (action_count / view_count.to_f) * 100 end - # rubocop:enable Naming/MemoizedInstanceVariableName def status if archived? diff --git a/app/models/congress_message_campaign.rb b/app/models/congress_message_campaign.rb index 00177abad..4d33b5edf 100644 --- a/app/models/congress_message_campaign.rb +++ b/app/models/congress_message_campaign.rb @@ -50,7 +50,7 @@ def member_fills_url CongressForms.member_fills_url(campaign_tag) end - def target_bioguide_list=(x) # rubocop:todo Naming/MethodParameterName + def target_bioguide_list=(x) self.target_bioguide_ids = x.map(&:presence).compact.join(",") end diff --git a/app/models/congress_scorecard.rb b/app/models/congress_scorecard.rb index 71851149a..092f922c8 100644 --- a/app/models/congress_scorecard.rb +++ b/app/models/congress_scorecard.rb @@ -6,8 +6,6 @@ class CongressScorecard < ActiveRecord::Base belongs_to :action_page def increment! - # rubocop:todo Rails/SkipsModelValidations CongressScorecard.increment_counter(:counter, id) # Increments counter atomically - # rubocop:enable Rails/SkipsModelValidations end end diff --git a/app/models/source_file.rb b/app/models/source_file.rb index efac7e463..076fab998 100644 --- a/app/models/source_file.rb +++ b/app/models/source_file.rb @@ -56,7 +56,7 @@ def to_jq_upload } end - def is_image? # rubocop:todo Naming/PredicateName + def is_image? !!file_content_type.try(:match, /image/) end diff --git a/app/models/twitter.rb b/app/models/twitter.rb index 9801034f8..0ea83eaac 100644 --- a/app/models/twitter.rb +++ b/app/models/twitter.rb @@ -1,5 +1,5 @@ class Twitter - def self.has_api_keys? # rubocop:todo Naming/PredicateName + def self.has_api_keys? Rails.application.secrets.twitter_api_key.present? && Rails.application.secrets.twitter_api_secret.present? && Rails.application.secrets.twitter_oauth_token.present? && diff --git a/app/queries/action_page_filters.rb b/app/queries/action_page_filters.rb index 64f362821..d0ba042d3 100644 --- a/app/queries/action_page_filters.rb +++ b/app/queries/action_page_filters.rb @@ -46,12 +46,12 @@ def parse_date_range filters[:date_range].split(" - ").map { |d| Time.zone.parse(d) } end - def valid_query?(f, val) # rubocop:todo Naming/MethodParameterName + def valid_query?(f, val) validate_filter_name f !empty_value? val end - def validate_filter_name(f) # rubocop:todo Naming/MethodParameterName + def validate_filter_name(f) raise ArgumentError, "unrecognized filter #{f}" unless VALID_FILTERS.include? f end end diff --git a/app/views/action_page/index.atom.builder b/app/views/action_page/index.atom.builder index bb5377c9f..20788a34a 100644 --- a/app/views/action_page/index.atom.builder +++ b/app/views/action_page/index.atom.builder @@ -3,7 +3,7 @@ atom_feed do |feed| feed.subtitle(t(:summary)) feed.updated(@actionPages[0].created_at) unless @actionPages.empty? - @actionPages.each do |actionPage| # rubocop:todo Naming/BlockParameterName + @actionPages.each do |actionPage| feed.entry(actionPage) do |entry| entry.link(rel: "enclosure", type: actionPage.featured_image.content_type || "image/png", href: URI.join(root_url, image_path(actionPage.featured_image))) diff --git a/app/views/action_page/index.json.jbuilder b/app/views/action_page/index.json.jbuilder index 892d699b7..761f1f25b 100644 --- a/app/views/action_page/index.json.jbuilder +++ b/app/views/action_page/index.json.jbuilder @@ -1,4 +1,3 @@ -# rubocop:todo Naming/BlockParameterName json.array! @actionPages do |actionPage| json.url action_page_url actionPage json.title actionPage.title @@ -10,4 +9,3 @@ json.array! @actionPages do |actionPage| end end end -# rubocop:enable Naming/BlockParameterName diff --git a/lib/congress_forms.rb b/lib/congress_forms.rb index d2d62b74f..9a6b549cd 100644 --- a/lib/congress_forms.rb +++ b/lib/congress_forms.rb @@ -55,7 +55,7 @@ def label I18n.t value, scope: :congress_forms, default: value.sub("$", "").humanize end - def is_select? # rubocop:todo Naming/PredicateName + def is_select? options_hash != nil end diff --git a/lib/related_content.rb b/lib/related_content.rb index 28fb671f6..6e3fc3066 100644 --- a/lib/related_content.rb +++ b/lib/related_content.rb @@ -37,9 +37,7 @@ def image attr_reader :url, :page, :loaded_successfully - # rubocop:todo Naming/MemoizedInstanceVariableName def open_page @page ||= Nokogiri::HTML(open(url)) end - # rubocop:enable Naming/MemoizedInstanceVariableName end diff --git a/lib/tasks/ahoy.rake b/lib/tasks/ahoy.rake index f63df1997..dad99d536 100644 --- a/lib/tasks/ahoy.rake +++ b/lib/tasks/ahoy.rake @@ -1,9 +1,7 @@ namespace :ahoy do desc "Fix name for view events" task fix_views: :environment do - # rubocop:todo Rails/SkipsModelValidations Ahoy::Event.where("properties ->> 'actionType' = 'view'").update_all(name: "View") - # rubocop:enable Rails/SkipsModelValidations end task fix_action_page_ids: :environment do diff --git a/lib/tasks/congress.rake b/lib/tasks/congress.rake index fb942835a..9b26a577f 100644 --- a/lib/tasks/congress.rake +++ b/lib/tasks/congress.rake @@ -43,11 +43,9 @@ namespace :congress do twitter_id = info["social"]["twitter"] next unless twitter_id - # rubocop:todo Rails/SkipsModelValidations CongressMember .where(bioguide_id: info["id"]["bioguide"]) .update_all(twitter_id: twitter_id) - # rubocop:enable Rails/SkipsModelValidations end end end diff --git a/spec/requests/congress_messages_spec.rb b/spec/requests/congress_messages_spec.rb index cc1eed4ad..999912027 100644 --- a/spec/requests/congress_messages_spec.rb +++ b/spec/requests/congress_messages_spec.rb @@ -40,7 +40,7 @@ def stub_congress_forms_find_with_one_rep end describe "#new" do - def get_congress_message_form # rubocop:todo Naming/AccessorMethodName + def get_congress_message_form campaign_id = action_page.congress_message_campaign_id get("/congress_message_campaigns/#{campaign_id}/congress_messages/new", params: { street_address: location.street, @@ -74,9 +74,7 @@ def get_congress_message_form # rubocop:todo Naming/AccessorMethodName it "to target bioguide_ids" do campaign = FactoryBot.create(:congress_message_campaign, :targeting_bioguide_ids) - # rubocop:todo Rails/SkipsModelValidations action_page.update_attribute(:congress_message_campaign, campaign) - # rubocop:enable Rails/SkipsModelValidations get_congress_message_form expect(response.body).to include("C000880") expect(response.body).not_to include("A000360") @@ -85,9 +83,7 @@ def get_congress_message_form # rubocop:todo Naming/AccessorMethodName it "to target a single chamber" do members.last.update(chamber: "house", district: 10) campaign = FactoryBot.create(:congress_message_campaign, :targeting_senate) - # rubocop:todo Rails/SkipsModelValidations action_page.update_attribute(:congress_message_campaign, campaign) - # rubocop:enable Rails/SkipsModelValidations get_congress_message_form expect(response.body).to include("C000880") expect(response.body).not_to include("A000360") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 57a06c102..b1d9cc540 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -58,14 +58,14 @@ def login_as_collaborator sign_in FactoryBot.create(:collaborator_user) end -def set_weak_password(user) # rubocop:todo Naming/AccessorMethodName +def set_weak_password(user) weak_password = "12345678" user.password = weak_password user.password_confirmation = weak_password user.save end -def set_strong_password(user) # rubocop:todo Naming/AccessorMethodName +def set_strong_password(user) weak_password = "strong passwords defeat lobsters covering wealth" user.password = weak_password user.password_confirmation = weak_password diff --git a/spec/tasks/signatures_spec.rb b/spec/tasks/signatures_spec.rb index 4c76c2cbe..ae8c56948 100644 --- a/spec/tasks/signatures_spec.rb +++ b/spec/tasks/signatures_spec.rb @@ -14,12 +14,8 @@ regular_petition = FactoryBot.create(:petition_complete_with_one_hundred_signatures) petition_with_dups = FactoryBot.create(:petition_complete_with_one_hundred_signatures) - # rubocop:todo Rails/SkipsModelValidations petition_with_dups.signatures.take(20).each { |sig| sig.update_column(:email, "dup1@example.com") } - # rubocop:enable Rails/SkipsModelValidations - # rubocop:todo Rails/SkipsModelValidations petition_with_dups.signatures.take(10).each { |sig| sig.update_column(:email, "dup2@example.com") } - # rubocop:enable Rails/SkipsModelValidations distinct_emails = petition_with_dups.signatures.pluck(:email).uniq From 452571693b52be62bf063f4cd27e85f6f9bc0bcc Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Wed, 10 Apr 2024 10:13:34 -0700 Subject: [PATCH 083/113] Subclass ApplicationRecord per rubocop This is recommended in rails 5+ https://www.rubydoc.info/gems/rubocop-rails/RuboCop/Cop/Rails/ApplicationRecord Delete .rubocop_todo.yml --- .rubocop.yml | 2 - .rubocop_todo.yml | 186 ------------------------ app/models/action_institution.rb | 2 +- app/models/action_page.rb | 2 +- app/models/affiliation.rb | 2 +- app/models/affiliation_type.rb | 2 +- app/models/ahoy/event.rb | 2 +- app/models/application_record.rb | 3 + app/models/bounce.rb | 2 +- app/models/call_campaign.rb | 2 +- app/models/category.rb | 2 +- app/models/complaint.rb | 2 +- app/models/congress_member.rb | 2 +- app/models/congress_message_campaign.rb | 2 +- app/models/congress_scorecard.rb | 2 +- app/models/email_campaign.rb | 2 +- app/models/featured_action_page.rb | 2 +- app/models/institution.rb | 2 +- app/models/partner.rb | 2 +- app/models/partnership.rb | 2 +- app/models/petition.rb | 2 +- app/models/signature.rb | 2 +- app/models/source_file.rb | 2 +- app/models/subscription.rb | 2 +- app/models/topic.rb | 2 +- app/models/topic_category.rb | 2 +- app/models/topic_set.rb | 2 +- app/models/tweet.rb | 2 +- app/models/tweet_target.rb | 2 +- app/models/user.rb | 2 +- app/models/user_preference.rb | 2 +- app/models/visit.rb | 2 +- 32 files changed, 32 insertions(+), 217 deletions(-) delete mode 100644 .rubocop_todo.yml create mode 100644 app/models/application_record.rb diff --git a/.rubocop.yml b/.rubocop.yml index dd2575558..78146cc79 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,6 @@ require: - rubocop-rails - rubocop-performance -inherit_from: .rubocop_todo.yml - inherit_gem: rubocop-github: - config/default.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index ccf6a115e..000000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,186 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 100` -# on 2021-02-11 14:07:46 -0800 using RuboCop version 0.82.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 3 -# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# ForbiddenPrefixes: is_, has_, have_ -# AllowedMethods: is_a? -# MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: - Exclude: - - 'spec/**/*' - -# Offense count: 45 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: snake_case, camelCase -Naming/VariableName: - Exclude: - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/mailer_controller.rb' - - 'app/controllers/admin/petitions_controller.rb' - - 'app/controllers/congress_messages_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/controllers/users_controller.rb' - - 'app/controllers/welcome_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/helpers/devise_helper.rb' - - 'app/mailers/user_mailer.rb' - - 'app/models/markdown_renderer.rb' - - 'app/views/action_page/index.atom.builder' - - 'app/views/action_page/index.json.jbuilder' - - 'spec/controllers/action_page_controller_spec.rb' - - 'spec/controllers/admin/institutions_controller_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Rails/ApplicationController: - Exclude: - - 'app/controllers/exceptions_controller.rb' - - 'spec/controllers/concerns/request_origin_validation_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Rails/ApplicationMailer: - Exclude: - - 'app/mailers/user_mailer.rb' - -# Offense count: 29 -# Cop supports --auto-correct. -Rails/ApplicationRecord: - Exclude: - - 'app/models/action_institution.rb' - - 'app/models/action_page.rb' - - 'app/models/affiliation.rb' - - 'app/models/affiliation_type.rb' - - 'app/models/ahoy/event.rb' - - 'app/models/bounce.rb' - - 'app/models/call_campaign.rb' - - 'app/models/category.rb' - - 'app/models/complaint.rb' - - 'app/models/congress_member.rb' - - 'app/models/congress_message_campaign.rb' - - 'app/models/congress_scorecard.rb' - - 'app/models/email_campaign.rb' - - 'app/models/featured_action_page.rb' - - 'app/models/institution.rb' - - 'app/models/partner.rb' - - 'app/models/partnership.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/source_file.rb' - - 'app/models/subscription.rb' - - 'app/models/topic.rb' - - 'app/models/topic_category.rb' - - 'app/models/topic_set.rb' - - 'app/models/tweet.rb' - - 'app/models/tweet_target.rb' - - 'app/models/user.rb' - - 'app/models/user_preference.rb' - - 'app/models/visit.rb' - -# Offense count: 2 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: slashes, arguments -Rails/FilePath: - Exclude: - - 'lib/tasks/webshims_asset_compile.rake' - -# Offense count: 25 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/HasManyOrHasOneDependent: - Exclude: - - 'app/models/action_page.rb' - - 'app/models/affiliation_type.rb' - - 'app/models/call_campaign.rb' - - 'app/models/congress_message_campaign.rb' - - 'app/models/email_campaign.rb' - - 'app/models/institution.rb' - - 'app/models/partner.rb' - - 'app/models/petition.rb' - - 'app/models/signature.rb' - - 'app/models/topic_category.rb' - - 'app/models/tweet.rb' - - 'app/models/user.rb' - - 'app/models/visit.rb' - -# Offense count: 15 -# Configuration parameters: Include. -# Include: app/helpers/**/*.rb -Rails/HelperInstanceVariable: - Exclude: - - 'app/helpers/action_page_helper.rb' - - 'app/helpers/application_helper.rb' - - 'app/helpers/devise_helper.rb' - - 'app/helpers/petition_helper.rb' - -# Offense count: 6 -# Configuration parameters: Include. -# Include: app/controllers/**/*.rb -Rails/LexicallyScopedActionFilter: - Exclude: - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/admin/partners_controller.rb' - - 'app/controllers/petition_controller.rb' - - 'app/controllers/sessions_controller.rb' - - 'app/controllers/tools_controller.rb' - -# Offense count: 3 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/UniqueValidationWithoutIndex: - Exclude: - - 'app/models/congress_member.rb' - - 'app/models/institution.rb' - - 'app/models/partner.rb' - -# Offense count: 1 -Security/Open: - Exclude: - - 'lib/related_content.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle. -# SupportedStyles: nested, compact -Style/ClassAndModuleChildren: - Exclude: - - 'app/models/ahoy/event.rb' - - 'lib/monkey_patches/octet_stream_override.rb' - -# Offense count: 17 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'app/controllers/action_page_controller.rb' - - 'app/controllers/admin/action_pages_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/concerns/action_page_display.rb' - - 'app/controllers/concerns/request_origin_validation.rb' - - 'app/controllers/congress_messages_controller.rb' - - 'app/controllers/partners_controller.rb' - - 'app/controllers/registrations_controller.rb' - - 'app/controllers/sessions_controller.rb' - - 'app/controllers/tools_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/models/ahoy/event.rb' - - 'lib/call_tool.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Exclude: - - 'spec/**/*' - - 'app/controllers/tools_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/models/action_page.rb' - - 'app/models/petition.rb' diff --git a/app/models/action_institution.rb b/app/models/action_institution.rb index 8609ba92d..cd57fab1f 100644 --- a/app/models/action_institution.rb +++ b/app/models/action_institution.rb @@ -1,4 +1,4 @@ -class ActionInstitution < ActiveRecord::Base +class ActionInstitution < ApplicationRecord belongs_to :institution belongs_to :action_page diff --git a/app/models/action_page.rb b/app/models/action_page.rb index e4dc3ed10..6177e401a 100644 --- a/app/models/action_page.rb +++ b/app/models/action_page.rb @@ -1,4 +1,4 @@ -class ActionPage < ActiveRecord::Base +class ActionPage < ApplicationRecord extend AmazonCredentials extend FriendlyId diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 39a8b3c7f..3034772e2 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -1,4 +1,4 @@ -class Affiliation < ActiveRecord::Base +class Affiliation < ApplicationRecord belongs_to :action_page belongs_to :signature belongs_to :affiliation_type diff --git a/app/models/affiliation_type.rb b/app/models/affiliation_type.rb index 3a83e66b7..9a084ab4a 100644 --- a/app/models/affiliation_type.rb +++ b/app/models/affiliation_type.rb @@ -1,4 +1,4 @@ -class AffiliationType < ActiveRecord::Base +class AffiliationType < ApplicationRecord belongs_to :action_page has_many :affiliations end diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb index b2dde3b46..51e900b4f 100644 --- a/app/models/ahoy/event.rb +++ b/app/models/ahoy/event.rb @@ -1,5 +1,5 @@ module Ahoy - class Event < ActiveRecord::Base + class Event < ApplicationRecord self.table_name = "ahoy_events" belongs_to :visit diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/bounce.rb b/app/models/bounce.rb index a3deb6c0a..c1780fdaa 100644 --- a/app/models/bounce.rb +++ b/app/models/bounce.rb @@ -1,2 +1,2 @@ -class Bounce < ActiveRecord::Base +class Bounce < ApplicationRecord end diff --git a/app/models/call_campaign.rb b/app/models/call_campaign.rb index 37c8f7d9d..dd8c55198 100644 --- a/app/models/call_campaign.rb +++ b/app/models/call_campaign.rb @@ -1,3 +1,3 @@ -class CallCampaign < ActiveRecord::Base +class CallCampaign < ApplicationRecord has_one :action_page end diff --git a/app/models/category.rb b/app/models/category.rb index 20d05d870..aa92bc0c4 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,4 @@ -class Category < ActiveRecord::Base +class Category < ApplicationRecord validates :title, presence: true validates :title, format: { with: /\A[\w\s&]+\Z/ } end diff --git a/app/models/complaint.rb b/app/models/complaint.rb index b0904e938..3b14e25b0 100644 --- a/app/models/complaint.rb +++ b/app/models/complaint.rb @@ -1,2 +1,2 @@ -class Complaint < ActiveRecord::Base +class Complaint < ApplicationRecord end diff --git a/app/models/congress_member.rb b/app/models/congress_member.rb index 48c5c9399..83fc6d3dc 100644 --- a/app/models/congress_member.rb +++ b/app/models/congress_member.rb @@ -1,4 +1,4 @@ -class CongressMember < ActiveRecord::Base +class CongressMember < ApplicationRecord validates :bioguide_id, uniqueness: true scope :current, -> { where("? <= term_end", Time.zone.now) } diff --git a/app/models/congress_message_campaign.rb b/app/models/congress_message_campaign.rb index 4d33b5edf..3e2ee674e 100644 --- a/app/models/congress_message_campaign.rb +++ b/app/models/congress_message_campaign.rb @@ -1,4 +1,4 @@ -class CongressMessageCampaign < ActiveRecord::Base +class CongressMessageCampaign < ApplicationRecord belongs_to :topic_category has_one :action_page diff --git a/app/models/congress_scorecard.rb b/app/models/congress_scorecard.rb index 092f922c8..ecca65aeb 100644 --- a/app/models/congress_scorecard.rb +++ b/app/models/congress_scorecard.rb @@ -2,7 +2,7 @@ # petition action that drew in a signature from one of their constituents # So calling #counter on a model will display the number of signatures from # that member's constituents -class CongressScorecard < ActiveRecord::Base +class CongressScorecard < ApplicationRecord belongs_to :action_page def increment! diff --git a/app/models/email_campaign.rb b/app/models/email_campaign.rb index c62a1d6f5..fceb74b87 100644 --- a/app/models/email_campaign.rb +++ b/app/models/email_campaign.rb @@ -1,4 +1,4 @@ -class EmailCampaign < ActiveRecord::Base +class EmailCampaign < ApplicationRecord belongs_to :topic_category has_one :action_page diff --git a/app/models/featured_action_page.rb b/app/models/featured_action_page.rb index bdbe57360..60deafad2 100644 --- a/app/models/featured_action_page.rb +++ b/app/models/featured_action_page.rb @@ -1,4 +1,4 @@ -class FeaturedActionPage < ActiveRecord::Base +class FeaturedActionPage < ApplicationRecord belongs_to :action_page validates :action_page, :weight, presence: true diff --git a/app/models/institution.rb b/app/models/institution.rb index 39ef502bf..e5b0ed75b 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -1,4 +1,4 @@ -class Institution < ActiveRecord::Base +class Institution < ApplicationRecord require "csv" extend FriendlyId diff --git a/app/models/partner.rb b/app/models/partner.rb index b198042d9..170b0dadf 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -1,4 +1,4 @@ -class Partner < ActiveRecord::Base +class Partner < ApplicationRecord extend AmazonCredentials acts_as_paranoid has_many :subscriptions diff --git a/app/models/partnership.rb b/app/models/partnership.rb index 7f832d22b..0576af137 100644 --- a/app/models/partnership.rb +++ b/app/models/partnership.rb @@ -1,4 +1,4 @@ -class Partnership < ActiveRecord::Base +class Partnership < ApplicationRecord belongs_to :partner belongs_to :action_page end diff --git a/app/models/petition.rb b/app/models/petition.rb index e7f5dd393..6869f85fe 100644 --- a/app/models/petition.rb +++ b/app/models/petition.rb @@ -1,4 +1,4 @@ -class Petition < ActiveRecord::Base +class Petition < ApplicationRecord has_one :action_page has_many :signatures after_initialize :set_goal diff --git a/app/models/signature.rb b/app/models/signature.rb index d708b7ea4..280de879a 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -1,4 +1,4 @@ -class Signature < ActiveRecord::Base +class Signature < ApplicationRecord include GoingPostal belongs_to :user, optional: true diff --git a/app/models/source_file.rb b/app/models/source_file.rb index 076fab998..3bc2eed72 100644 --- a/app/models/source_file.rb +++ b/app/models/source_file.rb @@ -1,4 +1,4 @@ -class SourceFile < ActiveRecord::Base +class SourceFile < ApplicationRecord include Rails.application.routes.url_helpers validates :file_name, :file_content_type, :file_size, :key, :bucket, presence: true diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 81cf3cbf4..36322681b 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,4 +1,4 @@ -class Subscription < ActiveRecord::Base +class Subscription < ApplicationRecord belongs_to :partner, counter_cache: true validates :email, presence: true, email: true validates :email, uniqueness: { scope: :partner_id } diff --git a/app/models/topic.rb b/app/models/topic.rb index 3e69c04c2..667c86dd5 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,3 +1,3 @@ -class Topic < ActiveRecord::Base +class Topic < ApplicationRecord belongs_to :topic_set end diff --git a/app/models/topic_category.rb b/app/models/topic_category.rb index 2abd4a57c..a7884bf96 100644 --- a/app/models/topic_category.rb +++ b/app/models/topic_category.rb @@ -1,4 +1,4 @@ -class TopicCategory < ActiveRecord::Base +class TopicCategory < ApplicationRecord has_many :topic_sets, dependent: :destroy has_many :email_campaigns has_many :congress_message_campaigns diff --git a/app/models/topic_set.rb b/app/models/topic_set.rb index 916375ee2..ecda608f8 100644 --- a/app/models/topic_set.rb +++ b/app/models/topic_set.rb @@ -1,4 +1,4 @@ -class TopicSet < ActiveRecord::Base +class TopicSet < ApplicationRecord belongs_to :topic_category has_many :topics, dependent: :destroy end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 1034e100b..f94782e25 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -1,4 +1,4 @@ -class Tweet < ActiveRecord::Base +class Tweet < ApplicationRecord has_one :action_page has_many :tweet_targets alias :targets :tweet_targets diff --git a/app/models/tweet_target.rb b/app/models/tweet_target.rb index 260c74bf1..a3cc8079a 100644 --- a/app/models/tweet_target.rb +++ b/app/models/tweet_target.rb @@ -1,4 +1,4 @@ -class TweetTarget < ActiveRecord::Base +class TweetTarget < ApplicationRecord extend AmazonCredentials require "open-uri" diff --git a/app/models/user.rb b/app/models/user.rb index 3d122615b..23524c336 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ require "civicrm" -class User < ActiveRecord::Base +class User < ApplicationRecord include CiviCRM::UserMethods include PgSearch::Model diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 2bf83b6da..200d8ccf9 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,4 +1,4 @@ -class UserPreference < ActiveRecord::Base +class UserPreference < ApplicationRecord belongs_to :user validates :name, presence: true validates :value, presence: true diff --git a/app/models/visit.rb b/app/models/visit.rb index 6bb47fed0..9bcf891d7 100644 --- a/app/models/visit.rb +++ b/app/models/visit.rb @@ -1,4 +1,4 @@ -class Visit < ActiveRecord::Base +class Visit < ApplicationRecord has_many :ahoy_events, class_name: "Ahoy::Event" belongs_to :user end From ea38d35db6cd851ad24e67523b201e742a6a744a Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Wed, 10 Apr 2024 12:36:38 -0700 Subject: [PATCH 084/113] Enable NewCops and fix --- .rubocop.yml | 3 ++- app/controllers/admin/action_pages_controller.rb | 2 +- app/controllers/admin/institutions_controller.rb | 2 +- app/controllers/admin/topic_sets_controller.rb | 2 +- app/helpers/action_page_helper.rb | 6 +++--- app/models/institution.rb | 2 +- app/models/signature.rb | 6 +++--- app/models/tweet_target.rb | 2 +- config.ru | 2 +- lib/call_tool.rb | 6 +----- lib/places.rb | 2 ++ spec/requests/admin/events_spec.rb | 4 ++-- spec/requests/sns_spec.rb | 2 +- 13 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 78146cc79..77493af09 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,8 @@ inherit_gem: AllCops: TargetRailsVersion: 6.1 TargetRubyVersion: 3.0 - NewCops: disable + NewCops: enable + SuggestExtensions: false Exclude: - 'db/**/*' - 'config/**/*' diff --git a/app/controllers/admin/action_pages_controller.rb b/app/controllers/admin/action_pages_controller.rb index 8e3304000..296a5678b 100644 --- a/app/controllers/admin/action_pages_controller.rb +++ b/app/controllers/admin/action_pages_controller.rb @@ -23,7 +23,7 @@ class Admin::ActionPagesController < Admin::ApplicationController allow_collaborators_to :index, :edit def index - @categories = Category.all.order(:title) + @categories = Category.order(:title) @authors = User.authors.order(:last_name) @actionPages = filter_action_pages diff --git a/app/controllers/admin/institutions_controller.rb b/app/controllers/admin/institutions_controller.rb index 924f8a656..ca2783305 100644 --- a/app/controllers/admin/institutions_controller.rb +++ b/app/controllers/admin/institutions_controller.rb @@ -3,7 +3,7 @@ class Admin::InstitutionsController < Admin::ApplicationController before_action :set_categories, only: %i[new edit upload index] def index - @institutions = Institution.includes(:action_pages).all.order(created_at: :desc) + @institutions = Institution.includes(:action_pages).order(created_at: :desc) @institutions = @institutions.search(params[:q]) if params[:q].present? @institutions = @institutions.where(category: params[:category]) if params[:category].present? && params[:category] != "All" @institutions = @institutions.paginate(page: params[:page], per_page: 20) diff --git a/app/controllers/admin/topic_sets_controller.rb b/app/controllers/admin/topic_sets_controller.rb index 582c8dc06..7dab61a0b 100644 --- a/app/controllers/admin/topic_sets_controller.rb +++ b/app/controllers/admin/topic_sets_controller.rb @@ -1,6 +1,6 @@ class Admin::TopicSetsController < Admin::ApplicationController def index - topic_sets = TopicSet.all.order(:tier) + topic_sets = TopicSet.order(:tier) render json: topic_sets end diff --git a/app/helpers/action_page_helper.rb b/app/helpers/action_page_helper.rb index aba5e4848..2f322a71d 100644 --- a/app/helpers/action_page_helper.rb +++ b/app/helpers/action_page_helper.rb @@ -66,9 +66,9 @@ def parse_email_text(options = {}) name = html_escape(options[:name]) email_text - .gsub(/\$TITLE/, title) - .gsub(/\$URL/, url) - .gsub(/\$NAME/, name) + .gsub("$TITLE", title) + .gsub("$URL", url) + .gsub("$NAME", name) end def visible_partners diff --git a/app/models/institution.rb b/app/models/institution.rb index e5b0ed75b..ef6a8d1ee 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -40,7 +40,7 @@ def self.import(category, names) end def self.categories - all.distinct.pluck(:category) + distinct.pluck(:category) end def included_in_active_actions? diff --git a/app/models/signature.rb b/app/models/signature.rb index 280de879a..ff7a34449 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -38,7 +38,7 @@ def self.to_csv(options = {}) CSV.generate(options) do |csv| csv << column_names - all.find_each do |sub| + find_each do |sub| csv << sub.attributes.values_at(*column_names) end end @@ -50,7 +50,7 @@ def self.to_presentable_csv(options = {}) CSV.generate(**options) do |csv| csv << column_names - all.find_each do |signature| + find_each do |signature| csv << signature.to_csv_line end end @@ -62,7 +62,7 @@ def self.to_affiliation_csv(options = {}) CSV.generate(options) do |csv| csv << column_names - all.find_each do |s| + find_each do |s| affiliation = s.affiliations.first or next csv << [ diff --git a/app/models/tweet_target.rb b/app/models/tweet_target.rb index a3cc8079a..7af6dce98 100644 --- a/app/models/tweet_target.rb +++ b/app/models/tweet_target.rb @@ -24,7 +24,7 @@ def attach_twitter_image_without_delay # ref: https://dev.twitter.com/overview/general/user-profile-images-and-banners response = access_token.request(:get, "https://api.twitter.com/1.1/users/show.json?screen_name=#{twitter_id}") user_info = JSON.parse response.body - user_image_url = user_info["profile_image_url_https"].gsub(/_normal\./, "_bigger.") + user_image_url = user_info["profile_image_url_https"].gsub("_normal.", "_bigger.") self.image = URI.parse(user_image_url) save diff --git a/config.ru b/config.ru index 846e1c70a..b3b26408d 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path("config/environment", __dir__) +require File.expand_path("config/environment", __dir__) run Rails.application diff --git a/lib/call_tool.rb b/lib/call_tool.rb index 685b446f0..0714715ec 100644 --- a/lib/call_tool.rb +++ b/lib/call_tool.rb @@ -43,11 +43,7 @@ def self.enabled? def self.get(action, params = {}) RestClient.get endpoint(action), params: params rescue RestClient::BadRequest => e - begin - error = JSON.parse(e.http_body)["error"] - rescue StandardError - raise - end + error = JSON.parse(e.http_body)["error"] # Don't raise for twilio error 13224: number invalid unless error.match?(/^13224:/) diff --git a/lib/places.rb b/lib/places.rb index 85cf4b8e7..d29c96107 100644 --- a/lib/places.rb +++ b/lib/places.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/CollectionLiteralLength module Places def self.us_state_codes { "Alabama" => "AL", @@ -325,3 +326,4 @@ def self.country_codes ].freeze end end +# rubocop:enable Metrics/CollectionLiteralLength diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb index ff350215d..5a3a352d3 100644 --- a/spec/requests/admin/events_spec.rb +++ b/spec/requests/admin/events_spec.rb @@ -19,7 +19,7 @@ expect(response.code).to eq "200" # Default is to return data for the previous month. - expect(JSON.parse(response.body).keys) + expect(response.parsed_body.keys) .to include(*(1..31).map { |i| format("Dec %d 2018", i) }) end @@ -32,7 +32,7 @@ headers: { "ACCEPT" => "application/json" } # Returns one datapoint per day in range. - expect(JSON.parse(response.body).keys) + expect(response.parsed_body.keys) .to eq([ "Jan 1 2019", "Jan 2 2019", diff --git a/spec/requests/sns_spec.rb b/spec/requests/sns_spec.rb index 2195fbb77..e033ac71a 100644 --- a/spec/requests/sns_spec.rb +++ b/spec/requests/sns_spec.rb @@ -11,7 +11,7 @@ body = File.read("./spec/fixtures/files/sns_complaint.json") post "/complaint/#{Rails.application.secrets.amazon_authorize_key}", params: body, headers: headers - expect(JSON.parse(response.body)["success"]).to be true + expect(response.parsed_body["success"]).to be true expect(Complaint.count).to eq 1 end end From c85608357ddb075041380e0fb56675923be23fd8 Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Thu, 11 Apr 2024 11:19:02 -0700 Subject: [PATCH 085/113] upgrade rspec-rails --- Gemfile | 2 +- Gemfile.lock | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 3e67eba33..1549c9190 100644 --- a/Gemfile +++ b/Gemfile @@ -114,7 +114,7 @@ group :development, :test do gem "database_cleaner", "~> 1" gem "factory_bot_rails", "~> 6.2" gem "rails-controller-testing" - gem "rspec-rails", "~> 4.0" + gem "rspec-rails", "~> 6.1" gem "rubocop" gem "rubocop-github", "~> 0.16" gem "rubocop-performance", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 651589b45..4de5d5578 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -182,7 +182,7 @@ GEM railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.0) + diff-lcs (1.5.1) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dotenv (2.8.1) @@ -371,23 +371,23 @@ GEM netrc (~> 0.8) rexml (3.2.6) rouge (4.1.3) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (4.1.2) - actionpack (>= 4.2) - activesupport (>= 4.2) - railties (>= 4.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.12.1) + rspec-support (~> 3.13.0) + rspec-rails (6.1.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) rubocop (1.56.4) base64 (~> 0.1.1) json (~> 2.3) @@ -556,7 +556,7 @@ DEPENDENCIES react-rails (~> 1) redcarpet (~> 3) rest-client (~> 2) - rspec-rails (~> 4.0) + rspec-rails (~> 6.1) rubocop rubocop-github (~> 0.16) rubocop-performance From 35141271d37cd78578e688fe909b841a9942155d Mon Sep 17 00:00:00 2001 From: Syd Young Date: Mon, 6 May 2024 21:35:07 -0700 Subject: [PATCH 086/113] Email action small refactors while debugging --- .../application/tools/email.js.erb | 1 + app/controllers/tools_controller.rb | 3 +- app/views/tools/_email.html.erb | 64 ++----------------- app/views/tools/_lookup_state_rep.html.erb | 43 +++++++++++++ spec/factories/email_campaigns.rb | 2 +- 5 files changed, 52 insertions(+), 61 deletions(-) create mode 100644 app/views/tools/_lookup_state_rep.html.erb diff --git a/app/assets/javascripts/application/tools/email.js.erb b/app/assets/javascripts/application/tools/email.js.erb index d5dcdec9c..9a240425a 100644 --- a/app/assets/javascripts/application/tools/email.js.erb +++ b/app/assets/javascripts/application/tools/email.js.erb @@ -8,6 +8,7 @@ $(document).on('ready', function() { dnt = true; }, 0); }); + $('#target-email button').on('click', function() { $('.thank-you').show(); $('#email-tool').hide(); diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb index 32d1b4f0c..eab006174 100644 --- a/app/controllers/tools_controller.rb +++ b/app/controllers/tools_controller.rb @@ -106,7 +106,7 @@ def tweet end def email - unless (@user && @user.events.emails.find_by(action_page_id: params[:action_id])) || (params[:dnt] == "true") + unless @user&.taken_action?(@action_page) || params[:dnt] == "true" ahoy.track "Action", { type: "action", actionType: "email", actionPageId: params[:action_id] }, action_page: @action_page @@ -129,6 +129,7 @@ def email def state_reps @email_campaign = EmailCampaign.find(params[:email_campaign_id]) @actionPage = @email_campaign.action_page + # TODO: strong params this address = "#{params[:street_address]} #{params[:zipcode]}" civic_api_response = CivicApi.state_rep_search(address, @email_campaign.leg_level) @state_reps = JSON.parse(civic_api_response.body)["officials"] diff --git a/app/views/tools/_email.html.erb b/app/views/tools/_email.html.erb index b38071c69..8db628e27 100644 --- a/app/views/tools/_email.html.erb +++ b/app/views/tools/_email.html.erb @@ -16,67 +16,13 @@ + <%= render 'tools/lookup_state_rep' %> + <% else %> + <%= render 'tools/send_email' %> + <% end %>
+