Skip to content

Commit

Permalink
Merge pull request #1395 from alphagov/upgrade-to-ruby-2.7
Browse files Browse the repository at this point in the history
Upgrade to ruby 2.7.1
  • Loading branch information
Celia Collins committed Sep 25, 2020
2 parents afa38dd + 298f429 commit d6b26bd
Show file tree
Hide file tree
Showing 31 changed files with 80 additions and 74 deletions.
4 changes: 2 additions & 2 deletions app/builders/bulk_subscriber_list_email_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def initialize(subject:, body:, subscriber_lists:)
@subscriber_lists = subscriber_lists
end

def self.call(*args)
new(*args).call
def self.call(**args)
new(**args).call
end

def call
Expand Down
4 changes: 2 additions & 2 deletions app/builders/digest_email_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def initialize(address:, digest_items:, digest_run:, subscriber_id:)
@subscriber_id = subscriber_id
end

def self.call(*args)
new(*args).call
def self.call(**args)
new(**args).call
end

def call
Expand Down
10 changes: 5 additions & 5 deletions app/builders/message_email_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def records
@records ||= begin
now = Time.zone.now

recipients_and_messages.map do |address:, message:, subscriptions:, subscriber_id:|
recipients_and_messages.map do |x|
{
address: address,
subject: subject(message),
body: body(message, subscriptions, address),
subscriber_id: subscriber_id,
address: x[:address],
subject: subject(x[:message]),
body: body(x[:message], x[:subscriptions], x[:address]),
subscriber_id: x[:subscriber_id],
created_at: now,
updated_at: now,
}
Expand Down
4 changes: 2 additions & 2 deletions app/builders/subscriber_auth_email_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def initialize(subscriber:, destination:, token:)
@token = token
end

def self.call(*args)
new(*args).call
def self.call(**args)
new(**args).call
end

def call
Expand Down
4 changes: 2 additions & 2 deletions app/builders/subscription_auth_email_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def initialize(address:, token:, topic_id:, frequency:)
@frequency = frequency
end

def self.call(*args)
new(*args).call
def self.call(*args, **kwargs)
new(*args, **kwargs).call
end

def call
Expand Down
4 changes: 2 additions & 2 deletions app/builders/subscription_confirmation_email_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ def initialize(subscription:)
@subscription = subscription
end

def self.call(*args)
new(*args).call
def self.call(**args)
new(**args).call
end

def call
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/subscriber_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class SubscriberListsController < ApplicationController
def index
subscriber_list = FindExactQuery.new(find_exact_query_params).exact_match
subscriber_list = FindExactQuery.new(**find_exact_query_params).exact_match
if subscriber_list
render json: subscriber_list.to_json
else
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/content_change_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(content_change, frequency: "immediate")
@frequency = frequency
end

def self.call(*args)
new(*args).call
def self.call(*args, **kwargs)
new(*args, **kwargs).call
end

def call
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/message_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def initialize(message, frequency: "immediate")
@frequency = frequency
end

def self.call(*args)
new(*args).call
def self.call(*args, **kwargs)
new(*args, **kwargs).call
end

def call
Expand Down
2 changes: 1 addition & 1 deletion app/queries/subscriber_lists_by_criteria_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call
attr_reader :initial_scope, :criteria_rules

def rule_condition(scope, rule)
return type_rule(scope, rule) if rule[:type]
return type_rule(scope, **rule) if rule[:type]
return any_of_rule(scope, rule[:any_of]) if rule[:any_of]
return all_of_rule(scope, rule[:all_of]) if rule[:all_of]

Expand Down
4 changes: 2 additions & 2 deletions app/services/application_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApplicationService
def self.call(*args)
new(*args).call
def self.call(*args, **kwargs)
new(*args, **kwargs).call
end

private_class_method :new
Expand Down
6 changes: 5 additions & 1 deletion app/services/auth_token_generator_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ def initialize(data, expiry: 1.week)
@expiry = expiry
end

def self.call(*args)
new(*args).call
end

def call
len = ActiveSupport::MessageEncryptor.key_len(CIPHER)
key = ActiveSupport::KeyGenerator.new(secret).generate_key("", len)
crypt = ActiveSupport::MessageEncryptor.new(key, OPTIONS)
crypt = ActiveSupport::MessageEncryptor.new(key, **OPTIONS)
token = crypt.encrypt_and_sign(data, expires_in: expiry)
CGI.escape(token)
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/delivery_request_service/delay_provider.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class DeliveryRequestService::DelayProvider
def self.call(*args)
new.call(*args)
def self.call(**args)
new.call(**args)
end

def call(**_args)
Expand Down
4 changes: 2 additions & 2 deletions app/services/delivery_request_service/notify_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def initialize
@template_id = EmailAlertAPI.config.notify.fetch(:template_id)
end

def self.call(*args)
new.call(*args)
def self.call(**args)
new.call(**args)
end

def call(address:, subject:, body:, reference:)
Expand Down
4 changes: 2 additions & 2 deletions app/services/delivery_request_service/pseudo_provider.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class DeliveryRequestService::PseudoProvider
LOG_PATH = Rails.root.join("log/pseudo_email.log").freeze

def self.call(*args)
new.call(*args)
def self.call(**args)
new.call(**args)
end

def call(address:, subject:, body:, reference:)
Expand Down
2 changes: 1 addition & 1 deletion app/services/immediate_email_generation_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ImmediateEmailGenerationService < ApplicationService
BATCH_SIZE = 5000

def initialize(content)
def initialize(content, **)
@content = content
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/matched_content_change_generation_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MatchedContentChangeGenerationService < ApplicationService
def initialize(content_change)
def initialize(content_change, **)
@content_change = content_change
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/matched_message_generation_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MatchedMessageGenerationService < ApplicationService
def initialize(message)
def initialize(message, **)
@message = message
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/s3_email_archive_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class S3EmailArchiveService < ApplicationService

# For batch we expect an array of hashes containing email data in the format
# from EmailArchivePresenter
def initialize(batch)
def initialize(batch, **)
@batch = batch
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/unpublish_handler_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UnpublishHandlerService < ApplicationService

attr_reader :content_id, :redirect

def initialize(content_id, redirect)
def initialize(content_id, redirect, **)
@content_id = content_id
@redirect = redirect
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/unsubscribe_all_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UnsubscribeAllService < ApplicationService
attr_reader :subscriber, :reason

def initialize(subscriber, reason)
def initialize(subscriber, reason, **)
@subscriber = subscriber
@reason = reason
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/unsubscribe_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UnsubscribeService < ApplicationService
attr_reader :subscriber, :subscriptions, :reason

def initialize(subscriber, subscriptions, reason)
def initialize(subscriber, subscriptions, reason, **)
@subscriber = subscriber
@subscriptions = subscriptions
@reason = reason
Expand Down
2 changes: 1 addition & 1 deletion lib/reports/brexit_subscribers_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.call(*args)
def call
subscriber_lists =
date.empty? ? brexit_lists : brexit_lists_before_date
CSV($stdout, headers: CSV_HEADERS, write_headers: true) do |csv|
CSV.instance($stdout, headers: CSV_HEADERS, write_headers: true) do |csv|
subscriber_lists.each do |list|
csv << row_data(list)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/reports/living_in_europe_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def present_subscriber_list(subscriber_list, at:)
end

def export_csv(subscriber_lists, at: nil)
CSV($stdout, headers: CSV_HEADERS, write_headers: true) do |csv|
CSV.instance($stdout, headers: CSV_HEADERS, write_headers: true) do |csv|
subscriber_lists.find_each do |subscriber_list|
csv << present_subscriber_list(subscriber_list, at: at)
end
end
end

def export_detailed_csv(subscriber_lists, at: nil)
CSV($stdout, headers: %i[title subscribed unsubscribed immediately daily weekly], write_headers: true) do |csv|
CSV.instance($stdout, headers: %i[title subscribed unsubscribed immediately daily weekly], write_headers: true) do |csv|
subscriber_lists.find_each do |subscriber_list|
csv << present_travel_advice_report(subscriber_list, at: at)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/queries/find_exact_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def build_query(params = {})
government_document_supertype: "",
}

described_class.new(defaults.merge(params))
described_class.new(**defaults.merge(params))
end

def create_subscriber_list(params = {})
Expand Down
26 changes: 13 additions & 13 deletions spec/queries/matched_for_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def execute_query(query_hash, field: :tags)
end

