expect(page).to have_css("h3", text: "Expected text here...")
click_button "Submit"
expect(page).to(
have_css("h3", text: "Expected text here..."),
"stay on page on invalid form submit"
)
# For database-backed models: | |
class Thing < ApplicationRecord | |
validates :name, presence: true | |
end | |
# For Plain Old Ruby Object models: | |
class Thing | |
include ActiveModel::Model | |
# Further defences to consider adding: | |
# - Restrict access to permitted IP address(es) | |
# - Use rack-attack to throttle requests and prevent brute force | |
# attack attempts to determine correct username and password | |
# - Favor long, random username and password | |
class Api::V1::ResultsController < Api::ApiController | |
def update | |
... | |
end |
# 1. Create a file class_variables.rb with the contents below | |
# 2. Run the file with `ruby class_variables.rb` in Terminal | |
# 3. Review the output and the code below and explore why: | |
# | |
# - the class variable @@total_results_count correctly counts the number | |
# of all Result instances. | |
# | |
# - the class variable @@errors does not track the errors for | |
# a single instance, instead it wrongly tracks *all* errors | |
# for all Result instances. |
This page lists the options for breaking single-line expressions into multiple lines in Ruby.
Developers and teams need to come to their own decisions about which guideline(s) they prefer (preferences below are just my personal choices and I encourage you to disregard them).
# With trailing parens
x = [1, 2, 3].join(
'-'
Source repos linked to from https://github.com/eliotsykes/real-world-rails/tree/master/apps
apps/advocate-defence-payments/Gemfile
apps/alonetone/Gemfile
apps/asciinema.org/Gemfile
apps/askthem/Gemfile
apps/atet/Gemfile
apps/catarse/Gemfile
apps/classroom/Gemfile
apps/cloudnet/Gemfile
require 'set' | |
def is_valid(code) | |
openers_to_closers = { | |
'(' => ')', | |
'{' => '}', | |
'[' => ']' | |
} | |
openers = Set.new(openers_to_closers.keys.to_set) |
Expect some false positives here, but hopefully most of these are open source Rails apps that use (or once used) AngularJS.
If you'd like to help update the list, please comment below with any of these apps you discover do not use AngularJS and include my username (@eliotsykes) in your message.
# Create file at lib/tasks/check_rollbar.rake | |
require 'securerandom' | |
# Run this with `heroku run rake check_rollbar` | |
desc "Check Rollbar reports errors raised in Rake tasks" | |
task check_rollbar: :environment do | |
unique_msg = "Hello from rake check_rollbar (unique identifier: #{SecureRandom.hex})" | |
begin | |
raise ActiveRecord::RecordNotFound, unique_msg |
Search done on collected Rails codebases at https://github.com/eliotsykes/real-world-rails/
$ ag -G Gemfile skylight
apps/adopt-a-hydrant/Gemfile.lock
181: skylight (0.10.6)
233: skylight