From 4d24432f2c2d1030fdd6191ba58f0b4782564257 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Mon, 13 May 2019 17:35:58 -0500 Subject: [PATCH] Change default firmware_hard from "none" to nil, plus FBJS stuff --- app/models/fbos_config.rb | 2 +- app/mutations/devices/create_seed_data.rb | 2 +- app/mutations/devices/seeders/abstract_seeder.rb | 5 +++++ .../seeders/{xl_one_four.rb => genesis_xl_one_four.rb} | 6 +++++- ...0513221836_undo_column_default_firmware_hardware.rb | 5 +++++ db/structure.sql | 5 +++-- package.json | 2 +- .../api/configs/fbos_configs_controller_spec.rb | 7 ++++--- .../api/devices/devices_controller_seed_spec.rb | 10 ++++++++++ spec/models/fbos_config_spec.rb | 2 +- 10 files changed, 36 insertions(+), 10 deletions(-) rename app/mutations/devices/seeders/{xl_one_four.rb => genesis_xl_one_four.rb} (78%) create mode 100644 db/migrate/20190513221836_undo_column_default_firmware_hardware.rb diff --git a/app/models/fbos_config.rb b/app/models/fbos_config.rb index f1fc2bf9e..eaf5d5fd5 100644 --- a/app/models/fbos_config.rb +++ b/app/models/fbos_config.rb @@ -6,7 +6,7 @@ class FbosConfig < ApplicationRecord after_save :maybe_sync_nerves, on: [:create, :update] FIRMWARE_HARDWARE = [ - NONE = "none", + NONE = nil, ARDUINO = "arduino", FARMDUINO = "farmduino", FARMDUINO_K14 = "farmduino_k14", diff --git a/app/mutations/devices/create_seed_data.rb b/app/mutations/devices/create_seed_data.rb index 20b62217b..0a99892ce 100644 --- a/app/mutations/devices/create_seed_data.rb +++ b/app/mutations/devices/create_seed_data.rb @@ -7,7 +7,7 @@ module Devices "genesis_1.2" => Devices::Seeders::GenesisOneTwo, "genesis_1.3" => Devices::Seeders::GenesisOneThree, "genesis_1.4" => Devices::Seeders::GenesisOneFour, - "genesis_xl_1.4" => Devices::Seeders::XlOneFour, + "genesis_xl_1.4" => Devices::Seeders::GenesisXlOneFour, "none" => Devices::Seeders::None, } diff --git a/app/mutations/devices/seeders/abstract_seeder.rb b/app/mutations/devices/seeders/abstract_seeder.rb index 6ebe2d9cb..82945ce9c 100644 --- a/app/mutations/devices/seeders/abstract_seeder.rb +++ b/app/mutations/devices/seeders/abstract_seeder.rb @@ -30,6 +30,7 @@ module Devices :settings_device_name, :settings_enable_encoders, :settings_firmware, + :settings_map_xl, # TOOLS ================================== :tools_seed_bin, @@ -76,6 +77,10 @@ module Devices @device = device end + def settings_map_xl + device.web_app_config.update_attributes!(map_xl: false) + end + def plants PLANTS.map { |x| Points::Create.run!(x, device: device) } end diff --git a/app/mutations/devices/seeders/xl_one_four.rb b/app/mutations/devices/seeders/genesis_xl_one_four.rb similarity index 78% rename from app/mutations/devices/seeders/xl_one_four.rb rename to app/mutations/devices/seeders/genesis_xl_one_four.rb index e295148ac..bac73733e 100644 --- a/app/mutations/devices/seeders/xl_one_four.rb +++ b/app/mutations/devices/seeders/genesis_xl_one_four.rb @@ -1,6 +1,6 @@ module Devices module Seeders - class XlOneFour < AbstractGenesis + class GenesisXlOneFour < AbstractGenesis def settings_firmware device .fbos_config @@ -18,6 +18,10 @@ module Devices def settings_default_map_size_y device.web_app_config.update_attributes!(map_size_y: 2_900) end + + def settings_map_xl + device.web_app_config.update_attributes!(map_xl: true) + end end end end diff --git a/db/migrate/20190513221836_undo_column_default_firmware_hardware.rb b/db/migrate/20190513221836_undo_column_default_firmware_hardware.rb new file mode 100644 index 000000000..bb633e93e --- /dev/null +++ b/db/migrate/20190513221836_undo_column_default_firmware_hardware.rb @@ -0,0 +1,5 @@ +class UndoColumnDefaultFirmwareHardware < ActiveRecord::Migration[5.2] + def change + change_column_default(:fbos_configs, :firmware_hardware, from: "none", to: nil) + end +end diff --git a/db/structure.sql b/db/structure.sql index 4c4d4033c..9be588052 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -430,7 +430,7 @@ CREATE TABLE public.fbos_configs ( sequence_complete_log boolean DEFAULT false, sequence_init_log boolean DEFAULT false, network_not_found_timer integer, - firmware_hardware character varying DEFAULT 'arduino'::character varying, + firmware_hardware character varying, api_migrated boolean DEFAULT true, os_auto_update boolean DEFAULT true, arduino_debug_messages boolean DEFAULT false, @@ -2965,6 +2965,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20190501143201'), ('20190502163453'), ('20190504170018'), -('20190512015442'); +('20190512015442'), +('20190513221836'); diff --git a/package.json b/package.json index 3ffd33561..9f3397058 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "coveralls": "3.0.3", "enzyme": "3.9.0", "enzyme-adapter-react-16": "1.12.1", - "farmbot": "7.0.9", + "farmbot": "7.1.0", "farmbot-toastr": "1.0.3", "i18next": "15.1.0", "jest": "24.8.0", diff --git a/spec/controllers/api/configs/fbos_configs_controller_spec.rb b/spec/controllers/api/configs/fbos_configs_controller_spec.rb index f8dbdd03d..726e564b0 100644 --- a/spec/controllers/api/configs/fbos_configs_controller_spec.rb +++ b/spec/controllers/api/configs/fbos_configs_controller_spec.rb @@ -26,13 +26,14 @@ describe Api::FbosConfigsController do arduino_debug_messages: false, network_not_found_timer: nil, os_auto_update: true, - firmware_hardware: "none", + firmware_hardware: nil, api_migrated: true }.to_a.map do |key, value| - actual = json[key] + actual = json.fetch(key) expected = value correct = actual == expected - fail "#{key} should be #{expected} but got #{actual}" unless correct + friendly_actual_var = actual|| "nil or false" + fail "#{key} should be #{expected} but got #{friendly_actual_var}" unless correct end { created_at: String, updated_at: String } diff --git a/spec/controllers/api/devices/devices_controller_seed_spec.rb b/spec/controllers/api/devices/devices_controller_seed_spec.rb index 179cf0788..692978428 100644 --- a/spec/controllers/api/devices/devices_controller_seed_spec.rb +++ b/spec/controllers/api/devices/devices_controller_seed_spec.rb @@ -61,6 +61,10 @@ describe Api::DevicesController do device.name end + def settings_map_xl?(device) + device.web_app_config.map_xl + end + def settings_enable_encoders?(device) c = device.firmware_config @@ -216,6 +220,7 @@ describe Api::DevicesController do expect(settings_device_name?(device)).to eq("FarmBot Genesis") expect(settings_enable_encoders?(device)).to be(true) expect(settings_firmware?(device)).to eq("arduino") + expect(settings_map_xl?(device)).to be(false) expect(tool_slots_slot_1?(device).name).to eq("Seeder") expect(tool_slots_slot_2?(device).name).to eq("Seed Bin") expect(tool_slots_slot_3?(device).name).to eq("Seed Tray") @@ -265,6 +270,7 @@ describe Api::DevicesController do expect(settings_device_name?(device)).to eq("FarmBot Genesis") expect(settings_enable_encoders?(device)).to be(true) expect(settings_firmware?(device)).to eq("farmduino") + expect(settings_map_xl?(device)).to be(false) expect(tool_slots_slot_1?(device).name).to eq("Seeder") expect(tool_slots_slot_2?(device).name).to eq("Seed Bin") expect(tool_slots_slot_3?(device).name).to eq("Seed Tray") @@ -315,6 +321,7 @@ describe Api::DevicesController do expect(settings_device_name?(device)).to eq("FarmBot Genesis") expect(settings_enable_encoders?(device)).to be(true) expect(settings_firmware?(device)).to eq("farmduino_k14") + expect(settings_map_xl?(device)).to be(false) expect(tool_slots_slot_1?(device).name).to eq("Seeder") expect(tool_slots_slot_2?(device).name).to eq("Seed Bin") expect(tool_slots_slot_3?(device).name).to eq("Seed Tray") @@ -358,6 +365,7 @@ describe Api::DevicesController do expect(settings_device_name?(device)).to eq("FarmBot Genesis XL") expect(settings_enable_encoders?(device)).to be(true) expect(settings_firmware?(device)).to eq("farmduino_k14") + expect(settings_map_xl?(device)).to be(true) expect(tool_slots_slot_1?(device).name).to eq("Seeder") expect(tool_slots_slot_2?(device).name).to eq("Seed Bin") expect(tool_slots_slot_3?(device).name).to eq("Seed Tray") @@ -409,6 +417,7 @@ describe Api::DevicesController do expect(settings_device_name?(device)).to eq("FarmBot Express") expect(settings_enable_encoders?(device)).to be(false) expect(settings_firmware?(device)).to eq("express_k10") + expect(settings_map_xl?(device)).to be(false) expect(tool_slots_slot_1?(device).name).to eq("Seed Trough 1") expect(tool_slots_slot_2?(device).name).to eq("Seed Trough 2") expect(tool_slots_slot_3?(device).name).to eq("Seed Trough 3") @@ -455,6 +464,7 @@ describe Api::DevicesController do expect(settings_device_name?(device)).to eq("FarmBot Express XL") expect(settings_enable_encoders?(device)).to be(false) expect(settings_firmware?(device)).to eq("express_k10") + expect(settings_map_xl?(device)).to be(false) expect(tool_slots_slot_1?(device).name).to eq("Seed Trough 1") expect(tool_slots_slot_2?(device).name).to eq("Seed Trough 2") expect(tool_slots_slot_3?(device).name).to eq("Seed Trough 3") diff --git a/spec/models/fbos_config_spec.rb b/spec/models/fbos_config_spec.rb index 38a50856a..b35564647 100644 --- a/spec/models/fbos_config_spec.rb +++ b/spec/models/fbos_config_spec.rb @@ -42,6 +42,6 @@ describe FbosConfig do end it "has default firmware_hardware" do - expect(FbosConfig.create!.firmware_hardware).to eq("none") + expect(FbosConfig.create!.firmware_hardware).to eq(nil) end end