Skip to content

Commit

Permalink
Use data structures whenever submitting calendar types
Browse files Browse the repository at this point in the history
This will help tackle #3819 from LV side.

It also adds a requirement on Elixir v1.9+.
  • Loading branch information
josevalim committed May 1, 2020
1 parent 4beb65a commit f0049f0
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 52 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
language: elixir
elixir:
- 1.9
- 1.10
otp_release:
- 22.0
matrix:
include:
- elixir: 1.7
otp_release: 21.0
- elixir: 1.8
otp_release: 21.0
- elixir: 1.9
otp_release: 22.0
otp_release: 21.0
sudo: false
env:
global:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Changelog for v1.6

Phoenix v1.6 requires Elixir v1.9+.

## 1.6.0-dev

### Enhancements

### Bug fixes

* [mix phx.gen.live] Fix a bug where tests with `utc_datetime` fields did not pass out of the box

### Deprecations

* [Endpoint] Phoenix now requires Cowboy v2.7+
Expand Down
4 changes: 2 additions & 2 deletions guides/deployment/heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ The buildpack uses a predefined Elixir and Erlang version but to avoid surprises

```
# Elixir version
elixir_version=1.8.1
elixir_version=1.10.3
# Erlang version
# available versions https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds/blob/master/otp-versions
erlang_version=21.2.5
erlang_version=22.2.8
```

### Adding the Phoenix Server and Assets Buildpack
Expand Down
4 changes: 2 additions & 2 deletions installer/lib/mix/tasks/phx.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ defmodule Mix.Tasks.Phx.New do
end

defp elixir_version_check! do
unless Version.match?(System.version(), "~> 1.7") do
Mix.raise "Phoenix v#{@version} requires at least Elixir v1.7.\n " <>
unless Version.match?(System.version(), "~> 1.9") do
Mix.raise "Phoenix v#{@version} requires at least Elixir v1.9.\n " <>
"You have #{System.version()}. Please update accordingly"
end
end
Expand Down
2 changes: 1 addition & 1 deletion installer/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Phx.New.MixProject do
app: :phx_new,
start_permanent: Mix.env() == :prod,
version: @version,
elixir: "~> 1.7",
elixir: "~> 1.9",
deps: deps(),
package: [
maintainers: [
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_single/config/prod.secret.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ config :<%= app_name %>, <%= endpoint_module %>,
],
secret_key_base: secret_key_base

# ## Using releases (Elixir v1.9+)
# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_single/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule <%= app_module %>.MixProject do
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",<% end %>
elixir: "~> 1.7",
elixir: "~> 1.9",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix<%= if gettext do %>, :gettext<% end %>] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_umbrella/apps/app_name/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule <%= app_module %>.MixProject do
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.7",
elixir: "~> 1.9",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config :<%= web_app_name %>, <%= endpoint_module %>,
],
secret_key_base: secret_key_base

# ## Using releases (Elixir v1.9+)
# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_umbrella/apps/app_name_web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule <%= web_namespace %>.MixProject do
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.7",
elixir: "~> 1.9",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix<%= if gettext do %>, :gettext<% end %>] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
Expand Down
22 changes: 10 additions & 12 deletions lib/mix/phoenix/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ defmodule Mix.Phoenix.Schema do
|> inspect_value(value)
end
defp inspect_value(:decimal, value), do: "Decimal.new(\"#{value}\")"
defp inspect_value(:utc_datetime, value), do: "DateTime.from_naive!(~N[#{value}], \"Etc/UTC\")"
defp inspect_value(:utc_datetime_usec, value), do: "DateTime.from_naive!(~N[#{value}], \"Etc/UTC\")"
defp inspect_value(_type, value), do: inspect(value)

defp drop_unique(info) do
Expand All @@ -207,12 +205,12 @@ defmodule Mix.Phoenix.Schema do
:boolean -> true
:map -> %{}
:text -> "some #{key}"
:date -> %Date{year: 2010, month: 4, day: 17}
:time -> %Time{hour: 14, minute: 0, second: 0}
:time_usec -> %Time{hour: 14, minute: 0, second: 0, microsecond: {0, 6}}
:date -> ~D[2010-04-17]
:time -> ~T[14:00:00]
:time_usec -> ~T[14:00:00.000000]
:uuid -> "7488a646-e31f-11e4-aace-600308960662"
:utc_datetime -> "2010-04-17T14:00:00Z"
:utc_datetime_usec -> "2010-04-17T14:00:00.000000Z"
:utc_datetime -> ~U[2010-04-17T14:00:00Z]
:utc_datetime_usec -> ~U[2010-04-17T14:00:00.000000Z]
:naive_datetime -> ~N[2010-04-17 14:00:00]
:naive_datetime_usec -> ~N[2010-04-17 14:00:00.000000]
_ -> "some #{key}"
Expand All @@ -227,12 +225,12 @@ defmodule Mix.Phoenix.Schema do
:boolean -> false
:map -> %{}
:text -> "some updated #{key}"
:date -> %Date{year: 2011, month: 5, day: 18}
:time -> %Time{hour: 15, minute: 1, second: 1}
:time_usec -> %Time{hour: 15, minute: 1, second: 1, microsecond: {0, 6}}
:date -> ~D[2011-05-18]
:time -> ~T[15:01:01]
:time_usec -> ~T[15:01:01.000000]
:uuid -> "7488a646-e31f-11e4-aace-600308960668"
:utc_datetime -> "2011-05-18T15:01:01Z"
:utc_datetime_usec -> "2011-05-18T15:01:01.000000Z"
:utc_datetime -> ~U[2011-05-18T15:01:01Z]
:utc_datetime_usec -> ~U[2011-05-18T15:01:01.000000Z]
:naive_datetime -> ~N[2011-05-18 15:01:01]
:naive_datetime_usec -> ~N[2011-05-18 15:01:01.000000]
_ -> "some updated #{key}"
Expand Down
6 changes: 0 additions & 6 deletions lib/phoenix/presence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,6 @@ defmodule Phoenix.Presence do
}
end

