mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-28 13:31:06 +00:00
Added ban information to user api
This commit is contained in:
parent
a3356e57d3
commit
f9f4485c95
3 changed files with 51 additions and 19 deletions
|
@ -17,6 +17,11 @@ class Api::V1::UsersController < Api::V1::BaseController
|
||||||
steam: {
|
steam: {
|
||||||
url: @steam.base_url,
|
url: @steam.base_url,
|
||||||
nickname: @steam.nickname
|
nickname: @steam.nickname
|
||||||
|
},
|
||||||
|
bans: {
|
||||||
|
gather: @user.banned?(Ban::TYPE_GATHER).present?,
|
||||||
|
mute: @user.banned?(Ban::TYPE_MUTE).present?,
|
||||||
|
site: @user.banned?(Ban::TYPE_SITE).present?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
|
@ -29,6 +29,25 @@ describe Api::V1::UsersController do
|
||||||
get :show, id: -1
|
get :show, id: -1
|
||||||
}.to raise_error(ActionController::RoutingError)
|
}.to raise_error(ActionController::RoutingError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns correct ban if user muted' do
|
||||||
|
create :ban, :mute, user: @user
|
||||||
|
get :show, id: @user.id
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(json['bans']['mute']).to eq(true)
|
||||||
|
end
|
||||||
|
it 'returns correct ban if user gather banned' do
|
||||||
|
create :ban, :gather, user: @user
|
||||||
|
get :show, id: @user.id
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(json['bans']['gather']).to eq(true)
|
||||||
|
end
|
||||||
|
it 'returns correct ban if user site banned' do
|
||||||
|
create :ban, :site, user: @user
|
||||||
|
get :show, id: @user.id
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(json['bans']['site']).to eq(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#index' do
|
describe '#index' do
|
||||||
|
|
|
@ -1,23 +1,31 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :ban do
|
factory :ban do
|
||||||
ban_type Ban::TYPE_SITE
|
ban_type Ban::TYPE_SITE
|
||||||
expiry Date.today + 1
|
expiry Date.today + 1
|
||||||
# Hack because of the awkward way bans are created (requires user_name)
|
# Hack because of the awkward way bans are created (requires user_name)
|
||||||
before(:create) do |ban|
|
before(:create) do |ban|
|
||||||
if ban.user.nil?
|
if ban.user.nil?
|
||||||
user = create :user
|
user = create :user
|
||||||
ban.user_name = user.username
|
ban.user_name = user.username
|
||||||
else
|
else
|
||||||
ban.user_name = ban.user.username
|
ban.user_name = ban.user.username
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :mute do
|
trait :mute do
|
||||||
ban_type Ban::TYPE_MUTE
|
ban_type Ban::TYPE_MUTE
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :expired do
|
trait :site do
|
||||||
expiry Date.yesterday - 1
|
ban_type Ban::TYPE_SITE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :gather do
|
||||||
|
ban_type Ban::TYPE_GATHER
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :expired do
|
||||||
|
expiry Date.yesterday - 1
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue