Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for...
Git can help you to find the next git tag that was set in the branch. This usually has the name of the version in it (as the...
Web forms can be made much more usable with a few HTML attributes. Short summary: type: Tells browsers about the input data type. Mobile browsers will select a virtual keyboard...
...based on this value. Some browsers will add simple validation, e.g. for type email. inputmode: Direct hint about the virtual keyboard to use. Inferred from type, but can be very...
If you're on Ruby 2.3+ there's a <<~ operator to automatically unindent HEREDOCs: str = <<~MESSAGE Hello Universe! This is me. Bye! MESSAGE If you have an older Ruby, you...
...can use the String#strip_heredoc method from ActiveSupport. See Summarizing heredoc in ruby and rails for an example. Technically, it looks for the least indented line in the whole...
...you want to clean up this code with the modularity gem, you might try something like this: class Foo does 'bar' end module BarTrait as_trait do class Bar
...you would have to change all references accordingly, which is quite unpleasant. You can solve it like that: module BarTrait as_trait do class self::Bar end end end
jQuery's removeClass removes the given class string from an element collection. If you want to remove multiple/unknown classes matching a given pattern, you can do that. For example, consider...
...node for the following HTML. We'll reference it by $element below. Option A: Selecting classes, then removing them You can iterate over existing classes, and select matching ones. The...
...file download links in an end-to-end test can be painful, especially with Selenium. The attached download_helpers.rb provides a download_link method for your Capybara tests. It returns a...
details[:disposition] # => 'attachment' or 'inline' details[:filename] # => 'report.txt' details[:text] # => file content as string details[:content_type] # => 'text/plain' Features Compared to other approaches this helper has many useful features...
In a nutshell: return statements inside blocks cause a method's return value to change. This is by design (and probably not even new to you, see below) -- but can...
...a problem, for example for the capture method of Rails. Consider these methods: def stuff puts 'yielding...' yield puts 'yielded.' true end We can call our stuff method with a...
...into your Webpack's assets folder or write an npm package with an own sass file that can be imported from the Webpack manifest. Load fonts from your assets folder...
...The first option turns out to be straightforward: Import the stylesheets in the index.js of the pack you're using: // webpack_source_path/application/index.js import './stylesheets/reset' import './stylesheets/main' // loads the fonts...
The closest is probably Nimbus Sans L, which is released under the GPL, AFPL, LPPL licenses. However, I couldn't find a way to convert Nimbus Sans L into a...
I finally settled with Liberation Sans, which is awesome for some reasons: Although it's available for free, it's a high quality font because its creation was...
...flaky tests. You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist the result of your test runs to a file. This is...
...necessary to be able to rerun examples. Add this to your spec/spec_helper.rb : config.example_status_persistence_file_path = 'spec/examples.txt' Rerun all failed examples using --only-failures bundle exec rspec --only-failures...
...lot less than you think. "private" does not apply to class methods defined on self This does not make anything private: class Foo private def self.foo 'foo' end end
...need to use private_class_method instead: class Foo def self.foo 'foo' end private_class_method :foo end "private" does not apply to define_method This does not make anything...
...has its weak points, but I want to point out that it has clear strengths, too. Pro Simple and beautiful interface. Outstandingly organized source code. Have never seen a JS...
...toolbar buttons, pass various callbacks, etc. Features a collection of great plugins. Easily extendable by self-made plugins. It is really simple to write one – see example below.
...to accept nested attributes for a record that is not an association, e.g.: class Site < ActiveRecord::Base def home_page @home_page ||= Page.find_by_name('home') end does 'accept_nested...
...attributes_for_member', :home_page end It has some limitations: Only works for singular member references ("belongs to"), not for a collection of references ("has many") No support for deletion...
...exactly(building, other_building) expect(unit.assignable_buildings).not_to include(unauthorized_building, nil) end ... See RSpec: Where to put custom matchers and other support code
Remember How to skip Sprockets asset compile during Capistrano deployment and Automatically skipping asset compilation when assets have not changed? Turns out there is an even better way to speed...
...up Capistrano deployments with asset compilation – and it's even simpler. Adding the asset cache directory to symlinked directories Popular asset managers for Rails are Sprockets and Webpacker. Both keep...
When you are using the #selector_for helper in Cucumber steps, as e.g. Spreewald does, the following snippet will save you typing. It recognizes a prose BEM-style selector and...
...maps it to the corresponding BEM class. For a variation on this idea, see An auto-mapper for ARIA labels and BEM classes in Cucumber selectors. Examples "the main menu...
You can use three different versions of the regular expression syntax in grep: basic: -G extended: -E(POSIX) perl: -P (PCRE) Difference between basic and extended: In basic regular expressions...
...the meta-characters '?', '+', '{', '|', '(', and ')' loose their special meaning; instead use the backslashed versions '?', '+', '{', '|', '(', and ')'. Difference between extended (POSIX) and perl (PCRE): E.g. \d is not supported in POSIX.
When your JavaScript bundle is so massive that you cannot load it all up front, I would recommend to load...
...test you can also use a handful of rake tasks to prepare the database structure directly. They can produce different results, though. In a nutshell, to ensure your test database...
...gains the correct structure: Don't use rake db:test:prepare carelessly or use rake db:test:clone_structure ← preferred :) or use rake db:migrate RAILS_ENV=test and don...
If you are using scrum in a project you might be familiar with planning poker, a playful way to agree on story estimates. PoinZ is an online planning poker app...
...AWS elasticache is memcached) telnet foohost23.cs2631.0001.euw1.cache.amazonaws.com 11211 Once you're connected, find out which 'slabs' exist within the cache: stats items STAT items:1:number 3550 STAT items:1:age...
...STAT items:1:evicted 0 STAT items:1:evicted_nonzero 0 STAT items:1:evicted_time 0 STAT items:1:outofmemory 0 STAT items:1:tailrepairs 0
Situation: You want to write a spec for a function inside an Angular service. This function at some point makes an API request and acts upon response. Notably, your Angular...
...uiRouter, although it is not used nor actually required for this test. Working test setup # Capitalized expressions are intended to be replaced with YOUR values describe 'SERVICE', -> beforeEach -> module 'MODULE...
tl;dr: Do not use merge! for session hashes. Use update instead. Outline Let's assume you're modifying the Rails session. For simplicity, let's also assume your session...
...is empty when you start (same effect when there is data): # In our example, we're in a Rack middleware request = Rack::Request.new(env) request.session.merge! :hello => 'Universe' request.session => {} Wat?
Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest change is that they moved away from their custom DSL...
...release_roles|...) :some_role do Resources Very helpful, leads you 90% of the upgrade: https://semaphoreci.com/blog/2013/11/26/capistrano-3-upgrade-guide.html Official documentation Many examples of SSHKit...