update current user schema/examples
This commit is contained in:
parent
c4509fd054
commit
e4a1ced8c2
7 changed files with 70 additions and 6 deletions
|
@ -17,7 +17,7 @@ module Api
|
|||
# only ask serializer to return is_admin field if we're on the
|
||||
# current_user action
|
||||
def default_scope
|
||||
super.merge(show_is_admin: action_name == 'current')
|
||||
super.merge(show_full_user: action_name == 'current')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,9 @@ module Api
|
|||
:generation
|
||||
|
||||
attribute :is_admin,
|
||||
if: -> { scope[:show_is_admin] && scope[:current_user] == object }
|
||||
if: -> { scope[:show_full_user] && scope[:current_user] == object }
|
||||
attribute :email,
|
||||
if: -> { scope[:show_full_user] && scope[:current_user] == object }
|
||||
|
||||
def avatar
|
||||
object.image.url(:sixtyfour)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"name": "user",
|
||||
"avatar": "https://s3.amazonaws.com/metamaps-assets/site/user.png",
|
||||
"generation": 0,
|
||||
"is_admin": false
|
||||
"is_admin": false,
|
||||
"email": "user@example.com"
|
||||
}
|
||||
}
|
||||
|
|
34
doc/api/schemas/_current_user.json
Normal file
34
doc/api/schemas/_current_user.json
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"name": "User",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "_id.json"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"avatar": {
|
||||
"format": "uri",
|
||||
"type": "string"
|
||||
},
|
||||
"generation": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"is_admin": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"name",
|
||||
"avatar",
|
||||
"generation",
|
||||
"is_admin",
|
||||
"email"
|
||||
]
|
||||
}
|
|
@ -15,9 +15,6 @@
|
|||
"generation": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"is_admin": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
|
12
doc/api/schemas/current_user.json
Normal file
12
doc/api/schemas/current_user.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "Current User Envelope",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "_current_user.json"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
}
|
|
@ -30,4 +30,22 @@ RSpec.describe 'users API', type: :request do
|
|||
expect(response).to match_json_schema(:user)
|
||||
expect(JSON.parse(response.body)['data']['id']).to eq user.id
|
||||
end
|
||||
|
||||
context 'RAML example' do
|
||||
let(:resource) { get_json_example(:user) }
|
||||
let(:collection) { get_json_example(:users) }
|
||||
let(:current) { get_json_example(:current_user) }
|
||||
|
||||
it 'resource matches schema' do
|
||||
expect(resource).to match_json_schema(:user)
|
||||
end
|
||||
|
||||
it 'collection matches schema' do
|
||||
expect(collection).to match_json_schema(:users)
|
||||
end
|
||||
|
||||
it 'current_user resource matches schema' do
|
||||
expect(current).to match_json_schema(:current_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue