...bar']) => /tmp/foo20220912-14561-3g93n1bar You can choose a different base directory than Dir.tmpdir e.g. Dir.mktmpdir('foo', Rails.root.join('tmp')) => /home/user/rails_example/tmp/foo20220912-14561-pyr8qd. This might be necessary when your tests are running on CI. For this...

...something with a temporary directory' do # ... end Option 4: Without Dir.mktmpdir Use something like "#{Rails.env}#{ENV['TEST_ENV_NUMBER']}" in you directory path when using Dir.mkdir. Further reading:

...shell commands inside other bundles. Example outline Consider this setup: my_project/Gemfile # says: gem 'rails', '~> 3.0.0' my_project/foo/Gemfile # says: gem 'rails', '~> 3.2.0' And, just to confirm this, these are the...

...installed Rails versions for each of the bundles: ~/my_project$ bundle show rails .../gems/rails-3.0.20 ~/my_project$ cd foo && bundle show rails .../gems/rails-3.2.13 Now you will usually just use bundle exec to run...

Returning an empty scope can come in handy, e.g. as a default object. In Rails 4 you can achieve this by calling none on your ActiveRecord model. MyModel.none # returns an...

...empty ActiveRecord::Relation object For older Rails versions you can use the attached initializer to get a none scope...

options: { search: 'window.toString() === \'[object GjsGlobal]\'', replace: 'window.toString() === \'[object Window]\'' } }] }) Fix for ESBuild / jsbundling-rails Add the package esbuild-plugin-text-replace to your package.json. Now add the following plugin...

...webpack = require('webpack') environment.plugins.prepend('Provide', new webpack.ProvidePlugin({ getJasmineRequireObj: ['spec/support/jasmine_provider.js', 'default'], })) Fix for ESBuild / jsbundling-rails

makandra dev

...after_logout idp_sign_out] end Unsafe redirect when trying to log out Since Rails 7 you need to pass allow_other_host: true to redirect_to to allow a...

github.com

Params are tricky Testing for request params is a little tricky because Rails hides details about how HTTP works. In particular GET requests encode their params in the URL...

...a month or a year. Next, start your application server for HTTPS. For a Rails application with Puma: bin/rails server -b 'ssl://0.0.0.0:3000?key=development.key&cert=development.crt'

...many more processes than just your tests while your test suite is running: The Rails server booted by each test process (in a separate process) The Chrome browser started by...

...is good programming practice to Don't Repeat Yourself (or DRY). In Ruby on Rails we keep our code DRY by sharing behavior by using inheritance, modules, traits or partials...

...insert many records is to have a single INSERT statement describing multiple rows. In Rails 6+ you can do so with ActiveRecord::Base.insert_all. This is very fast, but you...

When a user shares your content, a snippet with title, image, link and description appears in her timeline. By default...

...up releases, not assets. In order to clean up assets, you can use capistrano-rails. Just require 'capistrano/rails' in Capfile and add the following config: # config/deploy.rb set :keep_assets...

...remove any older versions. If you are using Webpacker, you need to configure capistrano-rails. If you are on Rails 3, you cannot use this to clean up assets. :keep...

postgresql.org

...twentieth in what ordering? The ordering is unknown, unless you specified ORDER BY. In Rails, if you use Record.first or Record.last, it will default to ordering by id.

...used to match rows without knowing a secret token: Potential Query Manipulation with Common Rails Practises CVE-2013-3211 MySQL madness and Rails

makandra dev

...use a light terminal theme Improving Diffs for Ruby, RSpec and Cucumber files See Rails developers: Have better context in Git diffs. This will correctly identify the beginning of a...

...Probably the best approach is to just convert emails (and usernames) to lowercase within Rails. Popular authentication libraries (like Clearance and Devise) already do this for you...

thegnar.com

...your view might be too isolated, since view-specs will mock a lot of rails behavior and render the view independent from the controller-logic. Therefore it will be more...

masilotti.com

...Fixtures are handy for development seed data, they can be loaded in development with: rails db:fixtures:load Downsides Less matchers & library support It is harder to mock with minitest...

This RailsCast demonstrated a very convenient method to activate VCR for a spec by simply tagging it with :vcr. For RSpec3 the code looks almost the same with a few...

...vcr and webmock gems installed, simply include: # spec/support/vcr.rb VCR.configure do |c| c.cassette_library_dir = Rails.root.join("spec", "vcr") c.hook_into :webmock end RSpec.configure do |c| c.around(:each, :vcr) do |example|

...so that a tcp connection is used instead of a socket connection. Configure rails application to use the database development: adapter: mysql2 database: projectname_development encoding: utf8mb4 collation: utf8mb4_unicode...

makandra dev
github.com

...ETag for responses that only differ in CSRF tokens or CSP nonces. By default Rails uses Rack::ETag to generate ETag headers by hashing the response body. In theory this...

...would enable caching for multiple requests to the same resource. However, since most Rails application layouts insert randomly rotating CSRF tokens and CSP nonces into the HTML, two requests for...

kernel.org

...mind that you may need to migrate your database as Git is unaware of Rails and will not cast any magic. If Git checked out a commit that is working...

...delay of ~1 minute. Note: This setup does not work, when you use the Rails driven_by method with a binary preloading for parallel tests. CI Optionally you can use...

...The following setup allows you to start Terminator in a split view with the Rails server running in the left pane and all remaining processes running via foreman in the...

type = Terminal parent = child1 profile = default command = env startup_cmd="bundle exec rails server" startup_attrs="-p 3000" bash [[[terminal3]]] type = Terminal parent = child1 profile = default command = 'env startup...