diff --git a/Gemfile b/Gemfile index a79dc6ffa..251305075 100755 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,10 @@ gem 'high_voltage', '~> 2.1.0' gem 'haml' gem 'rails-assets-ng-sortable' +gem 'figaro' # Store secrets the 12 factor way. TODO: Get off of this gem. +gem 'devise', github: 'plataformatec/devise' +gem 'mutations' + group :development, :test do gem 'pry' gem 'factory_girl_rails' @@ -30,8 +34,6 @@ group :development do gem 'metric_fu' # Run this to see where the code smells. metric_fu in terminal end -gem 'figaro' # Store secrets the 12 factor way. - group :test do gem 'rspec' gem 'rspec-rails' @@ -39,5 +41,3 @@ group :test do gem 'capybara' gem 'launchy' #save_and_open_page while debugging integration tests. end - -gem 'devise', github: 'plataformatec/devise' diff --git a/Gemfile.lock b/Gemfile.lock index d6bb84627..cbd3ec439 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -168,6 +168,8 @@ GEM connection_pool (~> 2.0) optionable (~> 0.2.0) multi_json (1.10.1) + mutations (0.7.2) + activesupport ng-rails-csrf (0.1.0) nokogiri (1.6.2.1) mini_portile (= 0.6.0) @@ -306,6 +308,7 @@ DEPENDENCIES launchy metric_fu mongoid (~> 4.0.0)! + mutations ng-rails-csrf pry rails (= 4.1.0) diff --git a/app/controllers/api/abstract_controller.rb b/app/controllers/api/abstract_controller.rb new file mode 100644 index 000000000..4e3f192f3 --- /dev/null +++ b/app/controllers/api/abstract_controller.rb @@ -0,0 +1,6 @@ +module Api + class AbstractController < ApplicationController + respond_to :json + before_action :authenticate_user! + end +end diff --git a/app/controllers/api/devices_controller.rb b/app/controllers/api/devices_controller.rb index a5b0ccdb3..ac3a3ce18 100644 --- a/app/controllers/api/devices_controller.rb +++ b/app/controllers/api/devices_controller.rb @@ -1,53 +1,53 @@ # Api::DevicesController is the RESTful endpoint for managing device related # settings. Consumed by the Angular SPA on the front end. -class Api::DevicesController < ApplicationController - respond_to :json - before_action :authenticate_user! - before_action :set_device, only: [:show, :edit, :update, :destroy] +module Api + class DevicesController < Api::AbstractController + before_action :set_device, only: [:show, :edit, :update, :destroy] - # GET /api/devices - def index - @devices = Device.where(user_id: current_user.id) - render json: @devices + # GET /api/devices + def index + @devices = Device.where(user_id: current_user.id) + render json: @devices + end + + # GET /api/devices/1 + # def show + # raise 'Not implemented.' + # end + + # POST /api/devices + def create + @device = Device.new(device_params) + @device.user = current_user + if @device.save + render json: @device + end + end + + # PATCH/PUT /api/devices/1 + def update + if @device.update(device_params) + render json: @device + end + end + + # DELETE /api/devices/1 + def destroy + if @device.user == current_user + @device.destroy + render nothing: true, status: 204 + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_device + @device = Device.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def device_params + params.permit([:name, :uuid, :token]) + end end - - # GET /api/devices/1 - # def show - # raise 'Not implemented.' - # end - - # POST /api/devices - def create - @device = Device.new(device_params) - @device.user = current_user - if @device.save - render json: @device - end - end - - # PATCH/PUT /api/devices/1 - def update - if @device.update(device_params) - render json: @device - end - end - - # DELETE /api/devices/1 - def destroy - if @device.user == current_user - @device.destroy - render nothing: true, status: 204 - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_device - @device = Device.find(params[:id]) - end - - # Only allow a trusted parameter "white list" through. - def device_params - params.permit([:name, :uuid, :token]) - end end diff --git a/app/controllers/api/sequences_controller.rb b/app/controllers/api/sequences_controller.rb new file mode 100644 index 000000000..47ece989b --- /dev/null +++ b/app/controllers/api/sequences_controller.rb @@ -0,0 +1,8 @@ +# Api::SequencesController performs CRUD on stored sequences +module Api + class SequencesController < Api::AbstractController + def create + binding.pry + end + end +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep deleted file mode 100755 index e69de29bb..000000000 diff --git a/config/routes.rb b/config/routes.rb index 8de433d3e..c23b6f52c 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ Dss::Application.routes.draw do mount JasmineRails::Engine => '/specs' if defined?(JasmineRails) namespace :api, defaults: {format: :json} do resources :devices, only: [:index, :destroy, :create, :update] + resources :sequences, only: [:create] end devise_for :users, :controllers => {:registrations => "registrations"} diff --git a/spec/controllers/api/sequences/sequences_create.rb b/spec/controllers/api/sequences/sequences_create.rb new file mode 100644 index 000000000..d047709f0 --- /dev/null +++ b/spec/controllers/api/sequences/sequences_create.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Api::SequencesController do + + include Devise::TestHelpers + + describe '#create' do + + let(:user) { FactoryGirl.create(:user) } + + it 'creates a new sequences for a user' do + sign_in user + post :create, {} + expect(response.status).to eq(200) + end + end +end