Skip to content

Commit 8bb3e85

Browse files
committed
skip sb3 component import for non scratch projects
1 parent 13b859f commit 8bb3e85

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/project_importer.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def create_components
5252
return if project.scratch_project?
5353

5454
components.each do |component|
55+
# .sb3 files are only ever imported as a ScratchComponent (see
56+
# create_scratch_component); they carry an :io/:file_path key that is not a
57+
# Component attribute, so skip them here to avoid building invalid rows.
58+
next if component[:extension] == 'sb3'
59+
5560
project_component = Component.new(**component)
5661
project.components << project_component
5762
end

spec/lib/project_importer_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,31 @@
115115
end
116116
end
117117

118+
context 'when a non-scratch project contains an sb3 file' do
119+
let(:project) { Project.find_by(identifier: importer.identifier, user_id: nil, locale: importer.locale) }
120+
let(:importer) do
121+
described_class.new(
122+
name: 'My amazing project',
123+
identifier: 'my-amazing-project',
124+
type: Project::Types::PYTHON,
125+
locale: 'en',
126+
components: [
127+
{ name: 'main', extension: 'py', content: 'print(\'hello\')', default: true },
128+
{ name: 'stray', extension: 'sb3', io: StringIO.new('ignored') }
129+
]
130+
)
131+
end
132+
133+
it 'does not raise when importing' do
134+
expect { importer.import! }.not_to raise_error
135+
end
136+
137+
it 'skips the sb3 file and only creates the standard components' do
138+
importer.import!
139+
expect(project.components.pluck(:extension)).to eq(['py'])
140+
end
141+
end
142+
118143
context 'when the project has type code_editor_scratch' do
119144
let(:scratch_project_file) { Tempfile.new(['test_scratch_project', '.sb3']) }
120145
let(:parser) { instance_double(Sb3Parser, parse: parser_result) }

0 commit comments

Comments
 (0)