Sha256: d9e555c35632ef7bd415bc052995935c610d18819ca1ddb68cf95ae7cc1daf46
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require 'rails_helper' require 'sorbet-rails/model_rbi_formatter' RSpec.describe ModelRbiFormatter do it 'loads all the models in the app' do expected_models = [ Potion, SpellBook, Wand, Wizard, ] Rails.application.eager_load! # Needed for Rails 6.0 Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk) all_models = ActiveRecord::Base.descendants expect((expected_models - all_models)).to eql([]) end it 'does not throw an error when given an abstract class' do formatter = ModelRbiFormatter.new(Potion, ['Potion']) expect_match_file( formatter.generate_rbi, 'expected_potion.rbi', ) end it 'generates correct rbi file for Wizard' do formatter = ModelRbiFormatter.new(Wizard, ['Wizard', 'Wand', 'SpellBook']) expect_match_file( formatter.generate_rbi, 'expected_wizard.rbi', ) end it 'generates strict belongs_to and generate overridden methods' do formatter = ModelRbiFormatter.new(Wand, ['Wizard', 'Wand', 'SpellBook']) expect_match_file( formatter.generate_rbi, 'expected_wand.rbi', ) end context 'there is a hidden model' do it 'fallbacks to use ActiveRecord::Relation' do formatter = ModelRbiFormatter.new(Wizard, ['Wizard', 'Wand']) expect_match_file( formatter.generate_rbi, 'expected_wizard_wo_spellbook.rbi', ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sorbet-rails-0.3.0 | spec/model_rbi_formatter_spec.rb |