Add deserialize method to CharacterSheetSection
This commit is contained in:
parent
c870e373bc
commit
d4b982ea16
|
@ -25,4 +25,22 @@ class CharacterSheetSection < ApplicationRecord
|
|||
def highest_order_index
|
||||
character_sheet_features.maximum(:order_index) || 1
|
||||
end
|
||||
|
||||
def self.deserialize(h)
|
||||
section = new
|
||||
|
||||
h["character_sheet_subsections"].each do |sub|
|
||||
section.character_sheet_subsections.deserialize(sub)
|
||||
end
|
||||
|
||||
h["stats"].each do |stat|
|
||||
section.stats.build(stat)
|
||||
end
|
||||
|
||||
h["text_fields"].each do |text_field|
|
||||
section.text_fields.build(text_field)
|
||||
end
|
||||
|
||||
section
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class TemplateBuilderTest < ActiveSupport::TestCase
|
||||
test "creates template from a CharacterSheetSection" do
|
||||
section = character_sheet_sections(:stats)
|
||||
template = TemplateBuilder.create!(
|
||||
name: "Test template",
|
||||
game_system: GameSystem.last,
|
||||
from: section,
|
||||
)
|
||||
template_hash = JSON.parse(template.content)
|
||||
assert_equal 1, template_hash["character_sheet_subsections"].count
|
||||
assert_equal 3, template_hash["stats"].count
|
||||
assert_equal "Stats", template_hash["name"]
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue