Skip to content

Commit

Permalink
Merge pull request #6 from sauspiel/works-with-rails42
Browse files Browse the repository at this point in the history
Works with rails42
  • Loading branch information
MSch committed Sep 16, 2014
2 parents 7cc484b + 892775a commit acbdfa9
Show file tree
Hide file tree
Showing 68 changed files with 752 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.7

Allow 4.2 Versions for Rails dependencies.

## 0.9.6

Update for Rails 4.1.0 final.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Gem Version](https://badge.fury.io/rb/postamt.png)](http://rubygems.org/gems/postamt)

Postamt is a sane, solution for performing database reads against a hot standby server with Rails 4.1.
Postamt is a sane, solution for performing database reads against a hot standby server with Rails 4.1 and 4.2.

If you use Rails 3.2 or 4.0, use Postamt version 0.9.2.

Expand Down
2 changes: 1 addition & 1 deletion lib/postamt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.overwritten_default_connections

# Called by Postamt::Railtie
def self.hook!
if Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR <= 1
if Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR <= 2
ActiveRecord::Base.default_connection_handler = Postamt::ConnectionHandler.new
elsif Rails::VERSION::MAJOR == 3 and Rails::VERSION::MINOR == 2
ActiveRecord::Base.connection_handler = Postamt::ConnectionHandler.new
Expand Down
2 changes: 1 addition & 1 deletion lib/postamt/connection_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def pool_for(klass)
@pools[connection] ||= begin
Postamt.configurations[connection.to_s] ||= Postamt.configurations['master']

spec = if Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR == 1
spec = if Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR <= 2
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new Postamt.configurations
resolver.spec(connection)
elsif Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR == 0
Expand Down
2 changes: 1 addition & 1 deletion lib/postamt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Postamt
VERSION = "0.9.6"
VERSION = "0.9.7"
end
4 changes: 2 additions & 2 deletions postamt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.required_ruby_version = '>= 2.1.1'
spec.add_dependency "railties", ["~> 4.1.0"]
spec.add_dependency "activerecord", ["~> 4.1.0"]
spec.add_dependency "railties", ["~> 4.1", "< 4.3"]
spec.add_dependency "activerecord", ["~> 4.1", "< 4.3"]
spec.add_dependency "thread_safe", [">= 0.3.3"]
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
Expand Down
12 changes: 12 additions & 0 deletions testapp42/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
16 changes: 16 additions & 0 deletions testapp42/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
source 'https://rubygems.org'

gem 'rails', '4.2.0.beta1'
gem 'pg'
gem 'pry-rails'

gem 'postamt', path: '..'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano', group: :development

# To use debugger
# gem 'debugger'
28 changes: 28 additions & 0 deletions testapp42/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
== README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
6 changes: 6 additions & 0 deletions testapp42/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Pgcharmer::Application.load_tasks
Empty file.
13 changes: 13 additions & 0 deletions testapp42/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require_tree .
13 changes: 13 additions & 0 deletions testapp42/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/
5 changes: 5 additions & 0 deletions testapp42/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
Empty file.
2 changes: 2 additions & 0 deletions testapp42/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file added testapp42/app/mailers/.keep
Empty file.
Empty file added testapp42/app/models/.keep
Empty file.
3 changes: 3 additions & 0 deletions testapp42/app/models/bar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Bar < ActiveRecord::Base
has_many :foos
end
Empty file.
5 changes: 5 additions & 0 deletions testapp42/app/models/foo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo < ActiveRecord::Base
self.default_connection = :slave

belongs_to :bar
end
14 changes: 14 additions & 0 deletions testapp42/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Pgcharmer</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 3 additions & 0 deletions testapp42/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions testapp42/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions testapp42/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
4 changes: 4 additions & 0 deletions testapp42/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
run Pgcharmer::Application
24 changes: 24 additions & 0 deletions testapp42/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Assets should be precompiled for production (so we don't need the gems loaded then)
Bundler.require(*Rails.groups(assets: %w(development test)))

module Pgcharmer
class Application < Rails::Application
# 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.

config.autoload_paths << config.root.join('lib')

# 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
end
end
4 changes: 4 additions & 0 deletions testapp42/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
15 changes: 15 additions & 0 deletions testapp42/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
development:
adapter: postgresql
database: postamt
username: master
encoding: utf8
slave:
username: slave

test:
adapter: postgresql
database: postamt_test
username: master
encoding: utf8
slave:
username: slave
5 changes: 5 additions & 0 deletions testapp42/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the rails application.
require File.expand_path('../application', __FILE__)

# Initialize the rails application.
Pgcharmer::Application.initialize!
27 changes: 27 additions & 0 deletions testapp42/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Pgcharmer::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# 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

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# 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.
config.assets.debug = true
end
80 changes: 80 additions & 0 deletions testapp42/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Pgcharmer::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
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
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
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

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Whether to fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'

# 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

# Set to :debug to see everything in the log.
config.log_level = :info

# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]

# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )

# 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

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
end
36 changes: 36 additions & 0 deletions testapp42/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Pgcharmer::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# 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.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# 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

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
end
Loading

0 comments on commit acbdfa9

Please sign in to comment.