]> source.dussan.org Git - redmine.git/commitdiff
Make sure the RSS token is getting destroyed and created.
authorEric Davis <edavis@littlestreamsoftware.com>
Mon, 21 Dec 2009 02:24:49 +0000 (02:24 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Mon, 21 Dec 2009 02:24:49 +0000 (02:24 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3210 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/my_controller.rb
test/functional/my_controller_test.rb

index da34418f8b0acc1b9dc9cfa3c6904d8fd5bd1bc7..64687d87e34db8839a4dd89c6acfe12900902f9e 100644 (file)
@@ -97,8 +97,12 @@ class MyController < ApplicationController
   
   # Create a new feeds key
   def reset_rss_key
-    if request.post? && User.current.rss_token
-      User.current.rss_token.destroy
+    if request.post?
+      if User.current.rss_token
+        User.current.rss_token.destroy
+        User.current.reload
+      end
+      User.current.rss_key
       flash[:notice] = l(:notice_feeds_access_key_reseted)
     end
     redirect_to :action => 'account'
index ef12d78646cbd00b3398a9aa82e26cfa0ecfa880..b87180745b0aead246501ce21dad1314cd8bbafe 100644 (file)
@@ -129,4 +129,38 @@ class MyControllerTest < ActionController::TestCase
     assert_response :success
     assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
   end
+
+  context "POST to reset_rss_key" do
+    context "with an existing rss_token" do
+      setup do
+        @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
+        post :reset_rss_key
+      end
+
+      should "destroy the existing token" do
+        assert_not_equal @previous_token_value, User.find(2).rss_key
+      end
+
+      should "create a new token" do
+        assert User.find(2).rss_token
+      end
+
+      should_set_the_flash_to /reset/
+      should_redirect_to('my account') {'/my/account' }
+    end
+    
+    context "with no rss_token" do
+      setup do
+        assert_nil User.find(2).rss_token
+        post :reset_rss_key
+      end
+
+      should "create a new token" do
+        assert User.find(2).rss_token
+      end
+
+      should_set_the_flash_to /reset/
+      should_redirect_to('my account') {'/my/account' }
+    end
+  end
 end