Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
# lib/sidekiq/middleware/server/retry_jobs_without_exception.rb
module Sidekiq
RetryWithoutException = Class.new(StandardError)
module Middleware
module Server
class RetryJobsWithoutException < RetryJobs
def call(worker, msg, queue)
begin
class SomeModel < ApplicationRecord
after_initialize do
if new_record?
{some_attribute: 'default value'}.each do |attribute, value|
public_send("#{attribute}=", value) unless public_send(attribute)
end
end
end
end
# frozen_string_literal: true
require "action_dispatch/testing/request_encoder"
module ActionDispatch
# Integration test methods such as ActionDispatch::Integration::Session#get
# and ActionDispatch::Integration::Session#post return objects of class
# TestResponse, which represent the HTTP response results of the requested
# controller actions.
#
class BaseAuditsController < ApplicationController
def self.inherited(other)
other.class_eval do
resource_name = controller_path.split('/').first.singularize
define_method("set_#{resource_name}") do
resource = organization.public_send(resource_name.pluralize).find(params["#{resource_name}_id"])
instance_variable_set("@#{resource_name}", resource)
end
Listen.to('app/controllers') do |modified, added, removed|
puts "modified absolute path: #{modified}"
puts "added absolute path: #{added}"
puts "removed absolute path: #{removed}"
end.start
'foo' + 42 # => TypeError: no implicit conversion of Integer into String
class Integer
def to_str
to_s
end
end
'foo' + 42 # => 'foo42'
class A
def self.foo
end
end
class B < A
end
mock_a = MiniTest::Mock.new
mock_b = MiniTest::Mock.new
class Foo < ApplicationRecord
def array
self[:array] ? LimitedArray.new(self[:array]) : self[:array]
end
def array=(value)
self[:array] = value ? LimitedArray.new(value.dup).to_a : value
end
end
json.sessions do
@session_groups.each_value do |sessions|
sessions.each do |session|
json.child! { json.call(session, :id) }
end
end
end
class NotStartingWithRailsConstraint
def matches?(request)
!request.path.starts_with?('/rails')
end
end