it "finds subscriber lists matching all topics" do
lists = execute_query(topics: %w[vat tax])
lists = execute_query({ topics: %w[vat tax] })
expect(lists).to eq([@all_topics_tax_vat])
end
end
Expand All @@ -73,12 +73,12 @@ def execute_query(query_hash, field: :tags)
end

it "finds subscriber lists matching on both of all and one of any topics" do
lists = execute_query(topics: %w[vat tax licensing])
lists = execute_query({ topics: %w[vat tax licensing] })
expect(lists).to eq([@all_topics_tax_vat_any_topics_licensing_paye])
end

it "does not find subscriber list for mixture of all and any topics when not all topics present" do
lists = execute_query(field: :links, query_hash: { topics: %w[vat licensing] })
lists = execute_query({ field: :links, query_hash: { topics: %w[vat licensing] } })
expect(lists).not_to include(@all_topics_tax_vat_any_topics_licensing_paye)
end
end
Expand All @@ -90,12 +90,12 @@ def execute_query(query_hash, field: :tags)
end

it "finds subscriber lists matching a mix of all topics and any policies" do
lists = execute_query(topics: %w[vat tax], policies: %w[economy industry])
lists = execute_query({ topics: %w[vat tax], policies: %w[economy industry] })
expect(lists).to eq([@all_topics_tax_vat_any_policies_economy_industry])
end

it "does not find subscriber list for mix of all topics and any policies when not all topics present" do
lists = execute_query(field: :links, query_hash: { topics: %w[vat], policies: %w[economy] })
lists = execute_query({ field: :links, query_hash: { topics: %w[vat], policies: %w[economy] } })
expect(lists).not_to include(@all_topics_tax_vat_any_policies_economy_industry)
end
end
Expand All @@ -108,17 +108,17 @@ def execute_query(query_hash, field: :tags)
end

it "finds subscriber lists matching a mix of all topics and policies" do
lists = execute_query(topics: %w[vat tax licensing], policies: %w[economy industry])
lists = execute_query({ topics: %w[vat tax licensing], policies: %w[economy industry] })
expect(lists).to include(@all_topics_tax_vat_all_policies_economy_industry)
end

it "does not find subscriber list for all topics when not all topics present" do
lists = execute_query(topics: %w[vat schools])
lists = execute_query({ topics: %w[vat schools] })
expect(lists).not_to include(@all_topics_tax_vat)
end

it "does not find subscriber list for mix of all topics and policies when not all policies present" do
lists = execute_query(topics: %w[vat tax ufos], policies: %w[economy acceptable_footwear])
lists = execute_query({ topics: %w[vat tax ufos], policies: %w[economy acceptable_footwear] })
expect(lists).to_not include(@all_topics_tax_vat_all_policies_economy_schools)
end
end
Expand All @@ -129,7 +129,7 @@ def execute_query(query_hash, field: :tags)
end

it "finds lists where all the link types in the subscription have a value present" do
lists = execute_query(topics: %w[licensing], another_link_thats_not_part_of_the_subscription: %w[elephants])
lists = execute_query({ topics: %w[licensing], another_link_thats_not_part_of_the_subscription: %w[elephants] })
expect(lists).to eq([@topics_any_licensing])
end
end
Expand All @@ -140,12 +140,12 @@ def execute_query(query_hash, field: :tags)
end

it "finds lists where all the link types in the subscription have a value present" do
lists = execute_query(topics: %w[licensing elephants])
lists = execute_query({ topics: %w[licensing elephants] })
expect(lists).to eq([@topics_any_licensing])
end

it "doesn't return lists which have no tag types present in the document" do
lists = execute_query(another_tag_thats_not_part_of_any_subscription: %w[elephants])
lists = execute_query({ another_tag_thats_not_part_of_any_subscription: %w[elephants] })
expect(lists).to eq([])
end
end
Expand All @@ -166,12 +166,12 @@ def execute_query(query_hash, field: :tags)
end

it "finds the list when the criteria values is a string that is present in the subscriber list values for the field" do
lists = execute_query(format: "employment_tribunal_decision")
lists = execute_query({ format: "employment_tribunal_decision" })
expect(lists).to eq([@subscriber_list])
end

it "does not find the list when the criteria values is a string that is not present in the subscriber list values for the field" do
lists = execute_query(format: "drug_safety_update")
lists = execute_query({ format: "drug_safety_update" })
expect(lists).to eq([])
end
end
Expand Down

0 comments on commit d6b26bd

Please sign in to comment.