# for which the block evaluates to true, # the second containing the rest. (1..6).partition { |v| n.even? } #=> [[2, 4, 6], [1, 3, 5]] Works well with destructuring assignment...

even, odd = (1..6).partition { |n| n.even? } even #=> [2, 4, 6]

...to use our own daho.im service. All daho.im subdomains resolve to your local IP (127.0.0.1). That means you can use a different hostname for different apps, and you will stay...

...logged in in each app: http://foo-app.daho.im:3000 => 127.0.0.1 http://bar-app.daho.im:3000 => 127.0.0.1 http://bam-app.daho.im:3000 => 127.0.0.1 Caution It's safe to use daho.im since it's our own domain. Don't use...

end describe '#age' do it { is_expected.to validate_inclusion_of(:age).in_range(1..100) } end end See the shoulda-matchers README for a full list of matchers provided...

docs.ruby-lang.org

The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...

...different data types to be formatted, such as %f for floats: sprintf('%f', 1) # => 1.000000 Example: This is quite useful to replace long strings such as API endpoints which might...

github.com

...are three ways to define your own RSpec matchers, with increasing complexibility and options: 1) Use RSpec::Matchers.define RSpec::Matchers.define :be_a_multiple_of do |expected| match do |actual|

block expectations If you want to use a block expectation like expect { rand(100) }.to produce_different_results, you have to use this syntax and call supports_block_expectations...

