souls 1.6.14 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1f5b7503da79dbf25731a98add082f609581378356a3dc5e8b694120604d80f
4
- data.tar.gz: 0a7acf59572db99719fd487cd825f06a2ea63102f7ca724c156b51ead6bd63d1
3
+ metadata.gz: 604dd7ee9586360aff67c1dc45aabcf0e9d66038d280aae8abb829af7856932a
4
+ data.tar.gz: 6d405c4bfa0def7d24e10290cf1e412f860849b142eb9515892f84c26ae22dd5
5
5
  SHA512:
6
- metadata.gz: 74fffc83bf9b0c26d4344d456e7bab11682e4677aa039986ba1946ee40a79e453909578665a238a8fcd55706172e812d250e9c4388b13956ec8a6deb32299d68
7
- data.tar.gz: e9b1c341bff09b76cf18c7d3f39a1aa36a00c26cc027600768d975de7d276422d5c3265a1a8bd9aeeb222fc7623336b37b8f518f2061799ce3b9014f1251d8de
6
+ metadata.gz: 3f6f0b54ce0703d05cc654cb91907ad9ac9e74a2380de623d3b3db38982784faf45652b96f77866778a312af94443fc427f85452a4b2392cae146efa69475126
7
+ data.tar.gz: 0fdba239a2f5f94e4990013207aa55c246f4dcf2457d03305e6f7f22ebe1f258cd2a142508391cf1365c6db42c0e80a7b052c0ba47b15595b22102e23b58bf1b
@@ -3,6 +3,8 @@ module Souls
3
3
  desc "setup_vpc_nat", "Set Up VPC Cloud Nat"
4
4
  method_option :range, default: "10.124.0.0/28", aliases: "--range", desc: "GCP VPC Network IP Range"
5
5
  def setup_vpc_nat
6
+ puts(Paint["Initializing NAT Setup This process might take about 10 min...", :yellow])
7
+ Souls::Gcloud.new.config_set
6
8
  create_network
7
9
  create_firewall_tcp(range: options[:range])
8
10
  create_firewall_ssh
@@ -11,13 +13,43 @@ module Souls
11
13
  create_router
12
14
  create_external_ip
13
15
  create_nat
14
- nat_credit
16
+ Souls::Sql.new.invoke(:setup_private_ip)
17
+ update_workflows
18
+ update_env
19
+ puts(Paint["Cloud NAT is All Set!\n", :white])
20
+ puts(
21
+ Paint % [
22
+ "Your Worker's External IP: %{white_text}",
23
+ :green,
24
+ { white_text: [get_external_ip.to_s, :white] }
25
+ ]
26
+ )
27
+ puts(Paint["\nYou can add this IP to third party white list", :white])
28
+ puts(Paint["\nPlease git push to update your github workflow now!", :yellow])
29
+ true
15
30
  rescue Thor::Error => e
16
31
  raise(Thor::Error, e)
17
32
  end
18
33
 
19
34
  private
20
35
 
36
+ def update_env
37
+ instance_name = Souls.configuration.instance_name
38
+ private_instance_ip = `gcloud sql instances list | grep #{instance_name} | awk '{print $6}'`.strip
39
+ Dir.chdir(Souls.get_mother_path.to_s) do
40
+ file_path = ".env.production"
41
+ env_production = File.readlines(file_path)
42
+ env_production[0] = "SOULS_DB_HOST=#{private_instance_ip}\n"
43
+ File.open(file_path, "w") { |f| f.write(env_production.join) }
44
+ end
45
+ system("gh secret set DB_HOST -b #{private_instance_ip}")
46
+ end
47
+
48
+ def get_external_ip
49
+ app_name = Souls.configuration.app
50
+ `gcloud compute addresses list | grep #{app_name}-worker-ip | awk '{print $2}'`.strip
51
+ end
52
+
21
53
  def create_network
22
54
  app_name = Souls.configuration.app
23
55
  system("gcloud compute networks create #{app_name}")
@@ -88,40 +120,24 @@ module Souls
88
120
  system("gcloud compute networks list")
89
121
  end
90
122
 
91
- def nat_credit
123
+ def update_workflows
92
124
  app_name = Souls.configuration.app
