Skip to content

Instantly share code, notes, and snippets.

View krzykamil's full-sized avatar
🤔

Krzysztof Piotrowski krzykamil

🤔
View GitHub Profile
@krzykamil
krzykamil / with_every_combination.rb
Created October 7, 2022 09:37
RSpec DSL for combo testing
module Support
module WithEveryCombination
# Takes an hash of variable names to all possible values, and creates RSpec contexts for
# every possible combination of values
#
# For example:
# with_every_combination(
# assignment: [Assignments::Models::Assignment.new, nil],
# start_date: [Date.current - rand(1..10).months, nil],
# end_date: [Date.current + rand(1..10).months, nil]
@krzykamil
krzykamil / services.rb
Created October 7, 2022 09:24
RSpec DSL for stubbing services
module Support
module Services
class HaveBeenCalledMatcher
include RSpec::Mocks::Matchers::Matcher
NotCalledYet = Class.new(StandardError)
def initialize(&block)
@matcher = RSpec::Mocks::Matchers::HaveReceived.new(:call, &block)
end
@krzykamil
krzykamil / decorations.rb
Created October 7, 2022 09:04
rspec matcher for decorator
# spec/support/matchers/decorations.rb
module Support
module Matchers
module Decorations
extend RSpec::Matchers::DSL
def decorated_object_attributes(model, klass: nil, user: nil, context: nil)
context ||= {}
attrs = { object: model }
@krzykamil
krzykamil / ticket_adapter.rb
Created November 17, 2021 15:39
example adapter
class Dev
attr_accessor :level, :money, :tickets
def initialize
@level = (1..3).to_a.sample
@money = 0
@tickets = []
end
def take_ticket(ticket)
# frozen_string_literal: true
desc "example task"
task :example_task, [:for_real] => [:environment] do |task, args|
ActiveRecord::Base.transaction do
# This is the way, do your thing here
unless args[:for_real] == "for_real"
raise "Discarded all changes. To do a real run invoke this task as follows:
bundle exec rake \"#{task.name}[for_real]\"\n"
end
class BaseService
attr_reader :result, :errors
def self.call(**args)
new(**args).tap(&:call)
end
def success?
errors.blank?
end
end
document.querySelectorAll('[data-tooltip-content^="Łukasz Żarski"]').forEach(gownoWartaWiadomosc => {gownoWartaWiadomosc.parentNode.parentNode.parentNode.style.display = "none";})
INSERT INTO
empty_new_table
SELECT
*
FROM
(WITH old_table_data AS (
SELECT
data1,
data2,
data3
@krzykamil
krzykamil / two_withs.sql
Created February 13, 2019 12:47
With double
WITH my_first_with AS (SELECT foo, c FROM bar) , my_second_with AS ( SELECT foo, c FROM my_first_with)
SELECT * FROM my_second_with
@krzykamil
krzykamil / with.sql
Created February 13, 2019 12:41
SQL WITH syntax
WITH my_subquery AS (SELECT * FROM table_name WHERE column_name_1 = value_1)
SELECT column_name_2 FROM my_subquery
WHERE coulumn_date > '2018-12-08'