Fixed model palette IDs as names

These are not IDs but names so this corrects the mistake that the API makes including providing a safe default (i.e. empty array) when the names are missing.

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-03-18 12:06:39 -06:00
parent 39a753f215
commit 635c252ec2
3 changed files with 37 additions and 6 deletions
+6 -2
View File
@@ -1,5 +1,7 @@
# frozen_string_literal: true
require "refinements/hash"
module TRMNL
module API
module Models
@@ -18,10 +20,10 @@ module TRMNL
:height,
:offset_x,
:offset_y,
:palette_ids,
:palette_names,
:css
) do
def self.for(attributes) = new(**attributes)
def self.for(attributes) = new(**attributes.transform_keys(palette_ids: :palette_names))
def initialize(**)
super
@@ -34,6 +36,8 @@ module TRMNL
private
def apply_defaults
self[:palette_names] ||= []
%i[colors bit_depth scale_factor rotation width height offset_x offset_y].each do |name|
self[name] ||= 0
end
+1 -1
View File
@@ -71,7 +71,7 @@ RSpec.describe TRMNL::API::Endpoints::Model do
height: 480,
offset_x: 10,
offset_y: 15,
palette_ids: %w[bw grey-4],
palette_names: %w[bw grey-4],
css: {
classes: {
device: "screen--v2",
+30 -3
View File
@@ -36,7 +36,34 @@ RSpec.describe TRMNL::API::Models::Model do
end
it "answers record for attributes" do
expect(described_class.for(attributes)).to eq(described_class[**attributes])
expect(described_class.for(attributes)).to eq(
described_class[
name: "test",
label: "Test",
description: "A test.",
kind: "trmnl",
colors: 2,
bit_depth: 1,
scale_factor: 1,
rotation: 90,
mime_type: "image/png",
width: 800,
height: 480,
offset_x: 10,
offset_y: 15,
palette_names: %w[bw grey-4],
css: {
classes: {
device: "screen--v2",
size: "screen--lg"
},
variables: [
%w[--screen-w 1040px],
%w[--screen-h 780px]
]
}
]
)
end
end
@@ -56,7 +83,7 @@ RSpec.describe TRMNL::API::Models::Model do
height: 0,
offset_x: 0,
offset_y: 0,
palette_ids: nil,
palette_names: [],
css: nil
)
end
@@ -84,7 +111,7 @@ RSpec.describe TRMNL::API::Models::Model do
height: 0,
offset_x: 0,
offset_y: 0,
palette_ids: nil,
palette_names: [],
css: nil
)
end