Skip to content

Instantly share code, notes, and snippets.

@wangjohn
wangjohn / gist:5290145
Last active December 15, 2015 16:38
Progress on Application Specific Rails Configuration

Tests Which Are Failing: test/generators/plugin_new_generator_test.rb (unable to open database file) - These tests fail because of the bundle install which takes the railties gem from master.

test/application/assets_test.rb - For some reason, the assets are really broken. - Seems like we're unable to open the database file, and this is causes the tests to fail.

Database File:

@wangjohn
wangjohn / gist:5177571
Last active December 15, 2015 01:09
Changes to Railties

Overview of Changes

Rails is no longer a singleton, and multiple applications can be initialized in a single Ruby process. The caveat is that these applications will share a single global configuration which is stored in Rails.config, which is created as soon as the first rails application is initialized.

This also means that Rails.config is available before the environment initialization occurs.

New Initialization Procedure

You can now initialize multiple rails applications. To do this, I've changed the initialization of an application to the following structure (you can see this inside of /config/application.rb).

@wangjohn
wangjohn / gist:5165009
Last active December 14, 2015 23:19
Backwards Compatibility with the new Rails configuration
# Should we allow this?
class Application < Rails::Application
config.timezone = 'New York'
end
Application.new do
config.something = 'Something else'
end
## Define an application
class Application < Rails::Application
end
Application.new do
config.assets = "something"
# This doesn't work
initializers do
Post.transaction do
while true
Post.new(:name => "Another New Post")
end
end
@wangjohn
wangjohn / gist:4709829
Created February 4, 2013 21:21
Tests for Unscoping
def test_unscope_overrides_default_scope
expected = Developer.order('name DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.unscope(:order).order('name DESC').collect { |dev| dev.name }
assert_equal expected, received
end
def test_unscope_after_reordering_and_combining
expected = Developer.order('id DESC, name DESC').collect { |dev| [dev.name, dev.id] }
received = DeveloperOrderedBySalary.reorder('name DESC').unscope(:order).order('id DESC, name DESC').collect { |dev| [dev.name, dev.id] }
assert_equal expected, received
@wangjohn
wangjohn / gist:4617394
Created January 24, 2013 03:27
Benchmarking test using ObjectSpace._id2ref() vs the current rails implementation of @records.each.
Test Code:
def test_benchmark_of_transactions
time = Benchmark.measure do
500.times do
Topic.transaction do
10000.times do
Topic.new
end
end