Ruby on Rails - May 2023
Ruby on Rails - May 2023

Ruby on Rails - May 2023

Hey Ruby people, this is me Sajjad Umar your own Desi Developer bringing you all the updates from #rubyonrails world.

???????? This is our 1st Birthday ????????

This is the 13th edition of Ruby on Rails Monthly, which makes this #newsletter 1 year old - ?? Congratulations to me and all the subscribers.

In the past 12 months, we have grown from 0 to a family of 2000+ subscribers which is a big deal, at least for me.

If you find this newsletter useful, please share it in your circle (LinkedIn, Twitter, or anywhere you like) with some of your thoughts about the newsletter. I'd consider that a birthday gift from all of you.

Shareable Link: https://bit.ly/rubyonrails-monthly

With that being said, let me start with some updates from Ruby on Rails - The Rails Foundation .

Rails World Call for Papers is now open

Rails World is the first conference hosted by the Rails Foundation and coincides with the 20th anniversary of the Ruby on Rails framework. It will take place on October 5 & 6, 2023 in the Beurs van Berlage in Amsterdam, Netherlands.

This CFP is open until June 16, and we are aiming to inform all applicants if they are accepted (or not) before tickets are released.

Submit your proposals here.

Read all the details here.

AppSignal is the newest contributing member of The Rails Foundation

AppSignal is the 3rd company to join hands with The Rails Foundation as a contributing member.

Read all the details here.

Rails World tickets

If you want to be notified when Rails World tickets go on sale, add yourself to the waitlist here.

The Ruby on Rails Interview Bible

A friend of mine Nezir Zahirovi? has authored some very handy interview prepration guides/ebooks, I've gone through the content of one of these ebooks named "The Ruby on Rails Interveiw Bible" and I can tell you it has a very good collection of ruby on rails interview questions.
You can buy these ebooks here.

Trilogy, a MySQL-compatible DB client now has its adapter for rails

The Trilogy database client and corresponding Active Record adapter were both open-sourced by GitHub last year. Shopify adopted Trilogy successfully in the Rails monolith several weeks ago.

With two major Rails applications running Trilogy successfully, it was the perfect time to have its own adapter.

Read all the details here.

Improved password length validation in the ActiveModel::SecurePassword module

This Pull Request has been created because we identified a need to improve password length validation for BCrypt compatibility in the ActiveModel::SecurePassword module.

The current validation only considers the character count, which may not accurately reflect the byte size limit imposed by BCrypt.

Read all the details here.

Reduced captures in ActiveSupport::Inflector#underscore

This Pull Request changes a gsub! in ActiveSupport::Inflector#underscore not to use captures.

This skips creating small strings by $1/$2 and appending an underscore, and instead, excludes the character to be kept from the replacement target.

Read all the details here.

Loading fixtures now show reason for foreign key error

Rails verify foreign keys when creating fixtures. Feedback from users since then is it would be handy to know which foreign keys are being violated.

Read all the details here.

Added ActiveSupport::MessagePack

To improve performance and reduce message size, ActiveSupport::MessagePack serializer has been added to rails.

Read all the details here.

Added support of USING INDEX for unique constraints in PostgreSQL

Added :using_index option to use an existing index when defining a unique constraint. When the :using_index option is used, the specified unique index is changed to a unique constraint.

add_unique_key :users, deferrable: :immediate, using_index: 'unique_index_name'        

Read all the details here.

Allowed queue adapters to provide a custom name

This gives queue adapters more freedom to name and organize their code.

For example, if FancyQueue wants to have their adapter at FancyQueue::ActiveJobAdapter, the inferred name would be active_job before this change. After this change, they can implement queue_adapter_name to return fancy_queue.

Read all the details here.

Added Common Table Expression (CTE) support for joins

Now joins can smoothly work with CTEs. left_outer_joins is also supported.

relation = Post
  .with(commented_posts: Comment.select(:post_id).distinct)
  #=> INNER JOIN commented_posts on posts.id = commented_posts.post_id
  .joins(:commented_posts)        