developer.chrome.com

} entries.sort((a, b) => { if (a.kind === b.kind) { return a.name.localeCompare(b.name) } return a.kind === 'directory' ? -1 : 1 }) for (const entry of entries) { const connector = '├─' const childPrefix = prefix + '│ ' if (entry.kind === 'file') { const file...

...explains some options to make browsers wrap inside a long word like "Donaudampfschifffahrt". Option 1: hyphens CSS property (preferred) Modern browsers can hyphenate natively. Use the hyphens CSS property:

The hyphens property has good browser support. If you need to support Safari < 17, you may need to also set -webkit-hyphen. If a browser lacks the dictionary for...

...has_many :users end Here activity 42 has four users: activity = Activity.find(42) activity.users.ids # => [1, 2, 3, 4] Let's say we want to do the same on all activities...

By reloading the object, its full list of associated users is restored: activity.reload.users.ids # => [1, 2, 3, 4] Reset the association cache Or you can reset the association cache: activity.users.reset...

Unfiltered: `User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."token" = $1 LIMIT $2 [["token", "secret-token"], ["LIMIT", 1]]` After the filter is applied:

...ms) SELECT "users".* FROM "users" WHERE "users"."token" = $1 LIMIT $2 [["token", "[FILTERED]"], ["LIMIT", 1]]` Unfortunately, this mechanism is not always applied, because of code dependencies. Some are written by...

...MembershipJob.perform_later(membership) second_blocked_job = MembershipJob.perform_later(membership) # Verify blocking behavior assert_equal(1, SolidQueue::ReadyExecution.count) assert_equal(1, SolidQueue::BlockedExecution.count) blocked = SolidQueue::BlockedExecution.last assert_equal(second_blocked_job.provider_job_id...

...with Rails 6 and below, or when the inverse scope may contain NULL values. [1] There are two different ways of "inverting a scope": As an example, consider the following...

...role" IN ('admin', 'superuser')) That also works with range conditions like where(created_at: 1.week.ago..), but does not work for missing (because its join statement is lost). So, sadly this...

...class that includes your module, and no longer exists after your test has finished. 1. Defining the class and assigning to a constant (preferred) describe Notifier do before do

masilotti.com

...quite manageable. Let’s dive into how this works. Only few fixture per model (1-2 is enough in most cases) You should only have a minimal amount of fixtures...

...User.count == 3 end Good example: test "user can be created" do assert_difference "User.count", 1 do post users_path, params: { first_name: "Foo", last_name: "Bar" } end end Conclusion

makandra dev

...within the diff. Colors The value for color configuration variables is a list of 1-2 colors and 0-1 attributes, separated by spaces. Colors: normal, black, red, green, yellow...

...and straightforward) Enable caching for individual test Enable caching for individual test (file cache) 1. Leave the default configuration 2. Add a caching helper which gives you a unique file...

...some_key')).to be(true) end end Enable caching for individual test (memory store) 1. Leave the default configuration 2. Now stub the Rails cache and clear it before each...

An example would be an AngularJS application where the following HTML actually works. [1] Hello Capybara will fail to find that link, even though looking it up via the...

...and click_link work, simply add href="#" to your element: Hello >> find_link("Hello") => # [1] Note that while it does work in your application (links are usually styled correctly, and...

Redis database size via Ruby client irb(main):002> Redis.new(url: 'redis://localhost:16380/1').info.fetch('maxmemory_human') => "512.00M" Redis database size via CLI $ redis-cli --port 16380 --database...

...1 INFO memory | grep maxmemory_human maxmemory_human:512.00M Memory footprint If you want to calculate the estimated Redis memory usage of a job, you can measure the consumed...

makandra dev

$ ruby --yjit -e "puts RubyVM::YJIT.enabled?" true # via ENV variable $ RUBY_YJIT_ENABLE=1 ruby -e "puts RubyVM::YJIT.enabled?" true # Start Ruby without YJIT, but enable it later

...to not use the CLI flag --yjit or the ENV variable RUBY_YJIT_ENABLE=1 for starting Rails processes on your server...

makandra dev

end def db_number # Returns a number between 2 and n. # Redis db#1 is used for development. db_number = 1 if rails_env == 'test' normalized_test_number = [ENV...

...TEST_ENV_NUMBER'].to_i, 1].max db_number += normalized_test_number end db_number end def port case rails_env when 'staging' # when 'production' # else 6379 # default Redis port...

...in SQL this looks like SELECT `models`.* FROM `models` WHERE `models`.`id` = 23 LIMIT 1 FOR UPDATE You have to do this at the point where the object is loaded...

# This block is called within a transaction, # account is already locked. account.balance -= 100 account.save! end More on row locking http://dev.mysql.com/doc/refman/5.1/en/innodb-locking-reads.html http://www.postgresql.org/docs/current/interactive/sql-select.html#SQL-FOR-UPDATE-SHARE Other types of...

...shutdown the Elasticsearch cluster, as soon as everything works as expected. flowchart TB subgraph "1" A0[App]-- Search -->ES0[Elasticsearch] A0[App]-- Update -->ES0[Elasticsearch] OS0[OpenSearch] end

...please refer to the breaking changes linked below. On request we may provide OpenSearch 1.x corresponding to Elasticsearch 7.x. How do you update your application? This depends on...

github.com

...Add this line to your application's Gemfile: gem 'capistrano', '~> 3.0' gem 'capistrano-maintenance', '~> 1.0' Add this line to you application's Capfile: require 'capistrano/maintenance' Enable task Present a maintenance...

...specifying the REASON and UNTIL environment variables: cap maintenance:enable REASON="hardware upgrade" UNTIL="12pm Central Time" You can use a different template for the maintenance page by setting the...

Always optimize: Don't do stupid things with the database. Avoid "n + 1" queries. Don't do costly calculations live when you can precalculate and cache. Don't...

...instantiate 1000s of records. Use query_diet. Add database indexes. Don't descend into callback hell. Use form models. Optimize on demand: Don't optimize without knowing what's actually...

...you might want to enable logging for the chromedriver itself. Here is how. Option 1: Use Selenium::WebDriver::Service In your test setup, you may already have something like Capybara...

...can also start chromedriver yourself in a terminal on a custom port: chromedriver --port=12345 --verbose --log-path=/tmp/chromedriver.log Then configure Selenium to connect to that port. Like in option...