Credo and formatting appeasement

pull/870/head
Ryan Arthur 6 years ago
parent 05935d825b
commit e34e9f1d02
  1. 18
      apps/block_scout_web/lib/block_scout_web/controllers/block_controller.ex
  2. 1
      apps/block_scout_web/test/block_scout_web/controllers/block_controller_test.exs
  3. 3
      apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex
  4. 3
      apps/explorer/lib/explorer/chain/block.ex

@ -6,15 +6,13 @@ defmodule BlockScoutWeb.BlockController do
alias Explorer.Chain alias Explorer.Chain
def index(conn, params) do def index(conn, params) do
Keyword.merge(
[ [
necessity_by_association: %{ necessity_by_association: %{
:transactions => :optional, :transactions => :optional,
[miner: :names] => :optional [miner: :names] => :optional
} }
], ]
paging_options(params) |> Keyword.merge(paging_options(params))
)
|> handle_render(conn, params) |> handle_render(conn, params)
end end
@ -23,21 +21,18 @@ defmodule BlockScoutWeb.BlockController do
end end
def reorg(conn, params) do def reorg(conn, params) do
Keyword.merge(
[ [
necessity_by_association: %{ necessity_by_association: %{
:transactions => :optional, :transactions => :optional,
[miner: :names] => :optional [miner: :names] => :optional
}, },
block_type: "Reorg" block_type: "Reorg"
], ]
paging_options(params) |> Keyword.merge(paging_options(params))
)
|> handle_render(conn, params) |> handle_render(conn, params)
end end
def uncle(conn, params) do def uncle(conn, params) do
Keyword.merge(
[ [
necessity_by_association: %{ necessity_by_association: %{
:transactions => :optional, :transactions => :optional,
@ -45,9 +40,8 @@ defmodule BlockScoutWeb.BlockController do
:nephews => :required :nephews => :required
}, },
block_type: "Uncle" block_type: "Uncle"
], ]
paging_options(params) |> Keyword.merge(paging_options(params))
)
|> handle_render(conn, params) |> handle_render(conn, params)
end end

@ -115,6 +115,7 @@ defmodule BlockScoutWeb.BlockControllerTest do
4 4
|> insert_list(:block, consensus: false) |> insert_list(:block, consensus: false)
|> Enum.map(& &1.hash) |> Enum.map(& &1.hash)
conn = get(conn, reorg_path(conn, :reorg)) conn = get(conn, reorg_path(conn, :reorg))
assert Enum.map(conn.assigns.blocks, & &1.hash) == Enum.reverse(reorg_hashes) assert Enum.map(conn.assigns.blocks, & &1.hash) == Enum.reverse(reorg_hashes)

@ -42,6 +42,7 @@ defmodule BlockScoutWeb.BlockPage do
end end
def visit_page(session, %Block{} = block) do def visit_page(session, %Block{} = block) do
visit(session, block_path(build_conn(), :show, block)) path = block_path(build_conn(), :show, block)
visit(session, path)
end end
end end

@ -97,16 +97,17 @@ defmodule Explorer.Chain.Block do
|> unique_constraint(:hash, name: :blocks_pkey) |> unique_constraint(:hash, name: :blocks_pkey)
end end
@doc """ @doc """
Adds to the given block's query a `where` with conditions to filter by the type of block; Adds to the given block's query a `where` with conditions to filter by the type of block;
`Uncle`, `Reorg`, or `Block`. `Uncle`, `Reorg`, or `Block`.
""" """
def block_type_filter(query, "Block"), do: where(query, [block], block.consensus == true) def block_type_filter(query, "Block"), do: where(query, [block], block.consensus == true)
def block_type_filter(query, "Reorg") do def block_type_filter(query, "Reorg") do
query query
|> join(:left, [block], uncles in assoc(block, :nephew_relations)) |> join(:left, [block], uncles in assoc(block, :nephew_relations))
|> where([block, uncles], block.consensus == false and is_nil(uncles.uncle_hash)) |> where([block, uncles], block.consensus == false and is_nil(uncles.uncle_hash))
end end
def block_type_filter(query, "Uncle"), do: where(query, [block], block.consensus == false) def block_type_filter(query, "Uncle"), do: where(query, [block], block.consensus == false)
end end

Loading…
Cancel
Save