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

telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
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
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
PragmaticBookshelf
Learn from the award-winning programming series that inspired the Elixir language, and go on a step-by-step journey through the most impo...
New
PragmaticBookshelf
Write Elixir tests that you can be proud of. Dive into Elixir’s test philosophy and gain mastery over the terminology and concepts that u...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
PragmaticBookshelf
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
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

Sub Categories: