parent
19b9e1e2c3
commit
77e13c2bc9
@ -1,18 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::DevicesController < ApiController
|
||||
before_action -> { doorkeeper_authorize! :read }
|
||||
before_action :require_user!
|
||||
|
||||
respond_to :json
|
||||
|
||||
def register
|
||||
Device.where(account: current_account, registration_id: params[:registration_id]).first_or_create!(account: current_account, registration_id: params[:registration_id])
|
||||
render_empty
|
||||
end
|
||||
|
||||
def unregister
|
||||
Device.where(account: current_account, registration_id: params[:registration_id]).delete_all
|
||||
render_empty
|
||||
end
|
||||
end
|
@ -1,38 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::DevicesController, type: :controller do
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { double acceptable?: true, resource_owner_id: user.id }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #register' do
|
||||
before do
|
||||
post :register, params: { registration_id: 'foo123' }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'registers device' do
|
||||
expect(Device.where(account: user.account, registration_id: 'foo123').first).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unregister' do
|
||||
before do
|
||||
post :unregister, params: { registration_id: 'foo123' }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'removes device' do
|
||||
expect(Device.where(account: user.account, registration_id: 'foo123').first).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue