Skip to content

Check that the card is NSG before serving xlarge images #411

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

Merged
merged 4 commits into from
Aug 22, 2025

Conversation

lahlidahlia
Copy link
Contributor

I really wanted to add some tests for this, but I'm not really sure how to go about that. It didn't look like it belonged in acceptance/cards_spec.rb or resources/card_resource_reads_spec.rb. Also, not really sure how to test a resource specifically.

Copy link

codecov bot commented Aug 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.44%. Comparing base (6023cf1) to head (f29bd90).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #411   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files          76       76           
  Lines        1348     1352    +4     
  Branches      181      183    +2     
=======================================
+ Hits         1327     1331    +4     
  Misses         21       21           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lahlidahlia
Copy link
Contributor Author

Oops, closed this by accident.

@plural
Copy link
Contributor

plural commented Aug 20, 2025

I really wanted to add some tests for this, but I'm not really sure how to go about that. It didn't look like it belonged in acceptance/cards_spec.rb or resources/card_resource_reads_spec.rb. Also, not really sure how to test a resource specifically.

The tests for the resources overall could use some love, but you can add test cases, just a bit indirectly. If you add new cards in test/fixtures/, you can seed things that you can then request. Check out spec/resources/card_resource_reads_spec.rb and the 'fields match' test for an example. You can do more like that but more targeted.

@@ -163,16 +163,16 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength

private

def images(id, has_narrative_image: false, face_index: nil)
def images(id, designed_by, has_narrative_image: false, face_index: nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are going by set, we want released_by, not designed_by.

For example. the latest printing of sure gamble does not have xlarge, but the class act does right now:

Image Image

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry i was not clear about the distinctions between released by and designed by in chat.

@@ -164,15 +164,16 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength
private

def images(id, has_narrative_image: false, face_index: nil)
printing = Printing.find(id)
Copy link
Contributor

Choose a reason for hiding this comment

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

In CardResource, you can use card_set_ids and pluck the first item out. That is the latest printing (they are sorted by date_release DESC) to avoid this extra read. You will need to do that in attribute :latest_printing_images

Copy link
Contributor

Choose a reason for hiding this comment

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

or add the equivalent xlarge_image? method in the Card model and use that. EIther way, don't add an extra find in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly it seems like they're sorted the other way around? Had to use printings.last. By the way, why do we have latest_printing_id and not latest_printing? The latter seems more useful to me.

@@ -74,7 +74,8 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength

unless @object.num_extra_faces.zero?
@object.face_indices.each do |index|
f = { index:, images: images(@object.latest_printing_id, face_index: index) }
f = { index:,
images: images(@object.latest_printing_id, @object.printings.last.xlarge_image?, face_index: index) }
Copy link
Contributor

Choose a reason for hiding this comment

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

ah, ok. so there is a lightly tricky thing here.

You removed a read in favor of a different read.

@object.printings does a fetch for all related printings and it is only an accident tht you found this in the last one. technically they are unordered but sometimes do the right thing.

you want @object.printing_ids_in_database.first which will use the array field from the already loaded object. You can't just use printing_ids because printings is a relationship and printing_ids is a helper for relationships that will give you the ids after a query and loading those associated records.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, i was too fixated on the "avoid a read" bit and missed the "this doesn't solve your problem" bit.

We will need to pull an extra attribute from the printing into the card view, which i can do quickly as a follow-up.

The actual, helpful, fix you need here is an explicit ordering of the printings or it will sometimes misbehave.

@object.printings.order(:date_release).reverse_order.first.xlarge_image? in this case.

@@ -74,7 +74,8 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength

unless @object.num_extra_faces.zero?
@object.face_indices.each do |index|
f = { index:, images: images(@object.latest_printing_id, face_index: index) }
f = { index:,
images: images(@object.latest_printing_id, @object.printings.last.xlarge_image?, face_index: index) }
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, i was too fixated on the "avoid a read" bit and missed the "this doesn't solve your problem" bit.

We will need to pull an extra attribute from the printing into the card view, which i can do quickly as a follow-up.

The actual, helpful, fix you need here is an explicit ordering of the printings or it will sometimes misbehave.

@object.printings.order(:date_release).reverse_order.first.xlarge_image? in this case.

@lahlidahlia lahlidahlia merged commit 4962f2f into NetrunnerDB:main Aug 22, 2025
5 checks passed
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.

2 participants