Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diffs cardinality many through, inc tests #153

Merged
merged 9 commits into from
Oct 4, 2023

Conversation

leftstanding
Copy link
Contributor

Resolves polymorphism association many through causes error.
Does this by first checking if the association has already been diffed in the association
If not then builds the diff.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
test/ecto_diff_test.exs Show resolved Hide resolved
lib/ecto_diff.ex Outdated Show resolved Hide resolved
test/ecto_diff_test.exs Outdated Show resolved Hide resolved
test/ecto_diff_test.exs Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (b91baf0) 85.71% compared to head (f2f813d) 87.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #153      +/-   ##
==========================================
+ Coverage   85.71%   87.25%   +1.54%     
==========================================
  Files           1        1              
  Lines          91      102      +11     
==========================================
+ Hits           78       89      +11     
  Misses         13       13              
Files Coverage Δ
lib/ecto_diff.ex 87.25% <100.00%> (+1.54%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leftstanding leftstanding self-assigned this Sep 30, 2023
lib/ecto_diff.ex Outdated
[_ | _] = diff ->
List.flatten(diff)

_ ->
Copy link

@luizmiranda7 luizmiranda7 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ I don't quite understand what is expected value here... perhaps an empty list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the through key is present, but the assoc_field key is not, the return could be [nil], so _ -> was to handle both [] || [nil]. I have changed how we handle this so it can expect only empty lists.

mix.exs Outdated Show resolved Hide resolved
test/ecto_diff_test.exs Outdated Show resolved Hide resolved
test/ecto_diff_test.exs Show resolved Hide resolved
lib/ecto_diff.ex Outdated
[_ | _] = diff ->
List.flatten(diff)

_ ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This should just be an empty list:

Suggested change
_ ->
[] ->

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time, the return could also be [nil]. Changed the way we handle this.

Copy link
Contributor

@brunohkbx brunohkbx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Also missing a CHANGELOG entry

lib/ecto_diff.ex Outdated Show resolved Hide resolved
lib/ecto_diff.ex Outdated Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, without the select_fields option changes, testing the fallback when getting a diff for cardinality many through is difficult. In a sense, this is good; almost always EctoDiff should be able to retrieve the diff for the association via the through association diff, eliminating duplicate work being required. However, this has been tested locally by disabling the default path (get already diffed values) and verifying that all the tests still pass. Currently, the only test for this case is when there is no change on the through association, which triggers the fallback and as a side effect verifies that the default path matches the fallback path.

@leftstanding leftstanding merged commit 3ff4479 into master Oct 4, 2023
7 checks passed
@leftstanding leftstanding deleted the diff-polymorphic-many-through branch October 4, 2023 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants