This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "@hotwired/stimulus"; | |
export default class extends Controller { | |
static targets = ["checkbox"] | |
checkAll() { | |
this.setAllCheckboxes(true); | |
} | |
checkNone() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<div data-controller="clipboard" class="flex flex-row mt-4 p-6"> | |
<input type="text" class="form-input text-black" value="SeCrEtKeY-42!" data-clipboard-target="source" readonly /> | |
<button class="mx-4 flex px-3 py-2 bg-slate-900 font-semibold rounded" data-clipboard-target="button" data-action="clipboard#copy"> | |
Copy | |
</button> | |
</div> | |
<div data-controller="clipboard" class="flex flex-row mt-4 p-6"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-controller="drawing" class="mt-4 p-6"> | |
<h1>Drawing Lines</h1> | |
<button | |
class="my-4 mx-4 px-3 py-2 bg-red-600 font-semibold rounded" | |
data-action="drawing#drawLine" | |
data-drawing-length-param="300" | |
data-drawing-direction-param="horizontal" | |
data-drawing-x-param="100" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry/effects' | |
class CurrentTimeMiddleware | |
include Dry::Effects::Handler.CurrentTime | |
def initialize(app) | |
@app = app | |
end | |
def call(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
include Dry::Effects::Handler.Reader(:current_user) | |
around_action :set_current_user | |
private | |
def set_current_user | |
with_current_user(current_user) { yield } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✓ ruby stack.rb | |
What do you want to do? (add, remove, see, count) | |
see | |
#<Plate:0x0000557c3f0598b0> | |
What do you want to do? (add, remove, see, count) | |
add | |
#<Plate:0x0000557c3f059c20> | |
#<Plate:0x0000557c3f0598b0> | |
#<Plate:0x0000557c3f890ce0> | |
What do you want to do? (add, remove, see, count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProviderMiddleware | |
include Dry::Effects::Handler.Resolve | |
def initialize(app, dependencies) | |
@app = app | |
@dependencies = dependencies | |
end | |
def call(env) | |
provide(@dependencies) { @app.(env) } |