scotdb01

scotdb01

Agile Web Development with Rails 7: Page 118 : Test fails

@rubys

Following through the book but using Rails 7.1.2.

When trying to run the test on page 118 I get -
`

Error:
ProductsControllerTest#test_can't_delete_product_in_cart:
ActiveRecord::RecordNotDestroyed: Failed to destroy Product with id=298486374
    app/controllers/products_controller.rb:52:in `destroy'
    test/controllers/products_controller_test.rb:58:in `block (2 levels) in <class:ProductsControllerTest>'
    test/controllers/products_controller_test.rb:57:in `block in <class:ProductsControllerTest>'


bin/rails test test/controllers/products_controller_test.rb:56


Finished in 0.706042s, 39.6577 runs/s, 86.3971 assertions/s.
28 runs, 61 assertions, 0 failures, 1 errors, 0 skips

Is this because of the different Rails version, or is this test not meant to pass?

Marked As Solved

rubys

rubys

Author of Agile Web Development With Rails

This is indeed a change in Rails 7.1, and thanks @novacose … I’ll include this change in the first update that targets a newer release of Rails.

Also Liked

novacose

novacose

@rubys

I decided to write my test like this

  test "can't delete product in cart" do
    assert_raises(ActiveRecord::RecordNotDestroyed) do
      delete product_url(products(:two))
    end

    assert Product.exists?(products(:two).id)

  end

Popular Pragmatic topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
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
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
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
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
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Latest in PragProg

View all threads ❯