...notice that the records you create are not deleted and will bleed into your specs the next time you run them. You probably have DatabaseCleaner configured to take care of...

...not bloating your test database with old records: RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:deletion) end config.before(:each) do DatabaseCleaner.strategy = :transaction end config.before(:each, transaction: false) do DatabaseCleaner.strategy...

makandra dev

Follow the installation guidelines at https://mise.jdx.dev/getting-started.html. Remove rbenv configuration Search for rbenv config in .bashrc and .profile and remove it: eval "$(rbenv init - bash)"

...rbenv config in .profile and remove it: source /home/$user/.rbenvrc Remove nvm configuration Search for nvm config in .bashrc and remove it: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM...

This card is a short summary on different ways of assigning multiple attributes to an instance of a class. Using positional parameters Using parameters is the default when assigning attributes...

...It works good for a small number of attributes, but becomes more difficult to read when using multiple attributes. Example: class User def initialize(salutation, first_name, last_name, street...

...posts; if you use pagination the queries will be more complicated, but the point still stands. Looks harmless enough? It is not. The problem ActiveRecord will rewrite this into a...

...query using LEFT JOINs which looks something like this: SELECT "blog_posts".*, "comments".*, "attachments".* FROM "blog_posts" LEFT OUTER JOIN "comments" ON "comments"."blog_post_id" = "blog_posts"."id"

...pretty_print method As an example, consider the following class. class MyClass # ... def inspect "#<#{self.class} attr1: #{attr1.inspect}, attr2: #{attr2.inspect}>" end end Instances of that class will inspect like #<MyClass attr1...

...Alice", attr2: "Bob">, but IRB will apply a single color (green) for everything. That is because MyClass implements only inspect. If it were to implement pretty_print, IRB would use...

...been released just a few days ago, allowing us to use Webpack 4. I successfully upgraded an existing real-world Webpack 3 application. Below are notes on everything that I...

Note that we prefer not using the Rails asset pipeline at all and serving all assets through Webpack for the sake of consistency. Preparations Remove version locks in Gemfile...

github.com

...Mocking the time zone You can't really change the local time zone of the Selenium-controlled browser. What you can do is change the time zone of the process...

...setting this from an individual test, since you don't know whether or not the Selenium-controlled browser has already launched. Note that we have only tested this with a...

Systemd's networkd will drop IP-Addresses configured by other processes like Keepalived's VRRP, when it is restarted. This may happen on updates. To prevent this following settings are...

...critical: yes to /etc/netplan/50-cloud-init.yaml eth1: addresses: - 192.0.2.67/24 gateway4: 192.0.2.1 nameservers: addresses: - 198.51.100.42 - 198.51.100.53 search: - example.lcal critical: yes run netplan generate This will add the CriticalConnection to your networkd configuration...

...if you do not know. How are cookies transferred between your browser and the server? Open the development tools in your browser for this page. Can you find the cookies...

...your browser stores for makandracards? In the network tab, can you see how the cookies are transferred to or from the server? Can you log yourself out by manipulating a...

...block evaluates to true. first_post_with_image = posts.find do |post| post.image end However, sometimes it's not the item you're interested in, but some value depening on it...

...image).find(&:present?).url If the mapping is a costly operation or has undesirable side effects, you need to do it in a single iteration instead. Single iteration solution with...

linux.die.net

...files. Those can be used to apply to a different repository [1] or by someone else (e.g. sent when sent to them via e-mail). Creating a patch in git...

...changes and commit them. Run git format-patch COMMIT_REFERENCE to convert all commits since the referenced commit (not including it) into patch files. For example, let's say you...

I recently noticed a new kind of flaky tests on the slow free tier GitHub Action runners: Integration tests were running on smaller screen sizes than specified in the device...

...metrics. The root cause was the use of Selenium's page.driver.resize_window_to methods, which by design does not block until the resizing process has settled: We discussed this issue...

Here are a few common patterns that will probably lead to flaky specs. If you notice them in your specs, please make sure that you have not introduced a flaky...

Using RSpec matchers One rule of thumb I try to follow in capybara tests is using capybara matchers and not plain rspec matchers. One example: visit(some_page)

...Learn to create test data effectively using factories. Decouple tests by having each test start with an empty database and create only the records needed for the test. Learn

...with every test. In our experience the use of fixtures can make a test suite hard to work with. In any non-trivial test suite there will be thousands of...

makandra Curriculum

...library => Google Drive) CLI tricks every developer should know Install the tldr tool using sudo apt install tldr. You can then get usage examples for every console command, e.g. tldr...

...ssh to get examples for the ssh command. (If there are no entries, run tldr -u and try again) Exercises Basic commands Experiment and do something useful with the following...

...with a nice way to grep through your project's files: The finder (ctrl + shift + f). Don't be discouraged about the notice 100+ matches in n+ files if your...

...searched keyword is too general or widely used in your project. RubyMine comes with a few ways to narrow down the resulting list, don't hesitate to apply those filters...

github.com

...a global variable in Rails? Ugh, that's the worst. If you need global state, you've probably reached for Thread.current. When you're using Thread.current, you must make sure...

...yourself or your cached data will stay in Thread.current. For Sidekiq, you can use request_store-sidekiq. Cronjobs are unaffected, as a new process is created each time...

Learn to treat files as an ActiveRecord attribute type, like :string or :integer Research Look at the README for the carrierwave gem Read about Common mistakes when storing file...

...the form where we can also fill in title, year, etc. On the movie show view, render a poster version that is 400 pixel wide, with a height that respects...

With passenger-status --show=requests you can get a huge JSON showing current information about the running passenger processes. This can be useful if you want to find out what...

...a passenger process is doing at the moment (for e.g. if one worker seems to be stuck): * PID: 4273 Sessions: 1 Processed: 47 Uptime: 50m 53s CPU: 43% Memory : 3644M...

github.com

...default it allows only accessing visible elements -- when you are using a driver that supports it (e.g. Selenium, not the default Rack::Test driver). Consider the following HTML: One

...true) or find(..., visible: :visible). Note that you could change the default behavior by setting the ignore_hidden_elements config option. However, ignoring invisible elements is a useful default.

...just barely wider than the container it should fit into, and it wraps a single word to a new line and it's not really pretty? Cry no more, for...

...in some browsers. When browsers encounter a text-wrapping element with text-wrap: balance style, they will try breaking to a new line sooner, if it balances out the width...

GoodJob and ActiveJob rescue exceptions internally, preventing exception_notification from triggering. This can cause silent job failures.To get notified, subscribe to ActiveJob events and configure GoodJob's on_thread_error...

...job failures, as they are handled internally by ActiveJob/GoodJob. ActiveSupport::Notifications.subscribe(/(enqueue_retry|retry_stopped|discard)\.active_job/) do |event_name, *, payload| exception = payload[:error] job = payload[:job]

Modern CSS offers the field-sizing property to allow elements to automatically adjust size (width and/or height) to fit their contents. The most common use case are textareas which start...

...fairly small (e.g. 2 or 3 rows tall) but grow when users enter longer text. Usage textarea { field-sizing: content; } That's it! At least in modern Chromium-based browsers...

...tough challenge. To get more detailed insights consider using the rack-mini-profiler gem. Setup with Unpoly Add the following gems: group :development do gem 'memory_profiler' gem 'rack-mini...

If you have slow views (Haml/Partials can be slow), consider caching them. Remove code & sql-queries that are not needed to render the page. Calling to_a blindly on...