potassium 5.2.2 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +103 -28
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.gitignore +2 -1
  5. data/.node-version +1 -0
  6. data/.rubocop.yml +530 -0
  7. data/.ruby-version +1 -1
  8. data/CHANGELOG.md +92 -1
  9. data/README.md +51 -45
  10. data/docs/DSL.md +5 -5
  11. data/lib/potassium/assets/.circleci/config.yml.erb +151 -0
  12. data/lib/potassium/assets/.eslintrc.json +352 -0
  13. data/lib/potassium/assets/.github/pull_request_template.md +9 -0
  14. data/lib/potassium/assets/.rubocop.yml +528 -0
  15. data/lib/potassium/assets/.stylelintrc.json +46 -0
  16. data/lib/potassium/assets/Makefile.erb +21 -32
  17. data/lib/potassium/assets/README.yml +59 -15
  18. data/lib/potassium/assets/active_admin/admin-component.vue +35 -0
  19. data/lib/potassium/assets/active_admin/admin_application.js +14 -0
  20. data/lib/potassium/assets/active_admin/init_activeadmin_vue.rb +10 -0
  21. data/lib/potassium/assets/app/graphql/graphql_controller.rb +55 -0
  22. data/lib/potassium/assets/app/graphql/mutations/login_mutation.rb +23 -0
  23. data/lib/potassium/assets/app/graphql/queries/base_query.rb +4 -0
  24. data/lib/potassium/assets/app/graphql/types/base/base_argument.rb +4 -0
  25. data/lib/potassium/assets/app/graphql/types/base/base_enum.rb +4 -0
  26. data/lib/potassium/assets/app/graphql/types/base/base_field.rb +5 -0
  27. data/lib/potassium/assets/app/graphql/types/base/base_input_object.rb +5 -0
  28. data/lib/potassium/assets/app/graphql/types/base/base_interface.rb +7 -0
  29. data/lib/potassium/assets/app/graphql/types/base/base_object.rb +5 -0
  30. data/lib/potassium/assets/app/graphql/types/base/base_scalar.rb +4 -0
  31. data/lib/potassium/assets/app/graphql/types/base/base_union.rb +4 -0
  32. data/lib/potassium/assets/app/graphql/types/mutation_type.rb +10 -0
  33. data/lib/potassium/assets/app/graphql/types/query_type.rb +13 -0
  34. data/lib/potassium/assets/app/javascript/app.spec.js +14 -0
  35. data/lib/potassium/assets/app/uploaders/base_uploader.rb +11 -0
  36. data/lib/potassium/assets/app/uploaders/image_uploader.rb +5 -0
  37. data/lib/potassium/assets/app/views/shared/_gtm_body.html.erb +4 -0
  38. data/lib/potassium/assets/app/views/shared/_gtm_head.html.erb +7 -0
  39. data/lib/potassium/assets/bin/release +1 -1
  40. data/lib/potassium/assets/bin/setup.erb +1 -1
  41. data/lib/potassium/assets/config/database_mysql.yml.erb +2 -2
  42. data/lib/potassium/assets/config/database_postgresql.yml.erb +2 -2
  43. data/lib/potassium/assets/config/graphql_playground.rb +20 -0
  44. data/lib/potassium/assets/config/puma.rb +1 -1
  45. data/lib/potassium/assets/config/shrine.rb +36 -0
  46. data/lib/potassium/assets/lib/tasks/auto_annotate_models.rake +2 -1
  47. data/lib/potassium/assets/package.json +4 -1
  48. data/lib/potassium/assets/redis.yml +1 -2
  49. data/lib/potassium/assets/testing/rails_helper.rb +2 -0
  50. data/lib/potassium/cli/commands/create.rb +12 -19
  51. data/lib/potassium/cli_options.rb +77 -26
  52. data/lib/potassium/helpers/gem-helpers.rb +1 -1
  53. data/lib/potassium/helpers/template-helpers.rb +8 -0
  54. data/lib/potassium/newest_version_ensurer.rb +19 -36
  55. data/lib/potassium/node_version_ensurer.rb +30 -0
  56. data/lib/potassium/recipes/admin.rb +3 -3
  57. data/lib/potassium/recipes/annotate.rb +1 -1
  58. data/lib/potassium/recipes/api.rb +93 -21
  59. data/lib/potassium/recipes/background_processor.rb +66 -19
  60. data/lib/potassium/recipes/ci.rb +10 -38
  61. data/lib/potassium/recipes/data_migrate.rb +44 -0
  62. data/lib/potassium/recipes/database.rb +4 -0
  63. data/lib/potassium/recipes/database_container.rb +7 -5
  64. data/lib/potassium/recipes/draper.rb +1 -10
  65. data/lib/potassium/recipes/file_storage.rb +66 -0
  66. data/lib/potassium/recipes/front_end.rb +225 -9
  67. data/lib/potassium/recipes/github.rb +93 -15
  68. data/lib/potassium/recipes/google_tag_manager.rb +90 -0
  69. data/lib/potassium/recipes/heroku.rb +42 -29
  70. data/lib/potassium/recipes/mailer.rb +18 -2
  71. data/lib/potassium/recipes/monitoring.rb +5 -0
  72. data/lib/potassium/recipes/node.rb +21 -0
  73. data/lib/potassium/recipes/rack_cors.rb +18 -15
  74. data/lib/potassium/recipes/schedule.rb +17 -2
  75. data/lib/potassium/recipes/style.rb +21 -3
  76. data/lib/potassium/recipes/vue_admin.rb +124 -0
  77. data/lib/potassium/templates/application.rb +10 -7
  78. data/lib/potassium/version.rb +7 -4
  79. data/potassium.gemspec +11 -6
  80. data/spec/features/api_spec.rb +25 -0
  81. data/spec/features/background_processor_spec.rb +19 -6
  82. data/spec/features/ci_spec.rb +7 -4
  83. data/spec/features/data_migrate_spec.rb +14 -0
  84. data/spec/features/database_container_spec.rb +1 -5
  85. data/spec/features/draper_spec.rb +1 -6
  86. data/spec/features/file_storage_spec.rb +75 -0
  87. data/spec/features/front_end_spec.rb +102 -0
  88. data/spec/features/github_spec.rb +53 -8
  89. data/spec/features/google_tag_manager_spec.rb +59 -0
  90. data/spec/features/graphql_spec.rb +71 -0
  91. data/spec/features/heroku_spec.rb +1 -1
  92. data/spec/features/mailer_spec.rb +16 -0
  93. data/spec/features/new_project_spec.rb +6 -14
  94. data/spec/features/node_spec.rb +28 -0
  95. data/spec/features/power_types_spec.rb +5 -16
  96. data/spec/features/schedule_spec.rb +11 -4
  97. data/spec/features/vue_admin_spec.rb +47 -0
  98. data/spec/spec_helper.rb +5 -0
  99. data/spec/support/fake_octokit.rb +31 -0
  100. data/spec/support/potassium_test_helpers.rb +26 -9
  101. data/tmp/.keep +0 -0
  102. metadata +152 -46
  103. data/lib/potassium/assets/.circleci/config.yml +0 -20
  104. data/lib/potassium/assets/Dockerfile.ci +0 -6
  105. data/lib/potassium/assets/active_admin/active_admin.js.coffee +0 -4
  106. data/lib/potassium/assets/active_admin/init_activeadmin_angular.rb +0 -8
  107. data/lib/potassium/assets/api/api_error_concern.rb +0 -32
  108. data/lib/potassium/assets/api/base_controller.rb +0 -9
  109. data/lib/potassium/assets/api/draper_responder.rb +0 -62
  110. data/lib/potassium/assets/api/responder.rb +0 -41
  111. data/lib/potassium/assets/aws.rb +0 -1
  112. data/lib/potassium/assets/bin/cibuild.erb +0 -100
  113. data/lib/potassium/assets/docker-compose.ci.yml +0 -11
  114. data/lib/potassium/assets/sidekiq_scheduler.yml +0 -9
  115. data/lib/potassium/assets/testing/paperclip.rb +0 -59
  116. data/lib/potassium/recipes/active_storage.rb +0 -40
  117. data/lib/potassium/recipes/angular_admin.rb +0 -56
  118. data/lib/potassium/recipes/aws_sdk.rb +0 -7
  119. data/lib/potassium/recipes/paperclip.rb +0 -47
  120. data/spec/features/active_storage_spec.rb +0 -30
  121. data/spec/features/front_end.rb +0 -30
