drop_table :locks end end # spec/models/lock_spec.rb describe Lock, '.acquire' do before :each do @reader, @writer = IO.pipe end def fork_with_new_connection config = ActiveRecord::Base.remove_connection fork do

...the same lock' do (1..20).each do |i| fork_with_new_connection do @reader.close ActiveRecord::Base.connection.reconnect! Lock.acquire('lock') do @writer.puts "Started: #{i}" sleep 0.01 @writer.puts "Finished: #{i}" end @writer.close...

...use the expand_path method with either the constant __FILE__ or the method __dir__. Read this card for more information about __FILE__ and __dir__. Example Structure: . ├── bin │   ├── format_changelog ├── CHANGELOG.md...

...that using request.cookies and response.cookies is not recommend by RSpec anymore as can be read in the documentation link above. Model specs Whenever you have to use the same cookie...

...and write solid unit tests. Beware that your class will not be able to read the cookies, since they are only available within the controller and view context. Because of...

makandra dev

...Ruby will fall back on the method definition in the class itself. You can read more about that in Henning's card How Ruby method lookup works or in the...

...class in a much more convenient way than using alias_method_chain. You can read more about this here. As prepended modules should thus overwrite the existing method definition in...

...default property descriptor, use Object.defineProperty(object, key, descriptor). Let's use that to define a read-only property user.name: let user = {} Object.defineProperty(user, 'name', { value: 'Max', writable: false }) user.name // => 'Max...

Attribute Effect get A function that is called when the property is read ("getter") set A function that is called when the property is written ("Setter")

...is intended to give you an introduction to this emerging aspect of web development. Read this introductory performance study on Pinterest by Smashing Magazine. Frame Budget Most screens have a...

...box.offsetHeight); // Forces the browser to re-render *now* } Verdict: Make sure you always first read, then write style-relevant values. How to debug: Chrome shows warning icons in the event...

ruby-doc.org

...change that index node. In some cases it might also be convenient to just read/write the lock file first and update the other file afterwards or vice versa, such that...

The method You can define the following method to lock a file from read and write access by methods like File.open and File.read. def exclusively_locked_access begin

If required, add more feature files in the same manner. From these, the reader should understand everything to know about the new feature you're building.

...examples you can think of:

it ' ' it ' ' it '...' end From these, the reader should understand everything to know about that method. When you're done listing examples, start...

...to all (especially larger teams), we think it is a helpful starting point. First, read the Gatekeeping for developers guide, then ask your developers to read it and follow it...

...In the row below the dev tool tabs, there's a throttling dropdown which reads "Online" by default. Inside the dropdown, you will find a few presets and an option...

...the row right below the dev tool tabs you will find an option which reads "No throtteling" by default. Pick one of the presets available there. (Almost) any application: trickle...

...cards are our internal best practices and tips for our daily work. They are read worldwide by developers looking for help and tips on web development with Ruby on Rails...

...the expansion of the knowledge base. How does makandra cards work? Many of our readers stumble across our cards when they have a problem and are researching the topic in...

...only available from Rails 8. There are cases where it might be fine to read directly, like: # Okay User.find(params[:id]) This still relies on params[:id] existing, so your...

...url_for(params.to_unsafe_h)` We have an extra card on this topic. Further reading It's also worth to read Rails: Using require and permit for attributes when configuring...

makandra dev

...not very future-proof: It breaks the ESM spec that demands imported modules to be read-only. It only works in some versions of Webpack (tested on Webpacker 5.4 with...

...when dependencies need approval (it is also the output of the failing licenses spec): Read on to learn what to do about the output. All decisions are written to doc/dependency_decisions.yml...

...to detect it manually. Check if current versions sport a license. Check package.json, composer.json, README. Once you know the license, tell LicenseFinder with bundle exec license_finder licenses add $DEPENDENCY...

...you think that wrapping transfer_money in a transaction would help, you should re-read this article from the top. What you should do instead is to wrap critical code...

By default, Rails views escape HTML in any strings you insert. If you want to insert HTML verbatim, you need...

...only hides visually, not technically: the element is still focusable and visible to screen readers. So, how can we fade an element while maintaining accessibility? Enter visibility. It also hides...

...visibility, the hidden element is truly hidden and neither focusable nor visible to screen readers. Alternatives If you're starting your transition from JavaScript, you can give the element the...

Code quality can be measured in four levels: (Working code) Reliable code (minimum) Readable code (ok for short-lived code) Changeable code (standard level) The code quality of a project...

However, you should not stop here. Any piece of code is usually read may times, so please make it readable: 2. Readable code Your code is here to...

api.rubyonrails.org

...of this and just use a plan transaction do. If you need ActiveRecord::Rollback, read on. The basic problem Not all databases support nested transactions. Therefore, Rails will sometimes silently...

...Gemfile.lock could never indicate which version of a gem was installed, i.e. the Gemfile read nokogiri (1.12.5) although nokogiri (1.12.5-x86_64-linux) might actually be installed. In addition, there...

...versions of Bundler (at least since 2.3) have two different behaviors: If your Gemfile.lock reads PLATFORMS: ruby, it might either install a compatible platform-specific version, or the plain ruby...

...make custom transcoding/conversion logic working. Unless you adapt your processor, this will now fail. Read the following paragraph on why and how to fix it. The workfile_path breaking custom...

...probably why CarrierWave 3.x introduces the new behavior, below. Still, FFMPEG will then read the video file, extract the first frame image and save it to the thumbnail.jpg file...

...are three examples how you can avoid polluting the global namespace. You can also read the Rubocop docs on LeakyConstantDeclaration about this topic. When would I need this?

w3c.github.io

...This can be useful for debugging. The following example visits a web page and reads the a headline's text contents. Create a session. You will get a JSON response...

...d '{"using":"tagName","value":"h1"}' {"sessionId":"...","status":0,"value":{"ELEMENT":"element-object-id-here"}} Read the element's text content by using the element's identifier received above:

...have just merged the branch \"$merged_branch_name\" into \"$branch_name\". " # Ask the question read -p "> Do you want to push \"$branch_name\" + delete the \"$merged_branch_name\" branch? (y/N...