diff --git a/app/controllers/devices_controller.rb b/app/controllers/devices_controller.rb new file mode 100644 index 0000000..3a47030 --- /dev/null +++ b/app/controllers/devices_controller.rb @@ -0,0 +1,14 @@ +class DevicesController < ApplicationController + respond_to :json + + def create + device = Device.create(device_params) + respond_with device, status: :created + end + + private + + def device_params + params.require(:device).permit(:model, :unique_id, :imei_number) + end +end diff --git a/config/application.rb b/config/application.rb index 6164282..f949266 100644 --- a/config/application.rb +++ b/config/application.rb @@ -31,5 +31,7 @@ module OnemdmServer # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + config.generators.assets = false + config.generators.helper = false end end diff --git a/config/routes.rb b/config/routes.rb index c4fc754..7e2c1f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ Rails.application.routes.draw do # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products + resources :devices # Example resource route with options: # resources :products do diff --git a/spec/controllers/devices_controller_spec.rb b/spec/controllers/devices_controller_spec.rb new file mode 100644 index 0000000..a71fef6 --- /dev/null +++ b/spec/controllers/devices_controller_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe DevicesController, type: :controller do + + describe "POST #create" do + it "creates a device" do + expect { + post :create, device: attributes_for(:device), format: :json + }.to change{ Device.count }.by(1) + #expect(response).to have_http_status(:success) + end + end + +end