Skip to content

Commit

Permalink
fix: live_data query params defaults to %{}
Browse files Browse the repository at this point in the history
used by the visual editor
  • Loading branch information
leandrocp committed Jan 14, 2025
1 parent 86ffe3a commit 4917920
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/beacon/web/data_source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Beacon.Web.DataSource do

require Logger

def live_data(site, path_info, query_params \\ %{})

def live_data(site, path_info, query_params) when is_atom(site) and is_list(path_info) and is_map(query_params) do
Beacon.apply_mfa(site, Beacon.Loader.fetch_live_data_module(site), :live_data, [path_info, query_params])
end
Expand Down
16 changes: 12 additions & 4 deletions test/beacon_web/data_source_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ defmodule Beacon.Web.DataSourceTest do
[site: site]
end

test "live_data", %{site: site} do
live_data = beacon_live_data_fixture()
beacon_live_data_assign_fixture(live_data: live_data, format: :text, key: "name", value: "beacon")
assert DataSource.live_data(site, ["foo", "bar"], %{}) == %{name: "beacon"}
describe "live_data" do
test "with existing data", %{site: site} do
live_data = beacon_live_data_fixture()
beacon_live_data_assign_fixture(live_data: live_data, format: :text, key: "name", value: "beacon")
assert DataSource.live_data(site, ["foo", "bar"], %{}) == %{name: "beacon"}
end

test "query params defaults to empty map", %{site: site} do
live_data = beacon_live_data_fixture()
beacon_live_data_assign_fixture(live_data: live_data, format: :text, key: "name", value: "beacon")
assert DataSource.live_data(site, ["foo", "bar"]) == %{name: "beacon"}
end
end

describe "page_title" do
Expand Down

0 comments on commit 4917920

Please sign in to comment.