-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_schema_snapshot_spec.rb
27 lines (22 loc) · 1.11 KB
/
example_schema_snapshot_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require "rails_helper"
# rubocop:disable RSpec/EmptyExampleGroup
RSpec.describe "Example" do
def self.snapshot_test(filename, generate)
it "generates correct #{filename} schema" do
User.find_or_create_by!(name: "User", role: :admin) # allows ActiveRecord to define instance methods for columns
schema = generate.call
path = Rails.root.join("test/files", filename)
unless File.file?(path)
File.open(path, "w") { |file| file.write(schema) }
end
SnapshotUpdate.prompt(path, schema) if ENV["THOR_MERGE"] && File.read(path) != schema
expect(File.read(path)).to eql(schema)
end
end
snapshot_test "schema.ts", -> { Schema.generate(include_all_fields: true) }
snapshot_test "test_schema.ts", -> { Schema.generate(context: { role: "test" }) }
snapshot_test "all_fields_false_schema.ts", -> { Schema.generate }
snapshot_test "excluded_fields_schema.ts", -> { Schema.generate(exclude_fields: { User: [:name, :posts] }) }
snapshot_test "json_schema.json", -> { Schema.generate(adapter: :json_schema, include_all_fields: true) }
end
# rubocop:enable RSpec/EmptyExampleGroup