@@ -1,22 +1,67 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe "GitHub" do
4
+ let(:org_name) { "platanus" }
5
+ let(:repo_name) { PotassiumTestHelpers::APP_NAME.dasherize }
6
+ let(:access_token) { "1234" }
7
+ let(:pr_template_file) { IO.read("#{project_path}/.github/pull_request_template.md") }
8
+
4
9
  before do
5
10
  drop_dummy_database
6
11
  remove_project_directory
7
12
  end
8
13
 
9
- it "create a the github repository" do
10
- create_dummy_project("github" => true)
11
- app_name = PotassiumTestHelpers::APP_NAME.dasherize
14
+ it "creates the github repository" do
15
+ create_dummy_project(
16
+ "github" => true,
17
+ "github_private" => false,
18
+ "github_has_org" => false,
19
+ "github_name" => repo_name,
20
+ "github_access_token" => access_token
21
+ )
22
+
23
+ expect(FakeOctokit).to have_created_repo(repo_name)
24
+ expect(pr_template_file).to include('Contexto')
25
+ end
26
+
27
+ it "creates the private github repository" do
28
+ create_dummy_project(
29
+ "github" => true,
30
+ "github_private" => true,
31
+ "github_has_org" => false,
32
+ "github_name" => repo_name,
33
+ "github_access_token" => access_token
34
+ )
35
+
36
+ expect(FakeOctokit).to have_created_private_repo(repo_name)
37
+ expect(pr_template_file).to include('Contexto')
38
+ end
39
+
40
+ it "creates the github repository for the organization" do
41
+ create_dummy_project(
42
+ "github" => true,
43
+ "github_private" => false,
44
+ "github_has_org" => true,
45
+ "github_org" => org_name,
46
+ "github_name" => repo_name,
47
+ "github_access_token" => access_token
48
+ )
12
49
 
