Skip to content

Commit 4917920

Browse files
committed
fix: live_data query params defaults to %{}
used by the visual editor
1 parent 86ffe3a commit 4917920

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/beacon/web/data_source.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ defmodule Beacon.Web.DataSource do
33

44
require Logger
55

6+
def live_data(site, path_info, query_params \\ %{})
7+
68
def live_data(site, path_info, query_params) when is_atom(site) and is_list(path_info) and is_map(query_params) do
79
Beacon.apply_mfa(site, Beacon.Loader.fetch_live_data_module(site), :live_data, [path_info, query_params])
810
end

test/beacon_web/data_source_test.exs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ defmodule Beacon.Web.DataSourceTest do
1515
[site: site]
1616
end
1717

18-
test "live_data", %{site: site} do
19-
live_data = beacon_live_data_fixture()
20-
beacon_live_data_assign_fixture(live_data: live_data, format: :text, key: "name", value: "beacon")
21-
assert DataSource.live_data(site, ["foo", "bar"], %{}) == %{name: "beacon"}
18+
describe "live_data" do
19+
test "with existing data", %{site: site} do
20+
live_data = beacon_live_data_fixture()
21+
beacon_live_data_assign_fixture(live_data: live_data, format: :text, key: "name", value: "beacon")
22+
assert DataSource.live_data(site, ["foo", "bar"], %{}) == %{name: "beacon"}
23+
end
24+
25+
test "query params defaults to empty map", %{site: site} do
26+
live_data = beacon_live_data_fixture()
27+
beacon_live_data_assign_fixture(live_data: live_data, format: :text, key: "name", value: "beacon")
28+
assert DataSource.live_data(site, ["foo", "bar"]) == %{name: "beacon"}
29+
end
2230
end
2331

2432
describe "page_title" do

0 commit comments

Comments
 (0)