bradleyscollins

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.rb was 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 module AuthenticationHelpers and 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.

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New
New

Other popular topics Top

mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
PragmaticBookshelf
Programming Ruby is the most complete book on Ruby, covering both the language itself and the standard library as well as commonly used t...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
New
First poster: AstonJ
Jan | Rethink the Computer. Jan turns your computer into an AI machine by running LLMs locally on your computer. It’s a privacy-focus, l...
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New
mindriot
Ok, well here are some thoughts and opinions on some of the ergonomic keyboards I have, I guess like mini review of each that I use enoug...
New

Sub Categories: