Delayed::Job.count
Delayed::Job.first.destroy
ACTION_LINK_BASE_URL = URI.parse('https://example.com/service.html') | |
# Action Link URL | |
# | |
# @example Example usage | |
# action_link_url('abc-123-xyz') #=> https://example.com/service.html?id=abc-123-xyz | |
# | |
# @param account_id [String] | |
# @return [String] | |
def action_link_url(account_id) |
routes = Rails.application.routes.routes.map { |r| r.path.spec.to_s } | |
# *OR* for even more attributes | |
Rails.application.routes.routes.map { |r| { alias: r.name, path: r.path.spec.to_s, controller: r.defaults[:controller], action: r.defaults[:action] } } |
# frozen_string_literal: true | |
require "rails_helper" | |
RSpec.describe Notifications, type: :mailer do | |
describe '.google_places_report_ready' do | |
let(:mail) { Notifications.google_places_report_ready } | |
let(:download_path) { '/google_places/download_report' } | |
it 'renders the subject' do |
volumes: | |
postgresql: | |
name: automotiontv-postgresql | |
external: true | |
x-restart_policy: &default_restart_policy | |
deploy: | |
restart_policy: | |
condition: on-failure | |
delay: 5s |
it 'downloads the file' do | |
expect(controller).to receive(:send_file).with(GooglePlacesApiClient::DEFAULT_CSV_FILEPATH, type: 'text/csv').and_call_original | |
get :download_report | |
end | |
# OR | |
it 'does not try to download the file' do | |
expect(controller).not_to receive(:send_file) | |
get :download_report |
# Stubbing a single class constant is a little finicky and can remove all constants of a class if not done right | |
MyClass::MY_CONSTANT_1 #=> 'foo' | |
MyClass::MY_CONSTANT_2 #=> 'bar' | |
# METHOD 1 (PREFERRED) | |
before(:example) do | |
stub_const('MyClass', MyClass) |
# Diff between Logger and ActiveSupport::Logger | |
https://stackoverflow.com/q/64433146/990637 | |
# Problem with Puma / .silence method when using Logger instead of ActiveSupport::Logger | |
https://github.com/rails/sprockets-rails/issues/376#issuecomment-287560399 |
RSpec.describe SomeClass do | |
describe '.some_method_that_writes_to_a_file' do | |
around(:example) do |example| | |
Dir.mktmpdir do |dir| | |
Dir.chdir(dir) do | |
example.run # Write file to a tmp directory that then gets deleted after each example | |
end | |
end | |
end |
require 'ostruct' | |
os = OpenStruct(foo: 1, bar: 2, baz: 3) | |
os.to_h.slice(:foo, :baz) #=> { foo: 1, baz: 3 } | |
os.to_h.values_at(:foo, :baz) #=> [1, 3] |