rails-code-generator 0.1.1 → 0.1.2
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/lib/generators/rails_code_generator/resources/templates/bulk/create_spec.rb.tt +1 -1
- data/lib/generators/rails_code_generator/resources/templates/bulk/update_spec.rb.tt +1 -2
- data/lib/generators/rails_code_generator/resources/templates/shared/normalizer.rb.tt +1 -1
- data/lib/generators/rails_code_generator/resources/templates/single/create_spec.rb.tt +1 -1
- data/lib/generators/rails_code_generator/resources/templates/single/update_spec.rb.tt +1 -2
- data/lib/rails/code/generator/model_attributes.rb +35 -2
- data/lib/rails/code/generator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e0a15856855079249ca288614458381ad6f14bf2a82da4a993fbf77a0581562
|
|
4
|
+
data.tar.gz: 5d2c2227de1cc9a03d4eb5de84a378f0dd4579433dde1cb78186481af6bcc807
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f05b2b9aad986e3762bd1bdd5b10ff1189ca9dbb0677703f3c8aa24bdd5d788ad03a721a54bb420b9d8a8b580888f768f6ff8562789f0b40b49851f2ca4fbd1
|
|
7
|
+
data.tar.gz: 62c9137dc2f4b00eaea6b56fa6d04feba68b7e153aa7f845b096e562d6c2d175bc167f9077d14fc0859e74f2caf24381bbe02188e8f51e66e2c92bdd814d85b5
|
|
@@ -11,7 +11,7 @@ RSpec.describe "[PATCH] /<%= route_path %>/:id", type: :request do
|
|
|
11
11
|
Given(:params) {
|
|
12
12
|
{
|
|
13
13
|
<%= table_name %>: {
|
|
14
|
-
|
|
14
|
+
<%= request_params_attributes_list %>
|
|
15
15
|
},
|
|
16
16
|
}.to_json
|
|
17
17
|
}
|
|
@@ -21,6 +21,5 @@ RSpec.describe "[PATCH] /<%= route_path %>/:id", type: :request do
|
|
|
21
21
|
Then { expect(response).to be_successful }
|
|
22
22
|
And { expect(response_body[:data]).not_to be_empty }
|
|
23
23
|
And { expect(response_body[:errors]).to be_empty }
|
|
24
|
-
And { expect(response_body.dig(:data, :name)).to eq "Changed <%= singular_name %> name" }
|
|
25
24
|
end
|
|
26
25
|
end
|
|
@@ -11,7 +11,7 @@ RSpec.describe "[PATCH] /<%= route_path %>/:id", type: :request do
|
|
|
11
11
|
Given(:params) {
|
|
12
12
|
{
|
|
13
13
|
<%= singular_name %>: {
|
|
14
|
-
|
|
14
|
+
<%= request_params_attributes_list %>
|
|
15
15
|
},
|
|
16
16
|
}.to_json
|
|
17
17
|
}
|
|
@@ -21,6 +21,5 @@ RSpec.describe "[PATCH] /<%= route_path %>/:id", type: :request do
|
|
|
21
21
|
Then { expect(response).to be_successful }
|
|
22
22
|
And { expect(response_body[:data]).not_to be_empty }
|
|
23
23
|
And { expect(response_body[:errors]).to be_empty }
|
|
24
|
-
And { expect(response_body.dig(:data, :name)).to eq "Changed <%= singular_name %> name" }
|
|
25
24
|
end
|
|
26
25
|
end
|
|
@@ -24,6 +24,24 @@ module Rails
|
|
|
24
24
|
"uuid" => :string,
|
|
25
25
|
}.freeze
|
|
26
26
|
|
|
27
|
+
FAKER_EXPRESSION_MAP = {
|
|
28
|
+
"string" => "Faker::Lorem.word",
|
|
29
|
+
"text" => "Faker::Lorem.paragraph",
|
|
30
|
+
"citext" => "Faker::Lorem.word",
|
|
31
|
+
"integer" => "Faker::Number.number(digits: 5)",
|
|
32
|
+
"bigint" => "Faker::Number.number(digits: 5)",
|
|
33
|
+
"float" => "Faker::Number.decimal(l_digits: 2).to_f",
|
|
34
|
+
"decimal" => "Faker::Number.decimal(l_digits: 2)",
|
|
35
|
+
"boolean" => "Faker::Boolean.boolean",
|
|
36
|
+
"date" => "Faker::Date.forward(days: 30)",
|
|
37
|
+
"datetime" => "Faker::Time.forward(days: 30)",
|
|
38
|
+
"timestamp" => "Faker::Time.forward(days: 30)",
|
|
39
|
+
"timestamptz" => "Faker::Time.forward(days: 30)",
|
|
40
|
+
"json" => "{}",
|
|
41
|
+
"jsonb" => "{}",
|
|
42
|
+
"uuid" => "Faker::Internet.uuid",
|
|
43
|
+
}.freeze
|
|
44
|
+
|
|
27
45
|
def model_attributes
|
|
28
46
|
@model_attributes ||= fetch_model_attributes
|
|
29
47
|
end
|
|
@@ -34,8 +52,9 @@ module Rails
|
|
|
34
52
|
format_symbol_list(names)
|
|
35
53
|
end
|
|
36
54
|
|
|
37
|
-
def normalizer_attributes_list
|
|
55
|
+
def normalizer_attributes_list(include_id: false)
|
|
38
56
|
names = model_attribute_names
|
|
57
|
+
names = [:id, *names] if include_id
|
|
39
58
|
return " # TODO: add attributes" if names.empty?
|
|
40
59
|
|
|
41
60
|
format_symbol_list(names, indent: 4)
|
|
@@ -47,6 +66,13 @@ module Rails
|
|
|
47
66
|
model_attributes.map { |attribute| validator_line_for(attribute) }.join("\n")
|
|
48
67
|
end
|
|
49
68
|
|
|
69
|
+
def request_params_attributes_list(indent: 10)
|
|
70
|
+
padding = " " * indent
|
|
71
|
+
return "#{padding}# TODO: add attributes" if model_attributes.empty?
|
|
72
|
+
|
|
73
|
+
model_attributes.map { |attribute| "#{padding}#{attribute[:name]}: #{faker_expression_for(attribute)}," }.join("\n")
|
|
74
|
+
end
|
|
75
|
+
|
|
50
76
|
private
|
|
51
77
|
|
|
52
78
|
def model_attribute_names
|
|
@@ -69,6 +95,10 @@ module Rails
|
|
|
69
95
|
end
|
|
70
96
|
end
|
|
71
97
|
|
|
98
|
+
def faker_expression_for(attribute)
|
|
99
|
+
FAKER_EXPRESSION_MAP.fetch(attribute[:type], "Faker::Lorem.word")
|
|
100
|
+
end
|
|
101
|
+
|
|
72
102
|
def fetch_model_attributes
|
|
73
103
|
klass = class_name.constantize
|
|
74
104
|
return [] unless klass.respond_to?(:columns)
|
|
@@ -76,9 +106,12 @@ module Rails
|
|
|
76
106
|
klass.columns.filter_map do |column|
|
|
77
107
|
next if EXCLUDED_COLUMNS.include?(column.name)
|
|
78
108
|
|
|
109
|
+
type = column.type.to_s
|
|
110
|
+
|
|
79
111
|
{
|
|
80
112
|
name: column.name,
|
|
81
|
-
|
|
113
|
+
type: type,
|
|
114
|
+
dry_type: DRY_TYPE_MAP[type],
|
|
82
115
|
}
|
|
83
116
|
end
|
|
84
117
|
rescue StandardError
|