Skip to content

Instantly share code, notes, and snippets.

View matsales28's full-sized avatar
🎯
Focusing

Matheus Sales matsales28

🎯
Focusing
View GitHub Profile
@matsales28
matsales28 / dinamic_nested_form.rb
Created April 12, 2023 14:57
This is a gist for creating nested dynamic forms with JS
## This is the helper method used to create the button to add multiple records
def link_to_add_new_record(name, f, association, **html_options)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render(association.to_s.singularize, builder: builder)
end
link_to(name, '#', class: html_options[:class], id: "add-new-record", data: {id: id, fields: fields.gsub("\n", "")})
end
@matsales28
matsales28 / have_rendered_component_matcher.rb
Created November 16, 2022 15:19
Create matcher for asserting components of ViewComponents have been rendered with arguments or not
# This gist was used to create have_rendered_page_component matcher, because our intention was to
# assure that a specific page_component was being rendered.
# This is overriding the instrumentation of ViewComponent
# to include the parameters that a component might receive when rendering.
# frozen_string_literal: true
require "active_support/notifications"
require "active_support/concern"
@matsales28
matsales28 / modules_with_arguments.rb
Last active August 25, 2023 19:46
Ruby modules with arguments
class Callable < Module
def self.[](method)
new(method)
end
def initialize(method)
@method = method
end
def included(base)
# frozen_string_literal: true
require 'simplecov'
require 'simplecov-console'
require 'capybara'
require "minitest/reporters"
require 'webmock/minitest'
class Minitest::Reporters::SpecReporter
def record_print_status(test)
print_colored_status(test)
print(" (%.2fs)" % test.time) unless test.time.nil?
# frozen_string_literal: true
require 'simplecov'
require 'simplecov-console'
require 'capybara'
require "minitest/reporters"
require 'webmock/minitest'
class Minitest::Reporters::SpecReporter
def record_print_status(test)
print_colored_status(test)
print(" (%.2fs)" % test.time) unless test.time.nil?