elixir

How can I make Elixir mix test output more verbose?

醉酒当歌 提交于 2020-07-18 08:42:22
问题 In my Elixir/Phoenix app, when I run mix test I get output like: $ mix test .... Finished in 0.09 seconds 4 tests, 0 failures with dots for each test that succeeded. How do I output the names of the tests that succeed instead? In Rails with rspec I used to do this with a .rspec file in the directory that looked like: $ cat .rspec --color -fd --tty Is there an equivalent in Elixir? 回答1: To print the names of the passing tests, you can pass --trace argument to mix test . For example, here's the

How can I make Elixir mix test output more verbose?

情到浓时终转凉″ 提交于 2020-07-18 08:41:01
问题 In my Elixir/Phoenix app, when I run mix test I get output like: $ mix test .... Finished in 0.09 seconds 4 tests, 0 failures with dots for each test that succeeded. How do I output the names of the tests that succeed instead? In Rails with rspec I used to do this with a .rspec file in the directory that looked like: $ cat .rspec --color -fd --tty Is there an equivalent in Elixir? 回答1: To print the names of the passing tests, you can pass --trace argument to mix test . For example, here's the

List possible train routes on a given model railway

那年仲夏 提交于 2020-07-10 07:07:58
问题 I want to calculate the available routes on a given model railway. Assumptions: All trains only start and stop on defined points which are called train stations. Trains do not collide during their trip. No need to worry about that. We don't have to think about the length of a train. We assume it is one locomotive which takes the space of an atom. On one train station only one train can stop. A train can start and stop on the same train station. The start position and the end position of all

List possible train routes on a given model railway

若如初见. 提交于 2020-07-10 07:06:53
问题 I want to calculate the available routes on a given model railway. Assumptions: All trains only start and stop on defined points which are called train stations. Trains do not collide during their trip. No need to worry about that. We don't have to think about the length of a train. We assume it is one locomotive which takes the space of an atom. On one train station only one train can stop. A train can start and stop on the same train station. The start position and the end position of all

How do I avoid Ecto matching incorrectly when comparing binary IDs with == in a Latin database?

浪尽此生 提交于 2020-07-10 03:25:39
问题 I've come across a problem with my Elixir Ecto MySQL database. We've found that the character set is latin, which is probably part of the problem. I have an object in the database with the id: field set to "3f0c7254-693f-4574-3f3f-256c3f3f5224". If I do a query on the database using this block of Elixir to generate the query: params |> Enum.reduce(@schema, fn {k, v}, query -> where(query, [b], field(b, ^k) == ^v) end) I can pass id: "b30c7254-69d1-4574-a489-256cd9c45224" to the query (as

a bug in erlang node after an error at another node

雨燕双飞 提交于 2020-06-17 09:56:06
问题 i created 2 erlang nodes in the same Windows machine with two cmd windows:'unclient@MYPC' and 'unserveur@MYPC' , the server code is very simple : -module(serveur). -export([start/0,recever/0,inverse/1]). %%%% start() -> process_flag(trap_exit,true), Pid=spawn_link(serveur,recever,[]), register(ownServer, Pid). %%%% recever() -> receive {From, X} ->From ! {ownServer,1/X} end. %%%% inverse(X) -> ownServer!{self(), X}, receive {'EXIT',_, _} ->start(), sorry; {ownServer, Reply} ->Reply end. so at

Convert a map into a keyword list in Elixir

对着背影说爱祢 提交于 2020-06-17 06:08:48
问题 I have a map of the form: %{"browser_name" => "Chrome", "platform" => "linux"} and I need to convert it to a keyword list: [browser_name: "Chrome", platform: "linux"] What's the best way of achieving this? 回答1: Wouldn't this work: def ConvertMapToKList(dict) do Enum.map(dict, fn({key, value}) -> {String.to_existing_atom(key), value} end) end 回答2: I would put it here for the sake of future readers. While one surely might blindly call String.to_atom/1 here and there, that approach is strongly

What do the on_delete options in Ecto.Migrations.references/2 do?

扶醉桌前 提交于 2020-05-28 09:59:26
问题 The Ecto documentation describes the options available to references/2 , but does not document what those options do. The options available are: :nothing :delete_all :nilify_all :restrict What do they do? 回答1: This is actually a SQL question at root. https://github.com/elixir-ecto/ecto_sql/blob/52f9d27a7ad86442f442bad2f7ebd19ba09ddc61/lib/ecto/adapters/myxql/connection.ex#L902-L905 The PostgreSQL documentation outlines these options clearly: :nothing - if any referencing rows still exist when

Using a Repo in an Ecto migration

守給你的承諾、 提交于 2020-05-15 09:42:27
问题 I've got an Ecto migration where I'd like to modify some columns but also migrate some data. For example: import Ecto.Query defmodule MyApp.Repo.Migrations.AddStatus do alter table(:foo) do add(:status, :text) end foos = from(f in MyApp.Foo, where: ...) |> MyApp.Repo.all Enum.each(foos, fn(foo) -> # There's then some complex logic here to work # out how to set the status based on other attributes of `foo` end) end Now, the problem here is that by calling MyApp.Repo.all the migration

Using a Repo in an Ecto migration

旧街凉风 提交于 2020-05-15 09:41:33
问题 I've got an Ecto migration where I'd like to modify some columns but also migrate some data. For example: import Ecto.Query defmodule MyApp.Repo.Migrations.AddStatus do alter table(:foo) do add(:status, :text) end foos = from(f in MyApp.Foo, where: ...) |> MyApp.Repo.all Enum.each(foos, fn(foo) -> # There's then some complex logic here to work # out how to set the status based on other attributes of `foo` end) end Now, the problem here is that by calling MyApp.Repo.all the migration