railman 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc1920be3b4235bb10d818b3b348a794035d0298
4
- data.tar.gz: bd8be02573c1b1757332c591117c5f95d16a93ea
3
+ metadata.gz: 2452bb4c3c783b6efe3694e9582281bbcd8bc5f9
4
+ data.tar.gz: 63fbcfea9787bb517762ccc91b06a183de7844ca
5
5
  SHA512:
6
- metadata.gz: f3637c9323a23861e65e360f3ee69fbdde437ba4ed1ce370ebcf367b9b02891b3c5bb4f5dfcb3a009256fe396d3f992c726b84cc9dd0383d88a6f788e9ef5d61
7
- data.tar.gz: 82c00e37a34acc67061c0112e2ff6627d6dbbeceab192aaa71bfb78927b32361cd60c33c546f81fc53e8c18a5a53a21d860a169a4a18ee65b4a8050759327e0f
6
+ metadata.gz: 4b0ecbc34ee75ad020c4516b20615515aeaad8ad67083d3f2b26bcd367f76581bb9397285fcc9bc8af9d7f5c688bcc70fb8fa9aedce93110289a0c4688375b74
7
+ data.tar.gz: 21daa85a4cbc6f3c4e6c154a94c83d64a92518bcc904aaf500fa26333a0f57a98d4ec28f37e4bfff7111c6c7bbd7f84076f0ba0c84318e823c451233ed46badc
data/lib/railman/cli.rb CHANGED
@@ -17,6 +17,22 @@ module Railman
17
17
  desc "new APPNAME", "Create new rails application named APPNAME"
18
18
  def new(app_name)
19
19
  say "Create a new rails application named: #{app_name}", :green
20
+ apply_rails_template(app_name)
21
+ say "The rails application '#{app_name}' was successfully created.", :green
22
+ say "Please check the settings in .env", :blue
23
+ end
24
+
25
+ desc "upgrade APPNAME", "Upgrade the rails upplication named APPNAME"
26
+ def upgrade(app_name)
27
+ puts "TODO upgrade the rails application: #{app_name}"
28
+ apply_rails_template(app_name, false)
29
+ say "The rails application '#{app_name}' was successfully upgraded.", :green
30
+ say "Please check the settings in .env", :blue
31
+ end
32
+
33
+ private
34
+
35
+ def apply_rails_template(app_name, create = true)
20
36
  @app_name = app_name
21
37
  @class_name = Thor::Util.camel_case(app_name)
22
38
  @admin_email = ask("What is the adminitrator email address?")
@@ -42,16 +58,11 @@ module Railman
42
58
  Dir.chdir app_name do
43
59
  run "bundle install"
44
60
  run "chmod +x bin/*"
45
- create_local_git_repository
46
- create_remote_git_repository(@repository) if yes?("Do you want me to create bitbucket repository named #{app_name}? (y/n)")
61
+ if create
62
+ create_local_git_repository
63
+ create_remote_git_repository(@repository) if yes?("Do you want me to create bitbucket repository named #{app_name}? (y/n)")
64
+ end
47
65
  end
48
- say "The rails application '#{app_name}' was successfully created.", :green
49
- say "Please check the settings in .env", :blue
50
- end
51
-
52
- desc "update APPNAME", "Update the rails upplication named APPNAME"
53
- def update(app_name)
54
- puts "TODO update the rails application: #{app_name}"
55
66
  end
56
67
  end
57
68
  end
@@ -1,3 +1,3 @@
1
1
  module Railman
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,3 +1 @@
1
- if [ "$(type -t direnv_load)" = 'function' ]; then
2
- PATH_add bin
3
- fi
1
+ PATH_add bin
@@ -1,7 +1,14 @@
1
1
  .DS_Store