93
- line = Paint["====================================", :yellow]
94
- puts("\n")
95
- puts(line)
96
- txt2 = <<~TEXT
97
- _____ ____ __ ____#{' '}
98
- / ___// __ \\/ / / / / %{red1}
99
- \\__ \\/ / / / / / / / %{red2}
100
- ___/ / /_/ / /_/ / /___%{red3}#{' '}
101
- /____/\\____/\\____/_____%{red4}#{' '}
102
- TEXT
103
- red1 = ["_____", :red]
104
- red2 = ["/ ___/", :red]
105
- red3 = ["(__ )", :red]
106
- red4 = ["/____/", :red]
107
- ms = Paint % [txt2, :cyan, { red1: red1, red2: red2, red3: red3, red4: red4 }]
108
- puts(ms)
109
- puts(line)
110
- welcome = Paint["VPC Network is All Set!", :white]
111
- puts(welcome)
112
- puts(line)
113
- endroll = <<~TEXT
114
-
115
- Edit `.github/workflow/worker.yml`
116
-
117
- Add these 2 options in \n`- name: Deploy to Cloud Run` step
118
- \n--vpc-connector=#{app_name}-connector \
119
- \n--vpc-egress=all \
120
-
121
- TEXT
122
- cd = Paint[endroll, :white]
123
- puts(cd)
124
- puts(line)
125
+ Dir.chdir(Souls.get_mother_path.to_s) do
126
+ api_workflow_path = ".github/workflows/api.yml"
127
+ worker_workflow_paths = Dir[".github/workflows/*.yml"]
128
+ worker_workflow_paths.delete(api_workflow_path)
129
+ File.open(api_workflow_path, "a") do |line|
130
+ line.write(" \\ \n --vpc-connector=#{app_name}-connector")
131
+ end
132
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [api_workflow_path.to_s, :white] }])
133
+ worker_workflow_paths.each do |file_path|
134
+ File.open(file_path, "a") do |line|
135
+ line.write(" \\ --vpc-connector=#{app_name}-connector \\")
136
+ line.write("\n --vpc-egress=all")
137
+ end
138
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
139
+ end
140
+ end
125
141
  end
126
142
  end
127
143
  end
@@ -122,7 +122,7 @@ module Souls
122
122
  instance_name = Souls.configuration.instance_name if instance_name.blank?
