Skip to content

Commit

Permalink
fix: Adds helpful error message upon failure
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Mar 31, 2023
1 parent 240369a commit 32d3b8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ require "ts_schema"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require_relative "../test/dummy/config/environment"

def generator(options)
config = TsSchema::Configuration.new(options)
TsSchema::SchemaGenerator.new(config)
end

# (If you use this, don't forget to add pry to your Gemfile!)
require "pry"
Pry.start
Expand Down
6 changes: 6 additions & 0 deletions lib/ts_schema/schema_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def map_associations(model)
ts_type: "#{association.class_name.constantize.model_name.param_key.camelize}[]"
}
end
rescue StandardError => e
print "#{model} has an incorrect association: #{association.name}\n"
print "Association details:\n"
print JSON.parse(association.to_json)
print "\n\n"
print e
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/schema_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ class SchemaGeneratorTest < ActiveSupport::TestCase

assert_includes map, {name: "deep?", ts_type: "'option1'|'option2'"}
end

test "it outputs types in alphabetical order" do
generator = TsSchema::SchemaGenerator.new
assert_equal generator.models.first.model_name, "Deep"
assert_equal generator.models.last.model_name, "Two"
end
end

0 comments on commit 32d3b8b

Please sign in to comment.