13
- expect(FakeGithub).to have_created_repo("platanus/#{app_name}")
50
+ expect(FakeOctokit).to have_created_repo_for_org(repo_name, org_name)
51
+ expect(pr_template_file).to include('Contexto')
14
52
  end
15
53
 
16
- it "create a the github private repository" do
17
- create_dummy_project("github" => true, "github-private" => true)
18
- app_name = PotassiumTestHelpers::APP_NAME.dasherize
54
+ it "creates the private github repository for the organization" do
55
+ create_dummy_project(
56
+ "github" => true,
57
+ "github_private" => true,
58
+ "github_has_org" => true,
59
+ "github_org" => org_name,
60
+ "github_name" => repo_name,
61
+ "github_access_token" => access_token
62
+ )
19
63
 
20
- expect(FakeGithub).to have_created_private_repo("platanus/#{app_name}")
64
+ expect(FakeOctokit).to have_created_private_repo_for_org(repo_name, org_name)
65
+ expect(pr_template_file).to include('Contexto')
21
66
  end
22
67
  end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Google Tag Manager" do
4
+ before :all do
5
+ remove_project_directory
6
+ create_dummy_project('google_tag_manager' => true)
7
+ end
8
+
9
+ let(:gtm_head_file_path) do
10
+ "#{project_path}/app/views/shared/_gtm_head.html.erb"
11
+ end
12
+ let(:gtm_body_file_path) do
13
+ "#{project_path}/app/views/shared/_gtm_body.html.erb"
14
+ end
15
+ let(:content_security_policy_file_path) do
16
+ "#{project_path}/config/initializers/content_security_policy.rb"
17
+ end
18
+ let(:application_layout_file) do
19
+ IO.read("#{project_path}/app/views/layouts/application.html.erb")
20
+ end
21
+ let(:content_security_policy_file) do
22
+ IO.read(content_security_policy_file_path)
23
+ end
24
+
25
+ it 'adds google tag manager script' do
26
+ expect(File).to be_file(gtm_head_file_path)
27
+ expect(File).to be_file(gtm_body_file_path)
28
+ expect(application_layout_file).to include('shared/gtm_head')
29
+ expect(application_layout_file).to include('shared/gtm_body')
30
+ end
31
+
32
+ it 'add content security policy' do
33
+ expect(content_security_policy_file)
34
+ .to include(content_security_policy_code)
35
+ end
36
+
37
+ def content_security_policy_code
38
+ <<~HERE
39
+ Rails.application.config.content_security_policy do |policy|
40
+ if Rails.env.development?
41
+ policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035'
42
+ policy.script_src :self, :https, :unsafe_eval
43
+ else
44
+ policy.script_src :self, :https
45
+ # google tag manager requires to enable unsafe inline:
46
+ # https://developers.google.com/tag-manager/web/csp
47
+ policy.connect_src :self, :https, 'https://www.google-analytics.com'
48
+ policy.script_src :self,
49
+ :https,
50
+ :unsafe_inline,
51
+ 'https://www.googletagmanager.com',
52
+ 'https://www.google-analytics.com',
53
+ 'https://ssl.google-analytics.com'
54
+ policy.img_src :self, :https, 'https://www.googletagmanager.com', 'https://www.google-analytics.com'
55
+ end
56
+ end
57
+ HERE
58
+ end
59
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "GraphQL" do
4
+ context 'when using only graphql' do
5
+ before :all do
6
+ drop_dummy_database
7
+ remove_project_directory
8
+ create_dummy_project("api" => :graphql)
9
+ end
10
+
11
+ it "adds graphql related gems to Gemfile" do
12
+ gemfile_content = IO.read("#{project_path}/Gemfile")
13
+ expect(gemfile_content).to include("gem 'graphql'")
14
+ expect(gemfile_content).to include("gem 'graphql_playground-rails'")
15
+ expect(gemfile_content).not_to include("gem 'graphiql'")
16
+ end
17
+
18
+ it 'installs and sets up graphql' do
19
+ schema = IO.read(
20
+ "#{project_path}/app/graphql/#{PotassiumTestHelpers::APP_NAME.dasherize.tr('-', '_')}_schema.rb"
21
+ )
22
+ expect(schema).to include(
23
+ "class #{PotassiumTestHelpers::APP_NAME.titleize.delete(' ')}Schema < GraphQL::Schema"
24
+ )
25
+
26
+ base_mutation = IO.read("#{project_path}/app/graphql/mutations/base_mutation.rb")
27
+ expect(base_mutation).to include('Types::Base::Base')
28
+ expect(base_mutation).not_to include('input_object_class')
29
+ expect(base_mutation).not_to include('RelayClassic')
30
+
31
+ controller = IO.read("#{project_path}/app/controllers/graphql_controller.rb")
32
+ expect(controller).to include('skip_before_action :verify_authenticity_token')
33
+ end
34
+
35
+ it 'sets up graphql playground' do
36
+ routes = IO.read("#{project_path}/config/routes.rb")
37
+ expect(routes).to include(
38
+ 'mount GraphqlPlayground::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"'
39
+ )
40
+ config = IO.read("#{project_path}/config/initializers/graphql_playground.rb")
41
+ expect(config).to include('GraphqlPlayground::Rails.configure do |config|')
42
+ end
43
+ end
44
+
45
+ context 'when using authentication' do
46
+ before :all do
47
+ drop_dummy_database
48
+ remove_project_directory
49
+ create_dummy_project("api" => :graphql, "devise": true)
50
+ end
51
+
52
+ it 'gathers jwt gem' do
53
+ gemfile_content = IO.read("#{project_path}/Gemfile")
54
+ expect(gemfile_content).to include("gem 'jwt'")
55
+ end
56
+
57
+ it 'Adds auth related mutation and controller' do
58
+ controller = IO.read("#{project_path}/app/controllers/graphql_controller.rb")
59
+ expect(controller).to include('get_current_user')
60
+ expect(controller).to include(
61
+ "#{PotassiumTestHelpers::APP_NAME.titleize.delete(' ')}Schema.execute"
62
+ )
63
+
64
+ mutation_type = IO.read("#{project_path}/app/graphql/types/mutation_type.rb")
65
+ expect(mutation_type).to include('field :login, mutation: Mutations::LoginMutation')
66
+
67
+ login_mutation = IO.read("#{project_path}/app/graphql/mutations/login_mutation.rb")
68
+ expect(login_mutation).to include('class Mutations::LoginMutation < Mutations::BaseMutation')
69
+ end
70
+ end
71
+ end
@@ -56,7 +56,7 @@ RSpec.describe "Heroku" do
56
56
  bin_release = IO.read(bin_release_path)
