Minor refactor before adding Sequence model

pull/117/head
Rick Carlino 2015-01-04 18:40:02 -06:00
parent 346057435e
commit 39986c0ea6
8 changed files with 87 additions and 52 deletions

View File

@ -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'

View File

@ -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)

View File

@ -0,0 +1,6 @@
module Api
class AbstractController < ApplicationController
respond_to :json
before_action :authenticate_user!
end
end

View File

@ -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

View File

@ -0,0 +1,8 @@
# Api::SequencesController performs CRUD on stored sequences
module Api
class SequencesController < Api::AbstractController
def create
binding.pry
end
end
end

View File

@ -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"}

View File

@ -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