Skip to content

Commit

Permalink
fix: fix naming of Arrow Shuttles context to plural Shuttles (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
meagharty authored Oct 9, 2024
1 parent 82ca904 commit f207f00
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 70 deletions.
4 changes: 2 additions & 2 deletions lib/arrow/shuttle/kml.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Arrow.Shuttle.KML do
defmodule Arrow.Shuttles.KML do
@moduledoc """
A struct for the full KML representation of a shape to be used with Saxy.Builder
"""
Expand All @@ -13,7 +13,7 @@ defmodule Arrow.Shuttle.KML do
element(
"Folder",
[],
Saxy.Builder.build(%Arrow.Shuttle.ShapeKML{name: name, coordinates: coordinates})
Saxy.Builder.build(%Arrow.Shuttles.ShapeKML{name: name, coordinates: coordinates})
)
end
end
2 changes: 1 addition & 1 deletion lib/arrow/shuttle/shape.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Arrow.Shuttle.Shape do
defmodule Arrow.Shuttles.Shape do
@moduledoc "schema for shuttle shapes for the db"
use Ecto.Schema
import Ecto.Changeset
Expand Down
4 changes: 2 additions & 2 deletions lib/arrow/shuttle/shape_kml.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule Arrow.Shuttle.ShapeKML do
defmodule Arrow.Shuttles.ShapeKML do
@moduledoc """
A struct for a shape representation to be used with Saxy.Builder
"""
defstruct [:name, :coordinates]
end

defimpl Saxy.Builder, for: Arrow.Shuttle.ShapeKML do
defimpl Saxy.Builder, for: Arrow.Shuttles.ShapeKML do
import Saxy.XML

def build(%{name: name, coordinates: coordinates}) do
Expand Down
2 changes: 1 addition & 1 deletion lib/arrow/shuttle/shape_upload.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Arrow.Shuttle.ShapeUpload do
defmodule Arrow.Shuttles.ShapeUpload do
@moduledoc "schema for shuttle shapes as an embedded schema"
use Ecto.Schema
import Ecto.Changeset
Expand Down
8 changes: 4 additions & 4 deletions lib/arrow/shuttle/shapes_upload.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
defmodule Arrow.Shuttle.ShapesUpload do
defmodule Arrow.Shuttles.ShapesUpload do
@moduledoc "schema for shapes upload"
use Ecto.Schema
import Ecto.Changeset

@type t :: %__MODULE__{
filename: String.t(),
shapes: list(Arrow.Shuttle.ShapeUpload.t())
shapes: list(Arrow.Shuttles.ShapeUpload.t())
}

embedded_schema do
field :filename, :string
embeds_many :shapes, Arrow.Shuttle.ShapeUpload
embeds_many :shapes, Arrow.Shuttles.ShapeUpload
end

@doc false
Expand Down Expand Up @@ -66,7 +66,7 @@ defmodule Arrow.Shuttle.ShapesUpload do
@doc """
Parses one or many Shapes from a map of the KML/XML
"""
@spec shapes_from_kml(map) :: {:ok, list(Arrow.Shuttle.ShapeUpload.t())} | {:error, any}
@spec shapes_from_kml(map) :: {:ok, list(Arrow.Shuttles.ShapeUpload.t())} | {:error, any}
def shapes_from_kml(saxy_shapes) do
placemarks = saxy_shapes["kml"]["Folder"]["Placemark"]

Expand Down
2 changes: 1 addition & 1 deletion lib/arrow/shuttle/stop.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Arrow.Shuttle.Stop do
defmodule Arrow.Shuttles.Stop do
@moduledoc false

use Ecto.Schema
Expand Down
12 changes: 6 additions & 6 deletions lib/arrow/shuttle.ex → lib/arrow/shuttles.ex
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
defmodule Arrow.Shuttle do
defmodule Arrow.Shuttles do
@moduledoc """
The Shuttle context.
The Shuttles context.
"""

import Ecto.Query, warn: false

alias Arrow.Repo
alias ArrowWeb.ErrorHelpers

alias Arrow.Shuttle.KML
alias Arrow.Shuttle.Shape
alias Arrow.Shuttle.ShapesUpload
alias Arrow.Shuttle.ShapeUpload
alias Arrow.Shuttles.KML
alias Arrow.Shuttles.Shape
alias Arrow.Shuttles.ShapesUpload
alias Arrow.Shuttles.ShapeUpload

@doc """
Returns the list of shapes.
Expand Down
2 changes: 1 addition & 1 deletion lib/arrow/stops.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Arrow.Stops do
import Ecto.Query, warn: false
alias Arrow.Repo

alias Arrow.Shuttle.Stop
alias Arrow.Shuttles.Stop

@doc """
Returns the list of stops.
Expand Down
18 changes: 9 additions & 9 deletions lib/arrow_web/controllers/shape_controller.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule ArrowWeb.ShapeController do
require Logger
alias Arrow.Shuttle.ShapesUpload
alias Arrow.Shuttles.ShapesUpload
alias ArrowWeb.ErrorHelpers
alias Ecto.Changeset
use ArrowWeb, :controller

alias Arrow.Shuttle
alias Arrow.Shuttles
alias ArrowWeb.Plug.Authorize

plug(Authorize, :view_disruption when action in [:index, :show, :download])
Expand All @@ -14,7 +14,7 @@ defmodule ArrowWeb.ShapeController do
plug(Authorize, :delete_disruption when action in [:delete])

def index(conn, _params) do
shapes = Shuttle.list_shapes()
shapes = Shuttles.list_shapes()
render(conn, :index, shapes: shapes)
end

Expand Down Expand Up @@ -68,7 +68,7 @@ defmodule ArrowWeb.ShapeController do
|> Enum.filter(fn shape -> shape["save"] == "true" end)
|> Enum.map(fn shape -> %{name: shape["name"], coordinates: shape["coordinates"]} end)

case Shuttle.create_shapes(saved_shapes) do
case Shuttles.create_shapes(saved_shapes) do
{:ok, []} ->
conn
|> put_flash(
Expand Down Expand Up @@ -100,14 +100,14 @@ defmodule ArrowWeb.ShapeController do
end

def show(conn, %{"id" => id}) do
shape = Shuttle.get_shape!(id)
shape_upload = Shuttle.get_shapes_upload(shape)
shape = Shuttles.get_shape!(id)
shape_upload = Shuttles.get_shapes_upload(shape)
render(conn, :show, shape: shape, shape_upload: shape_upload)
end

def download(conn, %{"id" => id}) do
enabled? = Application.get_env(:arrow, :shape_storage_enabled?)
shape = Shuttle.get_shape!(id)
shape = Shuttles.get_shape!(id)
basic_url = "https://#{shape.bucket}.s3.amazonaws.com/#{shape.path}"

{:ok, url} =
Expand All @@ -124,8 +124,8 @@ defmodule ArrowWeb.ShapeController do
end

def delete(conn, %{"id" => id}) do
shape = Shuttle.get_shape!(id)
{:ok, _shape} = Shuttle.delete_shape(shape)
shape = Shuttles.get_shape!(id)
{:ok, _shape} = Shuttles.delete_shape(shape)

conn
|> put_flash(:info, "Shape deleted successfully.")
Expand Down
2 changes: 1 addition & 1 deletion lib/arrow_web/controllers/shape_html.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ArrowWeb.ShapeView do
use ArrowWeb, :html
alias Arrow.Shuttle.ShapesUpload
alias Arrow.Shuttles.ShapesUpload

embed_templates "shape_html/*"

Expand Down
2 changes: 1 addition & 1 deletion lib/arrow_web/live/stop_live/stop_live.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ArrowWeb.StopViewLive do
use ArrowWeb, :live_view

alias Arrow.Shuttle.Stop
alias Arrow.Shuttles.Stop
alias Arrow.Stops
embed_templates "stop_live/*"

Expand Down
6 changes: 3 additions & 3 deletions test/arrow/shuttle/kml_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Arrow.Shuttle.KMLTest do
defmodule Arrow.Shuttles.KMLTest do
@moduledoc false
use Arrow.DataCase

@required_struct %Arrow.Shuttle.ShapeKML{
@required_struct %Arrow.Shuttles.ShapeKML{
name: "some shape",
coordinates: "-71.14163,42.39551 -71.14163,42.39551 -71.14163,42.39551"
}
Expand All @@ -24,7 +24,7 @@ defmodule Arrow.Shuttle.KMLTest do
]}
]}
]} =
Saxy.Builder.build(%Arrow.Shuttle.KML{
Saxy.Builder.build(%Arrow.Shuttles.KML{
xmlns: "http://www.opengis.net/kml/2.2",
Folder: @required_struct
})
Expand Down
4 changes: 2 additions & 2 deletions test/arrow/shuttle/shape_kml_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Arrow.Shuttle.ShapeKMLTest do
defmodule Arrow.Shuttles.ShapeKMLTest do
@moduledoc false
use Arrow.DataCase

@required_struct %Arrow.Shuttle.ShapeKML{
@required_struct %Arrow.Shuttles.ShapeKML{
name: "some shape",
coordinates: "-71.14163,42.39551 -71.14163,42.39551 -71.14163,42.39551"
}
Expand Down
4 changes: 2 additions & 2 deletions test/arrow/shuttle/shape_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Arrow.Shuttle.ShapeTest do
defmodule Arrow.Shuttles.ShapeTest do
use Arrow.DataCase

alias Arrow.Shuttle.Shape
alias Arrow.Shuttles.Shape

describe "changeset/2" do
test "validates shape name ends with -S" do
Expand Down
4 changes: 2 additions & 2 deletions test/arrow/shuttle/stop_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Arrow.Shuttle.StopTest do
defmodule Arrow.Shuttles.StopTest do
use Arrow.DataCase

alias Arrow.Shuttle.Stop
alias Arrow.Shuttles.Stop

@required_stop_params %{
stop_id: "stop_id",
Expand Down
48 changes: 24 additions & 24 deletions test/arrow/shuttle_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Arrow.ShuttleTest do
defmodule Arrow.ShuttlesTest do
use Arrow.DataCase

alias Arrow.Shuttle
alias Arrow.Shuttle.Shape
import Arrow.ShuttleFixtures
alias Arrow.Shuttles
alias Arrow.Shuttles.Shape
import Arrow.ShuttlesFixtures
import Test.Support.Helpers

describe "shapes with s3 functionality enabled (mocked)" do
Expand All @@ -16,7 +16,7 @@ defmodule Arrow.ShuttleTest do
reassign_env(:shape_storage_enabled?, true)
reassign_env(:shape_storage_prefix, "prefix/#{Ecto.UUID.generate()}/")

assert {:ok, %Shape{} = shape} = Shuttle.create_shape(@valid_shape)
assert {:ok, %Shape{} = shape} = Shuttles.create_shape(@valid_shape)
assert shape.name == "some name-S"
Application.put_env(:arrow, :shape_storage_enabled?, false)
end
Expand All @@ -26,25 +26,25 @@ defmodule Arrow.ShuttleTest do
Application.put_env(:arrow, :shape_storage_prefix, "prefix/#{Ecto.UUID.generate()}/")

assert {:ok, %Shape{} = shape} =
Shuttle.create_shape(%{name: "some name", coordinates: coords()})
Shuttles.create_shape(%{name: "some name", coordinates: coords()})

assert shape.name == "some name-S"
end

test "delete_shape/1 deletes the shape" do
reassign_env(:shape_storage_enabled?, true)

assert {:ok, %Shape{} = shape} = Shuttle.create_shape(@valid_shape)
assert {:ok, %Shape{}} = Shuttle.delete_shape(shape)
assert_raise Ecto.NoResultsError, fn -> Shuttle.get_shape!(shape.id) end
assert {:ok, %Shape{} = shape} = Shuttles.create_shape(@valid_shape)
assert {:ok, %Shape{}} = Shuttles.delete_shape(shape)
assert_raise Ecto.NoResultsError, fn -> Shuttles.get_shape!(shape.id) end
end

test "get_shapes_upload/1 returns a ShapesUpload changeset" do
reassign_env(:shape_storage_enabled?, true)

new_shape = s3_mocked_shape_fixture()
shape = Shuttle.get_shape!(new_shape.id)
assert %Ecto.Changeset{valid?: true} = Shuttle.get_shapes_upload(shape)
shape = Shuttles.get_shape!(new_shape.id)
assert %Ecto.Changeset{valid?: true} = Shuttles.get_shapes_upload(shape)
end
end

Expand All @@ -54,57 +54,57 @@ defmodule Arrow.ShuttleTest do

test "list_shapes/0 returns all shapes" do
shape = shape_fixture()
assert Shuttle.list_shapes() == [shape]
assert Shuttles.list_shapes() == [shape]
end

test "get_shape!/1 returns the shape with given id" do
shape = shape_fixture()
assert Shuttle.get_shape!(shape.id) == shape
assert Shuttles.get_shape!(shape.id) == shape
end

test "create_shapes/1 with valid data creates a shape" do
assert {:ok, [{:ok, %Shape{} = shape}]} = Shuttle.create_shapes([@valid_attrs])
assert {:ok, [{:ok, %Shape{} = shape}]} = Shuttles.create_shapes([@valid_attrs])
assert shape.name == "some name-S"
end

test "create_shapes/1 with invalid data returns error changeset" do
assert {:error, {"Failed to upload some shapes", changeset}} =
Shuttle.create_shapes([@invalid_attrs])
Shuttles.create_shapes([@invalid_attrs])

assert ["Name can't be blank "] = changeset
end

test "create_shapes/1 creates valid and returns errors for invalid" do
name = @valid_attrs.name
refute Repo.get_by(Arrow.Shuttle.Shape, name: name)
refute Repo.get_by(Arrow.Shuttles.Shape, name: name)

assert {:error, {"Failed to upload some shapes", changeset}} =
Shuttle.create_shapes([@valid_attrs, @invalid_attrs])
Shuttles.create_shapes([@valid_attrs, @invalid_attrs])

assert ["Name can't be blank "] = changeset
assert %Shape{name: ^name} = Repo.get_by(Arrow.Shuttle.Shape, name: name)
assert %Shape{name: ^name} = Repo.get_by(Arrow.Shuttles.Shape, name: name)
end

test "create_shape/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Shuttle.create_shape(@invalid_attrs)
assert {:error, %Ecto.Changeset{}} = Shuttles.create_shape(@invalid_attrs)
end

test "create_shape/1 with existing name returns an error" do
assert {:ok, %Shape{}} = Shuttle.create_shape(@valid_attrs)
assert {:ok, %Shape{}} = Shuttles.create_shape(@valid_attrs)
# Trying to create a second time throws an error
assert {:error, message} = Shuttle.create_shape(@valid_attrs)
assert {:error, message} = Shuttles.create_shape(@valid_attrs)
assert message =~ "already exists"
end

test "delete_shape/1 deletes the shape" do
shape = shape_fixture()
assert {:ok, %Shape{}} = Shuttle.delete_shape(shape)
assert_raise Ecto.NoResultsError, fn -> Shuttle.get_shape!(shape.id) end
assert {:ok, %Shape{}} = Shuttles.delete_shape(shape)
assert_raise Ecto.NoResultsError, fn -> Shuttles.get_shape!(shape.id) end
end

test "change_shape/1 returns a shape changeset" do
shape = shape_fixture()
assert %Ecto.Changeset{} = Shuttle.change_shape(shape)
assert %Ecto.Changeset{} = Shuttles.change_shape(shape)
end
end
end
2 changes: 1 addition & 1 deletion test/arrow/stops_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Arrow.StopsTest do
alias Arrow.Stops

describe "stops" do
alias Arrow.Shuttle.Stop
alias Arrow.Shuttles.Stop

import Arrow.StopsFixtures

Expand Down
4 changes: 2 additions & 2 deletions test/arrow_web/controllers/shape_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule ArrowWeb.ShapeControllerTest do
use ArrowWeb.ConnCase, async: true
alias Arrow.Repo
alias Arrow.Shuttle.Shape
alias Arrow.Shuttles.Shape

import Arrow.ShuttleFixtures
import Arrow.ShuttlesFixtures
import Test.Support.Helpers

@upload_attrs %{
Expand Down
2 changes: 1 addition & 1 deletion test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Arrow.Factory do
end

def stop_factory do
%Arrow.Shuttle.Stop{
%Arrow.Shuttles.Stop{
stop_id: sequence(:source_label, &"stop-#{&1}"),
stop_name: sequence(:source_label, &"Stop #{&1}"),
stop_desc: sequence(:source_label, &"Stop Description #{&1}"),
Expand Down
Loading

0 comments on commit f207f00

Please sign in to comment.