57
57
 
58
58
  expect(bin_release).to include('set -e')
59
- expect(bin_release).to include('bundle exec rails db:migrate')
59
+ expect(bin_release).to include('bundle exec rails db:migrate:with_data')
60
60
  expect(File.stat(bin_release_path)).to be_executable
61
61
  end
62
62
  end
@@ -4,6 +4,7 @@ RSpec.describe "Mailer" do
4
4
  let(:gemfile) { IO.read("#{project_path}/Gemfile") }
5
5
  let(:mailer_config) { IO.read("#{project_path}/config/mailer.rb") }
6
6
  let(:dev_config) { IO.read("#{project_path}/config/environments/development.rb") }
7
+ let(:sidekiq_config) { IO.read("#{project_path}/config/sidekiq.yml") }
7
8
 
8
9
  before(:all) { drop_dummy_database }
9
10
 
@@ -26,6 +27,8 @@ RSpec.describe "Mailer" do
26
27
  expect(dev_config).to include("sendgrid_dev_settings = {")
27
28
  expect(dev_config).to include("api_key: ENV['SENDGRID_API_KEY']")
28
29
  end
30
+
31
+ it { expect(sidekiq_config).to include("- mailers") }
29
32
  end
30
33
 
31
34
  context "when selecting aws_ses as mailer" do
