]> source.dussan.org Git - redmine.git/commitdiff
Fixed that Token.destroy_expired destroys API tokens.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Apr 2012 15:44:51 +0000 (15:44 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Apr 2012 15:44:51 +0000 (15:44 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9420 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/token.rb
test/unit/token_test.rb

index c6425f0faa067b8c2085fb472351ff6e67992c62..e979602515c3e3a2a1f08c910befcb2e85b04ccb 100644 (file)
@@ -34,7 +34,7 @@ class Token < ActiveRecord::Base
 
   # Delete all expired tokens
   def self.destroy_expired
-    Token.delete_all ["action <> 'feeds' AND created_on < ?", Time.now - @@validity_time]
+    Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - @@validity_time]
   end
 
 private
index 54c1cc9c82986fab927c65a5ea2676f0259e5d4f..fca97f6308545c4a725b90b9501c43ee1b80be9f 100644 (file)
@@ -35,4 +35,27 @@ class TokenTest < ActiveSupport::TestCase
     assert !Token.exists?(t1.id)
     assert  Token.exists?(t2.id)
   end
+
+  def test_destroy_expired_should_not_destroy_feeds_and_api_tokens
+    Token.delete_all
+
+    Token.create!(:user_id => 1, :action => 'api', :created_on => 7.days.ago)
+    Token.create!(:user_id => 1, :action => 'feeds', :created_on => 7.days.ago)
+
+    assert_no_difference 'Token.count' do
+      assert_equal 0, Token.destroy_expired
+    end
+  end
+
+  def test_destroy_expired_should_destroy_expired_tokens
+    Token.delete_all
+
+    Token.create!(:user_id => 1, :action => 'autologin', :created_on => 7.days.ago)
+    Token.create!(:user_id => 2, :action => 'autologin', :created_on => 3.days.ago)
+    Token.create!(:user_id => 3, :action => 'autologin', :created_on => 1.hour.ago)
+
+    assert_difference 'Token.count', -2 do
+      assert_equal 2, Token.destroy_expired
+    end
+  end
 end