souls 0.23.5 → 0.23.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -138
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -2
- data/exe/souls +68 -68
- data/lib/souls.rb +153 -141
- data/lib/souls/gcloud/compute.rb +61 -51
- data/lib/souls/gcloud/iam.rb +22 -24
- data/lib/souls/generate/application.rb +160 -160
- data/lib/souls/generate/connection.rb +13 -15
- data/lib/souls/generate/edge.rb +13 -15
- data/lib/souls/generate/model.rb +16 -17
- data/lib/souls/generate/mutation.rb +225 -221
- data/lib/souls/generate/policy.rb +44 -45
- data/lib/souls/generate/query.rb +49 -49
- data/lib/souls/generate/resolver.rb +121 -124
- data/lib/souls/generate/rspec_factory.rb +49 -52
- data/lib/souls/generate/rspec_model.rb +17 -18
- data/lib/souls/generate/rspec_mutation.rb +193 -199
- data/lib/souls/generate/rspec_policy.rb +38 -39
- data/lib/souls/generate/rspec_query.rb +133 -140
- data/lib/souls/generate/rspec_resolver.rb +147 -154
- data/lib/souls/generate/type.rb +34 -25
- data/lib/souls/init.rb +51 -50
- data/lib/souls/version.rb +2 -1
- data/souls.gemspec +12 -7
- metadata +5 -5
@@ -1,46 +1,45 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
3
|
+
## Generate Rspec Policy
|
4
|
+
def self.rspec_policy(class_name: "souls")
|
5
|
+
dir_name = "./spec/policies"
|
6
|
+
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
7
|
+
file_path = "./spec/policies/#{class_name}_policy_spec.rb"
|
8
|
+
return "RspecPolicy already exist! #{file_path}" if File.exist?(file_path)
|
9
|
+
|
10
|
+
File.open(file_path, "w") do |new_line|
|
11
|
+
new_line.write(<<~TEXT)
|
12
|
+
describe #{class_name.camelize}Policy do
|
13
|
+
subject { described_class.new(user, #{class_name.underscore}) }
|
14
|
+
|
15
|
+
let(:#{class_name.underscore}) { FactoryBot.create(:#{class_name.underscore}) }
|
16
|
+
|
17
|
+
context "being a visitor" do
|
18
|
+
let(:user) { FactoryBot.create(:user, user_role: :normal) }
|
19
|
+
|
20
|
+
it { is_expected.to permit_action(:index) }
|
21
|
+
it { is_expected.to permit_action(:show) }
|
22
|
+
it { is_expected.to forbid_actions([:create, :update, :delete]) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "being a user" do
|
26
|
+
let(:user) { FactoryBot.create(:user, user_role: :user) }
|
27
|
+
|
28
|
+
it { is_expected.to permit_actions([:create, :update]) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "being an admin" do
|
32
|
+
let(:user) { FactoryBot.create(:user, user_role: :admin) }
|
33
|
+
|
34
|
+
it { is_expected.to permit_actions([:create, :update, :delete]) }
|
36
35
|
end
|
37
|
-
|
38
|
-
|
39
|
-
puts Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }]
|
40
|
-
file_path
|
41
|
-
rescue StandardError => e
|
42
|
-
raise StandardError, e
|
36
|
+
end
|
37
|
+
TEXT
|
43
38
|
end
|
39
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
40
|
+
file_path
|
41
|
+
rescue StandardError => e
|
42
|
+
raise(StandardError, e)
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
@@ -1,174 +1,167 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
EOS
|
12
|
-
end
|
3
|
+
## Generate Rspec Query
|
4
|
+
def self.rspec_query_head(class_name: "souls")
|
5
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
6
|
+
File.open(file_path, "w") do |f|
|
7
|
+
f.write(<<~TEXT)
|
8
|
+
RSpec.describe \"#{class_name.camelize} Query テスト\" do
|
9
|
+
describe "#{class_name.camelize} データを取得する" do
|
10
|
+
TEXT
|
13
11
|
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
new_line.write
|
28
|
-
|
14
|
+
def self.rspec_query_after_head(class_name: "souls")
|
15
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
16
|
+
path = "./db/schema.rb"
|
17
|
+
@on = false
|
18
|
+
@user_exist = false
|
19
|
+
@relation_params = []
|
20
|
+
File.open(file_path, "a") do |new_line|
|
21
|
+
File.open(path, "r") do |f|
|
22
|
+
f.each_line.with_index do |line, _i|
|
23
|
+
if @on
|
24
|
+
if line.include?("end") || line.include?("t.index")
|
25
|
+
if @relation_params.empty?
|
26
|
+
new_line.write(<<-TEXT)
|
27
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
new_line.write
|
38
|
-
|
29
|
+
let(:query) do
|
30
|
+
data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
|
31
|
+
%(query {
|
32
|
+
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
33
|
+
id
|
34
|
+
TEXT
|
35
|
+
else
|
36
|
+
new_line.write(<<-TEXT)
|
37
|
+
let(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(', ')}) }
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
break
|
48
|
-
end
|
49
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
50
|
-
case name
|
51
|
-
when /$*_id\z/
|
52
|
-
relation_col = name.gsub("_id", "")
|
53
|
-
@relation_params << "#{name}: #{relation_col}.id"
|
54
|
-
new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
|
39
|
+
let(:query) do
|
40
|
+
data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
|
41
|
+
%(query {
|
42
|
+
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
43
|
+
id
|
44
|
+
TEXT
|
55
45
|
end
|
46
|
+
break
|
56
47
|
end
|
57
|
-
|
58
|
-
|
48
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
49
|
+
case name
|
50
|
+
when /$*_id\z/
|
51
|
+
relation_col = name.gsub("_id", "")
|
52
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
53
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
59
54
|
end
|
60
55
|
end
|
56
|
+
@on = true if table_check(line: line, class_name: class_name)
|
61
57
|
end
|
62
58
|
end
|
63
59
|
end
|
64
|
-
|
65
|
-
def rspec_query_params class_name: "souls"
|
66
|
-
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
67
|
-
path = "./db/schema.rb"
|
68
|
-
@on = false
|
69
|
-
File.open(file_path, "a") do |new_line|
|
70
|
-
File.open(path, "r") do |f|
|
71
|
-
f.each_line.with_index do |line, i|
|
72
|
-
if @on
|
73
|
-
if line.include?("end") || line.include?("t.index")
|
74
|
-
new_line.write <<-EOS
|
75
|
-
}
|
76
|
-
}
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
subject(:result) do
|
81
|
-
SoulsApiSchema.execute(query).as_json
|
82
|
-
end
|
83
|
-
|
84
|
-
it "return #{class_name.camelize} Data" do
|
85
|
-
begin
|
86
|
-
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}")
|
87
|
-
raise unless a1.present?
|
88
|
-
rescue
|
89
|
-
raise StandardError, result
|
90
60
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
61
|
+
|
62
|
+
def self.rspec_query_params(class_name: "souls")
|
63
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
64
|
+
path = "./db/schema.rb"
|
65
|
+
@on = false
|
66
|
+
File.open(file_path, "a") do |new_line|
|
67
|
+
File.open(path, "r") do |f|
|
68
|
+
f.each_line.with_index do |line, _i|
|
69
|
+
if @on
|
70
|
+
if line.include?("end") || line.include?("t.index")
|
71
|
+
new_line.write(<<~TEXT)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
)
|
75
|
+
end
|
76
|
+
#{' '}
|
77
|
+
subject(:result) do
|
78
|
+
SoulsApiSchema.execute(query).as_json
|
79
|
+
end
|
80
|
+
#{' '}
|
81
|
+
it "return #{class_name.camelize} Data" do
|
82
|
+
begin
|
83
|
+
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}")
|
84
|
+
raise unless a1.present?
|
85
|
+
rescue
|
86
|
+
raise StandardError, result
|
87
|
+
end
|
88
|
+
expect(a1).to include(
|
89
|
+
"id" => be_a(String),
|
90
|
+
TEXT
|
91
|
+
break
|
103
92
|
end
|
104
|
-
|
105
|
-
|
93
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
94
|
+
case name
|
95
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
96
|
+
next
|
97
|
+
else
|
98
|
+
new_line.write(" #{name.camelize(:lower)}\n")
|
106
99
|
end
|
107
100
|
end
|
101
|
+
@on = true if table_check(line: line, class_name: class_name)
|
108
102
|
end
|
109
103
|
end
|
110
104
|
end
|
105
|
+
end
|
111
106
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
107
|
+
def self.rspec_query_end(class_name: "souls")
|
108
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
109
|
+
path = "./db/schema.rb"
|
110
|
+
@on = false
|
111
|
+
File.open(file_path, "a") do |new_line|
|
112
|
+
File.open(path, "r") do |f|
|
113
|
+
f.each_line.with_index do |line, _i|
|
114
|
+
if @on
|
115
|
+
if line.include?("end") || line.include?("t.index")
|
116
|
+
new_line.write(<<~TEXT)
|
117
|
+
)
|
124
118
|
end
|
125
119
|
end
|
126
|
-
EOS
|
127
|
-
break
|
128
|
-
end
|
129
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
130
|
-
field ||= type_check type
|
131
|
-
array_true = line.include?("array: true")
|
132
|
-
case name
|
133
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
134
|
-
next
|
135
|
-
else
|
136
|
-
case type
|
137
|
-
when "text", "date", "datetime"
|
138
|
-
if array_true
|
139
|
-
new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
|
140
|
-
else
|
141
|
-
new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
|
142
|
-
end
|
143
|
-
when "boolean"
|
144
|
-
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
|
145
|
-
when "string", "bigint", "integer", "float"
|
146
|
-
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
147
120
|
end
|
148
|
-
|
121
|
+
TEXT
|
122
|
+
break
|
149
123
|
end
|
150
|
-
|
151
|
-
|
124
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
125
|
+
field ||= type_check(type)
|
126
|
+
array_true = line.include?("array: true")
|
127
|
+
case name
|
128
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
129
|
+
next
|
130
|
+
else
|
131
|
+
case type
|
132
|
+
when "text", "date", "datetime"
|
133
|
+
if array_true
|
134
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
135
|
+
else
|
136
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
137
|
+
end
|
138
|
+
when "boolean"
|
139
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
140
|
+
when "string", "bigint", "integer", "float"
|
141
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
142
|
+
end
|
152
143
|
end
|
153
144
|
end
|
145
|
+
@on = true if table_check(line: line, class_name: class_name)
|
154
146
|
end
|
155
147
|
end
|
156
|
-
file_path
|
157
148
|
end
|
149
|
+
file_path
|
150
|
+
end
|
158
151
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
152
|
+
def self.rspec_query(class_name: "souls")
|
153
|
+
singularized_class_name = class_name.singularize
|
154
|
+
file_path = "./spec/queries/#{singularized_class_name}_spec.rb"
|
155
|
+
return "RspecQuery already exist! #{file_path}" if File.exist?(file_path)
|
156
|
+
|
157
|
+
rspec_query_head(class_name: singularized_class_name)
|
158
|
+
rspec_query_after_head(class_name: singularized_class_name)
|
159
|
+
rspec_query_params(class_name: singularized_class_name)
|
160
|
+
rspec_query_end(class_name: singularized_class_name)
|
161
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
162
|
+
file_path
|
163
|
+
rescue StandardError => e
|
164
|
+
raise(StandardError, e)
|
172
165
|
end
|
173
166
|
end
|
174
167
|
end
|
@@ -1,193 +1,186 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
EOS
|
12
|
-
end
|
3
|
+
## Generate Rspec Resolver
|
4
|
+
def self.rspec_resolver_head(class_name: "souls")
|
5
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
6
|
+
File.open(file_path, "w") do |f|
|
7
|
+
f.write(<<~TEXT)
|
8
|
+
RSpec.describe \"#{class_name.camelize}Search Resolver テスト\" do
|
9
|
+
describe "削除フラグ false の #{class_name.camelize} を返却する" do
|
10
|
+
TEXT
|
13
11
|
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
def self.rspec_resolver_after_head(class_name: "souls")
|
15
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
16
|
+
path = "./db/schema.rb"
|
17
|
+
@on = false
|
18
|
+
@user_exist = false
|
19
|
+
@relation_params = []
|
20
|
+
File.open(file_path, "a") do |new_line|
|
21
|
+
File.open(path, "r") do |f|
|
22
|
+
f.each_line.with_index do |line, _i|
|
23
|
+
if @on
|
24
|
+
if line.include?("end") || line.include?("t.index")
|
25
|
+
if @relation_params.empty?
|
26
|
+
new_line.write(<<-TEXT)
|
27
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
let(:query) do
|
30
|
+
%(query {
|
31
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
32
|
+
isDeleted: false
|
33
|
+
}) {
|
34
|
+
edges {
|
35
|
+
cursor
|
36
|
+
node {
|
37
|
+
id
|
38
|
+
TEXT
|
39
|
+
else
|
40
|
+
new_line.write(<<-TEXT)
|
41
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(', ')}) }
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
break
|
56
|
-
end
|
57
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
58
|
-
case name
|
59
|
-
when /$*_id\z/
|
60
|
-
relation_col = name.gsub("_id", "")
|
61
|
-
@relation_params << "#{name}: #{relation_col}.id"
|
62
|
-
new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
|
43
|
+
let(:query) do
|
44
|
+
%(query {
|
45
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
46
|
+
isDeleted: false
|
47
|
+
}) {
|
48
|
+
edges {
|
49
|
+
cursor
|
50
|
+
node {
|
51
|
+
id
|
52
|
+
TEXT
|
63
53
|
end
|
54
|
+
break
|
64
55
|
end
|
65
|
-
|
66
|
-
|
56
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
57
|
+
case name
|
58
|
+
when /$*_id\z/
|
59
|
+
relation_col = name.gsub("_id", "")
|
60
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
61
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
67
62
|
end
|
68
63
|
end
|
64
|
+
@on = true if table_check(line: line, class_name: class_name)
|
69
65
|
end
|
70
66
|
end
|
71
67
|
end
|
68
|
+
end
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
}
|
85
|
-
nodes {
|
86
|
-
id
|
87
|
-
}
|
88
|
-
pageInfo {
|
89
|
-
endCursor
|
90
|
-
hasNextPage
|
91
|
-
startCursor
|
92
|
-
hasPreviousPage
|
70
|
+
def self.rspec_resolver_params(class_name: "souls")
|
71
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
72
|
+
path = "./db/schema.rb"
|
73
|
+
@on = false
|
74
|
+
File.open(file_path, "a") do |new_line|
|
75
|
+
File.open(path, "r") do |f|
|
76
|
+
f.each_line.with_index do |line, _i|
|
77
|
+
if @on
|
78
|
+
if line.include?("end") || line.include?("t.index")
|
79
|
+
new_line.write(<<-TEXT)
|
93
80
|
}
|
94
81
|
}
|
82
|
+
nodes {
|
83
|
+
id
|
84
|
+
}
|
85
|
+
pageInfo {
|
86
|
+
endCursor
|
87
|
+
hasNextPage
|
88
|
+
startCursor
|
89
|
+
hasPreviousPage
|
90
|
+
}
|
95
91
|
}
|
96
|
-
|
97
|
-
|
92
|
+
}
|
93
|
+
)
|
94
|
+
end
|
98
95
|
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
subject(:result) do
|
97
|
+
SoulsApiSchema.execute(query).as_json
|
98
|
+
end
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
116
|
-
case name
|
117
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
118
|
-
next
|
119
|
-
else
|
120
|
-
new_line.write " #{name.camelize(:lower)}\n"
|
121
|
-
end
|
100
|
+
it "return #{class_name.camelize} Data" do
|
101
|
+
begin
|
102
|
+
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}Search", "edges")[0]["node"]
|
103
|
+
raise unless a1.present?
|
104
|
+
rescue
|
105
|
+
raise StandardError, result
|
106
|
+
end
|
107
|
+
expect(a1).to include(
|
108
|
+
"id" => be_a(String),
|
109
|
+
TEXT
|
110
|
+
break
|
122
111
|
end
|
123
|
-
|
124
|
-
|
112
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
113
|
+
case name
|
114
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
115
|
+
next
|
116
|
+
else
|
117
|
+
new_line.write(" #{name.camelize(:lower)}\n")
|
125
118
|
end
|
126
119
|
end
|
120
|
+
@on = true if table_check(line: line, class_name: class_name)
|
127
121
|
end
|
128
122
|
end
|
129
123
|
end
|
124
|
+
end
|
130
125
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
126
|
+
def self.rspec_resolver_end(class_name: "souls")
|
127
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
128
|
+
path = "./db/schema.rb"
|
129
|
+
@on = false
|
130
|
+
File.open(file_path, "a") do |new_line|
|
131
|
+
File.open(path, "r") do |f|
|
132
|
+
f.each_line.with_index do |line, _i|
|
133
|
+
if @on
|
134
|
+
if line.include?("end") || line.include?("t.index")
|
135
|
+
new_line.write(<<~TEXT)
|
136
|
+
)
|
143
137
|
end
|
144
138
|
end
|
145
|
-
EOS
|
146
|
-
break
|
147
|
-
end
|
148
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
149
|
-
field ||= type_check type
|
150
|
-
array_true = line.include?("array: true")
|
151
|
-
case name
|
152
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
153
|
-
next
|
154
|
-
else
|
155
|
-
case type
|
156
|
-
when "text", "date", "datetime"
|
157
|
-
if array_true
|
158
|
-
new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
|
159
|
-
else
|
160
|
-
new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
|
161
|
-
end
|
162
|
-
when "boolean"
|
163
|
-
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
|
164
|
-
when "string", "bigint", "integer", "float"
|
165
|
-
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
166
139
|
end
|
167
|
-
|
140
|
+
TEXT
|
141
|
+
break
|
168
142
|
end
|
169
|
-
|
170
|
-
|
143
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
144
|
+
field ||= type_check(type)
|
145
|
+
array_true = line.include?("array: true")
|
146
|
+
case name
|
147
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
148
|
+
next
|
149
|
+
else
|
150
|
+
case type
|
151
|
+
when "text", "date", "datetime"
|
152
|
+
if array_true
|
153
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
154
|
+
else
|
155
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
156
|
+
end
|
157
|
+
when "boolean"
|
158
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
159
|
+
when "string", "bigint", "integer", "float"
|
160
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
161
|
+
end
|
171
162
|
end
|
172
163
|
end
|
164
|
+
@on = true if table_check(line: line, class_name: class_name)
|
173
165
|
end
|
174
166
|
end
|
175
|
-
file_path
|
176
167
|
end
|
168
|
+
file_path
|
169
|
+
end
|
177
170
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
171
|
+
def self.rspec_resolver(class_name: "souls")
|
172
|
+
singularized_class_name = class_name.singularize
|
173
|
+
file_path = "#{Dir.pwd}/spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
174
|
+
return "Resolver already exist! #{file_path}" if File.exist?(file_path)
|
175
|
+
|
176
|
+
rspec_resolver_head(class_name: singularized_class_name)
|
177
|
+
rspec_resolver_after_head(class_name: singularized_class_name)
|
178
|
+
rspec_resolver_params(class_name: singularized_class_name)
|
179
|
+
rspec_resolver_end(class_name: singularized_class_name)
|
180
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
181
|
+
file_path
|
182
|
+
rescue StandardError => e
|
183
|
+
raise(StandardError, e)
|
191
184
|
end
|
192
185
|
end
|
193
186
|
end
|