docbrown/config/application.rb
Anna Buianova 4c9a40be41 Dispatch events to the webhook endpoints #3715 (#3872)
* Start with webhooks: table and model

* Start with webhooks api

* Start with webhooks api

* Webhook::Event class and events list

* Remove commented callbacks

* Start with sending events to webhook endpoints

* A couple of tests for Articles::Creator

* Send event to webhook endpoint on article destroy

* Dispatch event on article update

* Dispatch event when an article updated from admin

* Spec for the webhook job

* One more test for the dispatch event job

* Integration-like spec for event dispatching to webhook endpoints when creating an article

* Use Addressable::URI to parse endpoint url

* Add oj as a faster fast_jsonapi backend

* Renamed serializers

* Move article serialization out of a model

* Don't allow to create a webhook event with invalid type

* Add fields for ArticleSerializer

* Fix webhook event job specs

* Specify timeout when dispatching events

* Fix webhook job spec

* Change webhook events queue name

* Change serialized article fields for the dispatchable events

* Include user data when serializing an article for webhook event

* Moved decorating out of Webhook::DispatchEvent, fixed most specs

* Fix route in ArticleSerializer

* Move Article decoration to Webhook::PayloadAdapter

* Refactor image url helpers to avoid including helpers into serializer

* Fix specs

* Default url options for production
2019-09-07 13:17:45 -04:00

77 lines
3.2 KiB
Ruby

require_relative "boot"
# only require Rails parts that we actually use, this shaves off some memory
# ActiveStorage, ActionCable and TestUnit are not currently used by the app
# see <https://github.com/rails/rails/blob/v5.2.3/railties/lib/rails/all.rb>
%w[
active_record/railtie
action_controller/railtie
action_view/railtie
action_mailer/railtie
active_job/railtie
sprockets/railtie
].each do |railtie|
require railtie
end
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PracticalDeveloper
class Application < Rails::Application
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.
# 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.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.autoload_paths += Dir["#{config.root}/app/labor/"]
config.autoload_paths += Dir["#{config.root}/app/decorators/"]
config.autoload_paths += Dir["#{config.root}/app/services/"]
config.autoload_paths += Dir["#{config.root}/app/liquid_tags/"]
config.autoload_paths += Dir["#{config.root}/app/observers/"]
config.autoload_paths += Dir["#{config.root}/app/black_box/"]
config.autoload_paths += Dir["#{config.root}/app/sanitizers"]
config.autoload_paths += Dir["#{config.root}/app/facades"]
config.autoload_paths += Dir["#{config.root}/app/errors"]
config.autoload_paths += Dir["#{config.root}/app/view_objects"]
config.autoload_paths += Dir["#{config.root}/lib/"]
config.active_record.observers = :article_observer, :reaction_observer, :comment_observer
config.active_job.queue_adapter = :delayed_job
config.middleware.use Rack::Deflater
# Globally handle Pundit::NotAuthorizedError by serving 404
config.action_dispatch.rescue_responses["Pundit::NotAuthorizedError"] = :not_found
# Rails 5.1 introduced CSRF tokens that change per-form.
# Unfortunately there isn't an easy way to use them and use view caching at the same time.
# Therefore we disable "per_form_csrf_tokens" for the time being.
config.action_controller.per_form_csrf_tokens = false
# After-initialize checker to add routes to reserved words
config.after_initialize do
Rails.application.reload_routes!
top_routes = []
Rails.application.routes.routes.each do |route|
route = route.path.spec.to_s
unless route.starts_with?("/:")
route = route.split("/")[1]
route = route.split("(")[0] if route&.include?("(")
top_routes << route
end
end
ReservedWords.all = [ReservedWords::BASE_WORDS + top_routes].flatten.compact.uniq
end
end
end