bradleyscollins
Agile Web Development with Rails 8: Outdated Content and Mild Technical Critique (p. 223)
The 2nd bullet on p. 223 reads as follows (highlighting mine):
- The system test in
test/system/users_test.rbwas generated by the scaffolding
generator we used at the start of the chapter. Those tests don’t pass. See
if you can get them to pass without breaking the other system tests. You’ll
recall we created the moduleAuthenticationHelpersand included it in all of
the system tests by default, so you might need to change the code to not
do that so that you can properly test the login functionality.
This bullet is the only place the text “AuthenticationHelpers” appears in the Rails 8 version of the book. It looks as if there has not been a proper AuthenticationHelpers module since the version of the book on Rails 6.
Additionally, we did not technically include it in the system tests. We monkey-patched ActiveSupport::TestCase. The get and set methods are only defined in ActionDispatch::IntegrationTest. Consequently, login_as() works in controller tests but fails in system tests.
I wonder if an approach more like the one in the Rails 6 version of the book might serve us better:
module AuthenticationHelpers
def login_as(user)
if respond_to? :visit
visit login_url
fill_in :name, with: user.name
fill_in :password, with: 'secret'
click_on 'Login'
else
post login_url, params: { name: user.name, password: 'secret' }
end
end
def logout
delete logout_url
end
def setup
login_as users(:one)
end
end
class ActionDispatch::IntegrationTest
include AuthenticationHelpers
end
class ActionDispatch::SystemTestCase
include AuthenticationHelpers
end
Or perhaps ditch conditional logic and implement login_as() separately in each monkey-patch:
module AuthenticationHelpers
def logout
delete logout_url
end
def setup
login_as users(:one)
end
end
class ActionDispatch::IntegrationTest
include AuthenticationHelpers
def login_as(user)
post login_url, params: { name: user.name, password: 'secret' }
end
end
class ActionDispatch::SystemTestCase
include AuthenticationHelpers
def login_as(user)
visit login_url
fill_in :name, with: user.name
fill_in :password, with: 'secret'
click_on 'Login'
end
end
Just some thoughts.
Popular Pragmatic Bookshelf topics
Other popular topics
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /html
- /opensuse
- /zig
- /centos
- /deepseek
- /php
- /scala
- /react-native
- /textmate
- /lisp
- /sublime-text
- /debian
- /nixos
- /agda
- /django
- /kubuntu
- /arch-linux
- /deno
- /nodejs
- /revery
- /ubuntu
- /spring
- /manjaro
- /diversity
- /lua
- /markdown
- /julia
- /slackware