Read all the details here.

Added intersects? to Relation

Ruby 3.1 added intersects? which is equivalent to (a & b).any?. Rubocop added a corresponding cop, Style/ArrayIntersect, which transforms the old style to use intersects?. Unfortunately as intersects? is not delegated on CollectionProxy, this leads to false positives that need to be disabled for no good reason other than the fact the method isn't delegated.

This PR add delegation of intersects? to Relation which fixes this.

Read all the details here.

Deprecated deferrable: true option of add_foreign_key

Because deferrable: true and deferrable: :deferred are hard to understand.

deferrable: true is deprecated in favor of deferrable: :immediate, and will be removed in Rails 7.2.

Read all the details here.

A lot of improvements to the documentation

A lot of improvements have been made to the documentation to help improve SEO.

PostgreSQL guide has also received new sections on INCLUDE, UNIQUE, and EXCLUDE.

Read all the details here.

Nested Hash-related= bug fixes in Edge Rails

Only flatten the first level of nested hash to preserve the nested structure.

Read all the details here.

Fixed pg 1.5.0 deprecation warning

This warning occurs when using the recently released pg gem version 1.5.0. The PR has been backported, so the next point release should quiet things!

Read all the details here.

On blank ActiveSupport::Cache it will consistently raise an ArgumentError?

This Pull Request adds a validation step in ActiveSupport::Cache::Store#normalize_key to ensure that an ArgumentError is consistently raised when the expanded cache key is nil or "" (empty) within all methods relying on #read_entry, #write_entry and #delete_entry (#read, #fetch, etc.).

Read all the details here.

Rails cookies RFC6265 is now compliant with domain: :all

Rails has incorrectly been adding leading dots to cookie domain values in Set-Cookie headers when the domain: :all option is present.

This leading dot was required in cookies based on RFC 2965 (October 2000), but RFC 6265 (April 2011) changed that behavior, making a leading dot strictly incorrect. This PR fixes the issue.

Read all the details here.

Deferrable foreign keys can now be passed to references

Fixed a bug in which deferrable foreign_key was ignored when passed to t.references.

Read all the details here.

Fixed: Rack::Test::UploadedFile.new with StringIO causes an exception

This Pull Request changes ActiveStorage::Attached::Changes::CreateOne#upload (and private #find_or_build_blob) so it does not call #open on a Rack::Test::UploadedFile if it does not respond to this method. It uses the object itself (which can be read from just like opened File).

Read all the details here.

Allowed symbols as queue names in ActiveJob test assertions

The pull request enables the acceptance of both symbols and strings by assert_enqueued_with and assert_performed_with. On the other hand, assert_enqueued_jobs and assert_performed_jobs already supported both symbol and string inputs.

Read all the details here.

Raise error if setting a config key that is a method name

Previously if you do:

config.load_defaults = 7.0        

it is silently accepted and may make the user believe the framework defaults are in place, but they are not.

This PR adds a NoMethodError so that the user can fix the above statement as follows:

config.load_defaults(7.0)        

Read all the details here.

Added load hook for ActiveRecord::ConnectionAdapters::Mysql2Adapter

You now have the freedom to expand the capabilities of the MySQL adapter using the hook provided below:

ActiveSupport.on_load(:active_record_mysql2adapter) do
  # add code to change some behaviour
end        

Read all the details here.

Fixed: updated_at not updating in before_update callback?

This Pull Request ensures that timestamps are rewritten once all update callbacks have run so that mutations made within them (if any) are recognised as updates, updating the updated_at timestamp as a result.

Read all the details here.

Fixed a bug in where deferrable foreign_key was ignored when passed to t.references

The Rails 7.0 update allowed deferrable foreign key constraints via the add_foreign_key method. This pull request extends this support to t.references also.

Read all the details here.

Using Rack::Test::UploadedFile.new with StringIO causes an exception?

