Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9215873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:17:57+00:00 2026-06-18T02:17:57+00:00

I am going through Hartl’s Rails Tutorial. I’m up to the first exercise of

  • 0

I am going through Hartl’s Rails Tutorial. I’m up to the first exercise of 9.6, where he asks me to test that the User admin attribute isn’t accessible. The justification is earlier in the book:

After Listing 9.42, Hartl’s Rails Tutorial says

If we omitted the attr_accessible list in the User model (or foolishly added :admin to the list), a malicious user could send a PUT request as follows:

put /users/17?admin=1

The corresponding exercise (exercise 9.6.1) in the tutorial says

add a test to verify that the User admin attribute isn’t accessible

I have completed that test with this code in user_spec.rb:

expect do
  @user.update_attributes(:admin => true)
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)

But I used stackoverflow to get that test. This was my original idea (in user_pages_spec.rb):

expect do
    put user_path(user) + "?admin=1"
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error) # or some other error

But I couldn’t get it to work.

So my questions are:

  1. Is my idea possible? Isn’t it better to test directly for what a potential hacker might do from the command line? Isn’t that the idea of Capybara, testing user actions?

  2. If it is possible, is there a difference between testing mass assignment and testing the PUT action?

  3. If it isn’t possible, why? Is it just not necessary or am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:17:58+00:00Added an answer on June 18, 2026 at 2:17 am

    I think I would argue with you that your test is actually better. Some would argue that the given answer is testing Rails functionality which really isn’t your job. However, I do think it’s frequently good to test things in several different directions.

    I was under the impression from back in my school days that it was impossible to send data via the URI except when doing a GET. A quick search of stackoverflow didn’t result in any confirmation. However, the wikipedia article seems to imply it:

    http://en.wikipedia.org/wiki/POST_%28HTTP%2

    I think the correct line of code would be

    put user_path(user), {user: {admin: 1}, id: user.id}
    

    I hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn to use Ruby on Rails (going through Hartl's tutorial for
I'm currently going through Michael Hartl's tutorial Ruby on Rails Tutorial http://ruby.railstutorial.org/ruby-on-rails-tutorial-book . I'm
I'm going through Michael Hartl's Ruby on Rails 3.2 Tutorial and I'm confused about
While going through Ruby On Rails Tutorial by Michael Hartl,in the section where the
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
I'm just starting to learn rails, and after going through Michael Hartl's Learn Rails
While going through the Learn Rails book written by Michael Hartl, I'm stumped on
So I'm going through Hartl's Tutorial on RoR and I'm at the end of
I'm going through Michael Hartl's Railstutorial and I am stuck on Exercise 9.6.2. I
I am going through the great Michael Hartl tutorial to build ruby app here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.