Code touch ups

pull/40/head
rick carlino 2014-05-13 06:55:38 -07:00
parent c7c013a565
commit 8261b4ccf0
7 changed files with 51 additions and 27 deletions

View File

@ -13,7 +13,7 @@ This Repo is the Web based side of the decision support system. It is the glue t
4. Start Mongo if you have not already done so. (typically via the `mongod` command)
3. `bundle install`
4. `rails s`
5. Checkout `http://localhost:3000`
5. Go to `http://localhost:3000`
# How to Contribute
@ -22,10 +22,10 @@ This Repo is the Web based side of the decision support system. It is the glue t
# Roadmap
This project is still in its infancy. Our current focus as of April 2014 is to create a basic system of control for the farmbot user via technologies such as:
This project is still in its infancy. Our current focus as of May 2014 is to create a basic system of control for the farmbot user via technologies such as:
* [Farmbot Controller](https://github.com/FarmBot/farmbot-raspberry-pi-controller)
* [Skynet IoT Messaging Platform](http://www.skynet.im) ([Github](https://github.com/skynetim/skynet))
* Ruby on Rails
Eventually, the DSS hopes to be a rich environment for users to manage their FarmBot and gain insights into the farming decision making process.
Eventually, the DSS hopes to be a rich environment for users to manage their FarmBot and gain insights into the farming decision process.

View File

@ -1,27 +1,28 @@
class Api::DevicesController < ApplicationController
before_action :authenticate!
before_action :ensure_logged_in
def index
@devices = Device.where(user_id: current_user.id)
render json: @devices
end
def create
@device = Device.new(device_params)
if @device.save
render json: @device, status: 201
else
render json: @device, status: 400
end
end
# def create # Not yet implemented - sit tight. Coming soon!
# @device = Device.new(device_params)
# if @device.save
# render json: @device, status: 201
# else
# render json: @device, status: 400
# end
# end
private
def device_params
params.require(:person).permit(:name, :age)
end
# def device_params
# params.require(:person).permit(:name, :age)
# end
def authenticate!
# Handles unauthorized / unauthenticated API requests.
def ensure_logged_in
unless current_user
render nothing: true, :status => :unauthorized
end

View File

@ -3,10 +3,4 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
# An overridable method for redirecting a new user to a particular page after
# registration
def after_sign_up_path_for(resource)
#doesn't seem to get called when Confirmable is active.
'dashboard/index.html'
end
end

View File

@ -2,9 +2,13 @@
# This is useful for caching things like SkyNey IDs, owner users, work logs, etc
class Device
include Mongoid::Document
belongs_to :user
# The SkyNet UUID of the device
field :uuid
field :name
# The SkyNet Authentication token for the device
field :token
# The 'Friendly Name' of the device. I recommend 'The Cabbage Patch Kid'
field :name
end

View File

@ -1,5 +1,29 @@
describe Api::DevicesController
require 'spec_helper'
it 'returns'
describe Api::DevicesController do
include Devise::TestHelpers
describe '#index' do
let(:user) do
user = FactoryGirl.create(:user)
user.devices << FactoryGirl.create(:device)
user
end
it 'returns all the users devices, as JSON' do
sign_in user
get :index
device = user.devices.first
expect(response.body).to include(device._id)
expect(response.status).to eq(200)
end
it 'handles requests from unauthenticated users' do
get :index
expect(response.status).to eq(401)
end
end
end

View File

@ -1,6 +1,7 @@
module Helpers
def sign_in_as(user)
#TODO: Sign in via Warden instead.
# For when you're actually testing the login UI components. Otherwise,
# consider using the devise test helper `sign_in`
visit new_user_session_path
fill_in 'user_email', with: user.email
fill_in 'user_password', with: user.password

View File

@ -12,7 +12,7 @@ describe 'User Session' do
it 'edits user settings' do
user = FactoryGirl.create(:user)
sign_in_as(user)
sign_in_as user
visit edit_user_registration_path
old_email = user.email
new_email = Faker::Internet.email