Skip to content

Commit

Permalink
Rescue from load_records if test fixture is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
serioushaircut committed Feb 19, 2024
1 parent 4ca60e5 commit 324e3f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/frozen_record/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def unload_fixture(model_class)

old_base_path = @cache[model_class]
model_class.base_path = old_base_path
model_class.load_records(force: true)

begin
model_class.load_records(force: true)
rescue
nil
end

@cache.delete(model_class)
end
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/test_helper/only_in_tests.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- id: 1
name: Some continent
12 changes: 12 additions & 0 deletions spec/test_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
expect(Continent.count).to be == 1
expect(Country.count).to be == 3
end

context "when the test fixture does not exist in normal base path" do
class OnlyInTest < FrozenRecord::Base; end
before do
test_fixtures_base_path = File.join(File.dirname(__FILE__), 'fixtures', 'test_helper')
FrozenRecord::TestHelper.load_fixture(OnlyInTest, test_fixtures_base_path)
end
it 'unload fixture gracefully recovers from an ' do

expect { FrozenRecord::TestHelper.unload_fixture(OnlyInTest) }.not_to raise_error
end
end
end

describe '.unload_fixtures' do
Expand Down

0 comments on commit 324e3f9

Please sign in to comment.