123
123
  system(
124
124
  "
125
- gcloud beta sql instances patch #{instance_name} \
125
+ gcloud sql instances patch #{instance_name} \
126
126
  --project=#{project_id} \
127
127
  --assign-ip \
128
128
  --authorized-networks=#{ip}
@@ -115,6 +115,8 @@ module Souls
115
115
 
116
116
  def get_latest_gem(app_name)
117
117
  file_path = "./#{app_name}/Gemfile"
118
+ souls_gem = "gem \"souls\", \"#{Souls::VERSION}\""
119
+ souls_gem = "gem \"souls\", \"#{Souls::VERSION}\", path: \"~/.local_souls/\"" if Souls::VERSION.length > 20
118
120
  File.open(file_path, "w") do |f|
119
121
  f.write(<<~TEXT)
120
122
  source "https://rubygems.org"
@@ -130,7 +132,7 @@ module Souls
130
132
  gem "rubocop", "1.22.3"
131
133
  gem "sinatra-activerecord", "2.0.23"
132
134
  gem "solargraph", "0.44.0"
133
- gem "souls", "#{Souls::VERSION}"
135
+ #{souls_gem}
134
136
  gem "steep", "0.46.0"
135
137
  gem "thor", "1.1.0"
136
138
  gem "tty-prompt", "0.23.1"
@@ -1,3 +1,5 @@
1
+ require "securerandom"
2
+
1
3
  module Souls
2
4
  class CLI < Thor
3
5
  desc "release", "Release Gem"
@@ -22,7 +24,7 @@ module Souls
22
24
  Whirly.status = status
23
25
  %w[api worker].each do |s_name|
24
26
  update_service_gemfile(service_name: s_name, version: souls_new_ver)
25
- result = Paint[update_repo(service_name: s_name, update_kind: update_kind), :green]
27
+ result = Paint[update_repo(service_name: s_name, version: souls_new_ver), :green]
26
28
  Whirly.status = result
27
29
  end
28
30
  overwrite_version(new_version: souls_new_ver)
@@ -40,6 +42,46 @@ module Souls
40
42
  end
41
43
  end
42
44
 
45
+ desc "release_local", "Release gem for local use"
46
+ def release_local
47
+ unless `git status`.include?("nothing to commit")
48
+ raise(
49
+ StandardError,
50
+ "You can only release to local with a clean working directory. Please commit your changes."
51
+ )
52
+ end
53
+
54
+ local_dir = "~/.local_souls/"
55
+
56
+ system("mkdir -p #{local_dir}")
57
+ souls_local_ver = generate_local_version
58
+
59
+ status = Paint["Saving Repo...", :yellow]
60
+ Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
61
+ Whirly.status = status
62
+
63
+ %w[api worker].each do |s_name|
64
+ update_service_gemfile(service_name: s_name, version: souls_local_ver, local: true)
65
+ result = Paint[update_repo(service_name: s_name, version: souls_local_ver), :green]
66
+ Whirly.status = result
67
+ end
68
+
69
+ Whirly.status = Paint["Creating local gem..."]
70
+
71
+ overwrite_version(new_version: souls_local_ver)
72
+ system("gem build souls.gemspec --output #{local_dir}souls-#{souls_local_ver}.gem")
73
+ Whirly.status = Paint["Done. Created gem at #{local_dir}souls-#{souls_local_ver}.gem"]
74
+ Whirly.status = Paint["Removing previous versions...", :white]
75
+ system("gem uninstall souls -x --force")
76
+
77
+ Whirly.status = Paint["Installing local gem..."]
78
+ system("gem install #{local_dir}souls-#{souls_local_ver}.gem")
79
+
80
+ Whirly.status = Paint["Cleaning up..."]
81
+ system("git checkout .")
82
+ end
83
+ end
84
+
43
85
  private
44
86
 
45
87
  def write_changelog(current_souls_ver:)
@@ -58,22 +100,20 @@ module Souls
58
100
  File.open("./CHANGELOG.md", "w") { |f| f.write(md) }
59
101
  end
60
102
 
61
- def update_repo(service_name: "api", update_kind: "patch")
103
+ def update_repo(service_name: "api", version: "0.0.1")
62
104
  current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
63
- current_ver = Souls.get_latest_version_txt(service_name: service_name)
64
- new_ver = Souls.version_detector(current_ver: current_ver, update_kind: update_kind)
65
105
  bucket_url = "gs://souls-bucket/boilerplates"
66
- file_name = "#{service_name}-v#{new_ver}.tgz"
106
+ file_name = "#{service_name}-v#{version}.tgz"
67
107
  release_name = "#{service_name}-latest.tgz"
68
108
 
69
109
  case current_dir_name
70
110
  when "souls"
71
- system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
72
- system("echo '#{new_ver}' > apps/#{service_name}/.souls_#{service_name}_version")
111
+ system("echo '#{version}' > lib/souls/versions/.souls_#{service_name}_version")
112
+ system("echo '#{version}' > apps/#{service_name}/.souls_#{service_name}_version")
73
113
  system("cd apps/ && tar -czf ../#{service_name}.tgz #{service_name}/ && cd ..")
74
114
  when "api", "worker", "console", "admin", "media"
75
- system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
76
- system("echo '#{new_ver}' > .souls_#{service_name}_version")
115
+ system("echo '#{version}' > lib/souls/versions/.souls_#{service_name}_version")
116
+ system("echo '#{version}' > .souls_#{service_name}_version")
77
117
  system("cd .. && tar -czf ../#{service_name}.tgz #{service_name}/ && cd #{service_name}")
78
118
  else
79
119
  raise(StandardError, "You are at wrong directory!")
@@ -83,31 +123,33 @@ module Souls
83
123
  system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{release_name}")
84
124
  system("gsutil cp .rubocop.yml #{bucket_url}/.rubocop.yml")
85
125
  FileUtils.rm("#{service_name}.tgz")
86
- "#{service_name}-v#{new_ver} Succefully Stored to GCS! "
126
+ "#{service_name}-v#{version} Succefully Stored to GCS! "
87
127
  end
88
128
 
89
- def update_service_gemfile(service_name: "api", version: "0.0.1")
129
+ def update_service_gemfile(service_name: "api", version: "0.0.1", local: false)
90
130
  file_dir = "./apps/#{service_name}"
91
131
  file_path = "#{file_dir}/Gemfile"
92
- gemfile_lock = "#{file_dir}/Gemfile.lock"
93
- tmp_file = "#{file_dir}/tmp/Gemfile"
132
+
133
+ write_txt = ""
94
134
  File.open(file_path, "r") do |f|
95
- File.open(tmp_file, "w") do |new_line|
96
- f.each_line do |line|
97
- gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
135
+ f.each_line do |line|
136
+ gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
137
+ write_txt +=
98
138
  if gem[0] == "souls"
99
- old_ver = gem[1].split(".")
100
- old_ver[2] = (old_ver[2].to_i + 1).to_s
101
- new_line.write(" gem \"souls\", \"#{version}\"\n")
139
+ if local
140
+ " gem \"souls\", \"#{version}\", path: \"~/.local_souls/\"\n"
141
+ else
142
+ " gem \"souls\", \"#{version}\"\n"
143
+ end
102
144
  else
103
- new_line.write(line)
145
+ line
104
146
  end
105
- end
106
147
  end
107
148
  end
108
- FileUtils.rm(file_path)
149
+ File.open(file_path, "w") { |f| f.write(write_txt) }
150
+
151
+ gemfile_lock = "#{file_dir}/Gemfile.lock"
109
152
  FileUtils.rm(gemfile_lock) if File.exist?(gemfile_lock)
110
- FileUtils.mv(tmp_file, file_path)
111
153
  puts(Paint["\nSuccessfully Updated #{service_name} Gemfile!", :green])
112
154
  end
113
155
 
@@ -145,5 +187,14 @@ module Souls
145
187
  FileUtils.rm(file_path)
146
188
  FileUtils.mv(new_file_path, file_path)
147
189
  end
190
+
191
+ def generate_local_version
192
+ max = 99_999_999_999
193
+ a = SecureRandom.random_number(max) + 9999
194
+ b = SecureRandom.random_number(max)
195
+ c = SecureRandom.random_number(max)
196
+
197
+ "#{a}.#{b}.#{c}"
198
+ end
148
199
  end
149
200
  end
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "1.6.14".freeze
2
+ VERSION = "1.7.2".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 1.6.14
1
+ 1.7.2
@@ -1 +1 @@
1
- 1.6.14
1
+ 1.7.2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.14
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-11-11 00:00:00.000000000 Z
13
+ date: 2021-11-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -147,8 +147,6 @@ files:
147
147
  - lib/souls/cli/delete/manager_rbs.rb
148
148
  - lib/souls/cli/delete/mutation.rb
149
149
  - lib/souls/cli/delete/mutation_rbs.rb
150
- - lib/souls/cli/delete/policy.rb
151
- - lib/souls/cli/delete/policy_rbs.rb
152
150
  - lib/souls/cli/delete/query.rb
153
151
  - lib/souls/cli/delete/query_rbs.rb
154
152
  - lib/souls/cli/delete/resolver.rb
@@ -157,7 +155,6 @@ files:
157
155
  - lib/souls/cli/delete/rspec_job.rb
158
156
  - lib/souls/cli/delete/rspec_manager.rb
159
157
  - lib/souls/cli/delete/rspec_mutation.rb
160
- - lib/souls/cli/delete/rspec_policy.rb
161
158
  - lib/souls/cli/delete/rspec_query.rb
162
159
  - lib/souls/cli/delete/rspec_resolver.rb
163
160
  - lib/souls/cli/delete/type.rb
@@ -183,8 +180,6 @@ files:
183
180
  - lib/souls/cli/generate/manager_rbs.rb
184
181
  - lib/souls/cli/generate/mutation.rb
185
182
  - lib/souls/cli/generate/mutation_rbs.rb
186
- - lib/souls/cli/generate/policy.rb
187
- - lib/souls/cli/generate/policy_rbs.rb
188
183
  - lib/souls/cli/generate/query.rb
189
184
  - lib/souls/cli/generate/query_rbs.rb
190
185
  - lib/souls/cli/generate/resolver.rb
@@ -193,7 +188,6 @@ files:
193
188
  - lib/souls/cli/generate/rspec_job.rb
194
189
  - lib/souls/cli/generate/rspec_manager.rb
195
190
  - lib/souls/cli/generate/rspec_mutation.rb
196
- - lib/souls/cli/generate/rspec_policy.rb
197
191
  - lib/souls/cli/generate/rspec_query.rb
198
192
  - lib/souls/cli/generate/rspec_resolver.rb
199
193
  - lib/souls/cli/generate/type.rb
@@ -232,7 +226,7 @@ licenses:
232
226
  metadata:
233
227
  homepage_uri: https://souls.elsoul.nl
234
228
  source_code_uri: https://github.com/elsoul/souls
235
- changelog_uri: https://github.com/elsoul/souls/releases/tag/v1.6.14
229
+ changelog_uri: https://github.com/elsoul/souls/releases/tag/v1.7.2
236
230
  post_install_message:
237
231
  rdoc_options: []
238
232
  require_paths:
@@ -1,15 +0,0 @@
1
- module Souls
2
- class Delete < Thor
3
- desc "policy [CLASS_NAME]", "Delete Policy File Template"
4
- def policy(class_name)
5
- dir_name = "./app/policies"
6
- FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
7
- file_path = "#{dir_name}/#{class_name.singularize}_policy.rb"
8
- FileUtils.rm(file_path)
9
- puts(Paint % ["Deleted file! : %{white_text}", :yellow, { white_text: [file_path.to_s, :white] }])
10
- file_path
11
- rescue Thor::Error => e
12
- raise(Thor::Error, e)
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- module Souls
2
- class Delete < Thor
3
- desc "policy_rbs [CLASS_NAME]", "Delete Policy RBS"
4
- def policy_rbs(class_name)
5
- file_path = ""
6
- Dir.chdir(Souls.get_mother_path.to_s) do
7
- file_dir = "./sig/api/app/graphql/policies/"
8
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
- singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_policy.rbs"
11
- FileUtils.rm(file_path)
12
- puts(Paint % ["Deleted file! : %{white_text}", :yellow, { white_text: [file_path.to_s, :white] }])
13
- end
14
- file_path
15
- rescue Thor::Error => e
16
- raise(Thor::Error, e)
17
- end
18
- end
19
- end
@@ -1,14 +0,0 @@
1
- module Souls
2
- class Delete < Thor
3
- desc "rspec_policy [CLASS_NAME]", "Delete Rspec Policy Test"
4
- def rspec_policy(class_name)
5
- singularized_class_name = class_name.singularize
6
- file_path = "./spec/policies/#{singularized_class_name}_policy_spec.rb"
7
- FileUtils.rm(file_path)
8
- puts(Paint % ["Deleted file! : %{white_text}", :yellow, { white_text: [file_path.to_s, :white] }])
9
- file_path
10
- rescue Thor::Error => e
11
- raise(Thor::Error, e)
12
- end
13
- end
14
- end
@@ -1,51 +0,0 @@
1
- module Souls
2
- class Generate < Thor
3
- desc "policy [CLASS_NAME]", "Generate Policy File Template"
4
- def policy(class_name)
5
- dir_name = "./app/policies"
6
- FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
7
- file_path = "#{dir_name}/#{class_name.singularize}_policy.rb"
8
- return "Policy already exist! #{file_path}" if File.exist?(file_path)
9
-
10
- File.open(file_path, "w") do |f|
11
- f.write(<<~TEXT)
12
- class #{class_name.camelize}Policy < ApplicationPolicy
13
- def show?
14
- true
15
- end
16
-
17
- def index?
18
- true
19
- end
20
-
21
- def create?
22
- user_permissions?
23
- end
24
-
25
- def update?
26
- user_permissions?
27
- end
28
-
29
- def delete?
30
- admin_permissions?
31
- end
32
-
33
- private
34
-
35
- def user_permissions?
36
- @user.master? or @user.admin? or @user.user?
37
- end
38
-
39
- def admin_permissions?
40
- @user.master? or @user.admin?
41
- end
42
- end
43
- TEXT
44
- end
45
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
46
- file_path
47
- rescue Thor::Error => e
48
- raise(Thor::Error, e)
49
- end
50
- end
51
- end
@@ -1,35 +0,0 @@
1
- module Souls
2
- class Generate < Thor
3
- desc "policy_rbs [CLASS_NAME]", "Generate Policy RBS"
4
- def policy_rbs(class_name)
5
- file_path = ""
6
- Dir.chdir(Souls.get_mother_path.to_s) do
7
- file_dir = "./sig/api/app/graphql/policies/"
8
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
- singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_policy.rbs"
11
- File.open(file_path, "w") do |f|
12
- f.write(<<~TEXT)
13
- class #{singularized_class_name.camelize}Policy
14
- @user: untyped
15
-
16
- def show?: -> true
17
- def index?: -> true
18
- def create?: -> bool
19
- def update?: -> bool
20
- def delete?: -> bool
21
-
22
- private
23
- def user_permissions?: -> untyped
24
- def admin_permissions?: -> untyped
25
- end
26
- TEXT
27
- end
28
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
29
- end
30
- file_path
31
- rescue Thor::Error => e
32
- raise(Thor::Error, e)
33
- end
34
- end
35
- end
@@ -1,45 +0,0 @@
1
- module Souls
2
- class Generate < Thor
3
- desc "rspec_policy [CLASS_NAME]", "Generate Rspec Policy Test from schema.rb"
4
- def rspec_policy(class_name)
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, roles: :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, roles: :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, roles: :admin) }
33
-
34
- it { is_expected.to permit_actions([:create, :update, :delete]) }
35
- end
36
- end
37
- TEXT
38
- end
39
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
40
- file_path
41
- rescue Thor::Error => e
42
- raise(Thor::Error, e)
43
- end
44
- end
45
- end