# TODO: Remove this on the next Phoenix version as we require v1.6
# and this will only be called by outdated child specs.
def start_link(opts \\ []) do
Phoenix.Presence.start_link(__MODULE__, Keyword.merge(@opts, opts))
end

# API

def track(%Phoenix.Socket{} = socket, key, meta) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Phoenix.MixProject do
# If the elixir requirement is updated, we need to make the installer
# use at least the minimum requirement used here. Although often the
# installer is ahead of Phoenix itself.
@elixir_requirement "~> 1.7"
@elixir_requirement "~> 1.9"

def project do
[
Expand Down
12 changes: 6 additions & 6 deletions test/mix/phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ defmodule Mix.PhoenixTest do
admin: true,
meta: %{},
name: "some name",
date_of_birth: %Date{year: 2010, month: 4, day: 17},
happy_hour: %Time{hour: 14, minute: 0, second: 0},
happy_hour_usec: %Time{hour: 14, minute: 0, second: 0, microsecond: {0, 6}},
joined: %NaiveDateTime{year: 2010, month: 4, day: 17, hour: 14, minute: 0, second: 0},
joined_utc: "2010-04-17T14:00:00Z",
joined_utc_usec: "2010-04-17T14:00:00.000000Z",
date_of_birth: ~D[2010-04-17],
happy_hour: ~T[14:00:00],
happy_hour_usec: ~T[14:00:00.000000],
joined: ~N[2010-04-17 14:00:00],
joined_utc: ~U[2010-04-17 14:00:00Z],
joined_utc_usec: ~U[2010-04-17 14:00:00.000000Z],
token: "7488a646-e31f-11e4-aace-600308960662",
other: "some other"
}
Expand Down
8 changes: 4 additions & 4 deletions test/mix/tasks/phx.gen.html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
assert file =~ "deleted_at: ~N[2010-04-17 14:00:00]"
assert file =~ "deleted_at_usec: ~N[2010-04-17 14:00:00.000000]"
assert file =~ "cost: \"120.5\""
assert file =~ "published_at: \"2010-04-17T14:00:00Z\""
assert file =~ "published_at_usec: \"2010-04-17T14:00:00.000000Z\""
assert file =~ "published_at: ~U[2010-04-17 14:00:00Z]"
assert file =~ "published_at_usec: ~U[2010-04-17 14:00:00.000000Z]"
assert file =~ "weight: 120.5"

assert file =~ "assert post.announcement_date == ~D[2011-05-18]"
assert file =~ "assert post.deleted_at == ~N[2011-05-18 15:01:01]"
assert file =~ "assert post.deleted_at_usec == ~N[2011-05-18 15:01:01.000000]"
assert file =~ "assert post.published_at == DateTime.from_naive!(~N[2011-05-18T15:01:01Z], \"Etc/UTC\")"
assert file =~ "assert post.published_at_usec == DateTime.from_naive!(~N[2011-05-18T15:01:01.000000Z], \"Etc/UTC\")"
assert file =~ "assert post.published_at == ~U[2011-05-18 15:01:01Z]"
assert file =~ "assert post.published_at_usec == ~U[2011-05-18 15:01:01.000000Z]"
assert file =~ "assert post.alarm == ~T[15:01:01]"
assert file =~ "assert post.alarm_usec == ~T[15:01:01.000000]"
assert file =~ "assert post.cost == Decimal.new(\"120.5\")"
Expand Down
8 changes: 3 additions & 5 deletions test/mix/tasks/phx.new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ defmodule Mix.Tasks.Phx.NewTest do
end)
end) =~ ~r"3 tests, 0 failures"

if Version.match?(System.version(), ">= 1.7.0") do
File.mkdir_p!("deps/phoenix")
File.cp_r!(Path.join(root, ".formatter.exs"), "deps/phoenix/.formatter.exs")
Mix.Task.run("format", ["--check-formatted"])
end
File.mkdir_p!("deps/phoenix")
File.cp_r!(Path.join(root, ".formatter.exs"), "deps/phoenix/.formatter.exs")
Mix.Task.run("format", ["--check-formatted"])
end
after
Code.delete_path Path.join(project_path, "_build/test/consolidated")
Expand Down
4 changes: 2 additions & 2 deletions test/phoenix/presence_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Phoenix.PresenceTest do

setup_all do
start_supervised! {Phoenix.PubSub, name: PresPub, pool_size: 1}
assert {:ok, _pid} = MyPresence.start_link([])
start_supervised! MyPresence
{:ok, pubsub: PresPub}
end

Expand Down Expand Up @@ -76,7 +76,7 @@ defmodule Phoenix.PresenceTest do

pid = spawn(fn -> :timer.sleep(:infinity) end)
Phoenix.PubSub.subscribe(config.pubsub, topic)
{:ok, _pid} = DefaultPresence.start_link(pubsub_server: config.pubsub)
start_supervised! {DefaultPresence, pubsub_server: config.pubsub}
DefaultPresence.track(pid, topic, "u1", %{name: "u1"})

assert_receive %Broadcast{topic: ^topic, event: "presence_diff", payload: %{
Expand Down

0 comments on commit f0049f0

Please sign in to comment.