2
- /.idea
3
- /.bundle
4
- /log/*
2
+ .idea
3
+ .bundle
4
+ log/*
5
5
  !/log/.keep
6
- /tmp
6
+ tmp
7
7
  .env
8
+
9
+ test/coverage
10
+ test/reports
11
+ test/screenshots
12
+
13
+ .sass-cache
14
+ public/assets
@@ -0,0 +1,27 @@
1
+ require 'simplecov-rcov'
2
+ class SimpleCov::Formatter::MergedFormatter
3
+ def format(result)
4
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
5
+ SimpleCov::Formatter::RcovFormatter.new.format(result)
6
+ end
7
+ end
8
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
9
+
10
+ SimpleCov.start do
11
+ coverage_dir 'test/coverage'
12
+
13
+ load_profile 'rails'
14
+
15
+ add_group 'Controllers', 'app/controllers'
16
+ add_group 'Mailers', 'app/mailers'
17
+ add_group 'Models', 'app/models'
18
+ add_group 'Helpers', 'app/helpers'
19
+ add_group 'Libraries', 'lib'
20
+
21
+ add_filter 'db'
22
+ add_filter 'test'
23
+ add_filter 'config'
24
+ add_filter 'vendor'
25
+ end
26
+
27
+
@@ -38,4 +38,12 @@ Eye.application APP_NAME do
38
38
  stop_command 'kill -QUIT {PID}'
39
39
  end
40
40
  end
41
+
42
+ process :sidekiq do
43
+ start_command "./bin/sidekiq -e #{RAILS_ENV} -C ./config/sidekiq.yml"
44
+ pid_file "./tmp/pids/sidekiq.pid"
45
+ stdall "log/sidekiq.log"
46
+ daemonize true
47
+ stop_signals [:USR1, 0, :TERM, 10.seconds, :KILL]
48
+ end
41
49
  end
@@ -17,10 +17,14 @@ gem 'bootstrap_form', '2.3.0' # form helper for twitter bootstrap
17
17
  gem 'bootstrap-datepicker-rails', '1.4.0' # bootstrap-datepicker
18
18
  gem 'active_link_to', '1.0.3' # automatically mark navigation link as active
19
19
 
20
- gem 'dalli' # memcached client
21
- gem 'kgio' # gives dalli 20-30% performance boost
20
+ gem 'dalli', '2.7.6' # memcached client
21
+ gem 'kgio', '2.10.0' # gives dalli 20-30% performance boost
22
+ gem 'redis-session-store' # store sessions in redis
22
23
 
23
- # todo add sidekiq for backgroud jobs
24
+ gem 'sidekiq', '4.1.1' # backgroud jobs
25
+ gem 'sidekiq-scheduler', '2.0.6' # scheduled background jobs
26
+ gem 'redis-namespace', '1.5.2' # share same redis instance for multiple applications
27
+ gem 'sinatra', '1.4.6', :require => false # for sidekiq-web
24
28
 
25
29
  gem 'unicorn', '4.8.3' # use unicorn as production server
26
30
  gem 'unicorn-rails', '1.1.0' # use unicorn as local server
@@ -33,18 +37,21 @@ group :development do
33
37
  gem 'better_errors' # better error pages in development
34
38
  gem 'binding_of_caller' # repl on the error page
35
39
  gem 'quiet_assets' # less noise in development log
40
+ gem 'letter_opener', '1.4.1' # for email tests in development
36
41
  # gem 'rack-mini-profiler'
37
42
  # gem 'flamegraph' # mini-profiler flamegraph extension (?pp=flamegraph)
38
43
  end
39
44
 
40
45
  group :test do
41
46
  gem 'minitest-reporters', '1.1.7' # generate xml for jenkins
47
+ gem 'minitest-screenshot-reporter', '0.0.2' # generate screenshots on capybara errors
42
48
  gem 'simplecov', require: false # generate coverage reports
43
49
  gem 'simplecov-rcov', '0.2.3', require: false # generate coverage reports for jenkins
44
50
  gem 'capybara', '2.6.0' # dsl for browser tests
45
51
  gem 'capybara_minitest_spec', '1.0.5' # capybara rspec-style matchers (must_have...)
46
52
  gem 'selenium-webdriver', '2.49.0' # use real browser for webtests
47
53
  gem 'poltergeist', '1.8.1' # headless tests with phantom.js
54
+ gem 'database_cleaner', '1.5.2' # cleanup test database after every integration test
48
55
  end
49
56
 
50
57
  # put additional application-specific gems to Gemfile.local
File without changes
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'sidekiq' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sidekiq', 'sidekiq')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'sidekiqctl' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sidekiq', 'sidekiqctl')
@@ -39,7 +39,10 @@ Rails.application.configure do
39
39
  # Raises error for missing translations
40
40
  # config.action_view.raise_on_missing_translations = true
41
41
 
42
- # TODO config.action_mailer.delivery_method = :letter_opener
42
+ config.action_mailer.delivery_method = :letter_opener
43
+
44
+ # Uncomment to test jobs with sidekiq locally. Start sidekiq with: sidekiq -C config/sidekiq.yml
45
+ # config.active_job.queue_adapter = :sidekiq
43
46
 
44
47
  config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
45
48
  end
@@ -56,6 +56,7 @@ Rails.application.configure do
56
56
 
57
57
  # Use a different cache store in production.
58
58
  # config.cache_store = :mem_cache_store
59
+ config.cache_store = :dalli_store, { namespace: ENV['APP_NAME'] }
59
60
 
60
61
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
62
  # config.action_controller.asset_host = 'http://assets.example.com'
@@ -88,10 +89,6 @@ Rails.application.configure do
88
89
  }
89
90
  config.action_mailer.default_url_options = { host: ENV['SMTP_DEFAULT_URL'] }
90
91
 
91
- config.middleware.use ExceptionNotification::Rack,
92
- email: {
93
- email_prefix: ENV['EXCEPTION_NOTIFICATION_EMAIL_PREFIX'],
94
- sender_address: ENV['EXCEPTION_NOTIFICATION_SENDER'],
95
- exception_recipients: ENV['ADMIN_EMAIL']
96
- }
92
+ # Use sidekiq as active job backend
93
+ config.active_job.queue_adapter = :sidekiq
97
94
  end
@@ -0,0 +1,23 @@
1
+ require 'exception_notification/rails'
2
+ require 'exception_notification/sidekiq'
3
+
4
+ ExceptionNotification.configure do |config|
5
+ # Ignore additional exception types.
6
+ # ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and ActionController::RoutingError are already added.
7
+ # config.ignored_exceptions += %w{ActionView::TemplateError CustomError}
8
+
9
+ # Adds a condition to decide when an exception must be ignored or not.
10
+ # The ignore_if method can be invoked multiple times to add extra conditions.
11
+ config.ignore_if do |exception, options|
12
+ not Rails.env.production?
13
+ end
14
+
15
+ # Notifiers =================================================================
16
+
17
+ # Email notifier sends notifications by email.
18
+ config.add_notifier :email, {
19
+ :email_prefix => ENV['EXCEPTION_NOTIFICATION_EMAIL_PREFIX'],
20
+ :sender_address => ENV['EXCEPTION_NOTIFICATION_SENDER'],
21
+ :exception_recipients => ENV['ADMIN_EMAIL']
22
+ }
23
+ end
@@ -1,3 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.session_store :cookie_store, key: '_<%= app_name %>_session'
3
+ Rails.application.config.session_store :redis_session_store, {
4
+ key: "_<%= app_name %>_session",
5
+ redis: { key_prefix: "<%= app_name %>:", expire_after: 2.minutes }
6
+ }
@@ -0,0 +1,19 @@
1
+ require 'sidekiq/scheduler'
2
+
3
+ # Configure Sidekiq Redis connection to use the '<%= app_name %>' namespace
4
+ redis_config = { url: 'redis://localhost:6379', namespace: '<%= app_name %>' }
5
+
6
+ Sidekiq.configure_server do |config|
7
+ config.redis = redis_config
8
+
9
+ #config.on(:startup) do
10
+ # Sidekiq.schedule = YAML.load_file(File.expand_path("../../../config/scheduler.yml",__FILE__))
11
+ # Sidekiq::Scheduler.reload_schedule!
12
+ #end
13
+ end
14
+
15
+ Sidekiq.configure_client do |config|
16
+ config.redis = redis_config
17
+ end
18
+
19
+
@@ -1,3 +1,20 @@
1
+ require 'sidekiq/web'
2
+ require 'sidekiq-scheduler/web'
3
+
4
+ Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_token]
5
+ Sidekiq::Web.set :sessions, Rails.application.config.session_options
6
+
7
+ # used to authenticate the user in sidekiq-web
8
+ class AdminConstraint
9
+ def matches?(request)
10
+ return false unless request.session[:user_id]
11
+ # todo user = User.find request.session[:user_id]
12
+ # todo user && user.admin?
13
+ end
14
+ end
15
+
1
16
  Rails.application.routes.draw do
17
+ mount Sidekiq::Web => '/sidekiq' # todo , :constraints => AdminConstraint.new
18
+
2
19
  root 'home#index'
3
20
  end
@@ -0,0 +1,4 @@
1
+ #recurring_hard_job:
2
+ # every: 10s
3
+ # class: "HardJob"
4
+ # queue: default
@@ -16,7 +16,5 @@ development:
16
16
  test:
17
17
  secret_key_base: <%= ENV["SECRET_TOKEN"] %>
18
18
 
19
- # Do not keep production secrets in the repository,
20
- # instead read values from the environment.
21
19
  production:
22
20
  secret_key_base: <%= ENV["SECRET_TOKEN"] %>
@@ -0,0 +1,14 @@
1
+ # Configuration file for Sidekiq.
2
+ # Options here can still be overridden by cmd line args.
3
+ # Run with: sidekiq -C config/sidekiq.yml
4
+ ---
5
+ :verbose: true
6
+ #:pidfile: tmp/pids/sidekiq.pid
7
+ :concurrency: 3
8
+ :production:
9
+ :concurency: 10
10
+ :timeout: 60
11
+ :queues:
12
+ - paperclip
13
+ - default
14
+ - mailers
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class HomepageTest < WebTest
4
+ test 'homepage' do
5
+ visit '/'
6
+ screenshot 'homepage'
7
+ must_have_content 'Welcome to: <%= @class_name %>'
8
+ end
9
+ end
@@ -1,10 +1,66 @@
1
+ require 'simplecov' if ENV['COVERAGE'] == 'true'
2
+
3
+ # default rails test configuration
1
4
  ENV['RAILS_ENV'] ||= 'test'
2
5
  require File.expand_path('../../config/environment', __FILE__)
3
6
  require 'rails/test_help'
4
7
 
5
- class ActiveSupport::TestCase
8
+ # use minitest-reporters to create xmls for jenkins and nicer terminal reporting
9
+ require 'minitest/reporters'
10
+ require 'minitest/reporters/screenshot_reporter'
11
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new,
12
+ Minitest::Reporters::JUnitReporter.new,
13
+ Minitest::Reporters::ScreenshotReporter.new]
14
+
15
+ # default test class for unit tests
16
+ class UnitTest < ActiveSupport::TestCase
6
17
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
18
  fixtures :all
19
+ end
20
+
21
+ # configure webtests with capybara and poltergeist (headless)
22
+ require 'capybara/rails'
23
+ require 'capybara_minitest_spec'
24
+ require 'capybara/poltergeist'
25
+
26
+ CAPYBARA_WINDOW_SIZE = [1024, 768]
27
+
28
+ if ENV['HEADLESS'] == 'true'
29
+ # headless driver configuration
30
+ Capybara.register_driver :poltergeist do |app|
31
+ poltergeist_options = { debug: false, timeout: 30, js_errors: true, window_size: CAPYBARA_WINDOW_SIZE }
32
+ Capybara::Poltergeist::Driver.new(app, poltergeist_options)
33
+ end
34
+ Capybara.default_driver = :poltergeist
35
+ else
36
+ # chrome browser driver configuration
37
+ Capybara.register_driver :selenium do |app|
38
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
39
+ end
40
+ Capybara.default_driver = :selenium
41
+ Capybara.current_session.driver.browser.manage.window.resize_to CAPYBARA_WINDOW_SIZE[0], CAPYBARA_WINDOW_SIZE[1]
42
+ end
43
+ Capybara.default_max_wait_time = 5 # how long should capybara wait for elements to appear on the page (ajax)
44
+
45
+ # use database_cleaner to clean the database after every test with truncation, instead of using transactional fixtures
46
+ require 'database_cleaner'
47
+ DatabaseCleaner.strategy = :truncation
48
+
49
+ # default test class for webtests
50
+ class WebTest < ActionDispatch::IntegrationTest
51
+ include Capybara::DSL
52
+ extend Minitest::Spec::DSL
53
+ include Minitest::Reporters::Screenshot
54
+
55
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
56
+ fixtures :all
57
+
58
+ # disable transactional fixtures, as we use DatabaseCleaner
59
+ self.use_transactional_fixtures = false
8
60
 
9
- # Add more helper methods to be used by all tests here...
61
+ # clean database after each test with database_cleaner
62
+ def after_teardown
63
+ super
64
+ DatabaseCleaner.clean
65
+ end
10
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Jancev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,6 +165,7 @@ files:
165
165
  - templates/rails_app/.envrc
166
166
  - templates/rails_app/.gitignore
167
167
  - templates/rails_app/.ruby-version
168
+ - templates/rails_app/.simplecov
168
169
  - templates/rails_app/Capfile
169
170
  - templates/rails_app/Eyefile.tt
170
171
  - templates/rails_app/Gemfile
@@ -178,6 +179,7 @@ files:
178
179
  - templates/rails_app/app/controllers/concerns/.keep
179
180
  - templates/rails_app/app/controllers/home_controller.rb
180
181
  - templates/rails_app/app/helpers/application_helper.rb
182
+ - templates/rails_app/app/jobs/.keep
181
183
  - templates/rails_app/app/mailers/.keep
182
184
  - templates/rails_app/app/models/.keep
183
185
  - templates/rails_app/app/models/concerns/.keep
@@ -190,6 +192,8 @@ files:
190
192
  - templates/rails_app/bin/rails
191
193
  - templates/rails_app/bin/rake
192
194
  - templates/rails_app/bin/setup
195
+ - templates/rails_app/bin/sidekiq
196
+ - templates/rails_app/bin/sidekiqctl
193
197
  - templates/rails_app/bin/spring
194
198
  - templates/rails_app/bin/unicorn
195
199
  - templates/rails_app/bin/unicorn_rails
@@ -206,18 +210,22 @@ files:
206
210
  - templates/rails_app/config/initializers/assets.rb
207
211
  - templates/rails_app/config/initializers/backtrace_silencers.rb
208
212
  - templates/rails_app/config/initializers/cookies_serializer.rb
213
+ - templates/rails_app/config/initializers/exception_notification.rb
209
214
  - templates/rails_app/config/initializers/filter_parameter_logging.rb
210
215
  - templates/rails_app/config/initializers/inflections.rb
211
216
  - templates/rails_app/config/initializers/mime_types.rb
212
217
  - templates/rails_app/config/initializers/session_store.rb.tt
218
+ - templates/rails_app/config/initializers/sidekiq.rb.tt
213
219
  - templates/rails_app/config/initializers/wrap_parameters.rb
214
220
  - templates/rails_app/config/locales/en.yml
215
221
  - templates/rails_app/config/locales/readme.txt
216
222
  - templates/rails_app/config/routes.rb
223
+ - templates/rails_app/config/scheduler.yml
217
224
  - templates/rails_app/config/secrets.yml
218
225
  - templates/rails_app/config/server/letsencrypt.conf.tt
219
226
  - templates/rails_app/config/server/logrotate.conf.tt
220
227
  - templates/rails_app/config/server/nginx.conf.tt
228
+ - templates/rails_app/config/sidekiq.yml
221
229
  - templates/rails_app/config/unicorn.rb.tt
222
230
  - templates/rails_app/db/seeds.rb
223
231
  - templates/rails_app/lib/assets/.keep
@@ -232,6 +240,7 @@ files:
232
240
  - templates/rails_app/test/fixtures/.keep
233
241
  - templates/rails_app/test/helpers/.keep
234
242
  - templates/rails_app/test/integration/.keep
243
+ - templates/rails_app/test/integration/homepage_test.rb.tt
235
244
  - templates/rails_app/test/mailers/.keep
236
245
  - templates/rails_app/test/models/.keep
237
246
  - templates/rails_app/test/test_helper.rb