@@ -38,5 +41,18 @@ RSpec.describe "Mailer" do
38
41
  it { expect(gemfile).to include("letter_opener") }
39
42
  it { expect(mailer_config).to include("delivery_method = :aws_sdk") }
40
43
  it { expect(dev_config).to include("delivery_method = :letter_opener") }
44
+ it { expect(sidekiq_config).to include("- mailers") }
45
+ end
46
+
47
+ context "when selecting a mailer and sidekiq" do
48
+ before :all do
49
+ drop_dummy_database
50
+ remove_project_directory
51
+ create_dummy_project(
52
+ "background_processor" => true, "email_service" => 'sendgrid'
53
+ )
54
+ end
55
+
56
+ it { expect(sidekiq_config).to include("- mailers") }
41
57
  end
42
58
  end
@@ -12,11 +12,11 @@ RSpec.describe "A new project" do
12
12
  expect { on_project { `bundle exec rails -v` } }.to_not output.to_stderr
13
13
  end
14
14
 
15
- it "is a valid rubocop project" do
16
- on_project do
17
- expect(run_rubocop).to eq(true)
18
- end
19
- end
15
+ # it "is a valid rubocop project" do
16
+ # on_project do
17
+ # expect(run_rubocop).to eq(true)
18
+ # end
19
+ # end
20
20
 
21
21
  it "configures postgresql" do
22
22
  database_config_file = IO.read("#{project_path}/config/database.yml")
@@ -26,18 +26,10 @@ RSpec.describe "A new project" do
26
26
  expect(gemfile).to include %{gem 'pg'}
