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

@@ -1,34 +1,36 @@
require 'test_helper'
class UserUpgradesControllerTest < ActionController::TestCase
setup do
@admin = FactoryGirl.create(:admin_user)
@user = FactoryGirl.create(:user)
end
context "#create" do
if Danbooru.config.coinbase_secret
setup do
@encrypted = ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret).encrypt_and_sign("#{@user.id},#{User::Levels::GOLD}")
@admin = FactoryGirl.create(:admin_user)
@user = FactoryGirl.create(:user)
end
context "for basic -> gold" do
should "promote the account" do
post :create, {:order => {:status => "completed", :custom => @encrypted}}
context "#create" do
setup do
@encrypted = ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret).encrypt_and_sign("#{@user.id},#{User::Levels::GOLD}")
end
context "for basic -> gold" do
should "promote the account" do
post :create, {:order => {:status => "completed", :custom => @encrypted}}
assert_response :success
@user.reload
assert_equal(User::Levels::GOLD, @user.level)
end
end
end
context "#new" do
setup do
Coinbase::Client.any_instance.stubs(:create_button).returns(OpenStruct.new)
end
should "render" do
get :new, {}, {:user_id => @user.id}
assert_response :success
@user.reload
assert_equal(User::Levels::GOLD, @user.level)
end
end
end
context "#new" do
setup do
Coinbase::Client.any_instance.stubs(:create_button).returns(OpenStruct.new)
end
should "render" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
end
end

View File

@@ -34,14 +34,17 @@ FactoryGirl.define do
factory(:janitor_user) do
level 35
can_approve_posts true
end
factory(:moderator_user) do
level 40
can_approve_posts true
end
factory(:admin_user) do
level 50
can_approve_posts true
end
end
end

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

View File

@@ -22,10 +22,10 @@ class JanitorTrialTest < ActiveSupport::TestCase
end
end
should "toggle the janitor flag on the user" do
should "toggle the can_approve_posts flag on the user" do
janitor_trial = JanitorTrial.create(:user_id => @user.id)
@user.reload
assert(@user.is_janitor?)
assert(@user.can_approve_posts?)
end
end
@@ -39,6 +39,12 @@ class JanitorTrialTest < ActiveSupport::TestCase
@janitor_trial.demote!
end
end
should "revoke approval privileges" do
@janitor_trial.demote!
@user.reload
assert_equal(false, @user.can_approve_posts?)
end
end
context "upon promotion" do

View File

@@ -102,9 +102,9 @@ class TagTest < ActiveSupport::TestCase
MEMCACHE.flush_all
end
should "be lockable by a janitor" do
should "be lockable by a moderator" do
@tag = FactoryGirl.create(:tag)
@tag.update_attributes({:is_locked => true}, :as => :janitor)
@tag.update_attributes({:is_locked => true}, :as => :moderator)
@tag.reload
assert_equal(true, @tag.is_locked?)
end

View File

@@ -14,25 +14,25 @@ class WikiPageTest < ActiveSupport::TestCase
context "A wiki page" do
context "that is locked" do
should "not be editable by a member" do
CurrentUser.user = FactoryGirl.create(:janitor_user)
CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryGirl.create(:user)
@wiki_page.update_attributes(:body => "hello")
assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
end
should "be editable by a janitor" do
CurrentUser.user = FactoryGirl.create(:janitor_user)
should "be editable by a moderator" do
CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryGirl.create(:janitor_user)
CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page.update_attributes(:body => "hello")
assert_equal([], @wiki_page.errors.full_messages)
end
end
context "updated by a janitor" do
context "updated by a moderator" do
setup do
@user = FactoryGirl.create(:janitor_user)
@user = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
@wiki_page = FactoryGirl.create(:wiki_page)
end
@@ -53,7 +53,7 @@ class WikiPageTest < ActiveSupport::TestCase
should "not allow the is_locked attribute to be updated" do
@wiki_page.update_attributes(:is_locked => true)
assert_equal(["Is locked can be modified by janitors only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages)
assert_equal(["Is locked can be modified by moderators only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages)
@wiki_page.reload
assert_equal(false, @wiki_page.is_locked?)
end