params.as_json now, I guess

pull/298/head^2
Rick Carlino 2016-11-23 13:30:16 -06:00
parent 72287857f2
commit f50b700855
10 changed files with 56 additions and 13 deletions

View File

@ -2,6 +2,7 @@ module Api
class AbstractController < ApplicationController
respond_to :json
before_action :authenticate_user!
ActionController::Parameters.permit_all_parameters = true
skip_before_action :verify_authenticity_token
after_action :skip_set_cookies_header
rescue_from(JWT::VerificationError) { |e| auth_err }
@ -23,6 +24,7 @@ module Api
end
private
# Disable cookies. This is an API!
def skip_set_cookies_header
request.session_options = {}

View File

@ -10,12 +10,12 @@ module Api
# POST /api/device
def create
mutate Devices::Create.run(params, user: current_user)
mutate Devices::Create.run(params.as_json, user: current_user)
end
# PATCH/PUT /api/device
def update
mutate Devices::Update.run(params, device: current_device)
mutate Devices::Update.run(params.as_json, device: current_device)
end
# DELETE /api/devices/1

View File

@ -7,7 +7,7 @@ module Api
# This controller action is barely RESTful.
# Replaces *all* existing peripherals with a new array of peripherals.
def create
mutate Peripherals::Create.run(params, device: current_device)
mutate Peripherals::Create.run(params.as_json, device: current_device)
end
def destroy

View File

@ -6,7 +6,7 @@ module Api
end
def create
mutate PlantingAreas::Create.run(params, device: current_device)
mutate PlantingAreas::Create.run(params.as_json, device: current_device)
end
def destroy

View File

@ -6,7 +6,7 @@ module Api
end
def create
mutate Plants::Create.run(params, device_params)
mutate Plants::Create.run(params.as_json, device_params)
end
def destroy

View File

@ -6,13 +6,15 @@ module Api
end
def create
mutate Regimens::Create.run(params, regimen_params)
mutate Regimens::Create.run(params.as_json, regimen_params)
end
def update
mutate Regimens::Update.run(params,
mutate Regimens::Update.run(params.as_json,
regimen_params,
regimen: the_regimen)
regimen: the_regimen)
rescue => e
binding.pry
end
def destroy

View File

@ -5,7 +5,7 @@ module Api
end
def create
mutate Schedules::Create.run(params,
mutate Schedules::Create.run(params.as_json,
device: current_device,
sequence: sequence)
end
@ -14,7 +14,7 @@ module Api
if schedule.device != current_device
raise Errors::Forbidden, 'Not your schedule.'
end
mutate Schedules::Update.run(params[:schedule],
mutate Schedules::Update.run(params[:schedule].as_json,
device: current_device,
schedule: schedule)
end

View File

@ -13,11 +13,11 @@ module Api
end
def create
mutate Sequences::Create.run(params, device: current_device)
mutate Sequences::Create.run(params.as_json, device: current_device)
end
def update
mutate Sequences::Update.run(params[:sequence],
mutate Sequences::Update.run(params[:sequence].as_json,
device: current_device,
sequence: sequence)
end

View File

@ -12,7 +12,7 @@ require 'pry'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'features/helpers'
require_relative './stuff'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

39
spec/stuff.rb 100644
View File

@ -0,0 +1,39 @@
module Helpers
AST_FIXTURE = File.read("./spec/lib/celery_script/ast_fixture3.json").freeze
# Create a VALID fake sequence.body for a particular user. Creates a fake
# subsequence in the DB when called.
def sequence_body_for(input)
body = JSON.parse(AST_FIXTURE)["body"]
case input
when User; id = FactoryGirl.create(:sequence, device: user.device).id
when Sequence; id = input.id
else; raise "?????"
end
body.map! do |node|
has_subseq = node.dig("args", "sub_sequence_id");
node["args"]["sub_sequence_id"] = id if has_subseq
node
end
body
end
def sign_in_as(user)
# 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
click_button 'Sign in'
end
def json
json = JSON.parse(response.body)
if json.is_a?(Array)
json.map(&:deep_symbolize_keys!)
else
json.deep_symbolize_keys!
end
end
end