ruby-doc.org

...read and write access by methods like File.open and File.read. def exclusively_locked_access begin @file_locked = true File.open(F"#{file_path}.lock"), 'w+') do |f| f.flock(File::LOCK_EX...

...that block make sure to do that manually and preferably wrap it it with begin and rescue if something might go wrong: begin f = File.open(file, File::CREAT) f.flock(File...

While verifying doubles in RSpec is a good default, it is limited in the amount of methods it actually is...

DirectUpload allows you to upload files to your file storage without having to wait for the form to submit. It...

Debugging your integration tests, that run a headless Chrome inside a docker image, is tricky. In many cases you can...

...code comments come into play: Use code comments to document Hows and Whys Group belonging lines with empty lines ("code paragraphs") New code is usually bright and clear to the...

index 0000000..a51cbad --- /dev/null +++ b/app/models/apple.rb @@ -0,0 +1,9 @@ +class Apple < Fruit + belongs_to :juice, class_name: 'AppleJuice' + + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.apples...

index 0000000..a51cbad --- /dev/null +++ b/app/models/pear.rb @@ -0,0 +1,9 @@ +class Pear < Fruit + belongs_to :juice, class_name: 'PearJuice' + + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.pears...

If your app does not need to support IE11, you can use most ES6 features without a build step. Just...

Event listeners are called in the order of their registration: button.addEventListener('click', () => console.log("I run first")) button.addEventListener('click', () => console.log("I...

...move the directory to its new location old_store_path = Pathname.new(old_store_dir) begin FileUtils.rmdir(old_store_path.parent) # cleanup empty directories afterwards rescue Errno::ENOTEMPTY => e # ignore exception for non-empty...

makandra dev

All browsers implement an event named beforeunload. It is fired when the active window is closed and can be used to display an alert to warn the user about unsaved...

...To trigger the alert, you have to call preventDefault() on the event. Note The beforeunload event is only dispatched when the user navigation makes a full page load, or if...

github.com

When handling nested hashes the RSpec output is often hard to read. Here the gem super_diff could help.

Sometimes we write plain SQL queries in migrations so we don't have to mock ActiveRecord classes. These two migrations...

makandra dev

If you want Sidekiq to be able to talk to Redis on staging and production servers, you need to add...

When you have two models in a has_many, has_one or belongs_to association, the :inverse_of option in Rails tells ActiveRecord that they're two sides of the...

...same association. Example with a has_many / belongs_to association: class Forum < ActiveRecord::Base has_many :posts, inverse_of: :forum end class Post < ActiveRecord::Base belongs_to :forum, inverse_of...

makandra dev

...installation supports YJIT, by running: $ ruby --yjit -v ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [x86_64-linux] If YJIT is not available, the output of this command will...

When you repeat complex assertions in your tests multiple times, it might be a good idea to extract a custom...

blog.saeloun.com

Rails' fragment caching caches subtrees of an HTML document tree. While constructing that tree though, it can be really hard...

The nokogiri gem provides different packages for several platforms. Each platform-specific variant ships pre-built binaries of libxml2, e.g...

...time of queries. While they serve similar purposes they do have some differences in behavior and implementation. PostgreSQL Timeout Type: statement_timeout Scope: Applies to all types of SQL statements...

...INSERT, UPDATE, DELETE). Units: Can be specified in various time units (milliseconds, seconds, minutes). Behavior: If any statement exceeds the specified timeout, PostgreSQL raises an error indicating the statement was...

When you find similar groups of expect calls in your tests, you can improve readability by extracting the group into...

makandra dev
tpgi.com

These are the top ten accessibility errors as researched by TPGi, a company focusing on accessibility. See the linked article...

When using Chrome for Selenium tests, the chromedriver binary will be used to control Chrome. To debug problems that stem...

makandra dev
github.com

...large number of ActiveRecord objects only to collect its ID. Edge Rider has a better way. Your relations gain a method #collect_ids that will fetch all IDs in a...

...number of ActiveRecord objects only to collect its column value. Edge Rider has a better way. Your relations gain a method #collect_column that will fetch all column values in...

When you don't only have a favicon.ico in your project but also PNGs of different sizes and backgrounds, you...