This Pull Request changes ActiveStorage::Attached::Changes::CreateOne#upload (and private #find_or_build_blob) so it does not call #open on a Rack::Test::UploadedFile if it does not respond to this method. It uses the object itself (which can be read from just like opened File).

Read all the details here.

Handled empty list of cache keys

This modification causes read_multi, write_multi, delete_multi and fetch_multi to terminate prematurely if they are invoked with an empty list.

Read all the details here.

Updated migration examples to showcase database-agnostic raw SQL execution

This Pull Request changes the code examples of active_record_migrations.md in sections 3.10, 3.11, and 3.12.

The previous example would error out in SQLite due to SQLite not supporting adding constraints in the ALTER TABLE command.

Read all the details here.

Use configured pk type in Action Mailbox migration

This PR adds a migrations_test.rb for Action Mailbox that closely mirrors the same file in ActiveStorage. It then adds a private primary_key_type method in the Action Mailbox migration which pulls a project's configured primary key type. This method is also closely modeled after Active Storage's.

Read all the details here.

Allowed passing nil to rewhere method

This change allows nil to be passed as a parameter to the rewhere method in ActiveRecord, instead of raising an error.

No alt text provided for this image
Source: GitHub

Read all the details here.

Support :message_pack as a cache serializer format

This commit adds support for :message_pack as an option for config.active_support.cache_format_version.

Read all the details here.

Improve cache performance for bare string values

Both the new 7.1 cache format and the previously mentioned :message_pack cache format have received performance enhancements for plain string values, such as view fragments.

Read all the details here.

Added matcher support to assert_enqueued_email_with

Previously, the assert_enqueued_with method permitted the usage of procs for matching arguments, while assert_enqueued_email_with did not allow for procs to be used for both arguments and parameters. However, the recently submitted pull request updated assert_enqueued_email_with to accept procs for both arguments and parameters.

Read all the details here.

Added picture_tag helper

This PR adds support for the HTML picture tag. It supports passing one element (String), multiple (an Array), or a Block if you need full control of what it's being generated. All properties that are passed to the helper will apply to the picture tag. If you need to pass properties to the img tag, you can do it inside the :image key.

Detailed examples on how to use this tag are provided in the PR.

Read all the details here.

Prevented duplicate filters for encrypted attributes

When an Active Record encrypted attribute is declared, a filter for it is automatically added to config.filter_parameters. Prior to this commit, the filter would be re-added every time the model was reloaded, this PR ensures filters are only added once so that?config.filter_parameters?does not grow unbounded.

Read all the details here.

Make Active Record's query cache an Least recently used (LRU)

The Active Record query cache has been updated to remove the least recently used entries, with a default of 100 entries. The cache's size can be modified by adjusting the configuration in the database.yml file.

Read all the details here.

Prevent non-anonymous modules from becoming frozen

Module#deep_dup was changed to return the module itself (not a copy) when the module is not anonymous. However, that causes non-anonymous modules to become frozen via value.deep_dup.freeze when passed to ActiveModel::Type::Helpers::Mutable#immutable_value. So, for example, class attributes can no longer be set on the module.

To prevent such issues, this commit removes the freeze from immutable_value. immutable_value is only called by ActiveRecord::PredicateBuilder#build_bind_attribute, which only cares that other code cannot mutate the value, not that the value is actually frozen.

Read all the details here.

Counters now accept an amount argument

The pull request being referred to proposes the addition of the "by" option to the increment_counter and decrement_counter methods. This would simplify the process of modifying counters by allowing for the use of an arbitrary value. An example of the new option's usage is provided.

Company.increment_counter(:likes_count, 5, by: 3)        

Read all the details here.

Allowed PredicateBuilder to recognize schema namespaced table names

In its previous implementation, ActiveRecord::PredicateBuilder made an assumption that column names would be specified using a single period in dot notation. If a table was namespaced in a schema and a column was specified in dot notation, the schema name was treated as the table name. With this pull request, it is now possible to specify columns in the format schema.table.column, in addition to table.column.

