Hi,
In a controler, how can we check that we are running a test (rake test).
Is there a connection object?
On 26 Aug 2008, at 10:54, Robert Plagnard wrote:
Hi,
In a controler, how can we check that we are running a test (rake
test).
Is there a connection object?
Check the value of RAILS_ENV
Fred
Frederick C. wrote:
On 26 Aug 2008, at 10:54, Robert Plagnard wrote:
Hi,
In a controler, how can we check that we are running a test (rake
test).
Is there a connection object?Check the value of RAILS_ENV
Fred
Super,
Thanks
Robert
On Tue, Aug 26, 2008 at 2:54 AM, Robert Plagnard
[email protected] wrote:
Hi,
In a controler, how can we check that we are running a test (rake test).
Is there a connection object?
I can’t help but ask… why?
Curious,
Robby
–
Robby R.
Chief Evangelist, Partner
PLANET ARGON, LLC
design // development // hosting
http://www.robbyonrails.com/
aim: planetargon
+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]
Robby R. wrote:
On Tue, Aug 26, 2008 at 2:54 AM, Robert Plagnard
[email protected] wrote:Hi,
In a controler, how can we check that we are running a test (rake test).
Is there a connection object?I can’t help but ask… why?
Curious,
Robby–
Robby R.
Chief Evangelist, PartnerPLANET ARGON, LLC
design // development // hostinghttp://www.planetargon.com/
http://www.robbyonrails.com/
aim: planetargon
Hi,
I am studying Noel Rappin’s “Professional Ruby on Rails” excellent book.
I met the problem of update user.is_active attribute p 83.
In users_controller :
def activate
find_user
@is_valid = Token.is_valid_for_user(@user, param[:token])
@user.update_attributes(:is_active=>@is_valid)
end
Everything was fine except that user.is_active was staying desperatly
false!
After replacing update_attributes by update_attributes! I found the
reason why. The user record was not valid because of the constraint :
validates_length_of :password, :minimum => 6
But the password is not stored in user, we only have encrypted_password.
It will not be a problem in production because we will have the password
at this moment.
But during the test, it’s not the case. And then you have 2 solutions :
One used by NR which is to comment the constraint to pass the test. I
don’t like it to much. The other idea was, when in test, to set a
password just before update the user record :
if RAILS_ENV = ‘test’
@user.password= ‘123456’
end
@user.update_attributes(:is_active=>@is_valid)
I don’t know if I was understandable, but it works as I want.
Robert
Robert Plagnard wrote:
In a controler, how can we check that we are running a test (rake
test).
Is there a connection object?
Check the value of RAILS_ENV
Now confess why your code needs to know that. You should either write
the code
to work no matter what its environment, or you should use a mock.
If you want to use Mocha, use any_instance if you don’t know which
instance your
controller will construct…
–
Phlip