
bobek
Ash Framework: How to test changes to resources?
For example the following test:
test "stores the actor that updated the record" do
actor = generate(user(role: :admin))
artist = generate(artist(name: "First Name"))
refute artist.updated_by_id == actor.id
artist = Music.update_artist!(artist, %{name: "Second Name"}, actor: actor)
assert artist.updated_by_id == actor.id
end
Looks very reasonable, but will currently fail with
For safety, we prevent any changes after that point because they will bypass validations or other action logic.. To proceed anyway,
you can useforce_change_attribute/3
. However, you should prefer a pattern like the below, which makes
any custom changes before calling the action.
Resource
|> Ash.Changeset.new()
|> Ash.Changeset.change_attribute(...)
|> Ash.Changeset.for_create(...)
Which definitely makes sense – prepare all changes prior creating the change set. But how to tight this up with a generator?
First Post!

sevenseacat
Sorry, I’m not following the problem here. Those tests about recording who updated a record shouldn’t fail - they don’t fail in the app at the end of the testing chapter. If you’re seeing failures, can you share the full error with stacktrace?
And what exactly are you looking to update the generators to do?
Popular Pragmatic Bookshelf topics








Modern Front-End Development for Rails - application does not start after run bin/setup (page xviii)


Other popular topics










Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /react
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /zig
- /scala
- /textmate
- /sublime-text
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /nodejs
- /diversity
- /lua
- /julia
- /c
- /slackware
- /neovim