rails-mermaid_erd_markdown 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS.md +1 -0
- data/.github/workflows/CI.yml +42 -0
- data/.github/workflows/codeql.yml +93 -0
- data/.rubocop.yml +30 -6
- data/.ruby-version +1 -0
- data/CHANGELOG.md +14 -1
- data/Gemfile +6 -9
- data/Gemfile.lock +88 -86
- data/README.md +111 -17
- data/Rakefile +1 -1
- data/bin/console +1 -1
- data/bin/rubocop +29 -0
- data/docs/examples/erd.yml +3 -3
- data/lib/rails-mermaid_erd_markdown/configuration.rb +11 -3
- data/lib/rails-mermaid_erd_markdown/generator.rb +169 -0
- data/lib/rails-mermaid_erd_markdown/markdown_document.rb +104 -0
- data/lib/rails-mermaid_erd_markdown/source_data.rb +63 -0
- data/lib/rails-mermaid_erd_markdown/version.rb +1 -1
- data/lib/rails-mermaid_erd_markdown.rb +3 -93
- data/rails-mermaid_erd_markdown.gemspec +6 -4
- data/test/example_output/mock_ERD.md +48 -0
- data/test/example_output/mock_ERD_index.md +10 -0
- data/test/example_output/mock_ERD_model.md +46 -0
- data/test/mock_data/models.rb +105 -0
- data/test/test_helper.rb +4 -2
- data/test/test_rails/rails-mermaid_erd_markdown/test_generator.rb +54 -0
- data/test/test_rails/rails-mermaid_erd_markdown/test_markdown_document.rb +76 -0
- data/test/test_rails/rails-mermaid_erd_markdown/test_source_data.rb +70 -0
- data/test/test_rails/test_rails-mermaid_erd_markdown.rb +0 -40
- metadata +23 -67
- data/test/dummy-rails/.dockerignore +0 -37
- data/test/dummy-rails/.ruby-version +0 -1
- data/test/dummy-rails/Rakefile +0 -6
- data/test/dummy-rails/app/assets/config/manifest.js +0 -4
- data/test/dummy-rails/app/assets/images/.keep +0 -0
- data/test/dummy-rails/app/assets/stylesheets/application.css +0 -15
- data/test/dummy-rails/app/channels/application_cable/channel.rb +0 -4
- data/test/dummy-rails/app/channels/application_cable/connection.rb +0 -4
- data/test/dummy-rails/app/controllers/application_controller.rb +0 -2
- data/test/dummy-rails/app/controllers/concerns/.keep +0 -0
- data/test/dummy-rails/app/helpers/application_helper.rb +0 -2
- data/test/dummy-rails/app/javascript/application.js +0 -3
- data/test/dummy-rails/app/javascript/controllers/application.js +0 -9
- data/test/dummy-rails/app/javascript/controllers/hello_controller.js +0 -7
- data/test/dummy-rails/app/javascript/controllers/index.js +0 -11
- data/test/dummy-rails/app/jobs/application_job.rb +0 -7
- data/test/dummy-rails/app/mailers/application_mailer.rb +0 -4
- data/test/dummy-rails/app/models/application_record.rb +0 -3
- data/test/dummy-rails/app/models/concerns/.keep +0 -0
- data/test/dummy-rails/app/views/layouts/application.html.erb +0 -16
- data/test/dummy-rails/app/views/layouts/mailer.html.erb +0 -13
- data/test/dummy-rails/app/views/layouts/mailer.text.erb +0 -1
- data/test/dummy-rails/bin/bundle +0 -114
- data/test/dummy-rails/bin/docker-entrypoint +0 -8
- data/test/dummy-rails/bin/importmap +0 -4
- data/test/dummy-rails/bin/rails +0 -4
- data/test/dummy-rails/bin/rake +0 -4
- data/test/dummy-rails/bin/setup +0 -33
- data/test/dummy-rails/config/application.rb +0 -27
- data/test/dummy-rails/config/boot.rb +0 -3
- data/test/dummy-rails/config/cable.yml +0 -10
- data/test/dummy-rails/config/credentials.yml.enc +0 -1
- data/test/dummy-rails/config/database.yml +0 -25
- data/test/dummy-rails/config/environment.rb +0 -5
- data/test/dummy-rails/config/environments/development.rb +0 -76
- data/test/dummy-rails/config/environments/production.rb +0 -97
- data/test/dummy-rails/config/environments/test.rb +0 -64
- data/test/dummy-rails/config/importmap.rb +0 -7
- data/test/dummy-rails/config/initializers/content_security_policy.rb +0 -25
- data/test/dummy-rails/config/initializers/filter_parameter_logging.rb +0 -8
- data/test/dummy-rails/config/initializers/inflections.rb +0 -16
- data/test/dummy-rails/config/initializers/permissions_policy.rb +0 -13
- data/test/dummy-rails/config/locales/en.yml +0 -31
- data/test/dummy-rails/config/puma.rb +0 -35
- data/test/dummy-rails/config/routes.rb +0 -10
- data/test/dummy-rails/config/storage.yml +0 -34
- data/test/dummy-rails/config.ru +0 -6
- data/test/dummy-rails/db/seeds.rb +0 -9
- data/test/dummy-rails/test/application_system_test_case.rb +0 -5
- data/test/dummy-rails/test/channels/application_cable/connection_test.rb +0 -13
- data/test/dummy-rails/test/controllers/.keep +0 -0
- data/test/dummy-rails/test/fixtures/files/.keep +0 -0
- data/test/dummy-rails/test/helpers/.keep +0 -0
- data/test/dummy-rails/test/integration/.keep +0 -0
- data/test/dummy-rails/test/mailers/.keep +0 -0
- data/test/dummy-rails/test/models/.keep +0 -0
- data/test/dummy-rails/test/system/.keep +0 -0
- data/test/dummy-rails/test/test_helper.rb +0 -15
- data/test/dummy-rails/vendor/.keep +0 -0
- data/test/dummy-rails/vendor/javascript/.keep +0 -0
- data/test/util/mock_ERD.md +0 -27
@@ -8,7 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["humzahkiani"]
|
9
9
|
spec.email = ["89326566+humzahkiani@users.noreply.github.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
11
|
+
spec.summary = "Extends the rails-mermaid_erd gem to generate mermaid ERDs in markdown " \
|
12
|
+
"for Ruby on Rails ActiveRecord Models"
|
12
13
|
spec.homepage = "https://github.com/humzahkiani/rails-mermaid_erd_markdown"
|
13
14
|
spec.license = "MIT"
|
14
15
|
spec.required_ruby_version = ">= 2.6.0"
|
@@ -16,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
16
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
18
|
spec.metadata["source_code_uri"] = "https://github.com/humzahkiani/rails-mermaid_erd_markdown"
|
18
19
|
spec.metadata["changelog_uri"] = "https://github.com/humzahkiani/rails-mermaid_erd_markdown/blob/main/CHANGELOG.md"
|
19
|
-
|
20
|
+
spec.metadata["github_repo"] = "ssh://github.com/humzahkiani/rails-mermaid_erd_markdown"
|
20
21
|
# Specify which files should be added to the gem when it is released.
|
21
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
23
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
@@ -26,10 +27,11 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
28
|
spec.require_paths = ["lib"]
|
28
29
|
|
29
|
-
#
|
30
|
+
# Runtime Dependencies
|
30
31
|
spec.add_dependency "rails", ">= 5.2"
|
31
|
-
spec.add_dependency "rails-mermaid_erd", "
|
32
|
+
spec.add_dependency "rails-mermaid_erd", ">= 0.4.2"
|
32
33
|
|
33
34
|
# For more information and examples about making a new gem, check out our
|
34
35
|
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
35
37
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
```mermaid
|
2
|
+
erDiagram
|
3
|
+
%% --------------------------------------------------------
|
4
|
+
%% Entity-Relationship Diagram
|
5
|
+
%% --------------------------------------------------------
|
6
|
+
|
7
|
+
%% table name: users
|
8
|
+
User{
|
9
|
+
integer id PK
|
10
|
+
string name
|
11
|
+
string email
|
12
|
+
datetime created_at
|
13
|
+
datetime updated_at
|
14
|
+
}
|
15
|
+
|
16
|
+
%% table name: profiles
|
17
|
+
Profile{
|
18
|
+
integer id PK
|
19
|
+
text bio
|
20
|
+
integer user_id FK
|
21
|
+
datetime created_at
|
22
|
+
datetime updated_at
|
23
|
+
}
|
24
|
+
|
25
|
+
%% table name: articles
|
26
|
+
Article{
|
27
|
+
integer id PK
|
28
|
+
string title
|
29
|
+
text content
|
30
|
+
integer user_id FK
|
31
|
+
datetime created_at
|
32
|
+
datetime updated_at
|
33
|
+
}
|
34
|
+
|
35
|
+
%% table name: comments
|
36
|
+
Comment{
|
37
|
+
integer id PK
|
38
|
+
string commenter
|
39
|
+
text body
|
40
|
+
integer article_id FK
|
41
|
+
datetime created_at
|
42
|
+
datetime updated_at
|
43
|
+
}
|
44
|
+
|
45
|
+
Article }o--|| User : "BT:user"
|
46
|
+
Profile }o--|| User : "BT:user"
|
47
|
+
Comment }o--|| Article : "BT:article"
|
48
|
+
```
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Entity Relationship Diagrams
|
2
|
+
|
3
|
+
Each model has its own ERD diagram. The diagram shows the selected model, plus 1 associated model(s) deep. Click on the model name to view the diagram.
|
4
|
+
|
5
|
+
## Models
|
6
|
+
|
7
|
+
- [User](../User.md)
|
8
|
+
- [Profile](../Profile.md)
|
9
|
+
- [Article](../Article.md)
|
10
|
+
- [Comment](../Comment.md)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# User Entity-Relationship Diagram
|
2
|
+
|
3
|
+
## Associated Models
|
4
|
+
|
5
|
+
- [Article](../app/models/ERD_Article.md)
|
6
|
+
- [Profile](../app/models/ERD_Profile.md)
|
7
|
+
|
8
|
+
## Entity-Relationship Diagram
|
9
|
+
|
10
|
+
```mermaid
|
11
|
+
erDiagram
|
12
|
+
%% --------------------------------------------------------
|
13
|
+
%% Entity-Relationship Diagram
|
14
|
+
%% --------------------------------------------------------
|
15
|
+
|
16
|
+
%% table name: users
|
17
|
+
User{
|
18
|
+
integer id PK
|
19
|
+
string name
|
20
|
+
string email
|
21
|
+
datetime created_at
|
22
|
+
datetime updated_at
|
23
|
+
}
|
24
|
+
|
25
|
+
%% table name: articles
|
26
|
+
Article{
|
27
|
+
integer id PK
|
28
|
+
string title
|
29
|
+
text content
|
30
|
+
integer user_id FK
|
31
|
+
datetime created_at
|
32
|
+
datetime updated_at
|
33
|
+
}
|
34
|
+
|
35
|
+
%% table name: profiles
|
36
|
+
Profile{
|
37
|
+
integer id PK
|
38
|
+
text bio
|
39
|
+
integer user_id FK
|
40
|
+
datetime created_at
|
41
|
+
datetime updated_at
|
42
|
+
}
|
43
|
+
|
44
|
+
Article }o--|| User : "BT:user"
|
45
|
+
Profile }o--|| User : "BT:user"
|
46
|
+
```
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module MockData
|
2
|
+
module Models
|
3
|
+
def user_model
|
4
|
+
{
|
5
|
+
TableName: "users", ModelName: "User", IsModelExist: true,
|
6
|
+
Columns: [
|
7
|
+
{ name: "id", type: :integer, key: "PK", comment: nil },
|
8
|
+
{ name: "name", type: :string, key: "", comment: nil },
|
9
|
+
{ name: "email", type: :string, key: "", comment: nil },
|
10
|
+
{ name: "created_at", type: :datetime, key: "", comment: nil },
|
11
|
+
{ name: "updated_at", type: :datetime, key: "", comment: nil }
|
12
|
+
]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def profile_model
|
17
|
+
{
|
18
|
+
TableName: "profiles", ModelName: "Profile", IsModelExist: true,
|
19
|
+
Columns: [
|
20
|
+
{ name: "id", type: :integer, key: "PK", comment: nil },
|
21
|
+
{ name: "bio", type: :text, key: "", comment: nil },
|
22
|
+
{ name: "user_id", type: :integer, key: "FK", comment: nil },
|
23
|
+
{ name: "created_at", type: :datetime, key: "", comment: nil },
|
24
|
+
{ name: "updated_at", type: :datetime, key: "", comment: nil }
|
25
|
+
]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def article_model
|
30
|
+
{
|
31
|
+
TableName: "articles", ModelName: "Article", IsModelExist: true,
|
32
|
+
Columns: [
|
33
|
+
{ name: "id", type: :integer, key: "PK", comment: nil },
|
34
|
+
{ name: "title", type: :string, key: "", comment: nil },
|
35
|
+
{ name: "content", type: :text, key: "", comment: nil },
|
36
|
+
{ name: "user_id", type: :integer, key: "FK", comment: nil },
|
37
|
+
{ name: "created_at", type: :datetime, key: "", comment: nil },
|
38
|
+
{ name: "updated_at", type: :datetime, key: "", comment: nil }
|
39
|
+
]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def comment_model
|
44
|
+
{
|
45
|
+
TableName: "comments", ModelName: "Comment", IsModelExist: true,
|
46
|
+
Columns: [
|
47
|
+
{ name: "id", type: :integer, key: "PK", comment: nil },
|
48
|
+
{ name: "commenter", type: :string, key: "", comment: nil },
|
49
|
+
{ name: "body", type: :text, key: "", comment: nil },
|
50
|
+
{ name: "article_id", type: :integer, key: "FK", comment: nil },
|
51
|
+
{ name: "created_at", type: :datetime, key: "", comment: nil },
|
52
|
+
{ name: "updated_at", type: :datetime, key: "", comment: nil }
|
53
|
+
]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def article_relation
|
58
|
+
{
|
59
|
+
LeftModelName: "Article",
|
60
|
+
LeftValue: "}o",
|
61
|
+
Line: "--",
|
62
|
+
RightModelName: "User",
|
63
|
+
RightValue: "||",
|
64
|
+
Comment: "BT:user"
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def profile_relation
|
69
|
+
{
|
70
|
+
LeftModelName: "Profile",
|
71
|
+
LeftValue: "}o",
|
72
|
+
Line: "--",
|
73
|
+
RightModelName: "User",
|
74
|
+
RightValue: "||",
|
75
|
+
Comment: "BT:user"
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def comment_relation
|
80
|
+
{
|
81
|
+
LeftModelName: "Comment",
|
82
|
+
LeftValue: "}o",
|
83
|
+
Line: "--",
|
84
|
+
RightModelName: "Article",
|
85
|
+
RightValue: "||",
|
86
|
+
Comment: "BT:article"
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def stubbed_model_data
|
91
|
+
{
|
92
|
+
Models: [
|
93
|
+
user_model,
|
94
|
+
profile_model,
|
95
|
+
article_model,
|
96
|
+
comment_model
|
97
|
+
], Relations: [
|
98
|
+
article_relation,
|
99
|
+
profile_relation,
|
100
|
+
comment_relation
|
101
|
+
]
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
4
|
require "rails-mermaid_erd_markdown"
|
5
5
|
require "rails-mermaid_erd_markdown/configuration"
|
6
|
+
require "rails-mermaid_erd_markdown/generator"
|
7
|
+
require "rails-mermaid_erd_markdown/markdown_document"
|
8
|
+
require "rails-mermaid_erd_markdown/source_data"
|
6
9
|
|
7
|
-
require "minitest/autorun"
|
8
|
-
require File.expand_path("./dummy-rails/config/environment", __dir__)
|
10
|
+
require "minitest/autorun"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../mock_data/models"
|
4
|
+
require "test_helper"
|
5
|
+
|
6
|
+
class MermaidErdMarkdown::GeneratorTest < Minitest::Test
|
7
|
+
include MockData::Models
|
8
|
+
|
9
|
+
def test_index_markdown
|
10
|
+
markdown_file_path = File.expand_path(
|
11
|
+
"../../example_output/mock_ERD_index.md", __dir__
|
12
|
+
)
|
13
|
+
mock_markdown = File.read(markdown_file_path)
|
14
|
+
|
15
|
+
files = {
|
16
|
+
"User" => "User.md",
|
17
|
+
"Profile" => "Profile.md",
|
18
|
+
"Article" => "Article.md",
|
19
|
+
"Comment" => "Comment.md"
|
20
|
+
}
|
21
|
+
|
22
|
+
result = MermaidErdMarkdown::Generator.new.index_markdown(files)
|
23
|
+
|
24
|
+
assert_equal mock_markdown, result
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_model_markdown
|
28
|
+
markdown_file_path = File.expand_path(
|
29
|
+
"../../example_output/mock_ERD_model.md", __dir__
|
30
|
+
)
|
31
|
+
mock_markdown = File.read(markdown_file_path)
|
32
|
+
|
33
|
+
source = {
|
34
|
+
Models: [user_model, article_model, profile_model],
|
35
|
+
Relations: [article_relation, profile_relation]
|
36
|
+
}
|
37
|
+
|
38
|
+
result = MermaidErdMarkdown::Generator.new.model_markdown(source)
|
39
|
+
|
40
|
+
assert_equal mock_markdown, result
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_mermaid_markdown
|
44
|
+
markdown_file_path =
|
45
|
+
File.expand_path("../../example_output/mock_ERD.md", __dir__)
|
46
|
+
mock_markdown = File.read(markdown_file_path)
|
47
|
+
|
48
|
+
result = MermaidErdMarkdown::Generator.new.mermaid_markdown(
|
49
|
+
stubbed_model_data
|
50
|
+
)
|
51
|
+
|
52
|
+
assert_equal mock_markdown, result
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class MermaidErdMarkdown::MarkdownDocumentTest < Minitest::Test
|
6
|
+
def test_generate
|
7
|
+
markdown = MermaidErdMarkdown::MarkdownDocument.create do
|
8
|
+
add(header("Header"))
|
9
|
+
add(subheader("Subheader"))
|
10
|
+
add(list_item("List item"))
|
11
|
+
add(link("Link", "https://example.com"))
|
12
|
+
add("")
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal <<~MARKDOWN, markdown
|
16
|
+
# Header
|
17
|
+
|
18
|
+
## Subheader
|
19
|
+
|
20
|
+
- List item
|
21
|
+
[Link](https://example.com)
|
22
|
+
MARKDOWN
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_erd
|
26
|
+
model = {
|
27
|
+
TableName: "table",
|
28
|
+
ModelName: "Table",
|
29
|
+
IsModelExist: true,
|
30
|
+
Columns: [{
|
31
|
+
name: "name",
|
32
|
+
type: "type",
|
33
|
+
key: "key",
|
34
|
+
comment: "comment"
|
35
|
+
}]
|
36
|
+
}
|
37
|
+
relation = {
|
38
|
+
LeftModelName: "left_model",
|
39
|
+
LeftValue: "left_value",
|
40
|
+
Line: "--",
|
41
|
+
RightValue: "right_value",
|
42
|
+
RightModelName: "right_model",
|
43
|
+
Comment: "comment"
|
44
|
+
}
|
45
|
+
|
46
|
+
markdown = MermaidErdMarkdown::MarkdownDocument.create do
|
47
|
+
erd do
|
48
|
+
add(
|
49
|
+
erd_table(model[:TableName], model[:ModelName]) do
|
50
|
+
erd_table_column(model[:Columns].first)
|
51
|
+
end
|
52
|
+
)
|
53
|
+
add(
|
54
|
+
erd_relation(relation)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
add("")
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_equal <<~MARKDOWN, markdown
|
61
|
+
```mermaid
|
62
|
+
erDiagram
|
63
|
+
%% --------------------------------------------------------
|
64
|
+
%% Entity-Relationship Diagram
|
65
|
+
%% --------------------------------------------------------
|
66
|
+
|
67
|
+
%% table name: table
|
68
|
+
Table{
|
69
|
+
type name key
|
70
|
+
}
|
71
|
+
|
72
|
+
left_model left_value--right_value right_model : "comment"
|
73
|
+
```
|
74
|
+
MARKDOWN
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../mock_data/models"
|
4
|
+
require "test_helper"
|
5
|
+
|
6
|
+
class MermaidErdMarkdown::SourceDataTest < Minitest::Test
|
7
|
+
include MockData::Models
|
8
|
+
|
9
|
+
def test_split_output
|
10
|
+
expected_user = {
|
11
|
+
Models: [user_model, article_model, profile_model],
|
12
|
+
Relations: [article_relation, profile_relation]
|
13
|
+
}
|
14
|
+
expected_profile = {
|
15
|
+
Models: [profile_model, user_model],
|
16
|
+
Relations: [profile_relation]
|
17
|
+
}
|
18
|
+
expected_article = {
|
19
|
+
Models: [article_model, user_model, comment_model],
|
20
|
+
Relations: [article_relation, comment_relation]
|
21
|
+
}
|
22
|
+
expected_comment = {
|
23
|
+
Models: [comment_model, article_model],
|
24
|
+
Relations: [comment_relation]
|
25
|
+
}
|
26
|
+
expected = [
|
27
|
+
expected_user,
|
28
|
+
expected_profile,
|
29
|
+
expected_article,
|
30
|
+
expected_comment
|
31
|
+
]
|
32
|
+
|
33
|
+
RailsMermaidErd::Builder.stub :model_data, stubbed_model_data do
|
34
|
+
result = MermaidErdMarkdown::SourceData.new.split_output
|
35
|
+
|
36
|
+
assert_equal expected, result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_split_output_with_depth
|
41
|
+
expected_user = {
|
42
|
+
Models: [user_model, article_model, profile_model, comment_model],
|
43
|
+
Relations: [article_relation, profile_relation, comment_relation]
|
44
|
+
}
|
45
|
+
expected_profile = {
|
46
|
+
Models: [profile_model, user_model, article_model],
|
47
|
+
Relations: [profile_relation, article_relation]
|
48
|
+
}
|
49
|
+
expected_article = {
|
50
|
+
Models: [article_model, user_model, comment_model, profile_model],
|
51
|
+
Relations: [article_relation, comment_relation, profile_relation]
|
52
|
+
}
|
53
|
+
expected_comment = {
|
54
|
+
Models: [comment_model, article_model, user_model],
|
55
|
+
Relations: [comment_relation, article_relation]
|
56
|
+
}
|
57
|
+
expected = [
|
58
|
+
expected_user,
|
59
|
+
expected_profile,
|
60
|
+
expected_article,
|
61
|
+
expected_comment
|
62
|
+
]
|
63
|
+
|
64
|
+
RailsMermaidErd::Builder.stub :model_data, stubbed_model_data do
|
65
|
+
result = MermaidErdMarkdown::SourceData.new.split_output(2)
|
66
|
+
|
67
|
+
assert_equal expected, result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,49 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "test_helper"
|
4
|
-
require "rails-mermaid_erd"
|
5
4
|
|
6
5
|
class MermaidErdMarkdownTest < Minitest::Test
|
7
6
|
def test_that_it_has_a_version_number
|
8
7
|
refute_nil MermaidErdMarkdown::VERSION
|
9
8
|
end
|
10
|
-
|
11
|
-
def setup
|
12
|
-
markdown_file_path = File.expand_path("../../test/util/mock_ERD.md", __dir__)
|
13
|
-
mock_erd = File.read(markdown_file_path)
|
14
|
-
@mock_erd = mock_erd
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_generate_mermaid_erd
|
18
|
-
stubbed_model_data = {
|
19
|
-
Models: [
|
20
|
-
{ TableName: "articles", ModelName: "Article", IsModelExist: true,
|
21
|
-
Columns: [
|
22
|
-
{ name: "id", type: :integer, key: "PK", comment: nil },
|
23
|
-
{ name: "title", type: :string, key: "", comment: nil },
|
24
|
-
{ name: "content", type: :text, key: "", comment: nil },
|
25
|
-
{ name: "created_at", type: :datetime, key: "", comment: nil },
|
26
|
-
{ name: "updated_at", type: :datetime, key: "", comment: nil }
|
27
|
-
] },
|
28
|
-
{ TableName: "comments", ModelName: "Comment", IsModelExist: true,
|
29
|
-
Columns: [
|
30
|
-
{ name: "id", type: :integer, key: "PK", comment: nil },
|
31
|
-
{ name: "commenter", type: :string, key: "", comment: nil },
|
32
|
-
{ name: "body", type: :text, key: "", comment: nil },
|
33
|
-
{ name: "article_id", type: :integer, key: "FK", comment: nil },
|
34
|
-
{ name: "created_at", type: :datetime, key: "", comment: nil },
|
35
|
-
{ name: "updated_at", type: :datetime, key: "", comment: nil }
|
36
|
-
] }
|
37
|
-
], Relations: [
|
38
|
-
{ LeftModelName: "Comment", LeftValue: "}o", Line: "--", RightModelName: "Article",
|
39
|
-
RightValue: "||", Comment: "BT:article" }
|
40
|
-
]
|
41
|
-
}
|
42
|
-
result = nil
|
43
|
-
|
44
|
-
RailsMermaidErd::Builder.stub :model_data, stubbed_model_data do
|
45
|
-
result = MermaidErdMarkdown.generate_mermaid_erd
|
46
|
-
end
|
47
|
-
assert_equal @mock_erd, result
|
48
|
-
end
|
49
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-mermaid_erd_markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- humzahkiani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: rails-mermaid_erd
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.4.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.4.2
|
41
41
|
description:
|
@@ -45,8 +45,12 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".github/CODEOWNERS.md"
|
49
|
+
- ".github/workflows/CI.yml"
|
50
|
+
- ".github/workflows/codeql.yml"
|
48
51
|
- ".gitignore"
|
49
52
|
- ".rubocop.yml"
|
53
|
+
- ".ruby-version"
|
50
54
|
- CHANGELOG.md
|
51
55
|
- CODE_OF_CONDUCT.md
|
52
56
|
- Gemfile
|
@@ -55,76 +59,26 @@ files:
|
|
55
59
|
- README.md
|
56
60
|
- Rakefile
|
57
61
|
- bin/console
|
62
|
+
- bin/rubocop
|
58
63
|
- bin/setup
|
59
64
|
- docs/examples/erd.yml
|
60
65
|
- lib/rails-mermaid_erd_markdown.rb
|
61
66
|
- lib/rails-mermaid_erd_markdown/configuration.rb
|
67
|
+
- lib/rails-mermaid_erd_markdown/generator.rb
|
68
|
+
- lib/rails-mermaid_erd_markdown/markdown_document.rb
|
69
|
+
- lib/rails-mermaid_erd_markdown/source_data.rb
|
62
70
|
- lib/rails-mermaid_erd_markdown/version.rb
|
63
71
|
- rails-mermaid_erd_markdown.gemspec
|
64
72
|
- sig/rails/mermaid_erd_markdown.rbs
|
65
|
-
- test/
|
66
|
-
- test/
|
67
|
-
- test/
|
68
|
-
- test/
|
69
|
-
- test/dummy-rails/app/assets/images/.keep
|
70
|
-
- test/dummy-rails/app/assets/stylesheets/application.css
|
71
|
-
- test/dummy-rails/app/channels/application_cable/channel.rb
|
72
|
-
- test/dummy-rails/app/channels/application_cable/connection.rb
|
73
|
-
- test/dummy-rails/app/controllers/application_controller.rb
|
74
|
-
- test/dummy-rails/app/controllers/concerns/.keep
|
75
|
-
- test/dummy-rails/app/helpers/application_helper.rb
|
76
|
-
- test/dummy-rails/app/javascript/application.js
|
77
|
-
- test/dummy-rails/app/javascript/controllers/application.js
|
78
|
-
- test/dummy-rails/app/javascript/controllers/hello_controller.js
|
79
|
-
- test/dummy-rails/app/javascript/controllers/index.js
|
80
|
-
- test/dummy-rails/app/jobs/application_job.rb
|
81
|
-
- test/dummy-rails/app/mailers/application_mailer.rb
|
82
|
-
- test/dummy-rails/app/models/application_record.rb
|
83
|
-
- test/dummy-rails/app/models/concerns/.keep
|
84
|
-
- test/dummy-rails/app/views/layouts/application.html.erb
|
85
|
-
- test/dummy-rails/app/views/layouts/mailer.html.erb
|
86
|
-
- test/dummy-rails/app/views/layouts/mailer.text.erb
|
87
|
-
- test/dummy-rails/bin/bundle
|
88
|
-
- test/dummy-rails/bin/docker-entrypoint
|
89
|
-
- test/dummy-rails/bin/importmap
|
90
|
-
- test/dummy-rails/bin/rails
|
91
|
-
- test/dummy-rails/bin/rake
|
92
|
-
- test/dummy-rails/bin/setup
|
93
|
-
- test/dummy-rails/config.ru
|
94
|
-
- test/dummy-rails/config/application.rb
|
95
|
-
- test/dummy-rails/config/boot.rb
|
96
|
-
- test/dummy-rails/config/cable.yml
|
97
|
-
- test/dummy-rails/config/credentials.yml.enc
|
98
|
-
- test/dummy-rails/config/database.yml
|
99
|
-
- test/dummy-rails/config/environment.rb
|
100
|
-
- test/dummy-rails/config/environments/development.rb
|
101
|
-
- test/dummy-rails/config/environments/production.rb
|
102
|
-
- test/dummy-rails/config/environments/test.rb
|
103
|
-
- test/dummy-rails/config/importmap.rb
|
104
|
-
- test/dummy-rails/config/initializers/content_security_policy.rb
|
105
|
-
- test/dummy-rails/config/initializers/filter_parameter_logging.rb
|
106
|
-
- test/dummy-rails/config/initializers/inflections.rb
|
107
|
-
- test/dummy-rails/config/initializers/permissions_policy.rb
|
108
|
-
- test/dummy-rails/config/locales/en.yml
|
109
|
-
- test/dummy-rails/config/puma.rb
|
110
|
-
- test/dummy-rails/config/routes.rb
|
111
|
-
- test/dummy-rails/config/storage.yml
|
112
|
-
- test/dummy-rails/db/seeds.rb
|
113
|
-
- test/dummy-rails/test/application_system_test_case.rb
|
114
|
-
- test/dummy-rails/test/channels/application_cable/connection_test.rb
|
115
|
-
- test/dummy-rails/test/controllers/.keep
|
116
|
-
- test/dummy-rails/test/fixtures/files/.keep
|
117
|
-
- test/dummy-rails/test/helpers/.keep
|
118
|
-
- test/dummy-rails/test/integration/.keep
|
119
|
-
- test/dummy-rails/test/mailers/.keep
|
120
|
-
- test/dummy-rails/test/models/.keep
|
121
|
-
- test/dummy-rails/test/system/.keep
|
122
|
-
- test/dummy-rails/test/test_helper.rb
|
123
|
-
- test/dummy-rails/vendor/.keep
|
124
|
-
- test/dummy-rails/vendor/javascript/.keep
|
73
|
+
- test/example_output/mock_ERD.md
|
74
|
+
- test/example_output/mock_ERD_index.md
|
75
|
+
- test/example_output/mock_ERD_model.md
|
76
|
+
- test/mock_data/models.rb
|
125
77
|
- test/test_helper.rb
|
78
|
+
- test/test_rails/rails-mermaid_erd_markdown/test_generator.rb
|
79
|
+
- test/test_rails/rails-mermaid_erd_markdown/test_markdown_document.rb
|
80
|
+
- test/test_rails/rails-mermaid_erd_markdown/test_source_data.rb
|
126
81
|
- test/test_rails/test_rails-mermaid_erd_markdown.rb
|
127
|
-
- test/util/mock_ERD.md
|
128
82
|
homepage: https://github.com/humzahkiani/rails-mermaid_erd_markdown
|
129
83
|
licenses:
|
130
84
|
- MIT
|
@@ -132,6 +86,8 @@ metadata:
|
|
132
86
|
homepage_uri: https://github.com/humzahkiani/rails-mermaid_erd_markdown
|
133
87
|
source_code_uri: https://github.com/humzahkiani/rails-mermaid_erd_markdown
|
134
88
|
changelog_uri: https://github.com/humzahkiani/rails-mermaid_erd_markdown/blob/main/CHANGELOG.md
|
89
|
+
github_repo: ssh://github.com/humzahkiani/rails-mermaid_erd_markdown
|
90
|
+
rubygems_mfa_required: 'true'
|
135
91
|
post_install_message:
|
136
92
|
rdoc_options: []
|
137
93
|
require_paths:
|
@@ -150,6 +106,6 @@ requirements: []
|
|
150
106
|
rubygems_version: 3.3.3
|
151
107
|
signing_key:
|
152
108
|
specification_version: 4
|
153
|
-
summary:
|
154
|
-
|
109
|
+
summary: Extends the rails-mermaid_erd gem to generate mermaid ERDs in markdown for
|
110
|
+
Ruby on Rails ActiveRecord Models
|
155
111
|
test_files: []
|