27
27
  end
28
28
 
29
- it "configures aws" do
30
- gemfile_content = IO.read("#{project_path}/Gemfile")
31
- expect(gemfile_content).to include("'aws-sdk', '~> 3'")
32
-
33
- initializer = IO.read("#{project_path}/config/initializers/aws.rb")
34
- expect(initializer).to include("Aws::VERSION")
35
- end
36
-
37
29
  it "configures the correct ruby version" do
38
30
  ruby_version_file = IO.read("#{project_path}/.ruby-version")
39
31
 
40
- expect(ruby_version_file).to eq("2.5")
32
+ expect(ruby_version_file).to eq("2.7")
41
33
  end
42
34
 
43
35
  it "setup ssl" do
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Node" do
4
+ let(:version) { "12" }
5
+
6
+ before(:all) do
7
+ drop_dummy_database
8
+ remove_project_directory
9
+ create_dummy_project
10
+ end
11
+
12
+ it "adds engine with node version to package.json" do
13
+ package_json_path = "#{project_path}/package.json"
14
+ expect(File).to be_file(package_json_path)
15
+ json_file = File.read(package_json_path)
16
+ js_package = JSON.parse(json_file)
17
+ expect(js_package).to have_key("engines")
18
+ expect(js_package["engines"]).to have_key("node")
19
+ expect(js_package["engines"]["node"]).to eq("#{version}.x")
20
+ end
21
+
22
+ it "adds .node-version with correct version" do
23
+ node_version_path = "#{project_path}/.node-version"
24
+ expect(File).to be_file(node_version_path)
25
+ node_version_file = File.read(node_version_path)
26
+ expect(node_version_file).to eq(version)
27
+ end
28
+ end
@@ -17,21 +17,10 @@ RSpec.describe "PowerTypes" do
17
17
  expect(readme).to include("Power-Types")
18
18
  end
19
19
 
20
- it "adds commands directory" do
21
- commands_directory = "#{project_path}/app/commands"
22
- expect(File.directory?(commands_directory)).to eq(true)
23
- end
24
-
25
- it "adds services directory" do
26
- services_directory = "#{project_path}/app/services"
27
- expect(File.directory?(services_directory)).to eq(true)
28
- end
29
- it "adds utils directory" do
30
- utils_directory = "#{project_path}/app/utils"
31
- expect(File.directory?(utils_directory)).to eq(true)
32
- end
33
- it "adds values directory" do
34
- values_directory = "#{project_path}/app/values"
35
- expect(File.directory?(values_directory)).to eq(true)
20
+ it "adds every power type directory" do
21
+ [:commands, :services, :observers, :utils, :values].each do |type|
22
+ commands_directory = "#{project_path}/app/#{type}"
23
+ expect(File.directory?(commands_directory)).to eq(true)
24
+ end
36
25
  end
37
26
  end
@@ -1,10 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe "schedule" do
4
+ let(:sidekiq_config) { IO.read("#{project_path}/config/sidekiq.yml") }
5
+
4
6
  before :all do
5
7
  drop_dummy_database
6
8
  remove_project_directory
7
- create_dummy_project("schedule" => true)
9
+ create_dummy_project(
10
+ "schedule" => true, "background_processor" => true, "email_service" => "sendgrid"
11
+ )
8
12
  end
9
13
 
10
14
  it "adds the sidekiq-scheduler gem to Gemfile" do
@@ -12,9 +16,12 @@ RSpec.describe "schedule" do
12
16
  expect(gemfile_content).to include("gem 'sidekiq-scheduler'")
13
17
  end
14
18
 
15
- it "creates the config with schedule" do
16
- initializer_content = IO.read("#{project_path}/config/sidekiq.yml")
17
- expect(initializer_content).to include(":schedule:")
19
+ it "adds schedule section to sidekiq config" do
20
+ expect(sidekiq_config).to include(":schedule:")
21
+ end
22
+
23
+ it "doesn't remove mailers queue" do
24
+ expect(sidekiq_config).to include("- mailers")
18
25
  end
