25 May 2012, 14:12
Generic-user-small

John Lane (6 posts)

I am working through the examples in the cucumber book. At chapter 15 I have added the search feature and step but I get a different error when trying to run cucumber.

I get:

@Can’t mass-assign protected attributes: user (ActiveModel::MassAssignmentSecurity::Error) ./features/step_definitions/user_steps.rb:15:in /^a User has posted the following messages:$/' features/search.feature:3:in Given a User has posted the following messages:’@

instead of

@No route matches [GET] “/search” (ActionController::RoutingError)@

I am using rails 3.2.3 in case that’s the cause here.

TO fix, I modified user_steps.rb:

Changed:

@message_attrs.merge({:user => user})@

to:

@message_attrs.merge({:user_id => user})@

28 May 2012, 09:12
Avatar_pragsmall

Matt Wynne (86 posts)

Thanks for posting the fix.

Yes, this is caused by a difference between the version of Rails we used in the book (3.1.3) and this newer version. You’ll need to use the exact same versions of all the gems and libraries as we’ve used in the book, otherwise things like this are bound to happen.

There are instructions in the appendix for ensuring you use the same set of gems as were used in the book.

30 Apr 2013, 18:01
Generic-user-small

Barry Collier (1 post)

UPDATE: The issue noted below is already reported in the errata (#50823): http://pragprog.com/titles/hwcuc/errata

FYI - the version of the book that I have (bought within the last few weeks) actually shows that same error in the actual text of the book throughout the entire 15th chapter.

For example, at the end of the chapter when you run cucumber the last time and show the expected results in the book, mine actually contains the following text:


And finally Cucumber is happy:

Feature: Search
Scenario: Find messages by content
Given a User has posted the following messages:
| content |
| I am making dinner |
| I just woke up |
| I am going to work |

Can’t mass-assign protected attributes: user (ActiveModel::MassAssignmentSecurity::Error) ./features/step_definitions/user_steps.rb:16


Matt Wynne; Aslak Hellesø y. The Cucumber Book, P2.0 (Barry Collier) (Kindle Locations 8368-8383). The Pragmatic Bookshelf (418844). 
  You must be logged in to comment