bluebase_api 1.1.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 +7 -0
- data/.envrc +1 -0
- data/.gitignore +22 -0
- data/.hound.yml +6 -0
- data/.rubocop.yml +12 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +8 -0
- data/bin/bluebase_api +13 -0
- data/bin/build +6 -0
- data/bin/bundler +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bluebase_api.gemspec +31 -0
- data/lib/bluebase_api.rb +4 -0
- data/lib/bluebase_api/actions.rb +25 -0
- data/lib/bluebase_api/app_builder.rb +379 -0
- data/lib/bluebase_api/generators/app_generator.rb +151 -0
- data/lib/bluebase_api/version.rb +5 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/github_spec.rb +10 -0
- data/spec/features/heroku_spec.rb +24 -0
- data/spec/features/new_project_spec.rb +68 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/bluebase_api.rb +49 -0
- data/spec/support/fake_github.rb +21 -0
- data/spec/support/fake_heroku.rb +32 -0
- data/templates/.envrc +1 -0
- data/templates/.hound.yml +12 -0
- data/templates/.rspec +2 -0
- data/templates/.rubocop.yml +20 -0
- data/templates/Gemfile.erb +65 -0
- data/templates/Guardfile +43 -0
- data/templates/README.md.erb +30 -0
- data/templates/app/controllers/api/base_controller.rb +3 -0
- data/templates/app/controllers/bluebase_api_application_controller.rb +5 -0
- data/templates/bin/setup +27 -0
- data/templates/bluebase_api_gitignore +18 -0
- data/templates/config/application.yml.sample.erb +27 -0
- data/templates/config/bluebase_api_routes.rb +7 -0
- data/templates/config/bluebase_api_secrets.yml +14 -0
- data/templates/config/database.yml.sample.erb +15 -0
- data/templates/config/database.yml.travis.erb +4 -0
- data/templates/config/devise.rb +298 -0
- data/templates/config/en.yml.erb +19 -0
- data/templates/config/figaro.rb +2 -0
- data/templates/config/i18n-tasks.yml +93 -0
- data/templates/config/smtp.rb +9 -0
- data/templates/config/staging.rb.erb +9 -0
- data/templates/spec/action_mailer.rb +5 -0
- data/templates/spec/database_cleaner_and_factory_girl_lint.rb +26 -0
- data/templates/spec/factory_girl.rb +3 -0
- data/templates/spec/i18n.rb +3 -0
- data/templates/spec/rails_helper.rb +32 -0
- data/templates/spec/spec_helper.rb +17 -0
- metadata +194 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
require "rails/generators/rails/app/app_generator"
|
|
3
|
+
|
|
4
|
+
module Bluebase_api
|
|
5
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
|
6
|
+
class_option :database, type: :string, aliases: "-d", default: "postgresql",
|
|
7
|
+
desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
|
8
|
+
|
|
9
|
+
class_option :heroku, type: :boolean, aliases: "-H", default: false,
|
|
10
|
+
desc: "Create staging and production Heroku apps"
|
|
11
|
+
|
|
12
|
+
class_option :skip_git, type: :boolean, default: false, desc: "Skip git init"
|
|
13
|
+
|
|
14
|
+
class_option :skip_bundle, type: :boolean, default: true, desc: "Don't run bundle install"
|
|
15
|
+
|
|
16
|
+
class_option :github, type: :string, aliases: "-G", default: nil,
|
|
17
|
+
desc: "Create Github repository and add remote origin pointed to repo"
|
|
18
|
+
|
|
19
|
+
class_option :skip_test_unit, type: :boolean, aliases: "-T", default: true,
|
|
20
|
+
desc: "Skip Test::Unit files"
|
|
21
|
+
|
|
22
|
+
# Invoked after Rails generates app
|
|
23
|
+
def finish_template
|
|
24
|
+
invoke :bluebase_api_customization
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def bluebase_api_customization
|
|
29
|
+
invoke :customize_root_files
|
|
30
|
+
invoke :customize_bin_files
|
|
31
|
+
invoke :customize_config_files
|
|
32
|
+
invoke :customize_spec_files
|
|
33
|
+
invoke :customize_app_directory
|
|
34
|
+
invoke :customize_public_directory
|
|
35
|
+
invoke :customize_vendor_directory
|
|
36
|
+
invoke :customize_lib_directory
|
|
37
|
+
invoke :customize_tmp_directory
|
|
38
|
+
invoke :setup_git_and_github
|
|
39
|
+
invoke :setup_heroku_apps
|
|
40
|
+
invoke :outro
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def customize_root_files
|
|
44
|
+
build :replace_gemfile
|
|
45
|
+
build :add_envrc
|
|
46
|
+
build :replace_gitignore
|
|
47
|
+
build :add_rubocop_and_hound_config
|
|
48
|
+
build :add_rvm_config
|
|
49
|
+
build :add_guardfile
|
|
50
|
+
build :add_dot_rspec
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def customize_bin_files
|
|
54
|
+
# Rails 4.2.0 comes with a setup script by default
|
|
55
|
+
# build :add_setup_to_bin
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def customize_config_files
|
|
59
|
+
build :configure_application_environment
|
|
60
|
+
build :configure_development_environment
|
|
61
|
+
build :configure_test_environment
|
|
62
|
+
build :configure_production_environment
|
|
63
|
+
build :add_staging_environment
|
|
64
|
+
build :add_devise_config
|
|
65
|
+
build :add_figaro_config
|
|
66
|
+
build :replace_en_yml
|
|
67
|
+
build :add_application_yml
|
|
68
|
+
build :add_database_yml if options[:database] == 'postgresql'
|
|
69
|
+
build :add_i18n_tasks_yml
|
|
70
|
+
build :replace_secrets_yml
|
|
71
|
+
build :add_smtp_settings
|
|
72
|
+
build :replace_routes_rb
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def customize_spec_files
|
|
76
|
+
build :add_spec_dirs
|
|
77
|
+
build :configure_rspec
|
|
78
|
+
build :configure_factorygirl
|
|
79
|
+
build :configure_actionmailer
|
|
80
|
+
build :configure_i18n
|
|
81
|
+
build :configure_database_cleaner
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def customize_lib_directory
|
|
85
|
+
build :remove_lib_assets_directory
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def customize_app_directory
|
|
89
|
+
build :configure_api_directory
|
|
90
|
+
build :configure_v1_directory
|
|
91
|
+
build :add_base_controller
|
|
92
|
+
build :replace_application_controller
|
|
93
|
+
build :add_serializers_directory
|
|
94
|
+
build :remove_app_assets_directory
|
|
95
|
+
build :remove_app_views_directory
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def customize_public_directory
|
|
99
|
+
build :remove_html_files
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def customize_vendor_directory
|
|
103
|
+
build :remove_vendor_assets_directories
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def customize_tmp_directory
|
|
107
|
+
build :remove_tmp_assets_directory
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def setup_git_and_github
|
|
111
|
+
if !options[:skip_git]
|
|
112
|
+
say "Initializing git"
|
|
113
|
+
build :git_init
|
|
114
|
+
if options[:github]
|
|
115
|
+
say "Creating github repo"
|
|
116
|
+
build :create_github_repo, options[:github]
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def setup_heroku_apps
|
|
122
|
+
if options[:heroku]
|
|
123
|
+
say "Creating heroku apps"
|
|
124
|
+
build :create_heroku_apps
|
|
125
|
+
build :set_heroku_remotes
|
|
126
|
+
build :set_heroku_env_variables
|
|
127
|
+
build :add_heroku_addons
|
|
128
|
+
build :set_memory_management_variable
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def outro
|
|
133
|
+
say "Your bluebase_api is complete!"
|
|
134
|
+
say "Remember to set:"
|
|
135
|
+
say "- Your database settings in config/database.yml"
|
|
136
|
+
say "- Your env variables in config/application.yml"
|
|
137
|
+
say "- Your Code Climate token in .travis.yml"
|
|
138
|
+
say "Afterward, you can now run bin/setup in your project directory to set up the app."
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def run_bundle
|
|
142
|
+
# We'll run it ourselves
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
private
|
|
146
|
+
|
|
147
|
+
def get_builder_class
|
|
148
|
+
Bluebase_api::AppBuilder
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
data/spec/fakes/bin/hub
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
feature 'Heroku' do
|
|
4
|
+
scenario 'Initialize a project with --heroku=true' do
|
|
5
|
+
run_bluebase_api('--heroku=true')
|
|
6
|
+
|
|
7
|
+
expect(FakeHeroku).to have_gem_included(project_path, 'rails_12factor')
|
|
8
|
+
expect(FakeHeroku).to have_created_app_for('staging')
|
|
9
|
+
expect(FakeHeroku).to have_created_app_for('production')
|
|
10
|
+
|
|
11
|
+
bin_setup = IO.read("#{project_path}/bin/setup")
|
|
12
|
+
app_name = Bluebase_apiTestHelpers::APP_NAME
|
|
13
|
+
|
|
14
|
+
expect(bin_setup).to include("figaro heroku:set -a #{app_name}-production -e production")
|
|
15
|
+
expect(bin_setup).to include("figaro heroku:set -a #{app_name}-staging -e production")
|
|
16
|
+
|
|
17
|
+
expect(bin_setup).to include("heroku join --app #{app_name}-staging")
|
|
18
|
+
expect(bin_setup).to include("heroku join --app #{app_name}-production")
|
|
19
|
+
|
|
20
|
+
expect(bin_setup).to include("heroku addons:add mandrill --app #{app_name}-production")
|
|
21
|
+
expect(bin_setup).to include("heroku addons:add newrelic:stark --app #{app_name}-production")
|
|
22
|
+
expect(bin_setup).to include("heroku addons:add rollbar --app #{app_name}-production")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
feature 'Initialize a new project with default configuration' do
|
|
4
|
+
# TODO: Write comprehensive specs
|
|
5
|
+
before { run_bluebase_api }
|
|
6
|
+
|
|
7
|
+
scenario 'staging config is inherited from production' do
|
|
8
|
+
staging_file = IO.read("#{project_path}/config/environments/staging.rb")
|
|
9
|
+
config_stub = "Rails.application.configure do"
|
|
10
|
+
|
|
11
|
+
expect(staging_file).to match(/^require_relative "production"/)
|
|
12
|
+
expect(staging_file).to match(/#{config_stub}/), staging_file
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
scenario 'generated .ruby-version is pulled from Bluebase_api .ruby-version' do
|
|
16
|
+
ruby_version_file = IO.read("#{project_path}/.ruby-version")
|
|
17
|
+
|
|
18
|
+
expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
scenario 'secrets.yml reads secret from env' do
|
|
22
|
+
secrets_file = IO.read("#{project_path}/config/secrets.yml")
|
|
23
|
+
|
|
24
|
+
expect(secrets_file).to match(/secret_key_base: <%= ENV\["SECRET_KEY_BASE"\] %>/)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
scenario 'action mailer support file is added' do
|
|
28
|
+
expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
scenario "i18n support file is added" do
|
|
32
|
+
expect(File).to exist("#{project_path}/spec/support/i18n.rb")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
scenario "raises on unpermitted parameters in all environments" do
|
|
36
|
+
result = IO.read("#{project_path}/config/application.rb")
|
|
37
|
+
|
|
38
|
+
expect(result).to match(
|
|
39
|
+
/^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
scenario "raises on missing translations in development and test" do
|
|
44
|
+
%w[development test].each do |environment|
|
|
45
|
+
environment_file =
|
|
46
|
+
IO.read("#{project_path}/config/environments/#{environment}.rb")
|
|
47
|
+
expect(environment_file).to match(
|
|
48
|
+
/^ +config.action_view.raise_on_missing_translations = true$/
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
scenario "specs for missing or unused translations" do
|
|
54
|
+
bin_setup = IO.read("#{project_path}/bin/setup")
|
|
55
|
+
expect(bin_setup).to include("cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
scenario "config file for i18n tasks" do
|
|
59
|
+
expect(File).to exist("#{project_path}/config/i18n-tasks.yml")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
scenario "generated en.yml is evaluated" do
|
|
63
|
+
locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
|
|
64
|
+
app_name = Bluebase_apiTestHelpers::APP_NAME
|
|
65
|
+
|
|
66
|
+
expect(locales_en_file).to match(/application: #{app_name.humanize}/)
|
|
67
|
+
end
|
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
require 'capybara/rspec'
|
|
3
|
+
require 'pry'
|
|
4
|
+
|
|
5
|
+
Bundler.require(:default, :test)
|
|
6
|
+
|
|
7
|
+
require (Pathname.new(__FILE__).dirname + '../lib/bluebase_api').expand_path
|
|
8
|
+
|
|
9
|
+
Dir['./spec/support/**/*.rb'].each { |file| require file }
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.include Bluebase_apiTestHelpers
|
|
12
|
+
|
|
13
|
+
config.before(:all) do
|
|
14
|
+
create_tmp_directory
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
config.before(:each) do
|
|
18
|
+
drop_dummy_database
|
|
19
|
+
remove_project_directory
|
|
20
|
+
|
|
21
|
+
FakeHeroku.clear!
|
|
22
|
+
FakeGithub.clear!
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Bluebase_apiTestHelpers
|
|
2
|
+
APP_NAME = "dummy"
|
|
3
|
+
|
|
4
|
+
def remove_project_directory
|
|
5
|
+
FileUtils.rm_rf(project_path)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def create_tmp_directory
|
|
9
|
+
FileUtils.mkdir_p(tmp_path)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def run_bluebase_api(arguments = nil)
|
|
13
|
+
Dir.chdir(tmp_path) do
|
|
14
|
+
Bundler.with_clean_env do
|
|
15
|
+
ENV["TESTING"] = "1"
|
|
16
|
+
|
|
17
|
+
%x(#{bluebase_api_bin} #{APP_NAME} #{arguments})
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def drop_dummy_database
|
|
23
|
+
if File.exist?(project_path)
|
|
24
|
+
Dir.chdir(project_path) do
|
|
25
|
+
Bundler.with_clean_env do
|
|
26
|
+
`rake db:drop`
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def project_path
|
|
33
|
+
@project_path ||= Pathname.new("#{tmp_path}/#{APP_NAME}")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def tmp_path
|
|
39
|
+
@tmp_path ||= Pathname.new("#{root_path}/tmp")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def bluebase_api_bin
|
|
43
|
+
File.join(root_path, "bin", "bluebase_api")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def root_path
|
|
47
|
+
File.expand_path("../../../", __FILE__)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class FakeGithub
|
|
2
|
+
RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'hub_commands'), File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
def initialize(args)
|
|
5
|
+
@args = args
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def run!
|
|
9
|
+
File.open(RECORDER, 'a') do |file|
|
|
10
|
+
file.write @args.join(' ')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.clear!
|
|
15
|
+
FileUtils.rm_rf RECORDER
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.has_created_repo?(repo_name)
|
|
19
|
+
File.read(RECORDER) == "create #{repo_name}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class FakeHeroku
|
|
2
|
+
RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'heroku_commands'), File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
def initialize(args)
|
|
5
|
+
@args = args
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def run!
|
|
9
|
+
File.open(RECORDER, 'a') do |file|
|
|
10
|
+
file.puts @args.join(' ')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.clear!
|
|
15
|
+
FileUtils.rm_rf RECORDER
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.has_gem_included?(project_path, gem_name)
|
|
19
|
+
gemfile = File.open(File.join(project_path, 'Gemfile'), 'a')
|
|
20
|
+
|
|
21
|
+
File.foreach(gemfile).any? do |line|
|
|
22
|
+
line.match(/#{Regexp.quote(gem_name)}/)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.has_created_app_for?(remote_name)
|
|
27
|
+
app_name = "#{Bluebase_apiTestHelpers::APP_NAME}-#{remote_name}"
|
|
28
|
+
expected_line = "create #{app_name} --remote #{remote_name}\n"
|
|
29
|
+
|
|
30
|
+
File.foreach(RECORDER).any? { |line| line == expected_line }
|
|
31
|
+
end
|
|
32
|
+
end
|
data/templates/.envrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PATH_add bin
|
data/templates/.rspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
Exclude:
|
|
3
|
+
- app/views/**/*
|
|
4
|
+
- app/helpers/application_helper.rb
|
|
5
|
+
- bin/*
|
|
6
|
+
- config/initializers/*
|
|
7
|
+
- db/schema.rb
|
|
8
|
+
- db/migrate/**/*devise*.rb
|
|
9
|
+
- spec/spec_helper.rb
|
|
10
|
+
- Guardfile
|
|
11
|
+
|
|
12
|
+
Metrics/LineLength:
|
|
13
|
+
Description: 'Limit lines to 110 characters.'
|
|
14
|
+
Max: 110
|
|
15
|
+
|
|
16
|
+
Style/StringLiterals:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Style/Documentation:
|
|
20
|
+
Enabled: false
|