19
26
 
20
27
  it "adds scheduler ui to the sidekiq initializer" do
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+ require "pry"
3
+ RSpec.describe "VueAdmin" do
4
+ before(:all) do
5
+ drop_dummy_database
6
+ remove_project_directory
7
+ create_dummy_project(:vue_admin => true, "admin" => true, "devise" => true)
8
+ end
9
+
10
+ it "adds component integration to active admin initializer" do
11
+ admin_initializer_path = "#{project_path}/config/initializers/active_admin.rb"
12
+ expect(File).to be_file(admin_initializer_path)
13
+ initializer_file = File.read(admin_initializer_path)
14
+ expect(initializer_file).to include("AUTO_BUILD_ELEMENTS")
15
+ end
16
+
17
+ it "adds layout tags to active admin layout initializer" do
18
+ initializer_path = "#{project_path}/config/initializers/init_activeadmin_vue.rb"
19
+ expect(File).to be_file(initializer_path)
20
+ end
21
+
22
+ it "adds vue_component to library" do
23
+ vue_component_lib_path = "#{project_path}/lib/vue_component.rb"
24
+ expect(File).to be_file(vue_component_lib_path)
25
+ vue_component_lib = File.read(vue_component_lib_path)
26
+ expect(vue_component_lib).to include("VueComponent")
27
+ end
28
+
29
+ it "adds admin_application pack to packs" do
30
+ application_pack_path = "#{project_path}/app/javascript/packs/admin_application.js"
31
+ expect(File).to be_file(application_pack_path)
32
+ end
33
+
34
+ it "adds admin_component to vue components" do
35
+ application_pack_path = "#{project_path}/app/javascript/components/admin-component.vue"
36
+ expect(File).to be_file(application_pack_path)
37
+ end
38
+
39
+ it "installs vue to project" do
40
+ package_json_path = "#{project_path}/package.json"
41
+ expect(File).to be_file(package_json_path)
42
+ json_file = File.read(package_json_path)
43
+ js_package = JSON.parse(json_file)
44
+ expect(js_package).to have_key("dependencies")
45
+ expect(js_package["dependencies"]).to have_key("vue")
46
+ end
47
+ end
data/spec/spec_helper.rb CHANGED
@@ -26,8 +26,13 @@ RSpec.configure do |config|
26
26
  create_tmp_directory
27
27
  end
28
28
 
29
+ config.after(:each) do
30
+ docker_cleanup
31
+ end
32
+
29
33
  config.before(:each) do
30
34
  FakeGithub.clear!
31
35
  FakeHeroku.clear!
36
+ FakeOctokit.clear!
32
37
  end
33
38
  end
@@ -0,0 +1,31 @@
1
+ class FakeOctokit
2
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'octokit'), File.dirname(__FILE__))
3
+
4
+ def initialize(options); end
5
+
6
+ def create_repository(repo_name, options)
7
+ File.open(RECORDER, 'a') do |file|
8
+ file.write "#{repo_name}, #{options.map { |key, value| "#{key}: #{value}" }}"
9
+ end
10
+ end
11
+
12
+ def self.clear!
13
+ FileUtils.rm_rf RECORDER
14
+ end
15
+
16
+ def self.has_created_repo?(repo_name)
17
+ File.read(RECORDER).include? repo_name
18
+ end
19
+
20
+ def self.has_created_private_repo?(repo_name)
21
+ has_created_repo?(repo_name) && File.read(RECORDER).include?("private: true")
22
+ end
23
+
24
+ def self.has_created_repo_for_org?(repo_name, org_name)
25
+ has_created_repo?(repo_name) && File.read(RECORDER).include?("organization: #{org_name}")
26
+ end
27
+
28
+ def self.has_created_private_repo_for_org?(repo_name, org_name)
29
+ has_created_private_repo?(repo_name) && has_created_repo_for_org?(repo_name, org_name)
30
+ end
31
+ end