Reputation: 1194
I'm currently running the unit tests of my RoR application with Rspec. One of my controllers should return a HTTP status 500 when it can not write a new entity to the database. I wish to test this behaviour and would like temporarily to mark my database is read-only.
Does anyone know if it is possible to do this?
I tried the technique mentioned in "How do I prepare test database(s) for Rails rspec tests without running rake spec?", but this approach does not work for me (since the controller reads from the database before writing to it).
Upvotes: 1
Views: 867
Reputation: 2796
I think you can just mock out corresponding Model requests, if you are testing the controller.
So, what exception should Model.create
throw? Try something like this:
Model.stub(:create).and_raise(ActiveRecord::ReadOnlyRecord)
Upvotes: 2