...uses mocha. This note shows to use RSpec stubs and mocks instead. Rspec 1 / Rails 2 Put the following into your env.rb: require 'spec/stubs/cucumber' Rspec 2 / Rails 3
...t like an ActiveSupport::HasWithIndifferentAccess. There are also some issues if you are on Rails < 4.1 and want it to replace #to_json (but you can always just call Oj.dump...
What I did test successfully was the workaround below. Workaround In Rails 4 you can wrap the output of Oj.dump(...) in an escape_json tag to escape...
...page for more information on calculating sizes of databases or tables. Connect to a Rails database with bin/rails dbconsole -p...
...not doing this. Use form models or vanilla methods instead. The :conditions option for Rails associations cannot take a lambda. This makes it hard to define conditions that must be...
...a typo. It's to prevent Ruby from interpolating the string at compile time. Rails is aware of this hack and will perform interpolation at runtime. See this article for...
.../../../../../../../../../etc/passwd%%0000.html) Someone tries to exploit CVE-2019-5418. If you use the latest Rails (or latest Rails LTS) you're safe. The exact versions that fix this issue are...
...Rails 6.0.0.beta3, 5.2.2.1, 5.1.6.2, 5.0.7.2, 4.2.11.1, Rails LTS 3.2.22.13 and Rails LTS...
After upgrading to Rails 6.1.7.2 one of our apps printed a wall of warnings while booting: /var/www/app/shared/bundle/ruby/2.6.0/gems/net-protocol-0.2.1/lib/net/protocol.rb:68: warning: already initialized constant Net::ProtocRetryError /home/deploy-app/.rbenv/versions/2.6.10/lib/ruby/2.6.0/net/protocol.rb:66: warning: previous definition of...
You will need to upgrade to RSpec >= 2 and rspec-rails >= 2 for Rails 3. Here are some hints to get started: In RSpec 2 the executable is rspec, not...
RSpec and rspec-rails have been completely refactored internally. All RSpec classes have been renamed from Spec::Something to RSpec::Something. This also means that every require 'spec/something' must...
If you want to make your Rails application be capable of sending SMTP emails, check out the action mailer configuration section in the Ruby on Rails guide.
...in your environment or individually applied to an email generated in your mailer: # production.rb: Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = smtp_settings end # test_mailer.rb def test_mail
Spring is a Rails application preloader. When debugging e.g. the rails gem, you'll be wondering why your raise, puts or debugger debugging statements have no effect. That's because...
...you can only write environment variables that subprocesses will see. For tests with a Rails application (i.e., that call rails or rake or other binstubbed commands), this method may help...
...fixing errors as they occur: Update gems as listed below, and bundle Boot a Rails console - see below for a list of changes you will probably need Run Specs with...
...constraints as possible. Boot the application in different environements to spot further issues, e.g. rails console staging Gem updates Replace ruby-debug with byebug or pry Replace mysql with mysql2...
...the standard configuration, though, it does not interpret the escape sequences used in the rails logfiles. To enable this type: less -R my_logfile.log You can also have an alias to...
...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...
Expiration of Rails sessions By default Rails sessions expire when the user closes her browser window. To change this edit your config/initializers/session_store.rb like this: ActionController::Base.session = { :key => '...', :secret => '...' :expire_after...
} In older Railses the initializer is not available. Set the option in the environment.rb instead: config.action_controller.session = { :key => '...', :secret => '...' :expire_after => 10.years } Expiration of Rails cookies In addition to the...
...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...
...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...
...they won't change their mind. [1] We are not talking about the the Rails session cookie here, though it often is a session cookie...
...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...
The ActionDispatch module of Rails gives you the helper method flash to access the flash messages in a response. describe PostsController, type: :request do describe 'update' do it 'shows a...
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...
You will get this when you are using the latest version of Rails with a recent version of Rack: SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
...future versions will even invalidate your existing user cookies. The warning is caused by Rails calling Rack incorrectly. It is unclear when this is going to be fixed in Rails...
...helps to modify the Accept-Language in tests. Here is an example for a Rails application with Cucumber integration tests: class ApplicationController OVERRIDE_HTTP_ACCEPT_LANGUAGE = nil def accept_language...
...tokens or CSP nonces. We have deprecated Rack::SteadyETag. We instead recommend reconfiguring your Rails app so two requests to the same resource produce the same HTML for a given...
There is a nasty bug in all version of Rails 2 and some versions of Rails 3.x where two chained scopes with hash conditions on the same attribute would...
...what a user may see or change. Workaround If you are using an affected Rails version and cannot switch to a fixed version, you can use this manual workaround.
...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...