API: fix api limits being lowered when user doesn't have api key.
This commit is contained in:
@@ -606,9 +606,9 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
def api_regen_multiplier
|
def api_regen_multiplier
|
||||||
# regen this amount per second
|
# regen this amount per second
|
||||||
if is_platinum? && api_key.present?
|
if is_platinum?
|
||||||
4
|
4
|
||||||
elsif is_gold? && api_key.present?
|
elsif is_gold?
|
||||||
2
|
2
|
||||||
else
|
else
|
||||||
1
|
1
|
||||||
@@ -618,9 +618,9 @@ class User < ActiveRecord::Base
|
|||||||
def api_burst_limit
|
def api_burst_limit
|
||||||
# can make this many api calls at once before being bound by
|
# can make this many api calls at once before being bound by
|
||||||
# api_regen_multiplier refilling your pool
|
# api_regen_multiplier refilling your pool
|
||||||
if is_platinum? && api_key.present?
|
if is_platinum?
|
||||||
60
|
60
|
||||||
elsif is_gold? && api_key.present?
|
elsif is_gold?
|
||||||
30
|
30
|
||||||
else
|
else
|
||||||
10
|
10
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ require 'test_helper'
|
|||||||
class ApiKeyTest < ActiveSupport::TestCase
|
class ApiKeyTest < ActiveSupport::TestCase
|
||||||
context "in all cases a user" do
|
context "in all cases a user" do
|
||||||
setup do
|
setup do
|
||||||
@user = FactoryGirl.create(:user, :name => "abcdef")
|
@user = FactoryGirl.create(:gold_user, :name => "abcdef")
|
||||||
@api_key = ApiKey.generate!(@user)
|
@api_key = ApiKey.generate!(@user)
|
||||||
@user.name.mb_chars.downcase
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "authenticate via api key" do
|
should "authenticate via api key" do
|
||||||
@@ -19,5 +18,11 @@ class ApiKeyTest < ActiveSupport::TestCase
|
|||||||
should "not authenticate with the wrong name" do
|
should "not authenticate with the wrong name" do
|
||||||
assert_nil(User.authenticate_api_key("xxx", @api_key.key))
|
assert_nil(User.authenticate_api_key("xxx", @api_key.key))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "have the same limits whether or not they have an api key" do
|
||||||
|
assert_no_difference(["@user.reload.api_regen_multiplier", "@user.reload.api_burst_limit"]) do
|
||||||
|
@user.api_key.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user