Read all the details here.

Default message serializer to :json_allow_marshal

This commit changes the default message serializer set by config.load_defaults 7.1 from :json to :json_allow_marshal so that upgraded apps can continue to read old messages without additional configuration.

Read all the details here.

Desi Developer

On the Desi Developer side of things, you might have noticed I started a short hand-drawn animated series with our very own Ruby Man as a superhero.

The goal of this short series is to attract future or existing junior programmers and introduce them to Ruby in an interesting way.

If you want to take part in this journey please share these shorts in your circle as well. This takes so much time and effort for me to come up with a storyline, draw all the animations by hand, and then do a voiceover. One thing is for sure, RubyMan will only become stronger from here on...

Other than the #rubyman, I've tried unboxing a tech gadget that I ordered to help me increase my productivity while I'm coding. Here is the unboxing video, a full review will be up in a week or two, so stay tuned for that.

If you have come so far, and you think this #newsletter or any of my content is providing any value to you, consider subscribing for a paid version of this newsletter on substack. A small amount of paid subscribers can help me keep all of my content free for everybody else.

Still waiting to celebrate my first paid subscriber to this newsletter. Wanna be the first one? Click Here.

And that is it for this month's edition, I'll be back next month with more ruby updates.

Until we meet again ??

GM Vin

Software Developer, Trainer and Blogger at Freelance

1 年

Good work Sajjad! Happy anniversary ??

Nezir Zahirovi?

Ruby on Rails, JavaScript - Full Stack Web Developer 19 years of experience.

1 年

Good work Sajjad! Happy anniversary ??

要查看或添加评论,请登录

Sajjad Umar的更多文章

  • Ruby on Rails?—?March 2025

    Ruby on Rails?—?March 2025

    All the Rails News That Matters, Once a Month. Ramadan Kareem! ?? Wishing you all peace, blessings, and a month filled…

  • Ruby on Rails - Feb 2025

    Ruby on Rails - Feb 2025

    All the Rails News That Matters, Once a Month. Hey everyone—Sajjad Umar here with the February edition of Ruby on Rails…

  • Ruby on Rails — Jan 2025

    Ruby on Rails — Jan 2025

    All the Rails News That Matters, Once a Month. Happy New Year, everyone! ?? This is Sajjad Umar, kicking off 2025 with…

  • Ruby on Rails?—?Dec 2024

    Ruby on Rails?—?Dec 2024

    It's the only Ruby on Rails newsletter you will ever need! Hey guys?—?this is Sajjad Umar back with another edition of…

  • Ruby on Rails - Nov 2024 (Edition #35)

    Ruby on Rails - Nov 2024 (Edition #35)

    Welcome to the 35th Edition of Ruby on Rails Monthly - Sajjad here with some exciting updates from Ruby on Rails world.…

  • Ruby on Rails - Oct 2024

    Ruby on Rails - Oct 2024

    The only Ruby on Rails newsletter you will ever need! Hey Ruby folks?—?this is a fascinating month for the Ruby on…

    1 条评论
  • Ruby on Rails - September 2024

    Ruby on Rails - September 2024

    Welcome to the September 2024 edition of Ruby on Rails Monthly, this is Sajjad Umar your own Desi Developer. I have a…

    1 条评论
  • Ruby on Rails - Aug 2024

    Ruby on Rails - Aug 2024

    It's the only Ruby on Rails newsletter you will ever need! Rails 7.2 is out! There has been close to 2,500 commits made…

  • Ruby on Rails - July 2024

    Ruby on Rails - July 2024

    The only Ruby on Rails newsletter you will ever need! Welcome to the latest edition of the Ruby on Rails Monthly…

  • Ruby on Rails?—?June 2024

    Ruby on Rails?—?June 2024

    The only Ruby on Rails Newsletter you will ever need! Welcome to the latest edition of the Ruby on Rails Monthly…

社区洞察

其他会员也浏览了