Don't include suspended_at or suspended_till unless suspended

This commit is contained in:
Robin Ward 2017-10-13 12:17:26 -04:00
parent dc2d9f05dc
commit f73a3cc0d4
3 changed files with 11 additions and 1 deletions

View File

@ -655,7 +655,7 @@ class User < ActiveRecord::Base
end end
def suspended? def suspended?
suspended_till && suspended_till > DateTime.now !!(suspended_till && suspended_till > DateTime.now)
end end
def suspend_record def suspend_record

View File

@ -44,6 +44,14 @@ class AdminUserListSerializer < BasicUserSerializer
object.suspended? object.suspended?
end end
def include_suspended_at?
object.suspended?
end
def include_suspended_till?
object.suspended?
end
def can_impersonate def can_impersonate
scope.can_impersonate?(object) scope.can_impersonate?(object)
end end

View File

@ -125,6 +125,7 @@ describe Admin::UsersController do
it "works properly" do it "works properly" do
Fabricate(:api_key, user: user) Fabricate(:api_key, user: user)
expect(user).not_to be_suspended
put( put(
:suspend, :suspend,
params: { params: {
@ -137,6 +138,7 @@ describe Admin::UsersController do
expect(response).to be_success expect(response).to be_success
user.reload user.reload
expect(user).to be_suspended
expect(user.suspended_at).to be_present expect(user.suspended_at).to be_present
expect(user.suspended_till).to be_present expect(user.suspended_till).to be_present
expect(ApiKey.where(user_id: user.id).count).to eq(0) expect(ApiKey.where(user_id: user.id).count).to eq(0)