elixir

phoenix / testing dates in controllers

守給你的承諾、 提交于 2019-12-11 18:55:57
问题 Having the following basic test (using ex_machina) : # factory def item_factory do %Api.Content.Item{ title: "Some title", content: "Some content", published_at: NaiveDateTime.utc_now } end # test test "lists all items", %{conn: conn} do item = insert(:item) conn = get conn, item_path(conn, :index) assert json_response(conn, 200)["data"] == [ %{ "content" => item.content, "published_at" => item.published_at, "title" => item.title, "id" => item.id } ] end Am getting an error on the date : left

How to query a third relation in Ecto Associations

♀尐吖头ヾ 提交于 2019-12-11 17:59:23
问题 Snapmail |> preload(:user) |> preload(:snapmail_cameras) |> preload([snapmail_cameras: :camera]) |> preload([snapmail_cameras: [camera: :vendor_model]]) |> preload([snapmail_cameras: [camera: [vendor_model: :vendor]]]) |> Repo.all I have above query in Ecto. in this. Each snapmail has a snapmail_camera and snapmail_camera has a camera_id which is camera's id (from camera table.) and Cameras table has a field status . I am trying to get only those snapmails where its snapmail_cameras 's camera

Unable to install semver for Phoenix Up & Running project

↘锁芯ラ 提交于 2019-12-11 17:29:14
问题 I tried forcefully removing npm & node as per Npm install cannot find module 'semver' Elixir version (elixir -v): Erlang/OTP 20 [erts-9.1.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] Elixir 1.5.2 Phoenix version (mix deps): installed today NodeJS version (node -v): 8.6.0 NPM version (npm -v): I force uninstalled node & npm with node, then did brew install npm brew install node I still get this error: ~/hello/assets/npm install module.js:538

How can I pass arguments to supervisor from command line

我怕爱的太早我们不能终老 提交于 2019-12-11 15:59:14
问题 I want to pass arguments to a supervisor while I start an application like mix run project.exs arg1 arg2 Now I don't know how to start an application with a script(exs) file which will start my supervisor (with those arguments) I know about escript: [main_module: App] in mix.exs, provide def main(args): and then: mix escript.build ./app but it doesn't help me I am totally new to elixir, any help would be appreciated. 回答1: Typically arguments are passed to an application by means of

pheonix api options call shows empty params

自作多情 提交于 2019-12-11 15:46:09
问题 I am making a phoenix api for my react frontend and I am sending a post request with an object of objects, and I figured that I need to use options in the api to get them beause with post it just failed, but now the params are empty. Why is that? What I send: axios .post(PAYMENT_SERVER_URL, { description, email: token.email, source: token.id, subscriptionID }) api router: pipeline :api do plug(:accepts, ["json"]) end scope "/api", MyApiWeb do pipe_through(:api) options("/users",

Mocking nested function with Mox (Elixir)

不想你离开。 提交于 2019-12-11 15:41:02
问题 I am new to both mocking and Elixir, and trying to use the mocking library Mox to improve my tests coverage (mocking the dependencies), I was hoping to be able to create tests for most of my most critical status processors, and other calculations that my application need. So I have been able to use the library, and as a first approach I got this mocked function to test fine: test "Mocked OK response test" do Parsers.MockMapsApi |> expect(:parse_get_distance_duration, fn _ -> {:ok, "test_body"

Phoenix/Elixir - cURL works, but HTTPoison fails

我的未来我决定 提交于 2019-12-11 15:25:56
问题 In my Phoenix app, I am trying to use the HTTPoison HTTP client (https://hexdocs.pm/httpoison/api-reference.html) to make a post request to the AgileCRM API. I was able to use cURL to make a successful request, but my attempt to replicate it in Phoenix is failing with a 401 UNAUTHORIZED error. My successful cURL: $ curl https://domain.agilecrm.com/dev/api/contacts/search/email \ -H "Accept: application/json" \ -d 'email_ids=["contact@test.com"]' \ -u admin@test.com:api_key which returns

How to simplify `case` iteraction when the code is almost the same

↘锁芯ラ 提交于 2019-12-11 14:30:00
问题 I have this code in my controller: def search(conn, %{"q" => param}) do locale = conn |> get_session(:locale) case locale do "pt" -> searchEmpresas = Skeleton.Customers.Empresa |> Skeleton.Customers.search_pt(param) searchLojas = Skeleton.Customers.Loja |> Skeleton.Customers.search_pt(param) searchEventos = Skeleton.News.Evento |> Skeleton.News.search_pt(param) "es" -> searchEmpresas = Skeleton.Customers.Empresa |> Skeleton.Customers.search_es(param) searchLojas = Skeleton.Customers.Loja |>

Migration database constraint

杀马特。学长 韩版系。学妹 提交于 2019-12-11 14:19:14
问题 I'm writing a migration file and one of the fields I'd like to set a DB (Postgres) constraint for: def change do create table(:reviews) do add(:title, :string) add(:contents, :string) add(:stars, :integer) add(:user_id, references(:users), null: false) add(:user_id, references(:users), null: false) timestamps() end Id like to set a constraint on the stars field to be integer values only 1-5. How can I do this with Ecto.Migration? 回答1: How can I do this with Ecto.Migration Ecto.Migration

How to disable context in Elixir/Phoenix generators and models completely?

随声附和 提交于 2019-12-11 14:06:18
问题 Phoenix has a generator: mix phx.gen.html Accounts User users name:string age:integer I don't want to use a context for my models, neihter do I want to provide its name. How to disable it? 回答1: I believe you want to use the --no-context flag. Generating without a schema or context file 回答2: You can still use the old generators as they were in 1.2 and earlier mix phoenix.gen.html User users name:string age:integer Note: use phoenix.gen.html instead of phx.gen.html . More at the Phoenix 1.3