...repositories. It's basically "Open Source Development 101". Way back in mid-2007, when Rails 1.2 was the new hotness and GitHub was still a year away from crawling out...
...saved to database directly as the the dumped object was not marked dirty, thus rails does not see the need to save it, even if the object is not present...
...add the following tests to test suites: # Make sure to require the previews Dir[Rails.root.join('spec/mailers/previews/*.rb')].each { |file| require(file) } ActionMailer::Preview.all.index_with(&:emails).each do |preview, mails|
Webpack is the future. We're using it in our latest Rails applications. For tests, we want to compile assets like for production. For parallel tests, we want to avoid...
...Dir.empty?(public_output_path) end delegate :public_output_path, to: :config private def test? Rails.env.test? end def parallel_tests? test? && !!parallel_tests_number end def parallel_tests_number
...our output will be more verbose than when we only need support modern browsers. Rails 5.1+ projects often use Webpacker to preconfigure the Webpack pipeline for us. The default configuration...
...have to run a separate process. # You'll also benefit from code reloading. if Rails.env.development? require 'sidekiq/testing' Sidekiq::Testing.inline!
tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/. The directory where you save your Paperclip attachments should not look like this: storage/photos/1...
...storage/test/photos/1/... storage/test/photos/2/... storage/test/attachments/1/... storage/test/attachments/2/... storage/test2/photos/1/... storage/test2/photos/2/... storage/test2/attachments/1/... storage/test2/attachments/2/... In order to implement this, make Rails.env and ENV['RAILS_TEST_NUMBER'] part of your path template: has_attached_file :attachment, :path...
Test one codebase against multiple sets of gem dependency sets (e.g. Rails 4.2, Rails 5.0). Test one codebase against multiple Ruby versions (e.g. Ruby 2.1.8, Ruby...
...possible dependency permutations (Ruby, gem set, database type). Manually exclude incompatible dependency permutations (e.g. Rails 5.0 does not work with Ruby 2.1). Let developers enter their local credentials for MySQL...
...mocked with Timecop. To integrate those two, we include and activate timemachine.js in our Rails layout whenever we see that Timecop is mocking the time: - if defined?(Timecop) && Timecop.top_stack...
...OVER() AS full_count FROM (/* some complicated subquery */) posts LIMIT 20 OFFSET 100; In Rails with will_paginate you might use it like this: posts = scope_complicated_scope.select('posts.*, COUNT(*) OVER() AS...
...for that. The reason why you never had to write this line is that Rails does this for you when it boots the environment. That also means that if you...
...have an embedded Rails app in your spec folder (like has_defaults), and you boot its environment, it should call Bundler.require for you and you don't need to require...
...For newer Ruby versions, use form_with_development_errors.rb. This monkey patches both form_for and form_with. Rails-XSS is required by default. So if your project doesn't support Rails-XSS...
...image running the headless Chrome (e.g. chrome:4444) The integration test is testing a Rails application (but it could be any other application, too) Start your integration test docker container...
...Stefan', color: 'red'} ] names = users.collect do |user| user[:name] end If you're using Rails 5+, this example is covered by Enumerable#pluck (users.pluck(:name)). But with a little extension...
...object-oriented scripting language Ruby rubymine 2018.3.2 jetbrains✓ classic The Most Intelligent Ruby and Rails IDE ... Switch channel and install most recent version: $ sudo snap refresh rubymine --channel=2018.2/stable...
...following project: ruby -v ruby 1.8.7 bundler -v Bundler version 1.13.7 gem -v 1.8.30 rails -v Rails 3.2.22.1 Running specs or features resulted in: uninitialized constant Gem::LOADED_SPECS_MUTEX...
...previous settings described in Maximum version of Rubygems and Bundler for Ruby 1.8.7 and Rails 2.3 (even the rails version was rails 3.2 and not 2.3) seems not to work...
...Note.all.preload(:attachments).ids.size # => 8 Note I created a bug report for this in the Rails project: https://github.com/rails/rails/issues/46455
...up on the disk check table sizes by disk usage instead. Connect to a Rails database with bin/rails dbconsole -p...
...want something similar, so we define our own helper object: let :helper do Spec::Rails::Example::HelperExampleGroup::HelperObject.new.tap do |helper| helper.send :extend, LayoutHelper end end it 'should work' helper.title('Hello...
helper.instance_variable_get('@content_for_title').should == 'Hello World' end This applies to Rails 2. Maybe RSpec 2 / Rails 3 are smarter...
...or controller) logic. Here is how. Note: this has only been tested on a Rails 2 application. It should work similarly for Rails 3. Put this into your ApplicationController:
Now you can use with_full_urls in views, helpers or controllers and Rails methods like url_for will generate "full" URLs that have a protocol and hostname. You...
Next, configure your application to use that middleware by putting this inside your Rails initializer block (config/environment.rb for Rails 2, config/application.rb for Rails 3): require 'lib/rack/cookie_stripper.rb' config.middleware.use Rack::CookieStripper...
...block where you define replacements (as you already know). This issue applies to both Rails 2 (with rails_xss) as well as Rails 3 applications. Here is a fix to...
...html_safe.gsub(/(f)/) { puts $1; 'b' } f => "boo" Why? This is because of the way rails_xss implements "unsafe" methods: # vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb UNSAFE_STRING_METHODS = [ ..., "gsub",...
for unsafe_method in UNSAFE...
...This is why we don't use "transactional fixtures" in our Cucumber tests, which Rails by default uses to clean up the database after each test. Instead we use DatabaseCleaner...
...can remove conditions, order, etc by using the unscope method. It is available on Rails 4+. Examples Consider an exemplary User class as follows. For the examples below, we will...
...scope of any constraints. users.unscoped ^ SELECT "users".* FROM "users" While unscope was introduced with Rails 4, the unscoped method has been around since Rails...