Skip to content

Commit ff0fdc8

Browse files
committed
test rails/parse helper
1 parent 13817d2 commit ff0fdc8

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

spec/helpers/parse_rails_spec.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'helpers/parse_rails'
5+
6+
RSpec.describe 'rails/parse helper', fakefs: true do
7+
it 'saves tables data' do
8+
rewriter =
9+
Synvert::Rewriter.new 'test', 'rails_parse_helper' do
10+
call_helper 'rails/parse'
11+
end
12+
13+
file_path = 'db/schema.rb'
14+
FileUtils.mkdir_p(File.dirname(file_path))
15+
File.write(file_path, <<~EOF)
16+
ActiveRecord::Schema[7.1].define(version: 2024_04_22_081242) do
17+
# These are extensions that must be enabled in order to support this database
18+
enable_extension "plpgsql"
19+
20+
create_table "users", force: :cascade do |t|
21+
t.string "name", null: false
22+
t.string "email", null: false
23+
t.datetime "created_at", null: false
24+
t.datetime "updated_at", null: false
25+
t.index ["email"], name: "index_users_on_email", unique: true
26+
end
27+
end
28+
EOF
29+
30+
rewriter.process
31+
32+
expect(rewriter.load_data(:rails_tables)).to eq({
33+
"users" => {
34+
columns: [
35+
{ name: "name", type: "string" },
36+
{ name: "email", type: "string" },
37+
{ name: "created_at", type: "datetime" },
38+
{ name: "updated_at", type: "datetime" }
39+
],
40+
indices: [
41+
{ columns: ["email"], name: "index_users_on_email" }
42+
]
43+
}
44+
})
45+
end
46+
end

0 commit comments

Comments
 (0)