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 8086285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:24:00+00:00 2026-06-05T18:24:00+00:00

The first user in my DB is the Super Admin, and I don’t want

  • 0

The first user in my DB is the Super Admin, and I don’t want anyone to be able to edit the email address associated with that account, so I have the following model spec, which is failing.

# from my User model spec 
describe "super admin" do
 let(:super_admin){ FactoryGirl.create(:admin, email: "test@email.com") }
 it "can't be edited by anyone" do
    expect do
      super_admin.update_attributes(email: 'email@test.com')
    end.not_to change(super_admin, :email)
  end
end

My controller has a before filter which redirects any user who attempts to edit the first database entry (the Super Admin).

I’m worried that the test above is failing. Am I wrong to be testing this out in the model, when editing this particular user is locked down by the controller, or should I still expect it to pass regardless of whether it’s in a request spec or a model spec?

PS – User model has email (string) and admin (boolean) fields. SuperAdmin is just the first User from the database, who happens to be an admin, nothing fancy

  • 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-05T18:24:01+00:00Added an answer on June 5, 2026 at 6:24 pm

    If the “cannot be edited by anyone” behaviour lives in the User model, then I suppose models/user_spec.rb is a good place to put the test, but if the logic doesn’t actually live in the model, why should the spec concern the model at all?

    You placed the logic in the controller, so if I were you, I’d put the specs for that behavior in the controller spec instead.

    And to actually answer your question: No, model specs does not execute controller before_filters, since they don’t touch any controller code.

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

Sidebar

Related Questions

I am writing one of my first apps where the idea is that user
I need add the first_name and last_name fields associated with that User model and
Note: This might seem like a Super User question at first, but please read
I am building my first user control and I would like to package the
When registering my first user in table 'users' the id is the same value
I did this: [User.first, User.last].to_xml and got this: <users type=array> <user> <created-at type=datetime>2010-03-16T06:40:51Z</created-at> <id
long time reader first time user. I'm putting together my first RoR application and
For example: The list is list of Users First entry: User -> Id=111 name=aaa
For an app I'm developing for Facebook, when the user first logs in, I'd
I have an app with a UITextField, amongst other things. When the user first

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.