From d306b65909ebf7cb1cd7408e14ff5ba7d1b4f2bd Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 2 Jan 2020 12:20:29 -0600 Subject: [PATCH 01/15] Use radio buttons for pin selection (instead of input text boxes) --- frontend/sequences/__tests__/Untitled-1 | 0 frontend/sequences/step_tiles/tile_reboot.tsx | 2 +- .../step_tiles/tile_set_servo_angle.tsx | 52 ++++++++++++++++--- 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 frontend/sequences/__tests__/Untitled-1 diff --git a/frontend/sequences/__tests__/Untitled-1 b/frontend/sequences/__tests__/Untitled-1 new file mode 100644 index 000000000..e69de29bb diff --git a/frontend/sequences/step_tiles/tile_reboot.tsx b/frontend/sequences/step_tiles/tile_reboot.tsx index 10037dc8c..872365531 100644 --- a/frontend/sequences/step_tiles/tile_reboot.tsx +++ b/frontend/sequences/step_tiles/tile_reboot.tsx @@ -16,7 +16,7 @@ interface MultiChoiceRadioProps { onChange(key: keyof T): void; } -const MultiChoiceRadio = +export const MultiChoiceRadio = (props: MultiChoiceRadioProps) => { const choices = Object.keys(props.choices); return diff --git a/frontend/sequences/step_tiles/tile_set_servo_angle.tsx b/frontend/sequences/step_tiles/tile_set_servo_angle.tsx index 8f5b3029f..0ee2680cb 100644 --- a/frontend/sequences/step_tiles/tile_set_servo_angle.tsx +++ b/frontend/sequences/step_tiles/tile_set_servo_angle.tsx @@ -5,6 +5,45 @@ import { ToolTips } from "../../constants"; import { StepWrapper, StepHeader, StepContent } from "../step_ui/index"; import { Row, Col } from "../../ui/index"; import { t } from "../../i18next_wrapper"; +import { MultiChoiceRadio } from "./tile_reboot"; +import { SetServoAngle } from "farmbot"; +import { editStep } from "../../api/crud"; + +const PACKAGE_CHOICES: Record = { + "4": "Pin 4", + "5": "Pin 5", +}; + +type Keys = + | "dispatch" + | "currentStep" + | "currentSequence" + | "index"; +type Props = Pick; + +const servoAngleChanger = (props: Props) => (y: string) => { + props.dispatch(editStep({ + step: props.currentStep, + sequence: props.currentSequence, + index: props.index, + executor(x: SetServoAngle) { + x.args.pin_number = parseInt(y, 10); + } + })); +}; + +function ServoPinSelection(props: Props) { + const { currentSequence, index, currentStep } = props; + const num = (currentStep as SetServoAngle).args.pin_number; + if (typeof num !== "number") { throw new Error("NO!"); } + const onChange = servoAngleChanger(props); + + return ; +} export function TileSetServoAngle(props: StepParams) { const { dispatch, currentStep, index, currentSequence } = props; @@ -22,17 +61,16 @@ export function TileSetServoAngle(props: StepParams) { - + - - + {t("Servo angle (0-180)")} + + Date: Thu, 2 Jan 2020 12:56:21 -0600 Subject: [PATCH 02/15] Fix test breakage in set_servo_angle. --- .../step_tiles/__tests__/tile_set_servo_angle_test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx b/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx index 101ae559b..29d38a6ac 100644 --- a/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx +++ b/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx @@ -28,10 +28,10 @@ describe("", () => { const block = mount(); const inputs = block.find("input"); const labels = block.find("label"); - expect(inputs.length).toEqual(3); - expect(labels.length).toEqual(2); + expect(inputs.length).toEqual(4); + expect(labels.length).toEqual(4); expect(inputs.first().props().placeholder).toEqual("Set Servo Angle"); expect(labels.at(0).text()).toContain("Servo pin"); - expect(inputs.at(1).props().value).toEqual(4); + expect(inputs.at(1).props().value).toEqual("4"); }); }); From f9e5559ee0e8bc94828ef54c43d6f9bad25d5017 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 2 Jan 2020 13:58:20 -0600 Subject: [PATCH 03/15] More tests + step color updates, DRY up perihperal selector. --- frontend/sequences/step_button_cluster.tsx | 2 +- .../__tests__/tile_set_servo_angle_test.tsx | 48 ++++++++++++++++++- .../step_tiles/pin_and_peripheral_support.tsx | 1 + .../step_tiles/tile_set_servo_angle.tsx | 14 +++--- .../sequences/step_tiles/tile_toggle_pin.tsx | 16 ++----- .../sequences/step_tiles/tile_write_pin.tsx | 27 ++++++++--- 6 files changed, 80 insertions(+), 28 deletions(-) diff --git a/frontend/sequences/step_button_cluster.tsx b/frontend/sequences/step_button_cluster.tsx index 35833377a..a40789560 100644 --- a/frontend/sequences/step_button_cluster.tsx +++ b/frontend/sequences/step_button_cluster.tsx @@ -55,7 +55,7 @@ export function StepButtonCluster(props: StepButtonProps) { pin_number: 4 } }} - color="yellow"> + color="orange"> {t("TOGGLE PERIPHERAL")} , ({ editStep: jest.fn() })); + import * as React from "react"; -import { TileSetServoAngle } from "../tile_set_servo_angle"; +import { TileSetServoAngle, pinNumberChanger, createServoEditFn, ServoPinSelection } from "../tile_set_servo_angle"; import { mount } from "enzyme"; import { fakeSequence } from "../../../__test_support__/fake_state/resources"; import { SetServoAngle } from "farmbot"; import { emptyState } from "../../../resources/reducer"; import { StepParams } from "../../interfaces"; +import { editStep } from "../../../api/crud"; describe("", () => { const currentStep: SetServoAngle = { @@ -18,7 +21,7 @@ describe("", () => { const fakeProps = (): StepParams => ({ currentSequence: fakeSequence(), currentStep: currentStep, - dispatch: jest.fn(), + dispatch: jest.fn((fn: Function) => typeof fn === "function" && fn()), index: 0, resources: emptyState().index, confirmStepDeletion: false, @@ -34,4 +37,45 @@ describe("", () => { expect(labels.at(0).text()).toContain("Servo pin"); expect(inputs.at(1).props().value).toEqual("4"); }); + + it("Changes pin number", () => { + const props = fakeProps(); + const fn = pinNumberChanger(props); + fn("5"); + expect(editStep).toHaveBeenCalledWith({ + step: props.currentStep, + sequence: props.currentSequence, + index: props.index, + executor: expect.any(Function) + }); + }); + + it("dissallows named_pins", () => { + const p = fakeProps(); + const step = p.currentStep; + if (step.kind === "set_servo_angle") { + step.args.pin_number = { + kind: "named_pin", + args: { pin_id: 0, pin_type: "Peripheral" } + }; + const boom = () => ServoPinSelection(p); + expect(boom).toThrowError(); + return; + } + + fail(); + }); + + it("creates a servo edit function", () => { + const props = fakeProps(); + const step = props.currentStep; + const fn = createServoEditFn("4"); + if (step.kind === "set_servo_angle") { + step.args.pin_number = 1; + fn(step); + expect(step.args.pin_number).toEqual(4); + } else { + fail(); + } + }); }); diff --git a/frontend/sequences/step_tiles/pin_and_peripheral_support.tsx b/frontend/sequences/step_tiles/pin_and_peripheral_support.tsx index ff0555ba7..6c866b572 100644 --- a/frontend/sequences/step_tiles/pin_and_peripheral_support.tsx +++ b/frontend/sequences/step_tiles/pin_and_peripheral_support.tsx @@ -210,6 +210,7 @@ export const setArgsDotPinNumber = switch (c.kind) { case "read_pin": case "write_pin": + case "toggle_pin": c.args.pin_number = dropDown2CeleryArg(resources, d); } } diff --git a/frontend/sequences/step_tiles/tile_set_servo_angle.tsx b/frontend/sequences/step_tiles/tile_set_servo_angle.tsx index 0ee2680cb..2216b17f9 100644 --- a/frontend/sequences/step_tiles/tile_set_servo_angle.tsx +++ b/frontend/sequences/step_tiles/tile_set_servo_angle.tsx @@ -21,22 +21,24 @@ type Keys = | "index"; type Props = Pick; -const servoAngleChanger = (props: Props) => (y: string) => { +export const createServoEditFn = (y: string) => (x: SetServoAngle) => { + x.args.pin_number = parseInt(y, 10); +}; + +export const pinNumberChanger = (props: Props) => (y: string) => { props.dispatch(editStep({ step: props.currentStep, sequence: props.currentSequence, index: props.index, - executor(x: SetServoAngle) { - x.args.pin_number = parseInt(y, 10); - } + executor: createServoEditFn(y) })); }; -function ServoPinSelection(props: Props) { +export function ServoPinSelection(props: Props) { const { currentSequence, index, currentStep } = props; const num = (currentStep as SetServoAngle).args.pin_number; if (typeof num !== "number") { throw new Error("NO!"); } - const onChange = servoAngleChanger(props); + const onChange = pinNumberChanger(props); return - - - - + ; diff --git a/frontend/sequences/step_tiles/tile_write_pin.tsx b/frontend/sequences/step_tiles/tile_write_pin.tsx index c6ec24d2c..86463ab7e 100644 --- a/frontend/sequences/step_tiles/tile_write_pin.tsx +++ b/frontend/sequences/step_tiles/tile_write_pin.tsx @@ -44,22 +44,35 @@ export interface WritePinStepParams { showPins: boolean; } -export class WritePinStep extends React.Component { +interface PinSelectProps extends StepParams { + width?: number; +}; - PinSelect = (): JSX.Element => { - const { currentSequence, resources, showPins } = this.props; - const { pin_number } = this.props.currentStep.args; - return +export const PinSelect = (props: PinSelectProps): JSX.Element => { + const step = props.currentStep; + if ( + step.kind === "write_pin" || + step.kind === "toggle_pin" || + step.kind === "read_pin") { + const { currentSequence, resources, showPins } = props; + const { pin_number } = step.args; + const width = props.width || 6; + + return ; } + throw new Error("Can't render " + step ? step.kind : "NULL"); +}; + +export class WritePinStep extends React.Component { PinValueField = (): JSX.Element => { const { dispatch, currentStep, index, currentSequence } = this.props; return (!(currentStep.args.pin_mode === 0) || currentStep.args.pin_value > 1) @@ -90,7 +103,7 @@ export class WritePinStep extends React.Component { confirmStepDeletion={this.props.confirmStepDeletion} /> - + From 0d9bf3ccc55f4d643f8aed95065bb435ca91fa0c Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 2 Jan 2020 15:46:52 -0600 Subject: [PATCH 04/15] Fix test breakage due to refactoring --- .../sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx b/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx index 47568204a..b09eb4def 100644 --- a/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx +++ b/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx @@ -27,10 +27,9 @@ describe("", () => { const block = mount(); const inputs = block.find("input"); const labels = block.find("label"); - expect(inputs.length).toEqual(2); + expect(inputs.length).toEqual(1); expect(labels.length).toEqual(1); expect(inputs.first().props().placeholder).toEqual("Toggle Pin"); - expect(labels.at(0).text()).toContain("Pin"); - expect(inputs.at(1).props().value).toEqual(13); + expect(labels.at(0).text()).toContain("Peripheral"); }); }); From f51e9ad4c904632bcecc696ff9284d4d4d190759 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 2 Jan 2020 16:05:12 -0600 Subject: [PATCH 05/15] Verbiage and color changes. --- frontend/sequences/step_button_cluster.tsx | 2 +- .../step_tiles/__tests__/tile_set_servo_angle_test.tsx | 2 +- .../sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx | 2 +- frontend/sequences/step_tiles/step_title_bar.tsx | 4 ++-- frontend/sequences/step_tiles/tile_reboot.tsx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/sequences/step_button_cluster.tsx b/frontend/sequences/step_button_cluster.tsx index a40789560..0f44a7bba 100644 --- a/frontend/sequences/step_button_cluster.tsx +++ b/frontend/sequences/step_button_cluster.tsx @@ -103,7 +103,7 @@ export function StepButtonCluster(props: StepButtonProps) { - {t("EMERGENCY LOCK")} + {t("E-STOP")} , ", () => { const labels = block.find("label"); expect(inputs.length).toEqual(4); expect(labels.length).toEqual(4); - expect(inputs.first().props().placeholder).toEqual("Set Servo Angle"); + expect(inputs.first().props().placeholder).toEqual("Control Servo"); expect(labels.at(0).text()).toContain("Servo pin"); expect(inputs.at(1).props().value).toEqual("4"); }); diff --git a/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx b/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx index b09eb4def..54f9a3ae2 100644 --- a/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx +++ b/frontend/sequences/step_tiles/__tests__/tile_toggle_pin_test.tsx @@ -29,7 +29,7 @@ describe("", () => { const labels = block.find("label"); expect(inputs.length).toEqual(1); expect(labels.length).toEqual(1); - expect(inputs.first().props().placeholder).toEqual("Toggle Pin"); + expect(inputs.first().props().placeholder).toEqual("Toggle Peripheral"); expect(labels.at(0).text()).toContain("Peripheral"); }); }); diff --git a/frontend/sequences/step_tiles/step_title_bar.tsx b/frontend/sequences/step_tiles/step_title_bar.tsx index c93c5b242..e84a21c96 100644 --- a/frontend/sequences/step_tiles/step_title_bar.tsx +++ b/frontend/sequences/step_tiles/step_title_bar.tsx @@ -21,7 +21,7 @@ function translate(input: Step): string { "take_photo": t("Take a Photo"), "resource_update": t("Mark As"), "assertion": t("Assertion"), - "set_servo_angle": t("Set Servo Angle"), + "set_servo_angle": t("Control Servo"), "wait": t("Wait"), "write_pin": t("Control Peripheral"), "sync": t("Sync"), @@ -39,7 +39,7 @@ function translate(input: Step): string { "home": t("Move to Home"), "factory_reset": t("Factory reset"), "reboot": t("Reboot"), - "toggle_pin": t("Toggle Pin"), + "toggle_pin": t("Toggle Peripheral"), "zero": t("Set zero"), "set_user_env": t("Set Farmware Env"), }; diff --git a/frontend/sequences/step_tiles/tile_reboot.tsx b/frontend/sequences/step_tiles/tile_reboot.tsx index 872365531..c81594edf 100644 --- a/frontend/sequences/step_tiles/tile_reboot.tsx +++ b/frontend/sequences/step_tiles/tile_reboot.tsx @@ -74,7 +74,7 @@ export const editTheRebootStep = export function TileReboot(props: StepParams) { const { dispatch, currentStep, index, currentSequence } = props; - const className = "set-zero-step"; + const className = "take-photo-step"; assertReboot(currentStep); return Date: Thu, 2 Jan 2020 16:45:32 -0600 Subject: [PATCH 06/15] Sizing and color changes pt III --- .../sequences/step_tiles/tile_set_servo_angle.tsx | 12 +++++------- frontend/sequences/step_tiles/tile_toggle_pin.tsx | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/sequences/step_tiles/tile_set_servo_angle.tsx b/frontend/sequences/step_tiles/tile_set_servo_angle.tsx index 2216b17f9..a758dc708 100644 --- a/frontend/sequences/step_tiles/tile_set_servo_angle.tsx +++ b/frontend/sequences/step_tiles/tile_set_servo_angle.tsx @@ -61,13 +61,7 @@ export function TileSetServoAngle(props: StepParams) { confirmStepDeletion={props.confirmStepDeletion} /> - - - - - - - + @@ -78,6 +72,10 @@ export function TileSetServoAngle(props: StepParams) { index={index} field={"pin_value"} /> + + + + ; diff --git a/frontend/sequences/step_tiles/tile_toggle_pin.tsx b/frontend/sequences/step_tiles/tile_toggle_pin.tsx index 5d51eb9a1..9ac8efd92 100644 --- a/frontend/sequences/step_tiles/tile_toggle_pin.tsx +++ b/frontend/sequences/step_tiles/tile_toggle_pin.tsx @@ -19,7 +19,7 @@ export function TileTogglePin(props: StepParams) { confirmStepDeletion={props.confirmStepDeletion} /> - + ; From d5bbc95b1f65d7648c2fab98591ee24b39032008 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 2 Jan 2020 17:07:06 -0600 Subject: [PATCH 07/15] Linter fix --- frontend/sequences/step_tiles/tile_write_pin.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/sequences/step_tiles/tile_write_pin.tsx b/frontend/sequences/step_tiles/tile_write_pin.tsx index 86463ab7e..283b4dd50 100644 --- a/frontend/sequences/step_tiles/tile_write_pin.tsx +++ b/frontend/sequences/step_tiles/tile_write_pin.tsx @@ -46,7 +46,7 @@ export interface WritePinStepParams { interface PinSelectProps extends StepParams { width?: number; -}; +} export const PinSelect = (props: PinSelectProps): JSX.Element => { const step = props.currentStep; From 2226d3b34b9d90c4a0e143d36ea0d69278481e62 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 08:18:21 -0600 Subject: [PATCH 08/15] Update unit tests to account for input position swap --- .../step_tiles/__tests__/tile_set_servo_angle_test.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx b/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx index e6d0dd0bf..6f0883cb4 100644 --- a/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx +++ b/frontend/sequences/step_tiles/__tests__/tile_set_servo_angle_test.tsx @@ -28,14 +28,17 @@ describe("", () => { }); it("renders inputs", () => { - const block = mount(); + const props = fakeProps(); + const block = mount(); const inputs = block.find("input"); const labels = block.find("label"); + const stepArgs = props.currentStep.args as SetServoAngle["args"]; expect(inputs.length).toEqual(4); expect(labels.length).toEqual(4); expect(inputs.first().props().placeholder).toEqual("Control Servo"); - expect(labels.at(0).text()).toContain("Servo pin"); - expect(inputs.at(1).props().value).toEqual("4"); + expect(labels.at(0).text()).toContain("Servo angle (0-180)"); + expect(inputs.at(1).props().value).toEqual(stepArgs.pin_value); + expect(inputs.at(2).props().value).toEqual("" + stepArgs.pin_number); }); it("Changes pin number", () => { From 721fea39b266d1eaefaf1ef04c6c83f9a851dd3a Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 09:31:48 -0600 Subject: [PATCH 09/15] First wave of 2.7.0 deprecation fixes --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 2 +- app/models/fragment.rb | 2 +- app/models/image.rb | 2 +- app/mutations/farm_events/fragment_helpers.rb | 2 +- app/mutations/fragments/preprocessor.rb | 2 +- docker_configs/api.Dockerfile | 2 +- spec/controllers/api/password_resets/password_resets_spec.rb | 2 +- spec/lib/celery_script/body_spec.rb | 2 +- spec/lib/celery_script/corpus_spec.rb | 4 ++-- spec/lib/celery_script/point_spec.rb | 2 +- spec/lib/celery_script/tree_climber_spec.rb | 2 +- spec/mutations/fragments/show_spec.rb | 4 ++-- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.ruby-version b/.ruby-version index 57cf282eb..24ba9a38d 100755 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.5 +2.7.0 diff --git a/Gemfile b/Gemfile index 1dd25d39a..d7c7a011a 100755 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source "https://rubygems.org" -ruby "~> 2.6.5" +ruby "~> 2.7.0" gem "rails" gem "active_model_serializers" diff --git a/Gemfile.lock b/Gemfile.lock index db0988022..4da63cf6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -341,7 +341,7 @@ DEPENDENCIES valid_url RUBY VERSION - ruby 2.6.5p114 + ruby 2.7.0p0 BUNDLED WITH 1.17.2 diff --git a/app/models/fragment.rb b/app/models/fragment.rb index 707caad09..da355cdc4 100644 --- a/app/models/fragment.rb +++ b/app/models/fragment.rb @@ -78,7 +78,7 @@ class Fragment < ApplicationRecord def self.from_celery(device:, kind:, args:, body:, owner:) p = { device: device, kind: kind, args: args, body: body } - flat_ast = Fragments::Preprocessor.run!(p) + flat_ast = Fragments::Preprocessor.run!(**p) Fragments::Create.run!(device: device, flat_ast: flat_ast, owner: owner) diff --git a/app/models/image.rb b/app/models/image.rb index 81a154849..50bbb57ea 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -43,7 +43,7 @@ class Image < ApplicationRecord has_one_attached :attachment def set_attachment_by_url(url) - attachment.attach(io: open(url), filename: "image_#{self.id}") + attachment.attach(io: URI.open(url), filename: "image_#{self.id}") self.attachment_processed_at = Time.now self end diff --git a/app/mutations/farm_events/fragment_helpers.rb b/app/mutations/farm_events/fragment_helpers.rb index 653f92c54..27d3748e3 100644 --- a/app/mutations/farm_events/fragment_helpers.rb +++ b/app/mutations/farm_events/fragment_helpers.rb @@ -16,7 +16,7 @@ module FarmEvents kind: "internal_#{kind}", args: {}, body: body } - flat_ast = Fragments::Preprocessor.run!(params) + flat_ast = Fragments::Preprocessor.run!(**params) Fragments::Create.run!(device: device, flat_ast: flat_ast, owner: owner) diff --git a/app/mutations/fragments/preprocessor.rb b/app/mutations/fragments/preprocessor.rb index 802c98dca..5710f8af4 100644 --- a/app/mutations/fragments/preprocessor.rb +++ b/app/mutations/fragments/preprocessor.rb @@ -5,7 +5,7 @@ module Fragments def self.run!(kind:, args:, body:, device:) canonical = {kind: kind, args: args, body: body} slicer = CeleryScript::Slicer.new - tree = CeleryScript::AstNode.new(canonical.deep_symbolize_keys) + tree = CeleryScript::AstNode.new(**canonical.deep_symbolize_keys) checker = CeleryScript::Checker.new(tree, Corpus, device) checker.run! slicer.run!(canonical) diff --git a/docker_configs/api.Dockerfile b/docker_configs/api.Dockerfile index 067bb8c10..0c0f0327e 100644 --- a/docker_configs/api.Dockerfile +++ b/docker_configs/api.Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.6.5 +FROM ruby:2.7.0 RUN wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - && \ sh -c 'VERSION_CODENAME=stretch; . /etc/os-release; echo "deb http://apt.postgresql.org/pub/repos/apt/ $VERSION_CODENAME-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' && \ apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql postgresql-contrib && \ diff --git a/spec/controllers/api/password_resets/password_resets_spec.rb b/spec/controllers/api/password_resets/password_resets_spec.rb index 5730cf819..84a59dca2 100644 --- a/spec/controllers/api/password_resets/password_resets_spec.rb +++ b/spec/controllers/api/password_resets/password_resets_spec.rb @@ -51,7 +51,7 @@ describe Api::PasswordResetsController do it "handles token expiration" do token = PasswordResetToken - .issue_to(user, { exp: Time.now.yesterday.to_i }) + .issue_to(user, **{ exp: Time.now.yesterday.to_i }) .encoded params = { password: "xpassword123", diff --git a/spec/lib/celery_script/body_spec.rb b/spec/lib/celery_script/body_spec.rb index 88518ec60..59c6cdd5e 100644 --- a/spec/lib/celery_script/body_spec.rb +++ b/spec/lib/celery_script/body_spec.rb @@ -9,7 +9,7 @@ describe "Body nodes" do let(:device) { FactoryBot.create(:device) } it "always always empty bodies" do - tree = CeleryScript::AstNode.new({ + tree = CeleryScript::AstNode.new(**{ "kind": "baz", "args": {}, "body": [] diff --git a/spec/lib/celery_script/corpus_spec.rb b/spec/lib/celery_script/corpus_spec.rb index 0da441975..79f9d06eb 100644 --- a/spec/lib/celery_script/corpus_spec.rb +++ b/spec/lib/celery_script/corpus_spec.rb @@ -5,7 +5,7 @@ describe CeleryScript::Corpus do let(:corpus) { Sequence::Corpus } it "handles valid move_absolute blocks" do - ok1 = CeleryScript::AstNode.new({ + ok1 = CeleryScript::AstNode.new(**{ kind: "move_absolute", args: { location: { @@ -75,7 +75,7 @@ describe CeleryScript::Corpus do end it "finds problems with nested nodes" do - bad = CeleryScript::AstNode.new({ + bad = CeleryScript::AstNode.new(**{ kind: "move_absolute", args: { location: { diff --git a/spec/lib/celery_script/point_spec.rb b/spec/lib/celery_script/point_spec.rb index 5e77a40b1..e655181cc 100644 --- a/spec/lib/celery_script/point_spec.rb +++ b/spec/lib/celery_script/point_spec.rb @@ -22,7 +22,7 @@ describe "Celery Script `point` node" do }.deep_symbolize_keys end - let(:tree) { CeleryScript::AstNode.new(hash) } + let(:tree) { CeleryScript::AstNode.new(**hash) } let(:corpus) { Sequence::Corpus } let(:device) { plant.device } let(:checker) { CeleryScript::Checker.new(tree, corpus, device) } diff --git a/spec/lib/celery_script/tree_climber_spec.rb b/spec/lib/celery_script/tree_climber_spec.rb index 90ea36846..2860b40c1 100644 --- a/spec/lib/celery_script/tree_climber_spec.rb +++ b/spec/lib/celery_script/tree_climber_spec.rb @@ -5,7 +5,7 @@ describe CeleryScript::TreeClimber do let(:node) do hash = JSON.parse(file_path).deep_symbolize_keys - CeleryScript::AstNode.new(hash) + CeleryScript::AstNode.new(**hash) end it "travels to each node with a callable object" do diff --git a/spec/mutations/fragments/show_spec.rb b/spec/mutations/fragments/show_spec.rb index ed79613c7..1bb8698eb 100644 --- a/spec/mutations/fragments/show_spec.rb +++ b/spec/mutations/fragments/show_spec.rb @@ -47,7 +47,7 @@ describe Fragments::Create do }, ], } - flat_ast = Fragments::Preprocessor.run!(origin) + flat_ast = Fragments::Preprocessor.run!(**origin) fragment = Fragments::Create.run!(flat_ast: flat_ast, owner: farm_event) result = Fragments::Show.run!(owner: farm_event) diff = Hashdiff.diff(origin.without(:device), result.deep_symbolize_keys) @@ -83,7 +83,7 @@ describe Fragments::Create do config.logger = spy_logger fragment = Fragments::Create.run!(device: device, owner: farm_event, - flat_ast: Fragments::Preprocessor.run!(origin)) + flat_ast: Fragments::Preprocessor.run!(**origin)) # Warm the cache up with two dry-runs: Fragments::Show.run!(owner: farm_event) Fragments::Show.run!(owner: farm_event) From 1383a5bb1aaeaf730fae422d1cb6e7581fe690ab Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 09:49:59 -0600 Subject: [PATCH 10/15] Round II of 2.7.0 deprecation fixes --- Gemfile | 1 + Gemfile.lock | 20 ++++++++++---------- app/lib/celery_script/ast_node.rb | 2 +- spec/lib/celery_script/body_spec.rb | 6 +++--- spec/lib/celery_script/checker_spec.rb | 12 +++++------- spec/lib/celery_script/corpus_spec.rb | 23 ++++++++++++----------- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Gemfile b/Gemfile index d7c7a011a..dd86b9bb1 100755 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem "scenic" gem "secure_headers" gem "tzinfo" # For validation of user selected timezone names gem "valid_url" +# gem "farady", "~> 1.0.0" group :development, :test do gem "climate_control" diff --git a/Gemfile.lock b/Gemfile.lock index 4da63cf6a..42c73db91 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,7 +109,7 @@ GEM factory_bot_rails (5.1.1) factory_bot (~> 5.1.0) railties (>= 4.2.0) - faker (2.9.0) + faker (2.10.0) i18n (>= 1.6, < 1.8) faraday (0.15.4) multipart-post (>= 1.2, < 3) @@ -119,7 +119,7 @@ GEM railties (>= 3.2, < 6.1) globalid (0.4.2) activesupport (>= 4.2.0) - google-api-client (0.36.1) + google-api-client (0.36.3) addressable (~> 2.5, >= 2.5.1) googleauth (~> 0.9) httpclient (>= 2.8.1, < 3.0) @@ -178,13 +178,13 @@ GEM passenger (6.0.4) rack rake (>= 0.8.1) - pg (1.1.4) + pg (1.2.1) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.1) + public_suffix (4.0.2) rabbitmq_http_api_client (1.12.0) faraday (~> 0.15.4) faraday_middleware (~> 0.13.0) @@ -193,7 +193,7 @@ GEM rack (2.0.8) rack-attack (6.2.2) rack (>= 1.0, < 3) - rack-cors (1.1.0) + rack-cors (1.1.1) rack (>= 2.0.0) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -245,12 +245,12 @@ GEM rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) - rspec-core (3.9.0) - rspec-support (~> 3.9.0) + rspec-core (3.9.1) + rspec-support (~> 3.9.1) rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-mocks (3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-rails (4.0.0.beta3) @@ -261,7 +261,7 @@ GEM rspec-expectations (~> 3.8) rspec-mocks (~> 3.8) rspec-support (~> 3.8) - rspec-support (3.9.0) + rspec-support (3.9.2) scenic (1.5.1) activerecord (>= 4.0.0) railties (>= 4.0.0) @@ -285,7 +285,7 @@ GEM sprockets (>= 3.0.0) thor (1.0.1) thread_safe (0.3.6) - tzinfo (1.2.5) + tzinfo (1.2.6) thread_safe (~> 0.1) uber (0.1.0) url (0.3.2) diff --git a/app/lib/celery_script/ast_node.rb b/app/lib/celery_script/ast_node.rb index 6009f31c7..3cd85e793 100644 --- a/app/lib/celery_script/ast_node.rb +++ b/app/lib/celery_script/ast_node.rb @@ -26,7 +26,7 @@ module CeleryScript def maybe_initialize(parent, leaf_or_node, key = NEVER) if is_node?(leaf_or_node) - AstNode.new(parent, leaf_or_node) + AstNode.new(parent, **leaf_or_node) else raise TypeCheckError, LEAVES_NEED_KEYS if key == NEVER AstLeaf.new(parent, leaf_or_node, key) diff --git a/spec/lib/celery_script/body_spec.rb b/spec/lib/celery_script/body_spec.rb index 59c6cdd5e..576beb260 100644 --- a/spec/lib/celery_script/body_spec.rb +++ b/spec/lib/celery_script/body_spec.rb @@ -19,7 +19,7 @@ describe "Body nodes" do end it "kicks back unexpected nodes" do - tree = CeleryScript::AstNode.new({ + tree = CeleryScript::AstNode.new(**{ "kind": "baz", "args": {}, "body": [{ "kind": "wrong", "args": {}}] @@ -30,7 +30,7 @@ describe "Body nodes" do end it "handles body members of nodes that shouldn't have bodies." do - tree = CeleryScript::AstNode.new({ + tree = CeleryScript::AstNode.new(**{ "kind": "baz", "args": {}, "body": [{ "kind": "wrong", "args": {}}] @@ -41,7 +41,7 @@ describe "Body nodes" do end it 'disallows leaves in the body field of a node' do - tree = CeleryScript::AstNode.new({ + tree = CeleryScript::AstNode.new(**{ "kind": "wrong", "args": {}, "body": [ diff --git a/spec/lib/celery_script/checker_spec.rb b/spec/lib/celery_script/checker_spec.rb index f0125c554..fa64f2fb8 100644 --- a/spec/lib/celery_script/checker_spec.rb +++ b/spec/lib/celery_script/checker_spec.rb @@ -14,9 +14,7 @@ describe CeleryScript::Checker do }.deep_symbolize_keys end - let(:tree) do - CeleryScript::AstNode.new(hash) - end + let(:tree) { CeleryScript::AstNode.new(**hash) } let (:corpus) { Sequence::Corpus } @@ -205,14 +203,14 @@ describe CeleryScript::Checker do it "catches bad `axis` nodes" do t = - CeleryScript::AstNode.new({ kind: "home", args: { speed: 100, axis: "?" } }) + CeleryScript::AstNode.new(kind: "home", args: { speed: 100, axis: "?" }) chk = CeleryScript::Checker.new(t, corpus, device) expect(chk.valid?).to be false expect(chk.error.message).to include("not a valid axis") end it "catches bad `package` nodes" do - t = CeleryScript::AstNode.new({ kind: "factory_reset", args: { package: "?" } }) + t = CeleryScript::AstNode.new(kind: "factory_reset", args: { package: "?" }) chk = CeleryScript::Checker.new(t, corpus, device) expect(chk.valid?).to be false expect(chk.error.message).to include("not a valid package") @@ -251,7 +249,7 @@ describe CeleryScript::Checker do }, ], } - tree = CeleryScript::AstNode.new(ast) + tree = CeleryScript::AstNode.new(**ast) chk = CeleryScript::Checker.new(tree, corpus, device) expect(chk.valid?).to be true end @@ -289,7 +287,7 @@ describe CeleryScript::Checker do }, ], } - tree = CeleryScript::AstNode.new(ast) + tree = CeleryScript::AstNode.new(**ast) chk = CeleryScript::Checker.new(tree, corpus, device) expect(chk.valid?).to be false message = "must provide a value for all parameters" diff --git a/spec/lib/celery_script/corpus_spec.rb b/spec/lib/celery_script/corpus_spec.rb index 79f9d06eb..b987a6ce6 100644 --- a/spec/lib/celery_script/corpus_spec.rb +++ b/spec/lib/celery_script/corpus_spec.rb @@ -30,7 +30,7 @@ describe CeleryScript::Corpus do check1 = CeleryScript::Checker.new(ok1, corpus, device) expect(check1.valid?).to be_truthy - ok2 = CeleryScript::AstNode.new({ + ok2 = CeleryScript::AstNode.new(**{ kind: "move_absolute", args: { location: { @@ -53,7 +53,7 @@ describe CeleryScript::Corpus do end it "kicks back invalid move_absolute nodes" do - bad = CeleryScript::AstNode.new({ + bad = CeleryScript::AstNode.new(**{ kind: "move_absolute", args: { location: 42, @@ -109,7 +109,7 @@ describe CeleryScript::Corpus do it "Handles message_type validations for version 1" do # This test is __ONLY__ relevant for version 1. # Change / delete / update as needed. - tree = CeleryScript::AstNode.new({ + tree = CeleryScript::AstNode.new(**{ "kind": "send_message", "args": { "message": "Hello, world!", @@ -122,7 +122,7 @@ describe CeleryScript::Corpus do end it "Handles channel_name validations" do - tree = CeleryScript::AstNode.new({ + tree = CeleryScript::AstNode.new(**{ "kind": "send_message", "args": { "message": "Hello, world!", @@ -141,7 +141,7 @@ describe CeleryScript::Corpus do it "validates tool_ids" do ast = { "kind": "tool", "args": { "tool_id": 0 } } - checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(ast), + checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast), corpus, device) expect(checker.valid?).to be(false) @@ -154,7 +154,8 @@ describe CeleryScript::Corpus do "resource_id" => 23, # Mutated to "0" later.. "label" => "mounted_tool_id", "value" => 1 } } - checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(ast), corpus, device) + checker = CeleryScript::Checker + .new(CeleryScript::AstNode.new(**ast), corpus, device) expect(checker.valid?).to be(true) expect(checker.tree.args[:resource_id].value).to eq(device.id) end @@ -167,7 +168,7 @@ describe CeleryScript::Corpus do "resource_id" => fake_id, "label" => "foo", "value" => "Should Fail" } } - hmm = CeleryScript::AstNode.new(ast) + hmm = CeleryScript::AstNode.new(**ast) expect(hmm.args.fetch(:resource_id).value).to eq(fake_id) checker = CeleryScript::Checker.new(hmm, corpus, device) expect(checker.valid?).to be(false) @@ -180,7 +181,7 @@ describe CeleryScript::Corpus do "resource_id" => 0, "label" => "foo", "value" => "Should Fail" } } - checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(ast), + checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast), corpus, device) expect(checker.valid?).to be(false) @@ -222,7 +223,7 @@ describe CeleryScript::Corpus do end it "sets a MAX_WAIT_MS limit for `wait` nodes" do - bad = CeleryScript::AstNode.new({ + bad = CeleryScript::AstNode.new(**{ kind: "wait", args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 }, }) @@ -236,7 +237,7 @@ describe CeleryScript::Corpus do pg = PointGroups::Create.run!(device: device, name: "cs checks", point_ids: []) - bad = CeleryScript::AstNode.new({ + bad = CeleryScript::AstNode.new(**{ kind: "point_group", args: { point_group_id: pg.id }, }) @@ -247,7 +248,7 @@ describe CeleryScript::Corpus do it "disallows invalid `point_group` nodes" do device.auto_sync_transaction do - bad = CeleryScript::AstNode.new({ + bad = CeleryScript::AstNode.new(**{ kind: "point_group", args: { point_group_id: -1 }, }) From ab94c0098cbaa598fd16f637897613a93f15ca9b Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 11:18:31 -0600 Subject: [PATCH 11/15] open() => URI.open() --- app/models/farmware_installation.rb | 2 +- lib/tasks/api.rake | 4 ++-- lib/tasks/coverage.rake | 5 +++-- lib/tasks/fe.rake | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/farmware_installation.rb b/app/models/farmware_installation.rb index 0847f8709..b188a03c7 100644 --- a/app/models/farmware_installation.rb +++ b/app/models/farmware_installation.rb @@ -50,7 +50,7 @@ class FarmwareInstallation < ApplicationRecord # SLOW I/O BOUND STUFF! Don't run this on the # main thread! def infer_package_name_from_url - string_io = open(url) + string_io = URI.open(url) string = string_io.read(MAX_JSON_SIZE) json = JSON.parse(string) pkg_name = json.fetch("package") diff --git a/lib/tasks/api.rake b/lib/tasks/api.rake index d4f36c0c4..c91047ec9 100644 --- a/lib/tasks/api.rake +++ b/lib/tasks/api.rake @@ -116,8 +116,8 @@ namespace :api do # 60 days is the current policy. cutoff = 60.days.ago # Download release data from github - string_page_1 = open("#{RELEASES_URL}?per_page=100&page=1").read - string_page_2 = open("#{RELEASES_URL}?per_page=100&page=2").read + string_page_1 = URI.open("#{RELEASES_URL}?per_page=100&page=1").read + string_page_2 = URI.open("#{RELEASES_URL}?per_page=100&page=2").read data = JSON.parse(string_page_1).push(*JSON.parse(string_page_2)) .map { |x| x.slice(VERSION, TIMESTAMP, PRERELEASE) } # Only grab keys that matter .reject { |x| x.fetch(VERSION).include?("-") } # Remove RC/Beta releases diff --git a/lib/tasks/coverage.rake b/lib/tasks/coverage.rake index 507a99352..c911e6134 100644 --- a/lib/tasks/coverage.rake +++ b/lib/tasks/coverage.rake @@ -14,7 +14,7 @@ FRACTION_DELIM = "/" # Fetch JSON over HTTP. Rails probably already has a helper for this :shrug: def open_json(url) begin - JSON.parse(open(url).read) + JSON.parse(URI.open(url).read) rescue *[OpenURI::HTTPError, SocketError] => exception puts exception.message return {} @@ -155,7 +155,8 @@ namespace :coverage do "compare against a PR's base branch and would always return 0% change." task run: :environment do # Fetch current build coverage data from the HTML summary. - statements, branches, functions, lines = Nokogiri::HTML(open(COVERAGE_FILE_PATH)) + statements, branches, functions, lines = + Nokogiri::HTML(URI.open(COVERAGE_FILE_PATH)) .css(CSS_SELECTOR) .map(&:text) .map { |x| x.split(FRACTION_DELIM).map(&:to_f) } diff --git a/lib/tasks/fe.rake b/lib/tasks/fe.rake index 374ef9b38..bae27e032 100644 --- a/lib/tasks/fe.rake +++ b/lib/tasks/fe.rake @@ -5,12 +5,12 @@ EXCLUDE = [] # Load package.json as JSON. def load_package_json() - return JSON.parse(open(PACKAGE_JSON_FILE).read) + return JSON.parse(URI.open(PACKAGE_JSON_FILE).read) end # Save JSON to package.json. def save_package_json(json) - open(PACKAGE_JSON_FILE, "w") { |file| + URI.open(PACKAGE_JSON_FILE, "w") { |file| file.write(JSON.pretty_generate(json)) file.puts } From 69ed6e89b7159bfe4b51270020c02f186c17b3f9 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 11:51:24 -0600 Subject: [PATCH 12/15] tile_reboot.tsx tests --- .../sequences/__tests__/tile_reboot_test.tsx | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/frontend/sequences/__tests__/tile_reboot_test.tsx b/frontend/sequences/__tests__/tile_reboot_test.tsx index c4d0b86c8..1406c7fc4 100644 --- a/frontend/sequences/__tests__/tile_reboot_test.tsx +++ b/frontend/sequences/__tests__/tile_reboot_test.tsx @@ -1,13 +1,14 @@ jest.mock("../../api/crud", () => { return { editStep: jest.fn() }; }); -import { TileReboot, editTheRebootStep } from "../step_tiles/tile_reboot"; -import { render } from "enzyme"; +import { TileReboot, editTheRebootStep, rebootExecutor, MultiChoiceRadio } from "../step_tiles/tile_reboot"; +import { render, mount } from "enzyme"; import React from "react"; import { StepParams } from "../interfaces"; import { fakeSequence } from "../../__test_support__/fake_state/resources"; import { buildResourceIndex } from "../../__test_support__/resource_index_builder"; import { editStep } from "../../api/crud"; +import { Reboot } from "farmbot"; const fakeProps = (): StepParams => { const currentSequence = fakeSequence(); @@ -55,4 +56,31 @@ describe("", () => { executor: expect.any(Function), }); }); + + it("executes the executor", () => { + const props = fakeProps(); + const step = props.currentStep as Reboot; + step.args.package = "X"; + const fn = rebootExecutor("arduino_firmware"); + fn(step); + expect(step.args.package).toBe("arduino_firmware"); + }); +}); + +describe("MultiChoiceRadio", () => { + it("triggers callbacks", () => { + const PACKAGE_CHOICES = { + "a": "1", + "b": "2" + }; + const onChange = jest.fn(); + const el = mount(); + const radio = el.find("input[type='radio']").first(); + radio.simulate("change", "a"); + expect(onChange).toHaveBeenCalledWith("a"); + }); }); From 8b14c32028b18e28de552d45898c86b135440efb Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 12:15:01 -0600 Subject: [PATCH 13/15] tile_write_pin.tsx tests --- .../__tests__/tile_write_pin_test.tsx | 54 +++++++++++-------- .../sequences/step_tiles/tile_write_pin.tsx | 2 +- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/frontend/sequences/step_tiles/__tests__/tile_write_pin_test.tsx b/frontend/sequences/step_tiles/__tests__/tile_write_pin_test.tsx index 6df956bea..07128682c 100644 --- a/frontend/sequences/step_tiles/__tests__/tile_write_pin_test.tsx +++ b/frontend/sequences/step_tiles/__tests__/tile_write_pin_test.tsx @@ -2,35 +2,36 @@ const mockEditStep = jest.fn(); jest.mock("../../../api/crud", () => ({ editStep: mockEditStep })); import * as React from "react"; -import { TileWritePin, WritePinStep } from "../tile_write_pin"; +import { TileWritePin, WritePinStep, PinSelect } from "../tile_write_pin"; import { mount, shallow } from "enzyme"; import { fakeSequence } from "../../../__test_support__/fake_state/resources"; import { WritePin } from "farmbot/dist"; import { emptyState } from "../../../resources/reducer"; import { FBSelect } from "../../../ui"; +import { StepParams } from "../../interfaces"; + +function fakeProps() { + const currentStep: WritePin = { + kind: "write_pin", + args: { + pin_number: 3, + pin_value: 2, + pin_mode: 1 + } + }; + return { + currentSequence: fakeSequence(), + currentStep: currentStep, + dispatch: jest.fn(), + index: 0, + resources: emptyState().index, + confirmStepDeletion: false, + shouldDisplay: () => false, + showPins: false, + }; +} describe("", () => { - function fakeProps() { - const currentStep: WritePin = { - kind: "write_pin", - args: { - pin_number: 3, - pin_value: 2, - pin_mode: 1 - } - }; - return { - currentSequence: fakeSequence(), - currentStep: currentStep, - dispatch: jest.fn(), - index: 0, - resources: emptyState().index, - confirmStepDeletion: false, - shouldDisplay: () => false, - showPins: false, - }; - } - it("renders inputs: Analog", () => { const wrapper = mount(); const inputs = wrapper.find("input"); @@ -91,3 +92,12 @@ describe("", () => { .toThrow("Not a write_pin block."); }); }); + +describe("", () => { + it("crashes on bad step `kind`s", () => { + const props = fakeProps() as StepParams; + props.currentStep = { kind: "execute", args: { sequence_id: 23 } }; + const boom = () => PinSelect(props); + expect(boom).toThrowError("PinSelect can't render execute"); + }); +}); diff --git a/frontend/sequences/step_tiles/tile_write_pin.tsx b/frontend/sequences/step_tiles/tile_write_pin.tsx index 283b4dd50..7ce62f7f9 100644 --- a/frontend/sequences/step_tiles/tile_write_pin.tsx +++ b/frontend/sequences/step_tiles/tile_write_pin.tsx @@ -69,7 +69,7 @@ export const PinSelect = (props: PinSelectProps): JSX.Element => { ; } - throw new Error("Can't render " + step ? step.kind : "NULL"); + throw new Error("PinSelect can't render " + step.kind); }; export class WritePinStep extends React.Component { From 6c6057c97f864340e08ee31edd3da38d9b6c1967 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 12:45:28 -0600 Subject: [PATCH 14/15] Bump bundler version --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 42c73db91..bace375ea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -344,4 +344,4 @@ RUBY VERSION ruby 2.7.0p0 BUNDLED WITH - 1.17.2 + 2.1.3 From 4b06a8ae11aeef79d6d4b77ba4792d36d7ecd574 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 3 Jan 2020 13:13:51 -0600 Subject: [PATCH 15/15] Revert URI.open() calls for now --- app/models/farmware_installation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/farmware_installation.rb b/app/models/farmware_installation.rb index b188a03c7..0847f8709 100644 --- a/app/models/farmware_installation.rb +++ b/app/models/farmware_installation.rb @@ -50,7 +50,7 @@ class FarmwareInstallation < ApplicationRecord # SLOW I/O BOUND STUFF! Don't run this on the # main thread! def infer_package_name_from_url - string_io = URI.open(url) + string_io = open(url) string = string_io.read(MAX_JSON_SIZE) json = JSON.parse(string) pkg_name = json.fetch("package")