Add API installation status update

This commit is contained in:
leenasn
2015-11-18 15:15:31 +05:30
parent 9ba5ea1e39
commit 354b42a70c
6 changed files with 64 additions and 0 deletions

17
app/admin/app.rb Normal file
View File

@@ -0,0 +1,17 @@
ActiveAdmin.register App do
permit_params :name, :package_name
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# permit_params :list, :of, :attributes, :on, :model
#
# or
#
# permit_params do
# permitted = [:permitted, :attributes]
# permitted << :other if resource.something?
# permitted
# end
end

View File

@@ -0,0 +1,14 @@
class InstallationsController < ApplicationController
before_action :authenticate_device
respond_to :json
def downloaded
Installation.find(params[:id]).downloaded!
render json:{}, status: :ok
end
def installed
Installation.find(params[:id]).installed!
render json:{}, status: :ok
end
end

View File

@@ -1,5 +1,7 @@
class App < ActiveRecord::Base
default_scope {order("name")}
has_many :batch_installations, dependent: :destroy
validates :name, :package_name, presence: true

View File

@@ -1,4 +1,6 @@
class Device < ActiveRecord::Base
default_scope {order ('id desc')}
enum status: [:active,:missing,:dead]
attr_accessor :status

View File

@@ -2,6 +2,8 @@ Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
post 'heartbeats', to: 'heartbeats#create', :defaults => { :format => :json }
post '/installations/downloaded', :defaults => { :format => :json }
post '/installations/installed', :defaults => { :format => :json }
ActiveAdmin.routes(self)
# The priority is based upon order of creation: first created -> highest priority.

View File

@@ -0,0 +1,27 @@
require 'rails_helper'
RSpec.describe InstallationsController, type: :controller do
let(:installation) {FactoryGirl.create(:installation)}
let(:device){installation.device}
before(:each)do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(device.access_token)
end
describe "POST #downloaded" do
it "upate installation with download status" do
post :downloaded, :id => installation.id , format: :json
expect(response).to have_http_status(:ok)
expect(Installation.last.downloaded?).to be true
end
end
describe "POST #installed" do
it "update installation with installed status" do
post :installed, :id => installation.id , format: :json
expect(response).to have_http_status(:ok)
expect(Installation.last.installed?).to be true
end
end
end