-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move helper functions to a better place. [#70]
- Loading branch information
Showing
6 changed files
with
120 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
- container! @gig do | ||
%h1.name= link_to @gig | ||
- for field <- fields do | ||
- field_class = dasherize(field) | ||
%div{class: field_class}= apply(__MODULE__, field, [@gig]) | ||
- for field_name <- fields do | ||
- field_class = dasherize(field_name) | ||
%div{class: field_class}= field @gig, field_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
defmodule ContraqWeb.GigView do | ||
@dialyzer :no_return | ||
use ContraqWeb, :view | ||
alias Contraq.Gigs.Gig | ||
|
||
@spec location(%Gig{}) :: String.t | ||
def location(%Gig{city: city, state: state}) do | ||
[city, state] |> Enum.reject(&is_nil/1) |> Enum.join(", ") | ||
end | ||
|
||
@spec time_range(%Gig{}) :: String.t | ||
def time_range(%Gig{start_time: start_time, end_time: end_time}) do | ||
for time <- [start_time, end_time] do | ||
Timex.format!(time, Application.get_env(:contraq, ContraqWeb)[:datetime_format]) | ||
end |> Enum.join("–") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule ContraqWeb.GigViewSpec do | ||
use ESpec.Phoenix, async: true, view: ContraqWeb.GigView | ||
alias Contraq.Factory | ||
|
||
let :attributes, do: %{} | ||
let :gig, do: Factory.build(:gig, attributes) | ||
|
||
describe ".location" do | ||
subject do: described_module.location gig | ||
|
||
context "city and state present" do | ||
it "returns the city and state, joined with a comma" do | ||
expect(subject).to eq "#{gig.city}, #{gig.state}" | ||
end | ||
end | ||
|
||
context "city not present" do | ||
let :attributes, do: %{city: nil} | ||
|
||
it "returns the state" do | ||
expect(subject).to eq gig.state | ||
end | ||
end | ||
|
||
context "state not present" do | ||
let :attributes, do: %{state: nil} | ||
|
||
it "returns the city" do | ||
expect(subject).to eq gig.city | ||
end | ||
end | ||
|
||
context "no location" do | ||
let :attributes, do: %{city: nil, state: nil} | ||
|
||
it "returns an empty string" do | ||
expect(subject).to eq "" | ||
end | ||
end | ||
end | ||
|
||
describe ".time_range" do | ||
subject do: described_module.time_range gig | ||
|
||
it "returns the starting and ending times for the gig, formatted and joined with an en-dash" do | ||
formatted_times = for time <- [gig.start_time, gig.end_time] do | ||
Timex.format! time, Application.get_env(:contraq, ContraqWeb)[:datetime_format] | ||
end | ||
expect(subject).to eq Enum.join(formatted_times, "–") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters