diff --git a/CHANGELOG.md b/CHANGELOG.md index 42bbd9aa..7f409175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +# 9.2.2 + + * Fix firmware locking error ("Can't perform X in Y state") + * Removal of dead code / legacy plus numerous unit test additions. + * Added coveralls test coverage reporter + * Unit test additions (+2.7% coverage :tada:) + * Updates to build instructions for third party developers + * Bug fix for criteria-based groups that have only one filter criteria. + # 9.2.1 * Improve firmware debug messages. diff --git a/VERSION b/VERSION index fcecff17..9c0e1ab9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.2.2-rc7 +9.2.2-rc8 diff --git a/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex b/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex index 5ea93963..2afc6348 100644 --- a/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex +++ b/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex @@ -49,7 +49,7 @@ defmodule FarmbotCore.Asset.CriteriaRetriever do needs_meta_filter = Repo.all(dynamic_query) # There we go. We have all the matching %Point{}s search_matches = search_meta_fields(pg, needs_meta_filter) - # ...but there are duplicates. We can remove them via uniq_by: + # ...but there are duplicates. We can remove them via uniq_by: Enum.uniq_by((search_matches ++ always_ok), fn p -> p.id end) end @@ -136,10 +136,10 @@ defmodule FarmbotCore.Asset.CriteriaRetriever do if days == 0 do { pg, accum } else - + op = day_criteria["op"] || "<" time = Timex.shift(Timex.now(), days: -1 * days) - + { pg, accum ++ [{"created_at", op, time}] } end end @@ -159,14 +159,19 @@ defmodule FarmbotCore.Asset.CriteriaRetriever do # NOT OK: Repo.query("SELECT foo WHERE bar IN $0", [[1, 2, 3]]) # OK: Repo.query("SELECT foo WHERE bar IN ($0, $1, $2)", [1, 2, 3]) defp stage_3({sql, args}, {full_query, full_args, count0}) when is_list(args) do - final = count0 + Enum.count(args) - 1 + arg_count = Enum.count(args) + final = count0 + (arg_count - 1) initial_state = {sql, count0} - {next_sql, _} = Enum.reduce(args, initial_state, fn - (_, {sql, ^count0}) -> {sql <> " ($#{count0},", count0+1} - (_, {sql, ^final}) -> {sql <> " $#{final})", final} - (_, {sql, count}) -> {sql <> " $#{count},", count+1} - end) - + {next_sql, _} = + if arg_count == 1 do + {sql <> " ($#{count0})", nil} + else + Enum.reduce(args, initial_state, fn + (_, {sql, ^count0}) -> {sql <> " ($#{count0},", count0+1} + (_, {sql, ^final}) -> {sql <> " $#{final})", final} + (_, {sql, count}) -> {sql <> " $#{count},", count+1} + end) + end {full_query ++ [next_sql], full_args ++ [args], final + 1} end diff --git a/farmbot_core/test/asset/criteria_retriever_test.exs b/farmbot_core/test/asset/criteria_retriever_test.exs index 1c845f1b..404c8d2e 100644 --- a/farmbot_core/test/asset/criteria_retriever_test.exs +++ b/farmbot_core/test/asset/criteria_retriever_test.exs @@ -24,6 +24,23 @@ defmodule FarmbotCore.Asset.CriteriaRetrieverTest do } } + @simple_point_group %PointGroup{ + point_ids: [], + sort_type: "xy_ascending", + criteria: %{ + "day" => %{ + "op" => "<", + "days_ago" => 0 + }, + "string_eq" => %{ + "pointer_type" => ["Plant"] + }, + "number_eq" => %{}, + "number_lt" => %{}, + "number_gt" => %{} + } + } + # Use this is a fake "Timex.now()" value when mocking. @now ~U[2222-12-10 02:22:22.222222Z] @five_days_ago ~U[2222-12-05 01:11:11.111111Z] @@ -90,6 +107,19 @@ defmodule FarmbotCore.Asset.CriteriaRetrieverTest do pg end + test "direct match on `pointer_type` via `string_eq`" do + Repo.delete_all(PointGroup) + Repo.delete_all(Point) + + point!(%{id: 1, pointer_type: "Plant"}) + point!(%{id: 2, pointer_type: "Weed"}) + point!(%{id: 3, pointer_type: "ToolSlot"}) + point!(%{id: 4, pointer_type: "GenericPointer"}) + + result = CriteriaRetriever.run(@simple_point_group) + assert Enum.count(result) == 1 + end + test "run/1" do expect(Timex, :now, fn -> @now end) pg = point_group_with_fake_points() diff --git a/farmbot_core/test/project_test.exs b/farmbot_core/test/project_test.exs index 0b6bbf70..d94e6d0d 100644 --- a/farmbot_core/test/project_test.exs +++ b/farmbot_core/test/project_test.exs @@ -1,6 +1,6 @@ defmodule FarmbotCore.ProjectTest do use ExUnit.Case - @opts [cd: Path.join("c_src", "farmbot-arduino-firmware")] + # @opts [cd: Path.join("c_src", "farmbot-arduino-firmware")] test "arduino_commit" do actual = FarmbotCore.Project.arduino_commit() diff --git a/farmbot_os/test/farmbot_os/lua/ext/firmware_test.exs b/farmbot_os/test/farmbot_os/lua/ext/firmware_test.exs index cb6e0ed7..66fb6812 100644 --- a/farmbot_os/test/farmbot_os/lua/ext/firmware_test.exs +++ b/farmbot_os/test/farmbot_os/lua/ext/firmware_test.exs @@ -22,14 +22,14 @@ defmodule FarmbotOS.Lua.Ext.FirmwareTest do lua = "return" expect(FarmbotCeleryScript.SysCalls, :move_absolute, 4, fn - (1, _, _, _) -> :ok - (_, _, _, _) -> {:error, msg} + 1, _, _, _ -> :ok + _, _, _, _ -> {:error, msg} end) - assert {[true], ^lua} = Firmware.move_absolute([1,2,3,4], lua) - assert {[nil, ^msg], ^lua} = Firmware.move_absolute([5,6,7,8], lua) - assert {[true], ^lua} = Firmware.move_absolute([1,2,3], lua) - assert {[nil, ^msg], ^lua} = Firmware.move_absolute([5,6,7], lua) + assert {[true], ^lua} = Firmware.move_absolute([1, 2, 3, 4], lua) + assert {[nil, ^msg], ^lua} = Firmware.move_absolute([5, 6, 7, 8], lua) + assert {[true], ^lua} = Firmware.move_absolute([1, 2, 3], lua) + assert {[nil, ^msg], ^lua} = Firmware.move_absolute([5, 6, 7], lua) end test "find_home/2" do