Fixed that rss key is generated twice when user is not reloaded (#10668).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9419 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
9817e1d744
commit
24c361eb0a
|
@ -284,14 +284,18 @@ class User < Principal
|
||||||
|
|
||||||
# Return user's RSS key (a 40 chars long string), used to access feeds
|
# Return user's RSS key (a 40 chars long string), used to access feeds
|
||||||
def rss_key
|
def rss_key
|
||||||
token = self.rss_token || Token.create(:user => self, :action => 'feeds')
|
if rss_token.nil?
|
||||||
token.value
|
create_rss_token(:action => 'feeds')
|
||||||
|
end
|
||||||
|
rss_token.value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return user's API key (a 40 chars long string), used to access the API
|
# Return user's API key (a 40 chars long string), used to access the API
|
||||||
def api_key
|
def api_key
|
||||||
token = self.api_token || self.create_api_token(:action => 'api')
|
if api_token.nil?
|
||||||
token.value
|
create_api_token(:action => 'api')
|
||||||
|
end
|
||||||
|
api_token.value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return an array of project ids for which the user has explicitly turned mail notifications on
|
# Return an array of project ids for which the user has explicitly turned mail notifications on
|
||||||
|
|
|
@ -585,6 +585,22 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert_equal key, @jsmith.rss_key
|
assert_equal key, @jsmith.rss_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rss_key_should_not_be_generated_twice
|
||||||
|
assert_difference 'Token.count', 1 do
|
||||||
|
key1 = @jsmith.rss_key
|
||||||
|
key2 = @jsmith.rss_key
|
||||||
|
assert_equal key1, key2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_api_key_should_not_be_generated_twice
|
||||||
|
assert_difference 'Token.count', 1 do
|
||||||
|
key1 = @jsmith.api_key
|
||||||
|
key2 = @jsmith.api_key
|
||||||
|
assert_equal key1, key2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "User#api_key" do
|
context "User#api_key" do
|
||||||
should "generate a new one if the user doesn't have one" do
|
should "generate a new one if the user doesn't have one" do
|
||||||
user = User.generate_with_protected!(:api_token => nil)
|
user = User.generate_with_protected!(:api_token => nil)
|
||||||
|
|
Loading…
Reference in New Issue