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
If the “cannot be edited by anyone” behaviour lives in the User model, then I suppose
models/user_spec.rbis 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.