We structure our CSS using the BEM pattern. Our naming convention for blocks, elements and modifiers has evolved over the years. This card shows our current style and various alternative...
...not mix styles and be consistent within a given project. Current convention Our current BEM naming convention looks like this:
Note how the modifier just starts with a dash (-pro...
} Enumerable#index_with (Rails 6+) To generate a hash where array elements become hash keys, and values are calculated from them, use index_with. users = User.all
Let the following setup: # my_model_spec.rb describe MyModel do it 'perfoms a test' it_behaves_like 'something shared' end # something_shared.rb shared_examples_for 'something shared' do it 'does something'
...a test' is spec/models/my_model_spec.rb[1:1]. The ID of the ExampleGroup created by it_behaves_like 'something shared' is spec/models/my_model_spec.rb[1:2] as it is the second ExampleGroup in the...
=> #<Capybara::Node::Element tag="div" path=... If you rely on this behavior in Capybara 3, affected features will fail. The gem no longer normalizes whitespace when finding...
...visible css ".haystack" with text "Hi! Try to match me." Re-enabling Cabyara 2 behavior in Capybara 3 After digging in the documentation, you might figure out that you can...
I had to modify the time for an application that I launch through Docker. Here is an approach that worked...
Rails offers a way to prepend (or append) view paths for the current request. This way, you can make the...
For string columns, MySQL indexes the left side of a string. That means an index can speed a like query...
...record, :match_requests_on).except(:example_group) VCR.use_cassette(name, options) { example.call } end end Behaviour If a spec is not tagged with :vcr, VCR will complain about any attempted HTTP...
...request. This is the default behaviour. If you want to turn this off temporarily, e.g. to communicate with an actual API while writing a new spec, simply add the line...
Some users might use Adblock Plus or similar browser plugins to reduce the number of ads displayed. If you run...
Some browsers render PNG images with color profiles and other shenanigans, some don't. The cleanest way to have consistent...
This page lists many query methods and options in ActiveRecord which do not sanitize raw SQL arguments and are not...
You can not use the hash_including argument matcher with a nested hash: describe 'user' do let(:user) { {id: 1...
...any cleanup yourself. Why? Understand this: before(:context) is run when the context/describe block begins, before(:context) is run outside of transactions, so data created here will bleed into other...
This talk shows simple and advanced usages of the ruby/debug debugger. It goes through a step by step debugging workflow...
When your Cucumber feature needs to browse the page HTML, and you are not sure how to express your query...
...lockfile carefully when submitting a commit. Note that the approach in this card works best, if you use yarn outdated or npm outdated together with yarn upgrade some_package or...
...more information about this issue. In Rails3+ you can also disable this annoyingly clever behavior. Why this is bad This has some develish implications for your deployment, because scopes written...
...t notice this during development. Let's say you have a model Note which belongs to an Author and has a string column category: class Note < ActiveRecord::Base
When using Sidekiq in your application, you must write thread-safe code. This wiki page also lists gems that are...
Rails is split into a large number of (sub-) frameworks. The most important and central of those are activesupport (extends...
...all routes, but may return early, a change has been introduced to add lazy behavior by adding an iterator block and yielding. This change breaks the adapter patch in routing...
...the window's resize event, that might call your event listener many times. A better way is to subscribe to changes of the MediaQueryList object that is returned by matchMedia...
I frequently find myself needing a combination of group_by, count and sort for quick statistics. Here's a method...
...API design, I thought it might be nice to write down a set of best practices. And poke fun at a couple widely-used APIs. Much of this may be...
...system's environment specifies. This is usually good enough. To test any timezone-dependent behavior in Chrome, you can change the time zone using the Chrome DevTools Protocol. Example