|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class RecordTypeTest < ActiveSupport::TestCase |
| 4 | + # Test that file_formats handles missing key gracefully |
| 5 | + test 'file_formats returns nil when file_formats key is missing' do |
| 6 | + record_data = { 'title' => 'Test Record' } |
| 7 | + record_type = Types::RecordType.send(:new, record_data, {}) |
| 8 | + |
| 9 | + result = record_type.file_formats |
| 10 | + assert_nil result, 'file_formats should return nil when key is missing' |
| 11 | + end |
| 12 | + |
| 13 | + # Test that file_formats handles explicit nil gracefully |
| 14 | + test 'file_formats returns nil when file_formats is nil' do |
| 15 | + record_data = { 'title' => 'Test Record', 'file_formats' => nil } |
| 16 | + record_type = Types::RecordType.send(:new, record_data, {}) |
| 17 | + |
| 18 | + result = record_type.file_formats |
| 19 | + assert_nil result, 'file_formats should return nil when value is nil' |
| 20 | + end |
| 21 | + |
| 22 | + # Test that file_formats works correctly when data is present |
| 23 | + test 'file_formats returns unique formats when present' do |
| 24 | + record_data = { |
| 25 | + 'title' => 'Test Record', |
| 26 | + 'file_formats' => %w[PDF PDF EPUB PDF] |
| 27 | + } |
| 28 | + record_type = Types::RecordType.send(:new, record_data, {}) |
| 29 | + |
| 30 | + result = record_type.file_formats |
| 31 | + assert_equal %w[PDF EPUB], result, 'file_formats should return unique values' |
| 32 | + end |
| 33 | +end |
0 commit comments