edgeapi.rubyonrails.org

The linked article suggests an interesting way to speed up tests of Rails + Postgres apps: PostgreSQL allows the creation of “unlogged” tables, which do not record data in the PostgreSQL...

...the project might need to re-recreate their test databases like so: bundle exec rails parallel:drop && bundle exec rails parallel:prepare

makandra dev

position: relative left: -50% float: left .clear clear: both Together with this helper: # Rails 3 def center_float(&block) concat( content_tag(:div, :class => 'center_float_outer_container') do...

...tag(:div, :class => 'center_float', &block) end end + content_tag(:div, :class => 'clear') ) end # Rails 2 def center_float(&block) html = "".html_safe html << content_tag(:div, :class => 'center_float...

...in webpack.config.js: { ... optimization: { minimize: true, minimizer: [ new TerserPlugin({ terserOptions: { ..., mangle: { properties: { regex: /^[_#]/ } } } }) ] } } Configuring Webpacker (Rails) To configure Webpack to mangle private properties, make a change to your Terser configuration in...

.sort_by(&:last) .to_h end end Just paste that snippet into a Rails console and use #count_by now! Usage examples Number of email addresses by domain: > User.all.count...

...Article.all.count_by &:brand Note that the last simple example can also be achieved with Rails internals: Article.group(:brand).count. This translates to SQL, so it executes fast. However, grouping is...

...like above: new(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout') Difference between Rails mailer and ERB Rails mailer <% if true %> <%= 'bar' %> <% end %> <%= 'foo' %> <%= 'bar' %> bar foo bar

...this requires the PP class from the pp gem. It is loaded in any Rails app already, but for plain Ruby you may need to require it.

blog.bigbinary.com

...posts"."user_id" = "users"."id" WHERE (posts.id > 10) Using includes usually works nicely, but Rails will apply some magic, as mentioned at the beginning of this card. This is subject...

This is quite an edge case, and appears like a bug in Rails (4.2.6) to me. Update: This is now documented on Edgeguides Ruby on Rails: If you set the...

The goal is to get Jasmine specs running in a Rails project using Webpacker, with the browser based test runner. Should be easily adaptable to a pure Webpack setup.

...is still true', () => { expect(true).toBe(true) }) }) Step 3: Add a /jasmine page in Rails # config/routes.rb Rails.application.routes.draw do # ... if Rails.env.development? || Rails.env.test? get 'jasmine', to: 'jasmine#index' end end # app/controllers/jasmine_controller.rb

github.com

RSpec.configure do |config| config.include Aegis::Matchers end In very old versions of Rails and RSpec you need to do this instead: ActiveSupport::TestCase.send :include, Aegis::Matchers

...issues in specific scenarios. Why does this matter? Mocked time in tests Consider a Rails application where you use the remember_me feature of Clearance for authentication. The cookie for...

When your Rails application offers downloading a bunch of files as ZIP archive, you basically have two options: Write a ZIP file to disk and send it as a download...

...Add zip_tricks to your Gemfile and bundle install. In your controller, include ZipTricks::RailsStreaming. You can then use the zip_tricks_stream method in controller actions to generated your...

...at self.class.ancestors. For example: config.before do # stuff that_fancy_method if is_a? Spec::Rails::Example::ControllerExampleGroup # more stuff end Find out if you are in a spec that knows...

...s request and response, like helper specs or controller specs: if is_a? Spec::Rails::Example::FunctionalExampleGroup that_fancy_request_thing end Note that you should not check via something...

We recently migrated a Rails application from yarn to npm. We decided to go this step instead of upgrading to > Yarn 2.0 to reduce the number of dependencies in our...

...your yarn.lock (after the first npm install you can relax the constraints again). jsbundling-rails supports NPM since v1.2.2. geordi supports package managers other than yarn since v11.1.0...

makandra dev
relishapp.com

...are verified. Note that this is enabled by default when you are using rspec-rails along with verifying doubles. So if you really need to verify some dynamically defined methods...

github.com

...This is arguably a good idea. As a workaround, use stub_const in your Rails specs like this: stub_const "#{SomeClass}::CONST", 'test' This will invoke Rails' autoloading and fix...

...end-to-end test for every small requirement. After we integrated Jasmine into a Rails app we often add an E2E test that opens that Jasmine runner and expects all...

...not rendered in controller specs. If you need it to happen, use: RSpec 1 (Rails 2): integrate_views RSpec 2 (Rails 3): render_views Note that you can't use...

...a command on all servers. bundle exec cap production app:run cmd='zgrep -P "..." RAILS_ROOT/log/production.log' Code # lib/capistrano/tasks/app.rake namespace :app do # Use e.g. to grep logs on all servers:

...cap production app:run_cmd cmd='zgrep -P "..." RAILS_ROOT/log/production.log' # # * Use RAILS_ROOT as a placeholder for the remote Rails root directory. # * Append ` || test $? =1;` to grep calls in order...

...and decide if any of it needs an update. Your main components (e.g. Ruby, Rails, Unpoly) should always be reasonably up to date. Keeping your dependencies up-to-date is...

...your jQuery version if desired. Here is an example how this might look: { "dependencies": { "@rails/webpacker": "4.x", "bootstrap-datepicker": "1.8.0", "bootstrap-sass": "3.4.1", "font-awesome": "4.7.x", "jquery": "2.2.4",

...be done by compiling the packs for production and search for a working example: RAILS_ENV=production bundle exec rake assets:precompile. Remember to remove the folder public/packs afterwards...

...does not apply to your "Background" steps How to set up database_cleaner for Rails with Cucumber and RSpec Before all in database transactions will fail

There is a way to use multiple databases in Rails. You may have asked yourself how you're able to keep your test databases clean, if you're running multiple...

...records to check if the migration works properly with those. after_initialize :readonly!, unless: -> { Rails.env.test? } end When defining multiple adapters in your database.yml, Rails needs to decide which one to...

...prevent this, you need to add ->{ uniq } as second argument to has_many (below Rails 4 it is a simple option: has_many :xyz, :uniq => true). Example