AssertIdentity v0.1.0 released

AssertIdentity has just been released. It’s a small helper library for ExUnit that provides assertions useful for comparing data structures by identity.

AssertIdentity really shines in applications that leverage Ecto. Consider the following:

def MyApp.PostTest do
  use MyApp.DataCase

  test "list_posts/0 returns all posts" do
    post = insert(:post)
    assert Posts.list_posts() == [post]
    assert_ids_match(Posts.list_posts(), [post])
  end
end

The first assertion fails when using factories that, for example, insert associations. (That’s because on the left-hand side you’ll have Ecto.Association.NotLoaded for the association values but on the right-hand side you’ll have a real association struct.)

The assert_ids_match/2 assertion passes because it instead plucks the :id key from each struct and compares those values (instead of an identity comparison on the whole struct).

Check out the docs for more examples and options on how to customize the identity assertion to your needs!

Links:

Elixir: Time for Some Configuration

I wrote a blog post to help people grok the different places where to configure an Elixir application and the difference between build time and runtime. Hope it clears things up!

https://blog.nytsoi.net/2020/05/05/elixir-time-for-configuration

Cloister :: Distributed Erlang like I am 5

To avoid an enormous boilerplate in each project running distributed erlang to deal with a hostile containerized environment, helpers are to be created. Welcome Cloister, another library to erase the line between local :nonode@nohost and distributed erlang.

https://rocket-science.ru/hacking/2020/05/07/cloister

Manipulating INTERVALs in Ecto fragments

Querying entries that were created N days/month/weeks/years ago can be a bit tricky with Ecto but definitely a very rewarding approach to the task! In this short post we will take a look at 2 common problems with manipulating INTERVALs and understand how to circumvent them. Enjoy!

https://dev.to/lessless/manipulating-intervals-in-ecto-fragments-3ofl

A wall too tall - Nerves & k3s

The story of wanting too much, taking on more than you can comfortably handle. And probably also a cool idea. Elixir, Nerves, devops and potentially some humility.

https://underjord.io/a-wall-too-tall-nerves-k3s.html

How to protect Amazon S3 media links with Elixir and Arc

Learn how to protect 🔒 your AWS S3 files in your Elixir project using Arc, in our latest blog post 👉 https://coletiv.com/blog/how-to-protect-amazon-s3-media-links-with-elixir-and-arc/

Build a clone of airbnb using @elixirphoenix LiveView

I have been working on a video course on Phoenix Live View for sometime now.

In the course, you will be learning how to create a real world app like a clone of Airbnb using Phoenix and Live View from scratch.

More details on the table of contents, trailer video and release date will be announced in the coming weeks.

Interested? Read more here: https://io.shankardevy.com/video-courses/phoenix-live-view and subscribe to get updates.

Getting started with Phoenix LiveDashboard

Happy Monday everyone and May the 4th be with you!

Check out my latest blog post on Phoenix LiveDashboard to learn how you can go about using it in your Phoenix application :)

https://akoutmos.com/post/phoenix_live_dashboard/

Dashboard screenshot

Specify a Port when Booting a Phoenix Application

mix phx.server doesn’t come with a -P or -p option, so here is a quick tip on how to specify a port for your Phoenix application.

https://programmingzen.com/specify-a-port-when-booting-a-phoenix-app/

many_to_many relationships in Ecto and Phoenix for Products and Tags

A comprehensive explanation of many_to_many relationships with an example: https://minhajuddin.com/2020/05/03/many-to-many-relationships-in-ecto-and-phoenix-for-products-and-tags/

Updates of Deep Work Hours

Changelog:

  • Upgrade from Phoenix 1.4 to 1.5
  • Update Phoenix.PubSub implementation
  • Update entries list upon insert via PubSub (thanks to video from Chris McCord)

https://github.com/co0lsky/deep-work-hours-phoenix/compare/2d290265ad4b017d4399145ebfa87ea215a4aae1…master

🐇 Opinionated RabbitMQ client to help you build balanced and consistent Consumers and Producers

rabbit_mq builds on amqp to deliver modules that are pre-configured with sensible defaults and follow design principles that improve and delicately balance both performance and reliability.

Docs can be found on Hex as well as GitHub.

Instrumenting Phoenix with Telemetry + LiveDashboard

LiveDashboard is here! Take a look at how to get it up and running and peek under the hood to better understand how it works together with Erlang + Elixir’s Telemetry offering. https://elixirschool.com/blog/instrumenting-phoenix-with-live-dashboard/

Local Metrics Aggregation With Counters

Recently I needed to get a better picture of how my application’s database connection pool was doing, but there was a bit of a hitch. DBConnection has a highly optimized queuing algorithm, but the downside of that optimization is that you can’t get an accurate picture of the number of idle and busy connections in the pool at any given time like you can with Poolboy. But we can use some telemetry events to get this information, with just a little bit of extra code to avoid adding a performance bottleneck to our applications!

http://devonestes.com/local-metrics-aggregation-with-counters

Developing with Elixir/OTP Course Review

I wrote a detailed review of Developing with Elixir/OTP by The Pragmatic Studio.

https://programmingzen.com/developing-with-elixir-otp-course-review/

Upgrade your use of render_existing with Phoenix 1.5

With the introduction of the new layouts in Phoenix 1.5, the traditional way of using render_existing/3 for dynamically calling render changes up a little bit. In this small post, I show you how to upgrade your use and address a common issue many of you seem to be hitting after upgrading your layouts.

https://morphic.pro/posts/upgrading-phoenix-1-5s-render-existing

Yggdrasil: Easy Pub-Sub in Elixir

Based on Phoenix.PubSub, I wrote Yggdrasil, an agnostic pub-sub library to connect different technologies under the same API.

I wrote a series of articles explaining Yggdrasil’s features:

Yggdrasil: Easy Pub-Sub in Elixir

Rustling up predictive sports betting models on the BEAM

https://www.youtube.com/watch?v=xmUfTl33-fU

ExUnited v0.1.2 has just been released

With the following improvements:

  • Add ability to use a different MIX_ENV when spawning nodes (solves meck related testing problems)
  • Add boolean flag to not start ExUnit

The README fragment concerning the :mix_env configuration:

ATTENTION: When also using meck-based packages

The following errors can occur when also using packages like mock or MecksUnit (which both use the Erlang library meck to mock functions) and spawning the nodes with the default environment :test:

  • (UndefinedFunctionError) function Some.Module.some_function/1 is undefined
  • (ErlangError) Erlang error: {{:undefined_module, < Some.Module >}

To tackle this, you should configure any other (Mix) environment to spawn the nodes with. Configure it like so:

# config/test.exs
import Config

config :ex_united,
  mix_env: :dev

You might also want to consider using a bogus environment (e.g. :void) to skip the non-relevant :dev dependencies, like credo or dialyxir probably. That will save some compile time.

And last but not least, please note that using a different environment within CI builds will require compiling the project in that particular environment on beforehand of the tests. Otherwise spawning the nodes will take too much time and that will cause timeout errors during the tests.

# .gitlab-ci.yml
before_script:
  ...
  - MIX_ENV=void mix deps.get
  - MIX_ENV=void mix run -e 'IO.puts("Done.")'
  - epmd -daemon
script:
  - mix test

ElixirMix Podcast 093: Multi-Tenant DBs with Lars Wikman

In this episode of ElixirMix, we catch up with Lars Wikman to talk about what he’s learned along his journey with Elixir and multi-tenant databases. We cover what multi-tenant means, various ways to do it and where it may or may not make sense. We learn about dynamic repos, query prefixes, how to deal with migrations, testing, and much more!

Podcast Episode

Previous page Next page