Commit a67e0cb1
Changed files (42)
app
models
views
config
environments
initializers
spec
app/models/photo.rb
@@ -1,5 +1,5 @@
class Photo < ApplicationRecord
- belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true
+ belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true, optional: true
scope :processed, ->{ where(image_processing: nil) }
def url_for(version_key, asset_host = ENV['ASSET_HOST'])
app/models/user_session.rb
@@ -4,15 +4,20 @@ class UserSession < ApplicationRecord
has_one :location, as: :locatable
before_create :set_unique_key
attr_readonly :key
- scope :active, -> { where("accessed_at >= ?", 2.weeks.ago).where(revoked_at: nil).includes(:user) }
+ scope :active, -> do
+ where("accessed_at >= ?", 20.minutes.ago)
+ .where("created_at >= ?", 1.day.ago)
+ .where(revoked_at: nil)
+ .includes(:user)
+ end
def revoke!
- self.revoked_at = Time.now
+ self.revoked_at = Time.current
save!
end
def access(request)
- self.accessed_at = Time.now
+ self.accessed_at = Time.current
self.ip = request.ip
self.user_agent = request.user_agent
self.location = Location.build_from_ip(request.ip)
@@ -28,6 +33,10 @@ class UserSession < ApplicationRecord
return nil if key.blank?
self.active.find_by(key: key)
end
+
+ def sweep(time = 1.day)
+ delete_all("accessed_at < ?", time.ago)
+ end
end
private
app/models/version.rb
@@ -19,7 +19,10 @@ class Version
if photo.is_processed?
"#{asset_host}/#{blob_key}"
else
- ActionController::Base.helpers.asset_path("#{key}_default.png")
+ ActionController::Base.helpers.asset_path(
+ "#{key}_default.png",
+ skip_pipeline: true
+ )
end
end
app/views/profiles/show.html.erb
@@ -5,7 +5,7 @@
<%= avatar_for(@user, clazz: 'img-thumbnail') %>
</div>
<div class="col-9">
- <h1><%= @user.name %> <small>A member since <%= @user.created_at.to_s :foomat %>, with <%= @user.creations.length %> creations.</small> </h1>
+ <h1><%= @user.name %> <small>A member since <%= local_time(@user.created_at) %>, with <%= @user.creations.length %> creations.</small> </h1>
<h5><%= @user.city %></h5>
<hr>
<% if @user.website.present? %>
app/views/tutorials/index.html.erb
@@ -6,7 +6,7 @@
<% @tutorials.each do |tutorial| %>
<tr>
<td>
- <h4><%= link_to tutorial.heading, tutorial.url %> <small><%= tutorial.created_at.to_s :foomat %></small></h4>
+ <h4><%= link_to tutorial.heading, tutorial.url %> <small><%= local_time(tutorial.created_at) %></small></h4>
<% tutorial.tags.each do |tag| -%>
<%= link_to tag.name, tutorial_tag_path(tag.name), class: 'badge badge-secondary' %>
<% end -%>
app/views/tutorials/show.html.erb
@@ -6,7 +6,7 @@
</div>
<div class="col">
<h3><%= @tutorial.heading %></h3>
- <small><%= @tutorial.created_at.to_s :foomat %></small>
+ <small><%= local_time(@tutorial.created_at) %></small>
<p>
<% @tutorial.tags.each do |tag| -%>
<%= link_to tutorial_tag_path(tag.name) do %>
bin/rails
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
-APP_PATH = File.expand_path('../../config/application', __FILE__)
+APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
bin/setup
@@ -1,29 +1,38 @@
#!/usr/bin/env ruby
require 'pathname'
+require 'fileutils'
+include FileUtils
# path to your application root.
-APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
-Dir.chdir APP_ROOT do
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
# This script is a starting point to setup your application.
- # Add necessary setup steps to this file:
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
- puts "== Installing dependencies =="
- system "gem install bundler --conservative"
- system "bundle check || bundle install"
# puts "\n== Copying sample files =="
- # unless File.exist?("config/database.yml")
- # system "cp config/database.yml.sample config/database.yml"
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
- system "bin/rake db:setup"
+ system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
- system "rm -f log/*"
- system "rm -rf tmp/cache"
+ system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
- system "touch tmp/restart.txt"
+ system! 'bin/rails restart'
end
bin/update
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+VENDOR_PATH = File.expand_path('..', __dir__)
+Dir.chdir(VENDOR_PATH) do
+ begin
+ exec "yarnpkg #{ARGV.join(" ")}"
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
config/environments/development.rb
@@ -9,55 +9,47 @@ Rails.application.configure do
# Do not eager load code on boot.
config.eager_load = false
- # Show full error reports and disable caching.
- config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ if Rails.root.join('tmp/caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
+ config.action_mailer.perform_caching = false
+ config.action_mailer.default_url_options = { host: "localhost:3000" }
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
- # Raise an error on page load if there are pending migrations
+ # Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
- config.assets.debug = false
-
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
- # yet still be able to expire them through the digest params.
- config.assets.digest = false
- #config.assets.prefix = 'dev-assets'
+ config.assets.debug = true
- # Adds additional error checking when serving assets at runtime.
- # Checks for improperly declared sprockets dependencies.
- # Raises helpful error messages.
- config.assets.raise_runtime_errors = true
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
- config.action_mailer.default_url_options = { :host => "localhost:3000" }
- config.action_mailer.smtp_settings = {
- :address => ENV['SMTP_HOST'],
- :port => ENV['SMTP_PORT'],
- :domain => ENV['SMTP_DOMAIN'],
- :user_name => ENV['SMTP_USERNAME'],
- :password => ENV['SMTP_PASSWORD'],
- :authentication => :plain,
- :enable_starttls_auto => true
- }
-
- config.after_initialize do
- Bullet.enable = true
- Bullet.alert = false
- Bullet.bullet_logger = true
- Bullet.console = true
- Bullet.rails_logger = true
- Bullet.add_footer = true
- end
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
config/environments/production.rb
@@ -5,7 +5,7 @@ Rails.application.configure do
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
- # your application in memory, allowing both thread web servers
+ # your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
@@ -14,15 +14,14 @@ Rails.application.configure do
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
- # Enable Rack::Cache to put a simple HTTP cache in front of your application
- # Add `rack-cache` to your Gemfile before enabling this.
- # For large-scale production use, consider using a caching reverse proxy like
- # NGINX, varnish or squid.
- # config.action_dispatch.rack_cache = true
+ # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
+ # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
+ # `config/secrets.yml.key`.
+ config.read_encrypted_secrets = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
- config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
@@ -31,48 +30,56 @@ Rails.application.configure do
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
- # yet still be able to expire them through the digest params.
- config.assets.digest = true
-
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ config.action_controller.asset_host = ENV['ASSET_HOST']
+
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
- # config.force_ssl = true
-
- # Specifies the header that your server uses for sending files.
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
- config.log_level = :info
+ config.log_level = :debug
# Prepend all log lines with the following tags.
- config.log_tags = [ lambda { |x| Time.now.utc }, :host, :remote_ip, :uuid ]
-
- # Use a different logger for distributed setups.
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+ config.log_tags = [ :request_id, :host, :remote_ip ]
# Use a different cache store in production.
- config.cache_store = :mem_cache_store, 'localhost:11211'
+ config.cache_store = :mem_cache_store
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
- config.action_controller.asset_host = ENV['ASSET_HOST']
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "cake_#{Rails.env}"
+ config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
+ config.action_mailer.asset_host = ENV['ASSET_HOST']
+ config.action_mailer.default_url_options = { host: 'www.cakeside.com' }
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = {
+ address: ENV['SMTP_HOST'],
+ authentication: :plain,
+ domain: ENV['SMTP_DOMAIN'],
+ enable_starttls_auto: true,
+ password: ENV['SMTP_PASSWORD'],
+ port: ENV['SMTP_PORT'],
+ user_name: ENV['SMTP_USERNAME'],
+ }
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
- # the I18n.default_locale when a translation can not be found).
+ # the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
@@ -81,22 +88,16 @@ Rails.application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
-
- # Ignore bad email addresses and do not raise email delivery errors.
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
- # config.action_mailer.raise_delivery_errors = false
- config.action_mailer.asset_host = ENV['ASSET_HOST']
- config.action_mailer.default_url_options = { :host => 'www.cakeside.com'}
- config.action_mailer.delivery_method = :smtp
- config.action_mailer.smtp_settings = {
- :address => ENV['SMTP_HOST'],
- :port => ENV['SMTP_PORT'],
- :domain => ENV['SMTP_DOMAIN'],
- :user_name => ENV['SMTP_USERNAME'],
- :password => ENV['SMTP_PASSWORD'],
- :authentication => :plain,
- :enable_starttls_auto => true
- }
end
config/environments/test.rb
@@ -12,11 +12,10 @@ Rails.application.configure do
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
- # Configure static asset server for tests with Cache-Control for performance.
- config.public_file_server.enabled = true
-
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
config.public_file_server.headers = {
- 'Cache-Control' => "public, max-age=3600"
+ 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}
# Show full error reports and disable caching.
@@ -28,15 +27,13 @@ Rails.application.configure do
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
+ config.action_mailer.perform_caching = false
+ config.action_mailer.default_url_options = { host: 'www.example.com' }
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
- config.action_mailer.default_url_options = { :host => 'www.blah.com'}
-
- # Randomize the order test cases are executed.
- config.active_support.test_order = :random
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
config/initializers/assets.rb
@@ -3,9 +3,12 @@
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
-# Add additional assets to the asset load path
+# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
-# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
-# Rails.application.config.assets.precompile += %w( search.js )
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
config/initializers/bullet.rb
@@ -0,0 +1,10 @@
+if Rails.env.development?
+ Rails.application.config.after_initialize do
+ Bullet.enable = true
+ Bullet.alert = false
+ Bullet.bullet_logger = true
+ Bullet.console = true
+ Bullet.rails_logger = true
+ Bullet.add_footer = true
+ end
+end
config/initializers/container.rb
@@ -21,7 +21,7 @@ if Rails.configuration.cache_classes
ConfigureContainerCommand.new.configure(container)
Spank::IOC.bind_to(container)
else
- ActionDispatch::Reloader.to_prepare do
+ ActiveSupport::Reloader.to_prepare do
container = Spank::Container.new
ConfigureContainerCommand.new.configure(container)
Spank::IOC.bind_to(container)
config/initializers/delayed_job_config.rb
@@ -1,3 +1,4 @@
+Rails.application.config.active_job.queue_adapter = :delayed_job
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 5
Delayed::Worker.max_attempts = 3
config/initializers/exception_notification.rb
@@ -0,0 +1,5 @@
+Rails.application.config.middleware.use ExceptionNotification::Rack, email: {
+ email_prefix: "[Boom! #{Rails.env}] ",
+ sender_address: %{"notifier" <notifier@cakeside.com>},
+ exception_recipients: ENV["EXCEPTION_EMAIL_ADDRESS"].try(:split, " "),
+} unless Rails.env.test?
config/initializers/new_framework_defaults_5_1.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains migration options to ease your Rails 5.1 upgrade.
+#
+# Once upgraded flip defaults one by one to migrate to the new default.
+#
+# Read the Guide for Upgrading Ruby on Rails for more info on each option.
+
+# Make `form_with` generate non-remote forms.
+Rails.application.config.action_view.form_with_generates_remote_forms = false
+
+# Unknown asset fallback will return the path passed in when the given
+# asset is not present in the asset pipeline.
+# Rails.application.config.assets.unknown_asset_fallback = false
config/initializers/rack_attack.rb
@@ -1,3 +1,4 @@
+Rails.application.config.middleware.use Rack::Attack
# Always allow requests from localhost
# (blacklist & throttles are skipped)
Rack::Attack.safelist('allow from localhost') do |request|
config/initializers/rack_cors.rb
@@ -0,0 +1,7 @@
+Rails.application.config.middleware.use Rack::Cors do
+ allow do
+ origins "*"
+ resource "/api/v2/*", headers: :any, methods: [:get, :post, :put, :delete, :options]
+ resource "/api/v2/*/*", headers: :any, methods: [:get, :post, :put, :delete, :options]
+ end
+end
config/initializers/session_store.rb
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file.
configuration = {
key: "_cake_eater_#{Rails.env}",
- expire_after: 2.weeks,
+ expire_after: 20.minutes,
secure: Rails.env.production?
}
Rails.application.config.session_store :cookie_store, configuration
config/initializers/wrap_parameters.rb
@@ -5,10 +5,10 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+ wrap_parameters format: [:json]
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
-# self.include_root_in_json = true
+# self.include_root_in_json = true
# end
config/locales/controllers/my/passwords/en.yml
@@ -1,6 +0,0 @@
----
-en:
- my:
- passwords:
- passwords_do_not_match: The passwords should match and should be a minimum of 6 characters.
- updated: Your password was updated.
config/locales/controllers/passwords/en.yml
@@ -1,4 +0,0 @@
----
-en:
- passwords:
- send_instructions: You will receive an email with instructions about how to reset your password in a few minutes.
config/locales/controllers/sessions/en.yml
@@ -1,8 +0,0 @@
----
-en:
- sessions:
- new:
- sign_in: "Sign In"
- create:
- failure:
- invalid: Invalid email or password.
config/locales/en.yml
@@ -1,8 +1,23 @@
---
en:
+ activerecord:
+ attributes:
+ search:
+ q: "Search query"
+ session:
+ email: 'Email'
+ password: 'Password'
+ user:
+ accepted: "Terms and conditions"
+ email: 'Email'
+ name: 'Full name'
+ password: 'Password'
avatar_uploaded: Your avatar has been updated.
logout: Sign Out
my:
+ passwords:
+ passwords_do_not_match: The passwords should match and should be a minimum of 6 characters.
+ updated: Your password was updated.
shared:
my_nav:
activity: "Activity"
@@ -19,16 +34,12 @@ en:
products: "Products"
sessions: "Sessions"
users: "Users"
+ passwords:
+ send_instructions: You will receive an email with instructions about how to reset your password in a few minutes.
profile_saved: Your settings have been updated successfully!
- activerecord:
- attributes:
- search:
- q: "Search query"
- session:
- email: 'Email'
- password: 'Password'
- user:
- accepted: "Terms and conditions"
- email: 'Email'
- name: 'Full name'
- password: 'Password'
+ sessions:
+ new:
+ sign_in: "Sign In"
+ create:
+ failure:
+ invalid: Invalid email or password.
config/application.rb
@@ -1,54 +1,36 @@
-require File.expand_path("../boot", __FILE__)
+require_relative 'boot'
+
+require "rails"
+%w(
+ active_record/railtie
+ action_controller/railtie
+ action_view/railtie
+ action_mailer/railtie
+ active_job/railtie
+ action_cable/engine
+ active_storage/engine
+ sprockets/railtie
+).each do |railtie|
+ begin
+ require railtie
+ rescue LoadError
+ end
+end
-# Pick the frameworks you want:
-require "active_model/railtie"
-require "active_job/railtie"
-require "active_record/railtie"
-require "action_controller/railtie"
-require "action_mailer/railtie"
-require "action_view/railtie"
-require "sprockets/railtie"
-# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
-# you"ve limited to :test, :development, or :production.
+# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Cake
class Application < Rails::Application
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.1
+
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
-
- # Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/app/services/application)
config.autoload_paths += %W(#{config.root}/app/services/infrastructure)
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = "Central Time (US & Canada)"
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- translations_path = Rails.root.join("config", "locales", "**", "*.{rb,yml}")
- config.i18n.load_path += Dir[translations_path]
- # config.i18n.default_locale = :de
-
- # Do not swallow errors in after_commit/after_rollback callbacks.
- config.active_record.raise_in_transactional_callbacks = true
- config.active_job.queue_adapter = :delayed_job
-
- config.middleware.use Rack::Cors do
- allow do
- origins "*"
- resource "/api/v2/*", headers: :any, methods: [:get, :post, :put, :delete, :options]
- resource "/api/v2/*/*", headers: :any, methods: [:get, :post, :put, :delete, :options]
- end
- end
- config.middleware.use ExceptionNotification::Rack, email: {
- email_prefix: "[Boom! #{Rails.env}] ",
- sender_address: %{"notifier" <notifier@cakeside.com>},
- exception_recipients: ENV["EXCEPTION_EMAIL_ADDRESS"].try(:split, " "),
- } unless Rails.env.test?
- config.middleware.use Rack::Attack
end
end
config/boot.rb
@@ -1,3 +1,3 @@
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: redis://localhost:6379/1
+ channel_prefix: cake_production
config/environment.rb
@@ -1,7 +1,5 @@
-# Load the rails application
-require File.expand_path('../application', __FILE__)
+# Load the Rails application.
+require_relative 'application'
-# Initialize the rails application
+# Initialize the Rails application.
Rails.application.initialize!
-Date::DATE_FORMATS[:foomat] = "%d/%m/%Y"
-Time::DATE_FORMATS[:foomat] = "%B. %d, %Y"
config/puma.rb
@@ -0,0 +1,56 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory. If you use this option
+# you need to make sure to reconnect any threads in the `on_worker_boot`
+# block.
+#
+# preload_app!
+
+# If you are preloading your application and using Active Record, it's
+# recommended that you close any connections to the database before workers
+# are forked to prevent connection leakage.
+#
+# before_fork do
+# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
+# end
+
+# The code in the `on_worker_boot` will be called if you are using
+# clustered mode by specifying a number of `workers`. After each worker
+# process is booted, this block will be run. If you are using the `preload_app!`
+# option, you will want to use this block to reconnect to any threads
+# or connections that may have been created at application boot, as Ruby
+# cannot share connections between processes.
+#
+# on_worker_boot do
+# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
+# end
+#
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
config/secrets.yml
@@ -5,18 +5,28 @@
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-# You can use `rake secret` to generate a secure secret key.
+# You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
+# Shared secrets are available across all environments.
+
+# shared:
+# api_key: a1B2c3D4e5F6
+
+# Environmental secrets are only available for that specific environment.
+
development:
- secret_key_base: 5a8d8856ac7ff89a031cc8370020c03f48be94e1d52a2ad02848bd27b1e8864f6c87626203b464b53d6ab9ed1c0e63d068b4b13a9998eb67105b1c2a5df071c3
+ secret_key_base: 1ed924a41f8dc3278c0bd50d973ede2f696cd4de4d200d1a0edd4409e54b2658c0fd1fe432ac69759bf4280a231b67533538f0900c084362f545215e0761435a
test:
- secret_key_base: a275a537c6ab6aedf787c652911b1f6d4ba733f12d07df51e5d1bebc134cef1bf750462cd338493d08c305a8764e3889f73e218e9f83d5add377b0282dd959e4
+ secret_key_base: ebd8beba60c7889855b12837af2020e396d06d720fc467b7e840ce23e00769504af77a67ae0d88d58c294b9fccf6677a7865f05383417cae8894d5e705b6cdea
+
+# Do not keep production secrets in the unencrypted secrets file.
+# Instead, either read values from the environment.
+# Or, use `bin/rails secrets:setup` to configure encrypted secrets
+# and move the `production:` environment over there.
-# Do not keep production secrets in the repository,
-# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
config/spring.rb
@@ -0,0 +1,6 @@
+%w(
+ .ruby-version
+ .rbenv-vars
+ tmp/restart.txt
+ tmp/caching-dev.txt
+).each { |path| Spring.watch(path) }
spec/jobs/publish_to_twitter_job_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe PublishToTwitterJob, :type => :job do
it "tweets about the new cake" do
subject.perform(cake)
expect(twitter).to have_received(:tweet).
- with("yummy By joe on http://www.blah.com/cakes/88-yummy!")
+ with("yummy By joe on http://www.example.com/cakes/88-yummy!")
end
end
spec/models/creation_spec.rb
@@ -1,23 +1,14 @@
require 'rails_helper'
describe Creation do
- subject { Creation.new }
-
- describe "should be able to set attributes" do
- it "should save name" do
- subject.name="HELLO WORLD"
- subject.category = create(:category)
- subject.save!
- expect(Creation.find(subject.id).name).to eql("HELLO WORLD")
- end
- end
+ subject { build(:creation) }
describe "#liked_by" do
let(:user) { create(:user) }
let(:creation) { create(:creation) }
context "when the user already likes the creation" do
- let!(:favorite) { creation.favorites.create(:user => user) }
+ let!(:favorite) { creation.favorites.create(user: user) }
let(:result) { creation.liked_by(user) }
it "returns the existing favorite" do
spec/models/photo_spec.rb
@@ -85,7 +85,10 @@ describe Photo do
end
def path_to(image_filename)
- ActionController::Base.helpers.asset_path(image_filename)
+ ActionController::Base.helpers.asset_path(
+ image_filename,
+ skip_pipeline: true
+ )
end
end
end
Gemfile
@@ -1,9 +1,9 @@
source 'https://rubygems.org'
-gem 'rails', '~> 5.0'
+gem 'rails', '~> 5.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
-gem 'coffee-rails', '~> 4.1.0'
+gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'bcrypt', '~> 3.1.7'
@@ -51,6 +51,7 @@ group :development do
gem 'capistrano-rails'
gem 'capistrano-rbenv', '~> 2.0', require: false
gem 'chef'
+ gem 'listen'
gem 'lol_dba'
gem 'pry-rails'
gem 'spring-commands-rspec'
Gemfile.lock
@@ -1,39 +1,39 @@
GEM
remote: https://rubygems.org/
specs:
- actioncable (5.0.6)
- actionpack (= 5.0.6)
- nio4r (>= 1.2, < 3.0)
+ actioncable (5.1.4)
+ actionpack (= 5.1.4)
+ nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
- actionmailer (5.0.6)
- actionpack (= 5.0.6)
- actionview (= 5.0.6)
- activejob (= 5.0.6)
+ actionmailer (5.1.4)
+ actionpack (= 5.1.4)
+ actionview (= 5.1.4)
+ activejob (= 5.1.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
- actionpack (5.0.6)
- actionview (= 5.0.6)
- activesupport (= 5.0.6)
+ actionpack (5.1.4)
+ actionview (= 5.1.4)
+ activesupport (= 5.1.4)
rack (~> 2.0)
- rack-test (~> 0.6.3)
+ rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
- actionview (5.0.6)
- activesupport (= 5.0.6)
+ actionview (5.1.4)
+ activesupport (= 5.1.4)
builder (~> 3.1)
- erubis (~> 2.7.0)
+ erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
- activejob (5.0.6)
- activesupport (= 5.0.6)
+ activejob (5.1.4)
+ activesupport (= 5.1.4)
globalid (>= 0.3.6)
- activemodel (5.0.6)
- activesupport (= 5.0.6)
- activerecord (5.0.6)
- activemodel (= 5.0.6)
- activesupport (= 5.0.6)
- arel (~> 7.0)
- activesupport (5.0.6)
+ activemodel (5.1.4)
+ activesupport (= 5.1.4)
+ activerecord (5.1.4)
+ activemodel (= 5.1.4)
+ activesupport (= 5.1.4)
+ arel (~> 8.0)
+ activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
@@ -42,7 +42,7 @@ GEM
activerecord (>= 4.2.8)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
- arel (7.1.4)
+ arel (8.0.0)
asin (2.0.2)
confiture (>= 0.1)
crack (>= 0.3)
@@ -571,9 +571,9 @@ GEM
uuidtools (~> 2.1)
cliver (0.3.2)
coderay (1.1.2)
- coffee-rails (4.1.1)
+ coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
- railties (>= 4.0.0, < 5.1.x)
+ railties (>= 4.0.0)
coffee-script (2.4.1)
coffee-script-source
execjs
@@ -713,6 +713,10 @@ GEM
kaminari-core (1.0.1)
kgio (2.11.0)
libyajl2 (1.2.0)
+ listen (3.1.5)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ ruby_dep (~> 1.2)
local_time (2.0.0)
lol_dba (2.1.4)
actionpack (>= 3.0)
@@ -793,19 +797,19 @@ GEM
rack-cors (1.0.1)
rack-mini-profiler (0.10.5)
rack (>= 1.2.0)
- rack-test (0.6.3)
- rack (>= 1.0)
- rails (5.0.6)
- actioncable (= 5.0.6)
- actionmailer (= 5.0.6)
- actionpack (= 5.0.6)
- actionview (= 5.0.6)
- activejob (= 5.0.6)
- activemodel (= 5.0.6)
- activerecord (= 5.0.6)
- activesupport (= 5.0.6)
+ rack-test (0.7.0)
+ rack (>= 1.0, < 3)
+ rails (5.1.4)
+ actioncable (= 5.1.4)
+ actionmailer (= 5.1.4)
+ actionpack (= 5.1.4)
+ actionview (= 5.1.4)
+ activejob (= 5.1.4)
+ activemodel (= 5.1.4)
+ activerecord (= 5.1.4)
+ activesupport (= 5.1.4)
bundler (>= 1.3.0)
- railties (= 5.0.6)
+ railties (= 5.1.4)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
@@ -816,9 +820,9 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
- railties (5.0.6)
- actionpack (= 5.0.6)
- activesupport (= 5.0.6)
+ railties (5.1.4)
+ actionpack (= 5.1.4)
+ activesupport (= 5.1.4)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
@@ -856,6 +860,7 @@ GEM
rspec_junit_formatter (0.2.3)
builder (< 4)
rspec-core (>= 2, < 4, != 2.12.0)
+ ruby_dep (1.5.0)
safe_yaml (1.0.4)
sass (3.5.1)
sass-listen (~> 4.0.0)
@@ -971,7 +976,7 @@ DEPENDENCIES
capistrano-rails
capistrano-rbenv (~> 2.0)
chef
- coffee-rails (~> 4.1.0)
+ coffee-rails (~> 4.2)
curb
daemons
dalli
@@ -1000,6 +1005,7 @@ DEPENDENCIES
js-routes
json (~> 2.1.0)
kaminari
+ listen
local_time
lol_dba
memory_profiler
@@ -1013,7 +1019,7 @@ DEPENDENCIES
rack-attack
rack-cors
rack-mini-profiler
- rails (~> 5.0)
+ rails (~> 5.1)
rails-controller-testing
rspec-rails
sass-rails (~> 5.0)