Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
$ bundle exec ruby spec.rb 1 ↵
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using bundler 1.17.3
Using diff-lcs 1.3
Using rspec-support 3.8.0
Using rspec-core 3.8.0
Using rspec-expectations 3.8.2
Using rspec-mocks 3.8.0
# app/controllers/owner/reservations_controller.rb
class Owner::ReservationsController < ApplicationController
def create
# …
end
end
@tbuehlmann
tbuehlmann / a.rb
Created February 10, 2019 11:51
demo
# a.rb
require_relative 'a/b'
module A
end
# 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