This commit is contained in:
r888888888
2015-06-25 13:51:05 -07:00
parent 3cc7dbbedc
commit 1d9596d7f2
64 changed files with 244 additions and 140 deletions

View File

@@ -36,7 +36,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
should "promote the janitor trial" do
post :promote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
@user.reload
assert(@user.is_janitor?)
assert(@user.can_approve_posts?)
@janitor_trial.reload
assert_equal(false, @janitor_trial.active?)
end
@@ -50,7 +50,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
should "demote the janitor trial" do
post :demote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
@user.reload
assert(!@user.is_janitor?)
assert(!@user.can_approve_posts?)
@janitor_trial.reload
assert_equal(false, @janitor_trial.active?)
end

View File

@@ -4,6 +4,7 @@ class PostsControllerTest < ActionController::TestCase
context "The posts controller" do
setup do
@user = FactoryGirl.create(:user)
@api_key = ApiKey.generate!(@user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa")
@@ -19,7 +20,6 @@ class PostsControllerTest < ActionController::TestCase
context "passing the api limit" do
setup do
User.any_instance.stubs(:api_hourly_limit).returns(5)
ApiKey.generate!(@user)
end
should "work" do
@@ -35,30 +35,30 @@ class PostsControllerTest < ActionController::TestCase
context "using http basic auth" do
should "succeed for password matches" do
@basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@user.bcrypt_cookie_password_hash}")}"
@basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@api_key.key}")}"
@request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
get :index, {:format => "json"}
assert_response :success
end
# should "fail for password mismatches" do
# @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:badpassword")}"
# @request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
# get :index, {:format => "json"}
# assert_response 403
# end
should "fail for password mismatches" do
@basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:badpassword")}"
@request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
get :index, {:format => "json"}
assert_response 401
end
end
context "using the api_key parameter" do
should "succeed for password matches" do
get :index, {:format => "json", :login => @user.name, :api_key => @user.bcrypt_cookie_password_hash}
get :index, {:format => "json", :login => @user.name, :api_key => @api_key.key}
assert_response :success
end
# should "fail for password mismatches" do
# get :index, {:format => "json", :login => @user.name, :api_key => "bad"}
# assert_response 403
# end
should "fail for password mismatches" do
get :index, {:format => "json", :login => @user.name, :api_key => "bad"}
assert_response 401
end
end
context "using the password_hash parameter" do