Skip to content

Commit

Permalink
Merge branch 'staging' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Sep 24, 2019
2 parents f5982bf + 066f304 commit 8361f5d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 17 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/point_groups_controller.rb
Expand Up @@ -6,6 +6,10 @@ def index
render json: your_point_groups
end

def show
render json: the_point_group
end

def create
mutate PointGroups::Create.run(raw_json, point_group_params)
end
Expand Down
35 changes: 20 additions & 15 deletions app/mutations/devices/sync.rb
Expand Up @@ -2,22 +2,27 @@ module Devices
class Sync < Mutations::Command
SEL = "SELECT id, updated_at FROM"
WHERE = "WHERE device_id = "
WHERE2 = "devices WHERE id = "

def self.basic_query(plural_resource, where = WHERE)
[SEL, plural_resource, where].join(" ")
end

QUERIES = {
devices: [SEL, WHERE2].join(" "),
farm_events: [SEL, "farm_events", WHERE].join(" "),
farmware_envs: [SEL, "farmware_envs", WHERE].join(" "),
farmware_installations: [SEL, "farmware_installations", WHERE].join(" "),
peripherals: [SEL, "peripherals", WHERE].join(" "),
pin_bindings: [SEL, "pin_bindings", WHERE].join(" "),
points: [SEL, "points", WHERE].join(" "),
regimens: [SEL, "regimens", WHERE].join(" "),
sensor_readings: [SEL, "sensor_readings", WHERE].join(" "),
sensors: [SEL, "sensors", WHERE].join(" "),
sequences: [SEL, "sequences", WHERE].join(" "),
tools: [SEL, "tools", WHERE].join(" "),
fbos_configs: [SEL, "fbos_configs", WHERE].join(" "),
firmware_configs: [SEL, "firmware_configs", WHERE].join(" "),
devices: basic_query("devices", "WHERE id = "),
farm_events: basic_query("farm_events"),
farmware_envs: basic_query("farmware_envs"),
farmware_installations: basic_query("farmware_installations"),
peripherals: basic_query("peripherals"),
pin_bindings: basic_query("pin_bindings"),
points: basic_query("points"),
regimens: basic_query("regimens"),
sensor_readings: basic_query("sensor_readings"),
sensors: basic_query("sensors"),
sequences: basic_query("sequences"),
tools: basic_query("tools"),
fbos_configs: basic_query("fbos_configs"),
firmware_configs: basic_query("firmware_configs"),
point_groups: basic_query("point_groups"),
}

STUB_FARMWARES = Api::FirstPartyFarmwaresController::STUBS.values.map do |x|
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -18,7 +18,7 @@
peripherals: [:create, :destroy, :index, :show, :update],
pin_bindings: [:create, :destroy, :index, :show, :update],
plant_templates: [:create, :destroy, :index, :update],
point_groups: [:index, :create, :update, :destroy],
point_groups: [:index, :show, :create, :update, :destroy],
regimens: [:create, :destroy, :index, :show, :update],
sensor_readings: [:create, :destroy, :index, :show],
sensors: [:create, :destroy, :index, :show, :update],
Expand Down
Expand Up @@ -28,6 +28,7 @@
FactoryBot.create(:sensor, device: device)
FactoryBot.create(:tool_slot, device: device)
FactoryBot.create(:tool, device: device)
FactoryBot.create(:point_group, device: device)
FakeSequence.create(device: device)

get :sync, params: {}, session: { format: :json }
Expand Down
20 changes: 20 additions & 0 deletions spec/controllers/api/point_groups/show_spec.rb
@@ -0,0 +1,20 @@
require "spec_helper"

describe Api::PointGroupsController do
include Devise::Test::ControllerHelpers

let(:user) { FactoryBot.create(:user) }
let(:device) { user.device }
let(:old_point_ids) do rando_points end

it "shows a single point group" do
PointGroup.destroy_all
PointGroupItem.destroy_all
sign_in device.users.first
pg = PointGroups::Create
.run!(device: device, point_ids: [], name: "PointGroups#show test")
get :show, params: { id: pg.id }
expect(response.status).to eq(200)
expect(json.fetch(:name)).to eq pg.name
end
end
3 changes: 2 additions & 1 deletion spec/factories/point_groups.rb
@@ -1,5 +1,6 @@
FactoryBot.define do
factory :point_group do
point_group_items
name { Faker::Games::Pokemon.name }
# point_group_items # TODO: Broke - RC 23 Sept 19
end
end
1 change: 1 addition & 0 deletions spec/mutations/devices/sync_spec.rb
Expand Up @@ -20,6 +20,7 @@
:sensors,
:sequences,
:tools,
:point_groups,
])

it "is different this time!" do
Expand Down

0 comments on commit 8361f5d

Please sign in to comment.