Topic: [rSpec] Testing Database Interactions
Hello again, another rSpec question which I hope you can help with.
I have the following method in my User model
raise ArgumentError if activation_key.nil?
user = find_by_activation_key(activation_key)
raise ActivationCodeNotFound if !user
raise AlreadyActivated.new(user) if user.activated?
The private activate! method just updates activated_at and sets an instance variable.
How do I go about testing this using BDD and rSpec? I need something already in the database, but I don't think I can do a fixture because the activation key is randomly generated. Can I create a record in the example and then test that? Does that adhere to BDD best practices and how do I go about it?
Any help on this would be greatly appreciated!