mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 13:11:18 +08:00
Fix all the errors to get our tests green on Rails 5.1.
This commit is contained in:
@ -14,19 +14,19 @@ describe Admin::UsersController do
|
||||
|
||||
context '.index' do
|
||||
it 'returns success' do
|
||||
xhr :get, :index
|
||||
get :index, format: :json
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'returns JSON' do
|
||||
xhr :get, :index
|
||||
get :index, format: :json
|
||||
expect(::JSON.parse(response.body)).to be_present
|
||||
end
|
||||
|
||||
context 'when showing emails' do
|
||||
|
||||
it "returns email for all the users" do
|
||||
xhr :get, :index, show_emails: "true"
|
||||
get :index, params: { show_emails: "true" }, format: :json
|
||||
data = ::JSON.parse(response.body)
|
||||
data.each do |user|
|
||||
expect(user["email"]).to be_present
|
||||
@ -36,7 +36,7 @@ describe Admin::UsersController do
|
||||
it "logs only 1 enty" do
|
||||
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(0)
|
||||
|
||||
xhr :get, :index, show_emails: "true"
|
||||
get :index, params: { show_emails: "true" }, format: :json
|
||||
|
||||
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(1)
|
||||
end
|
||||
@ -47,14 +47,14 @@ describe Admin::UsersController do
|
||||
describe '.show' do
|
||||
context 'an existing user' do
|
||||
it 'returns success' do
|
||||
xhr :get, :show, id: @user.id
|
||||
get :show, params: { id: @user.id }, format: :json
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
context 'an existing user' do
|
||||
it 'returns success' do
|
||||
xhr :get, :show, id: 0
|
||||
get :show, params: { id: 0 }, format: :json
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
end
|
||||
@ -66,19 +66,19 @@ describe Admin::UsersController do
|
||||
|
||||
it "does nothing without uesrs" do
|
||||
User.any_instance.expects(:approve).never
|
||||
xhr :put, :approve_bulk
|
||||
put :approve_bulk, format: :json
|
||||
end
|
||||
|
||||
it "won't approve the user when not allowed" do
|
||||
Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(false)
|
||||
User.any_instance.expects(:approve).never
|
||||
xhr :put, :approve_bulk, users: [evil_trout.id]
|
||||
put :approve_bulk, params: { users: [evil_trout.id] }, format: :json
|
||||
end
|
||||
|
||||
it "approves the user when permitted" do
|
||||
Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(true)
|
||||
User.any_instance.expects(:approve).once
|
||||
xhr :put, :approve_bulk, users: [evil_trout.id]
|
||||
put :approve_bulk, params: { users: [evil_trout.id] }, format: :json
|
||||
end
|
||||
|
||||
end
|
||||
@ -88,7 +88,7 @@ describe Admin::UsersController do
|
||||
|
||||
it 'calls generate_api_key' do
|
||||
User.any_instance.expects(:generate_api_key).with(@user)
|
||||
xhr :post, :generate_api_key, user_id: evil_trout.id
|
||||
post :generate_api_key, params: { user_id: evil_trout.id }, format: :json
|
||||
end
|
||||
end
|
||||
|
||||
@ -98,7 +98,7 @@ describe Admin::UsersController do
|
||||
|
||||
it 'calls revoke_api_key' do
|
||||
User.any_instance.expects(:revoke_api_key)
|
||||
xhr :delete, :revoke_api_key, user_id: evil_trout.id
|
||||
delete :revoke_api_key, params: { user_id: evil_trout.id }, format: :json
|
||||
end
|
||||
|
||||
end
|
||||
@ -109,13 +109,13 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(false)
|
||||
xhr :put, :approve, user_id: evil_trout.id
|
||||
put :approve, params: { user_id: evil_trout.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'calls approve' do
|
||||
User.any_instance.expects(:approve).with(@user)
|
||||
xhr :put, :approve, user_id: evil_trout.id
|
||||
put :approve, params: { user_id: evil_trout.id }, format: :json
|
||||
end
|
||||
|
||||
end
|
||||
@ -126,7 +126,7 @@ describe Admin::UsersController do
|
||||
|
||||
it "also revoke any api keys" do
|
||||
User.any_instance.expects(:revoke_api_key)
|
||||
xhr :put, :suspend, user_id: evil_trout.id
|
||||
put :suspend, params: { user_id: evil_trout.id }, format: :json
|
||||
end
|
||||
|
||||
end
|
||||
@ -138,12 +138,12 @@ describe Admin::UsersController do
|
||||
|
||||
it 'raises an error unless the user can revoke access' do
|
||||
Guardian.any_instance.expects(:can_revoke_admin?).with(@another_admin).returns(false)
|
||||
xhr :put, :revoke_admin, user_id: @another_admin.id
|
||||
put :revoke_admin, params: { user_id: @another_admin.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the admin flag' do
|
||||
xhr :put, :revoke_admin, user_id: @another_admin.id
|
||||
put :revoke_admin, params: { user_id: @another_admin.id }, format: :json
|
||||
@another_admin.reload
|
||||
expect(@another_admin).not_to be_admin
|
||||
end
|
||||
@ -160,18 +160,18 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_grant_admin?).with(@another_user).returns(false)
|
||||
xhr :put, :grant_admin, user_id: @another_user.id
|
||||
put :grant_admin, params: { user_id: @another_user.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
xhr :put, :grant_admin, user_id: 123123
|
||||
put :grant_admin, params: { user_id: 123123 }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the admin flag' do
|
||||
expect(AdminConfirmation.exists_for?(@another_user.id)).to eq(false)
|
||||
xhr :put, :grant_admin, user_id: @another_user.id
|
||||
put :grant_admin, params: { user_id: @another_user.id }, format: :json
|
||||
expect(AdminConfirmation.exists_for?(@another_user.id)).to eq(true)
|
||||
end
|
||||
end
|
||||
@ -181,7 +181,9 @@ describe Admin::UsersController do
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
it 'adds the user to the group' do
|
||||
xhr :post, :add_group, group_id: group.id, user_id: user.id
|
||||
post :add_group, params: {
|
||||
group_id: group.id, user_id: user.id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
expect(GroupUser.where(user_id: user.id, group_id: group.id).exists?).to eq(true)
|
||||
@ -193,7 +195,10 @@ describe Admin::UsersController do
|
||||
expect(group_history.target_user).to eq(user)
|
||||
|
||||
# Doing it again doesn't raise an error
|
||||
xhr :post, :add_group, group_id: group.id, user_id: user.id
|
||||
post :add_group, params: {
|
||||
group_id: group.id, user_id: user.id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
@ -207,31 +212,47 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_change_primary_group?).with(@another_user).returns(false)
|
||||
xhr :put, :primary_group, user_id: @another_user.id
|
||||
put :primary_group, params: {
|
||||
user_id: @another_user.id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 404 if the user doesn't exist" do
|
||||
xhr :put, :primary_group, user_id: 123123
|
||||
put :primary_group, params: {
|
||||
user_id: 123123
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "changes the user's primary group" do
|
||||
group.add(@another_user)
|
||||
xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: group.id
|
||||
put :primary_group, params: {
|
||||
user_id: @another_user.id, primary_group_id: group.id
|
||||
}, format: :json
|
||||
|
||||
@another_user.reload
|
||||
expect(@another_user.primary_group_id).to eq(group.id)
|
||||
end
|
||||
|
||||
it "doesn't change primary group if they aren't a member of the group" do
|
||||
xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: group.id
|
||||
put :primary_group, params: {
|
||||
user_id: @another_user.id, primary_group_id: group.id
|
||||
}, format: :json
|
||||
|
||||
@another_user.reload
|
||||
expect(@another_user.primary_group_id).to be_nil
|
||||
end
|
||||
|
||||
it "remove user's primary group" do
|
||||
group.add(@another_user)
|
||||
xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: ""
|
||||
|
||||
put :primary_group, params: {
|
||||
user_id: @another_user.id, primary_group_id: ""
|
||||
}, format: :json
|
||||
|
||||
@another_user.reload
|
||||
expect(@another_user.primary_group_id).to be(nil)
|
||||
end
|
||||
@ -244,18 +265,28 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_change_trust_level?).with(@another_user).returns(false)
|
||||
xhr :put, :trust_level, user_id: @another_user.id
|
||||
put :trust_level, params: {
|
||||
user_id: @another_user.id
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
xhr :put, :trust_level, user_id: 123123
|
||||
put :trust_level, params: {
|
||||
user_id: 123123
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it "upgrades the user's trust level" do
|
||||
StaffActionLogger.any_instance.expects(:log_trust_level_change).with(@another_user, @another_user.trust_level, 2).once
|
||||
xhr :put, :trust_level, user_id: @another_user.id, level: 2
|
||||
|
||||
put :trust_level, params: {
|
||||
user_id: @another_user.id, level: 2
|
||||
}, format: :json
|
||||
|
||||
@another_user.reload
|
||||
expect(@another_user.trust_level).to eq(2)
|
||||
expect(response).to be_success
|
||||
@ -268,7 +299,11 @@ describe Admin::UsersController do
|
||||
stat.time_read = SiteSetting.tl1_requires_time_spent_mins * 60
|
||||
stat.save!
|
||||
@another_user.update_attributes(trust_level: TrustLevel[1])
|
||||
xhr :put, :trust_level, user_id: @another_user.id, level: TrustLevel[0]
|
||||
|
||||
put :trust_level, params: {
|
||||
user_id: @another_user.id, level: TrustLevel[0]
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
@another_user.reload
|
||||
expect(@another_user.trust_level_locked).to eq(true)
|
||||
@ -282,12 +317,18 @@ describe Admin::UsersController do
|
||||
|
||||
it 'raises an error unless the user can revoke access' do
|
||||
Guardian.any_instance.expects(:can_revoke_moderation?).with(@moderator).returns(false)
|
||||
xhr :put, :revoke_moderation, user_id: @moderator.id
|
||||
put :revoke_moderation, params: {
|
||||
user_id: @moderator.id
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the moderator flag' do
|
||||
xhr :put, :revoke_moderation, user_id: @moderator.id
|
||||
put :revoke_moderation, params: {
|
||||
user_id: @moderator.id
|
||||
}, format: :json
|
||||
|
||||
@moderator.reload
|
||||
expect(@moderator.moderator).not_to eq(true)
|
||||
end
|
||||
@ -300,17 +341,17 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_grant_moderation?).with(@another_user).returns(false)
|
||||
xhr :put, :grant_moderation, user_id: @another_user.id
|
||||
put :grant_moderation, params: { user_id: @another_user.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
xhr :put, :grant_moderation, user_id: 123123
|
||||
put :grant_moderation, params: { user_id: 123123 }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the moderator flag' do
|
||||
xhr :put, :grant_moderation, user_id: @another_user.id
|
||||
put :grant_moderation, params: { user_id: @another_user.id }, format: :json
|
||||
@another_user.reload
|
||||
expect(@another_user.moderator).to eq(true)
|
||||
end
|
||||
@ -322,19 +363,26 @@ describe Admin::UsersController do
|
||||
|
||||
it 'does nothing without users' do
|
||||
UserDestroyer.any_instance.expects(:destroy).never
|
||||
xhr :delete, :reject_bulk
|
||||
delete :reject_bulk, format: :json
|
||||
end
|
||||
|
||||
it "won't delete users if not allowed" do
|
||||
Guardian.any_instance.stubs(:can_delete_user?).returns(false)
|
||||
UserDestroyer.any_instance.expects(:destroy).never
|
||||
xhr :delete, :reject_bulk, users: [reject_me.id]
|
||||
|
||||
delete :reject_bulk, params: {
|
||||
users: [reject_me.id]
|
||||
}, format: :json
|
||||
end
|
||||
|
||||
it "reports successes" do
|
||||
Guardian.any_instance.stubs(:can_delete_user?).returns(true)
|
||||
UserDestroyer.any_instance.stubs(:destroy).returns(true)
|
||||
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id]
|
||||
|
||||
delete :reject_bulk, params: {
|
||||
users: [reject_me.id, reject_me_too.id]
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['success'].to_i).to eq(2)
|
||||
@ -349,7 +397,11 @@ describe Admin::UsersController do
|
||||
it 'can handle some successes and some failures' do
|
||||
UserDestroyer.any_instance.stubs(:destroy).with(reject_me, anything).returns(false)
|
||||
UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true)
|
||||
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id]
|
||||
|
||||
delete :reject_bulk, params: {
|
||||
users: [reject_me.id, reject_me_too.id]
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['success'].to_i).to eq(1)
|
||||
@ -358,7 +410,11 @@ describe Admin::UsersController do
|
||||
|
||||
it 'reports failure due to a user still having posts' do
|
||||
UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError)
|
||||
xhr :delete, :reject_bulk, users: [reject_me.id]
|
||||
|
||||
delete :reject_bulk, params: {
|
||||
users: [reject_me.id]
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['success'].to_i).to eq(0)
|
||||
@ -374,12 +430,12 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_delete_user?).with(@delete_me).returns(false)
|
||||
xhr :delete, :destroy, id: @delete_me.id
|
||||
delete :destroy, params: { id: @delete_me.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 403 if the user doesn't exist" do
|
||||
xhr :delete, :destroy, id: 123123
|
||||
delete :destroy, params: { id: 123123 }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
@ -394,13 +450,13 @@ describe Admin::UsersController do
|
||||
end
|
||||
|
||||
it "returns an error" do
|
||||
xhr :delete, :destroy, id: @delete_me.id
|
||||
delete :destroy, params: { id: @delete_me.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "doesn't return an error if delete_posts == true" do
|
||||
UserDestroyer.any_instance.expects(:destroy).with(@user, has_entry('delete_posts' => true)).returns(true)
|
||||
xhr :delete, :destroy, id: @delete_me.id, delete_posts: true
|
||||
delete :destroy, params: { id: @delete_me.id, delete_posts: true }, format: :json
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
@ -408,7 +464,7 @@ describe Admin::UsersController do
|
||||
|
||||
it "deletes the user record" do
|
||||
UserDestroyer.any_instance.expects(:destroy).returns(true)
|
||||
xhr :delete, :destroy, id: @delete_me.id
|
||||
delete :destroy, params: { id: @delete_me.id }, format: :json
|
||||
end
|
||||
end
|
||||
|
||||
@ -418,7 +474,7 @@ describe Admin::UsersController do
|
||||
end
|
||||
|
||||
it "returns success" do
|
||||
xhr :put, :activate, user_id: @reg_user.id
|
||||
put :activate, params: { user_id: @reg_user.id }, format: :json
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['success']).to eq("OK")
|
||||
@ -430,7 +486,7 @@ describe Admin::UsersController do
|
||||
@reg_user.reload
|
||||
expect(@reg_user.email_confirmed?).to eq(false)
|
||||
|
||||
xhr :put, :activate, user_id: @reg_user.id
|
||||
put :activate, params: { user_id: @reg_user.id }, format: :json
|
||||
expect(response).to be_success
|
||||
|
||||
@reg_user.reload
|
||||
@ -444,14 +500,14 @@ describe Admin::UsersController do
|
||||
end
|
||||
|
||||
it "returns success" do
|
||||
xhr :put, :log_out, user_id: @reg_user.id
|
||||
put :log_out, params: { user_id: @reg_user.id }, format: :json
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['success']).to eq("OK")
|
||||
end
|
||||
|
||||
it "returns 404 when user_id does not exist" do
|
||||
xhr :put, :log_out, user_id: 123123
|
||||
put :log_out, params: { user_id: 123123 }, format: :json
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
end
|
||||
@ -464,18 +520,18 @@ describe Admin::UsersController do
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_block_user?).with(@reg_user).returns(false)
|
||||
UserBlocker.expects(:block).never
|
||||
xhr :put, :block, user_id: @reg_user.id
|
||||
put :block, params: { user_id: @reg_user.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 403 if the user doesn't exist" do
|
||||
xhr :put, :block, user_id: 123123
|
||||
put :block, params: { user_id: 123123 }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "punishes the user for spamming" do
|
||||
UserBlocker.expects(:block).with(@reg_user, @user, anything)
|
||||
xhr :put, :block, user_id: @reg_user.id
|
||||
put :block, params: { user_id: @reg_user.id }, format: :json
|
||||
end
|
||||
end
|
||||
|
||||
@ -486,18 +542,18 @@ describe Admin::UsersController do
|
||||
|
||||
it "raises an error when the user doesn't have permission" do
|
||||
Guardian.any_instance.expects(:can_unblock_user?).with(@reg_user).returns(false)
|
||||
xhr :put, :unblock, user_id: @reg_user.id
|
||||
put :unblock, params: { user_id: @reg_user.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 403 if the user doesn't exist" do
|
||||
xhr :put, :unblock, user_id: 123123
|
||||
put :unblock, params: { user_id: 123123 }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "punishes the user for spamming" do
|
||||
UserBlocker.expects(:unblock).with(@reg_user, @user, anything)
|
||||
xhr :put, :unblock, user_id: @reg_user.id
|
||||
put :unblock, params: { user_id: @reg_user.id }, format: :json
|
||||
end
|
||||
end
|
||||
|
||||
@ -505,7 +561,7 @@ describe Admin::UsersController do
|
||||
|
||||
it "uses ipinfo.io webservice to retrieve the info" do
|
||||
Excon.expects(:get).with("https://ipinfo.io/123.123.123.123/json", read_timeout: 10, connect_timeout: 10)
|
||||
xhr :get, :ip_info, ip: "123.123.123.123"
|
||||
get :ip_info, params: { ip: "123.123.123.123" }, format: :json
|
||||
end
|
||||
|
||||
end
|
||||
@ -518,7 +574,9 @@ describe Admin::UsersController do
|
||||
|
||||
UserDestroyer.any_instance.expects(:destroy).twice
|
||||
|
||||
xhr :delete, :delete_other_accounts_with_same_ip, ip: "42.42.42.42", exclude: -1, order: "trust_level DESC"
|
||||
delete :delete_other_accounts_with_same_ip, params: {
|
||||
ip: "42.42.42.42", exclude: -1, order: "trust_level DESC"
|
||||
}, format: :json
|
||||
end
|
||||
|
||||
end
|
||||
@ -526,14 +584,22 @@ describe Admin::UsersController do
|
||||
context ".invite_admin" do
|
||||
it "doesn't work when not via API" do
|
||||
controller.stubs(:is_api?).returns(false)
|
||||
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com'
|
||||
|
||||
post :invite_admin, params: {
|
||||
name: 'Bill', username: 'bill22', email: 'bill@bill.com'
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it 'should invite admin' do
|
||||
controller.stubs(:is_api?).returns(true)
|
||||
Jobs.expects(:enqueue).with(:critical_user_email, anything).returns(true)
|
||||
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com'
|
||||
|
||||
post :invite_admin, params: {
|
||||
name: 'Bill', username: 'bill22', email: 'bill@bill.com'
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
u = User.find_by_email('bill@bill.com')
|
||||
@ -545,7 +611,11 @@ describe Admin::UsersController do
|
||||
it "doesn't send the email with send_email falsy" do
|
||||
controller.stubs(:is_api?).returns(true)
|
||||
Jobs.expects(:enqueue).with(:user_email, anything).never
|
||||
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0'
|
||||
|
||||
post :invite_admin, params: {
|
||||
name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0'
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["password_url"]).to be_present
|
||||
@ -556,11 +626,11 @@ describe Admin::UsersController do
|
||||
it "also clears the user's primary group" do
|
||||
g = Fabricate(:group)
|
||||
u = Fabricate(:user, primary_group: g)
|
||||
xhr :delete, :remove_group, group_id: g.id, user_id: u.id
|
||||
delete :remove_group, params: { group_id: g.id, user_id: u.id }, format: :json
|
||||
|
||||
expect(u.reload.primary_group).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#sync_sso' do
|
||||
@ -592,7 +662,7 @@ describe Admin::UsersController do
|
||||
sso.username = "Hokli$$!!"
|
||||
sso.email = "bob2@bob.com"
|
||||
|
||||
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
|
||||
post :sync_sso, params: Rack::Utils.parse_query(sso.payload), format: :json
|
||||
expect(response).to be_success
|
||||
|
||||
user.reload
|
||||
@ -606,7 +676,7 @@ describe Admin::UsersController do
|
||||
sso.username = "dr_claw"
|
||||
sso.email = "dr@claw.com"
|
||||
sso.external_id = "2"
|
||||
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
|
||||
post :sync_sso, params: Rack::Utils.parse_query(sso.payload), format: :json
|
||||
expect(response).to be_success
|
||||
|
||||
user = User.find_by_email('dr@claw.com')
|
||||
@ -619,7 +689,7 @@ describe Admin::UsersController do
|
||||
sso.name = ""
|
||||
sso.external_id = "1"
|
||||
|
||||
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
|
||||
post :sync_sso, params: Rack::Utils.parse_query(sso.payload), format: :json
|
||||
expect(response.status).to eq(403)
|
||||
expect(JSON.parse(response.body)["message"]).to include("Primary email can't be blank")
|
||||
end
|
||||
|
Reference in New Issue
Block a user