-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read-only Bans API #345
base: master
Are you sure you want to change the base?
Read-only Bans API #345
Changes from all commits
bf1da06
fd6b8ea
51708e2
315382f
016911e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module API | ||
module V1 | ||
class BanSerializer < ActiveModel::Serializer | ||
type :ban | ||
|
||
attributes :id, :created_at, :terminated_at | ||
attribute(:type) { object.class.subject } | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'rails_helper' | ||
|
||
describe API::V1::UsersController do | ||
let(:key) { create(:api_key) } | ||
let(:user) { create(:user) } | ||
|
||
describe 'GET #bans' do | ||
context 'when unauthenticated' do | ||
it 'fails with unauthorized error' do | ||
get :bans, params: { id: user.id } | ||
|
||
expect(response).to have_http_status(:unauthorized) | ||
expect(json['status']).to eq(401) | ||
expect(json['message']).to eq('Unauthorized API key') | ||
end | ||
end | ||
|
||
context 'when authenticated' do | ||
context 'retrieving unbanned player' do | ||
it 'succeeds with 0 bans' do | ||
request.headers['X-API-Key'] = key.key | ||
get :bans, params: { id: user.id } | ||
|
||
expect(response).to have_http_status(:success) | ||
expect(json['bans'].length).to eq(0) | ||
end | ||
end | ||
|
||
context 'retrieving league banned player' do | ||
it 'succeeds with 1 league ban' do | ||
user.ban(:use, :leagues) | ||
|
||
request.headers['X-API-Key'] = key.key | ||
get :bans, params: { id: user.id } | ||
|
||
expect(response).to have_http_status(:success) | ||
expect(json['bans'].length).to eq(1) | ||
expect(json['bans'].first['type']).to eq('leagues') | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,6 @@ | |
|
||
# Include url helpers | ||
config.include Rails.application.routes.url_helpers | ||
|
||
config.include JsonHelpers | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module JsonHelpers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did try to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works for the other API requests. |
||
def json | ||
JSON.parse(response.body) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea, completely missed this. The API is tested with request tests, eg.
spec/requests/api/v1/users_spec.rb
.