Our preferred way of testing ActiveRecord is to simply create/update/destroy the record and then check if the expected behavior has happened. We used to bend over backwards to avoid touching...
...the database for this. For this we used a lot of stubbing and tricks like it_should_run_callbacks. Today we would rather make a few database queries than have...
...is defined incorrectly. Raise the attributes hash given to your :reject_if lambda to see if it looks like you expect. If you are nesting forms into nested forms, each...
...a new parent record together with a new child record and will need to save the parent before you can save the child. You can opt to only show the...
...you have too many inotify instances you may run into limits of your operating system. To find out which process is using them all up you can run:
...the cogwheel icon (or press F1 when focusing the dev tools) to open the settings overlay. Under "Preferences", in the "Appearance" section, find the "Panel layout" option. Set it to...
Alternatively, press Ctrl+Shift+P and search for "panel layout". Wat? Vertical means that the DOM tree is next to the styles/etc panel, like so:
...For ages, CSS transforms had to be defined using the transform property. For a single transformation, this was something like transform: scale(1.5), and multiple transformations could be applied by...
.example { transform: scale(1.5) rotate(45deg) translateY(-50%); } All modern browsers (Chrome & Edge 104+, Firefox 72+, Safari 14.1+, Samsung Internet 20+) also support individual properties for transforms.
...to lock a user in devise. Using the lockable module Customizing the user account status validation when logging in. It depends on your requirements which methods works best.
...user on soft delete We recommend to use option 2 when you want to couple the lock to the model's soft delete logic. Option 1 might also work when...
Or: How to avoid and refactor spaghetti code Please note that I tried to keep the examples small. The effects of the methods in this card are of course much...
...more significant with real / more complex code. What are the benefits of more modular code? Code is written once but read often (by your future self and other developers who...
ImageMagick can convert SVGs to raster image formats. Example for PNG: convert input.svg output.png If the SVG has a size of 24x24 (viewBox="0 0 24 24"), the resulting...
...PNG will also have a size of 24x24. Resizing An SVG's viewBox specifies the intended size, but vector image formats can be scaled freely. Resize flag (poor results)
If you already selected an element and want to get its parent, you can call find(:xpath, '..') on it. To get the grand-parent element, call find(:xpath, '../..'). Example
...href]).to eq("http://twitter.com/") About XPath There is a good overview on XPath syntax on w3schools. But as XPath expressions can get quite complex and hard to understand for...
...agent manually. Example: # exec resource: exec { "update_rubygems_${user}_${version}": command => "${home}/.rbenv/shims/gem update --system ${version}", unless => "${home}/.rbenv/shims/gem -v | /bin/grep ${version}", } This does execute rbenv commands. If puppet runs...
When doing some meta-programming magic and you want to do something for all attributes of a class, you may need to access connection or some of its methods (e.g...
...will encounter fun errors such as: PG::ConnectionBad (for missing databases on PostgreSQL) ActiveRecord::StatementInvalid: PG::UndefinedTable (when database exists, but has no tables) Generally speaking, evaluating model columns during...
...your lambda function via terraform, this code is usually zipped and uploaded to Amazon S3 by terraform. The ZIP file's hash is then stored to terraform's state. However...
...you're collaborating with colleages e.g. via git, each run of terraform will possibly see a different hash of the code's ZIP archive and try to replace the lambda...
...come across objects created by some gem or framework. You don't have the source code at hand, still need to inspect this object. Here are some tools to do...
...from Object. This makes the methods list drastically more relevant. You can also try subtracting other base classes like ActiveRecord::Base.methods etc. To further narrow it down you can also...
...an event handler, there are multiple methods to cancel event propagation, each with different semantics. event.preventDefault() Only prevents the default browser behavior for the click, i.e. going to a different...
...url or submitting a form. When invoked on a touchstart event, this also prevents mouse events like click to be triggered. event.stopPropagation() Prevents the event from bubbling up the DOM...
Sometimes you have a file that is related to a project, while not actually being part of it. You'd like to keep them around, but others won't need...
...them – e.g. some notes, a log, or a database dump. Sure, you have a project directory – but all of it is tracked by Git. A project's tmp/ directory is...
...in development. Note that there are services like badssl.com to test against weird SSL behavior. Self-signed certificates Talking to a host using a self-signed certificate will fail because...
...the certificate can not be verified. >> RestClient.get('https://self-signed.badssl.com/') RestClient::SSLCertificateNotVerified: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed Self-signed certificates...
...tell npm to install a package globally with npm -g install @puppeteer/browsers. However, it seems that its not possible that npx can run commands from global packages without referencing the...
...image, where a testing chrome and chromedriver is installed with a global npm package. Since there is no local project it was more useful to install the package in a...
In the past we validate and set default values for boolean attributes in Rails and not the database itself. Reasons for this: Older Rails didn't support database defaults when...
...the Rails upstream on constraints in the database, is adding default values in the schema of the database itself. We also encourage to set boolean attributes to not null. For...
PostgreSQL uses the C library's locale facilities for sorting strings: First, all the letters are compared, ignoring spaces and punctuation. It sorts upper and lower case letters together. So...
...the order will be something like a A b B c C Then, spaces and punctuation are compared to break ties. Example: Ruby PostgreSQL IMAGE3.jpg image2.jpg image.jpg image3.jpg image2.jpg
Module imports are hoisted (internally moved to the beginning of the current scope). Therefore, it doesn’t matter where you mention them in a module and the following...
Footgun example When you're not aware of import hoisting you may be surprised that your code runs in a different order than you see in the source file...
...instead of using the UI or creating records in the Rails console. This approach saves time and gives you useful defaults and associations right out of the box.
...that's not a float! This occurs because JavaScript uses double precision floats to store numbers. So according to IEEE floating point definition only numbers between...
...and 2^53 - 1 (9007199254740991) can safely be represented in JavaScript. Note that ECMAScript 6 will probably also offer Number.MAX_SAFE_INTEGER (and Number.MAX_SAFE_INTEGER) that point to those...
...use puppet-lint to find dead code in your project: # You probably need to set some ENV Variables, see https://github.com/voxpupuli/puppet-ghostbuster#environment-variables export HIERA_YAML_PATH="/home/bob/code/puppet/hiera.yaml" export PUPPETDB_URL...
...discouraged to load your JavaScript by a tag in the : The reason is that a tag will pause the DOM parser until the script has loaded and executed. This will delay the browser's first contentful paint. A much better default is to load your scripts with a tag: A deferred script has many useful properties: It does not block the browser from rendering content. Deferred scripts...
...can query the entire DOM tree with querySelector() and friends. document.readyState is 'interactive'. Deferred scripts will run before the DOMContentLoaded event. That means if your code waits to initialize until...