environment_configurable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +64 -0
- data/Rakefile +35 -0
- data/lib/environment_configurable.rb +45 -0
- data/spec/environment_configurable_spec.rb +73 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/stub_rails/app/controllers/application_controller.rb +10 -0
- data/spec/stub_rails/app/helpers/application_helper.rb +3 -0
- data/spec/stub_rails/config/boot.rb +110 -0
- data/spec/stub_rails/config/environment.rb +41 -0
- data/spec/stub_rails/config/environments/development.rb +17 -0
- data/spec/stub_rails/config/environments/production.rb +28 -0
- data/spec/stub_rails/config/environments/test.rb +28 -0
- data/spec/stub_rails/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/stub_rails/config/initializers/inflections.rb +10 -0
- data/spec/stub_rails/config/initializers/mime_types.rb +5 -0
- data/spec/stub_rails/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/stub_rails/config/initializers/session_store.rb +15 -0
- data/spec/stub_rails/config/routes.rb +43 -0
- data/spec/stub_rails/db/seeds.rb +7 -0
- data/spec/stub_rails/test/performance/browsing_test.rb +9 -0
- data/spec/stub_rails/test/test_helper.rb +38 -0
- data/spec/support/stub_helpers.rb +164 -0
- metadata +86 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Atomic Object
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# environment_configurable
|
2
|
+
|
3
|
+
Description
|
4
|
+
===========
|
5
|
+
|
6
|
+
A library that makes environment dependent configuration easy in rails.
|
7
|
+
|
8
|
+
Rationale
|
9
|
+
========
|
10
|
+
|
11
|
+
Environment dependent configuration is a common problem in rails, and we noticed
|
12
|
+
a common pattern:
|
13
|
+
|
14
|
+
* We tend to extract configuration variables to a yaml file
|
15
|
+
* We often wrap the yaml configuration in a configuration helper
|
16
|
+
|
17
|
+
Environment Configurable accomplishes both of these task succinctly.
|
18
|
+
|
19
|
+
Install
|
20
|
+
====
|
21
|
+
* gem install environment_configurable
|
22
|
+
* Add config.gem "environment_configurable" to your environment.rb file
|
23
|
+
|
24
|
+
Dependencies
|
25
|
+
============
|
26
|
+
|
27
|
+
* Rails 2.3.0 >=
|
28
|
+
|
29
|
+
Example
|
30
|
+
=======
|
31
|
+
|
32
|
+
class S3Helper
|
33
|
+
include EnvironmentConfigurable
|
34
|
+
configure_with "config/s3.yml"
|
35
|
+
|
36
|
+
def self.connect!
|
37
|
+
AWS::S3::Base.establish_connection!(
|
38
|
+
:access_key_id => config.access_key_id,
|
39
|
+
:secret_access_key => config.secret_access_key
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
s3.yml
|
45
|
+
|
46
|
+
production: &DEFAULTS
|
47
|
+
access_key_id: ACCESS_KEY_ID
|
48
|
+
secret_access_key: SECRET_ACCESS_KEY
|
49
|
+
bucket: the-prod-bucket
|
50
|
+
|
51
|
+
staging:
|
52
|
+
<<: *DEFAULTS
|
53
|
+
bucket: the-staging-bucket
|
54
|
+
|
55
|
+
development:
|
56
|
+
<<: *DEFAULTS
|
57
|
+
bucket: the-development-bucket
|
58
|
+
|
59
|
+
test:
|
60
|
+
<<: *DEFAULTS
|
61
|
+
bucket: the-test-bucket
|
62
|
+
|
63
|
+
|
64
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$:<< "vendor/gems/gems/rspec-1.2.9/lib"
|
2
|
+
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
task :default => [:spec]
|
6
|
+
|
7
|
+
desc "Executes bundler and grabs necessary dependencies to run tests"
|
8
|
+
task "setup:contrib" do
|
9
|
+
system("gem bundle")
|
10
|
+
end
|
11
|
+
|
12
|
+
Spec::Rake::SpecTask.new do |t|
|
13
|
+
t.spec_files = "spec/**/*_spec.rb"
|
14
|
+
t.spec_opts = ["-f s -c"]
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'jeweler'
|
19
|
+
Jeweler::Tasks.new do |s|
|
20
|
+
s.name = "environment_configurable"
|
21
|
+
s.summary = "A library that makes environment dependent configuration easy in rails."
|
22
|
+
s.description = "A library that makes environment dependent configuration easy in rails."
|
23
|
+
s.email = "github@atomicobject.com"
|
24
|
+
s.homepage = "http://github.com/atomicobject/environment_configurable"
|
25
|
+
s.authors = ["Atomic Object"]
|
26
|
+
s.executables = []
|
27
|
+
s.files = FileList["lib/**/*.rb", "LICENSE", "Rakefile"]
|
28
|
+
s.test_files = FileList["spec/**/*.rb"]
|
29
|
+
s.add_dependency "rails", ">=2.3.0"
|
30
|
+
end
|
31
|
+
|
32
|
+
Jeweler::GemcutterTasks.new
|
33
|
+
rescue LoadError
|
34
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EnvironmentConfigurable
|
2
|
+
module InstanceMethods
|
3
|
+
def config
|
4
|
+
self.class.config
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def configure_with(file)
|
10
|
+
@configured_with_file = "#{Rails.root}/#{file}"
|
11
|
+
unless File.exist?(@configured_with_file)
|
12
|
+
raise "Can't configure class #{self.name} -- no file #{@configured_with_file}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
unless @config_wrappers
|
18
|
+
@config_data = YAML.load(ERB.new(File.read(@configured_with_file)).result)
|
19
|
+
@config_wrappers = {}
|
20
|
+
@config_data.each do |env_name, hash|
|
21
|
+
@config_wrappers[env_name] = ConfigWrapper.new(hash)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@config_wrappers[Rails.env]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ConfigWrapper
|
29
|
+
def initialize(hash)
|
30
|
+
@hash = hash
|
31
|
+
end
|
32
|
+
def method_missing(method_name,*args)
|
33
|
+
key = method_name.to_s
|
34
|
+
super unless @hash.keys.include?(key)
|
35
|
+
@hash[key]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.included(receiver)
|
40
|
+
receiver.send(:include, InstanceMethods)
|
41
|
+
receiver.send(:extend, ClassMethods)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EnvironmentConfigurable do
|
4
|
+
class MyHouse
|
5
|
+
include EnvironmentConfigurable
|
6
|
+
configure_with "config/s3.yml"
|
7
|
+
|
8
|
+
def self.peek_access_key_id
|
9
|
+
config.access_key_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.peek_bucket
|
13
|
+
config.bucket
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.blow_up
|
17
|
+
config.oops
|
18
|
+
end
|
19
|
+
|
20
|
+
def i_access_key_id
|
21
|
+
config.access_key_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def i_bucket
|
25
|
+
config.bucket
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ErbTown
|
30
|
+
include EnvironmentConfigurable
|
31
|
+
configure_with "test_files/erb_example.yml"
|
32
|
+
|
33
|
+
def self.path
|
34
|
+
config.path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "gives a class clean, environment-specific access to a yml config" do
|
39
|
+
@yml_data = YAML.load_file("#{Rails.root}/config/s3.yml")
|
40
|
+
|
41
|
+
MyHouse.peek_access_key_id.should_not be_nil
|
42
|
+
MyHouse.peek_access_key_id.should == @yml_data["test"]["access_key_id"]
|
43
|
+
|
44
|
+
MyHouse.peek_bucket.should_not be_nil
|
45
|
+
MyHouse.peek_bucket.should == @yml_data["test"]["bucket"]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns nil for unknown config vars" do
|
49
|
+
lambda { MyHouse.blow_up }.should raise_error(NoMethodError, /oops/)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "explodes when config file is not there" do
|
53
|
+
lambda do
|
54
|
+
Class.new do
|
55
|
+
include EnvironmentConfigurable
|
56
|
+
configure_with "config/nono.yml"
|
57
|
+
end
|
58
|
+
end.should raise_error(/nono.yml/)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "erb loads the yaml files" do
|
62
|
+
ErbTown.path.should == File.join(Rails.root, "/the/path")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "provides instance methods with access to config as well" do
|
66
|
+
@yml_data = YAML.load_file("#{Rails.root}/config/s3.yml")
|
67
|
+
|
68
|
+
@my_house = MyHouse.new
|
69
|
+
@my_house.i_access_key_id.should == @yml_data["test"]["access_key_id"]
|
70
|
+
@my_house.i_bucket.should == @yml_data["test"]["bucket"]
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
here = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$:<< File.expand_path("../lib")
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] ||= 'test'
|
5
|
+
require File.join(here, "..", "vendor/gems/environment")
|
6
|
+
require 'stub_rails/config/environment'
|
7
|
+
require 'environment_configurable'
|
8
|
+
Bundler.require_env :test
|
9
|
+
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
config.include(SpecInstanceHelpers)
|
14
|
+
config.mock_with :mocha
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
Rails::GemDependency.add_frozen_gem_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GemBoot < Boot
|
52
|
+
def load_initializer
|
53
|
+
self.class.load_rubygems
|
54
|
+
load_rails_gem
|
55
|
+
require 'initializer'
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_rails_gem
|
59
|
+
if version = self.class.gem_version
|
60
|
+
gem 'rails', version
|
61
|
+
else
|
62
|
+
gem 'rails'
|
63
|
+
end
|
64
|
+
rescue Gem::LoadError => load_error
|
65
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
def rubygems_version
|
71
|
+
Gem::RubyGemsVersion rescue nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_version
|
75
|
+
if defined? RAILS_GEM_VERSION
|
76
|
+
RAILS_GEM_VERSION
|
77
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
78
|
+
ENV['RAILS_GEM_VERSION']
|
79
|
+
else
|
80
|
+
parse_gem_version(read_environment_rb)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def load_rubygems
|
85
|
+
min_version = '1.3.2'
|
86
|
+
require 'rubygems'
|
87
|
+
unless rubygems_version >= min_version
|
88
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
rescue LoadError
|
93
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_gem_version(text)
|
98
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def read_environment_rb
|
103
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# All that for this:
|
110
|
+
Rails.boot!
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file
|
2
|
+
|
3
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
|
+
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
|
5
|
+
|
6
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
8
|
+
|
9
|
+
Rails::Initializer.run do |config|
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Add additional load paths for your own custom dirs
|
15
|
+
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
16
|
+
|
17
|
+
# Specify gems that this application depends on and have them installed with rake gems:install
|
18
|
+
# config.gem "bj"
|
19
|
+
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
|
20
|
+
# config.gem "sqlite3-ruby", :lib => "sqlite3"
|
21
|
+
# config.gem "aws-s3", :lib => "aws/s3"
|
22
|
+
|
23
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
|
+
# :all can be used as a placeholder for all plugins not explicitly named
|
25
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
26
|
+
|
27
|
+
# Skip frameworks you're not going to use. To use Rails without a database,
|
28
|
+
# you must remove the Active Record framework.
|
29
|
+
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
30
|
+
|
31
|
+
# Activate observers that should always be running
|
32
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
33
|
+
|
34
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
35
|
+
# Run "rake -D time" for a list of tasks for finding time zone names.
|
36
|
+
config.time_zone = 'UTC'
|
37
|
+
|
38
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
39
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
40
|
+
# config.i18n.default_locale = :de
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# In the development environment your application's code is reloaded on
|
4
|
+
# every request. This slows down response time but is perfect for development
|
5
|
+
# since you don't have to restart the webserver when you make code changes.
|
6
|
+
config.cache_classes = false
|
7
|
+
|
8
|
+
# Log error messages when you accidentally call methods on nil.
|
9
|
+
config.whiny_nils = true
|
10
|
+
|
11
|
+
# Show full error reports and disable caching
|
12
|
+
config.action_controller.consider_all_requests_local = true
|
13
|
+
config.action_view.debug_rjs = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The production environment is meant for finished, "live" apps.
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.action_controller.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
config.action_view.cache_template_loading = true
|
11
|
+
|
12
|
+
# See everything in the log (default is :info)
|
13
|
+
# config.log_level = :debug
|
14
|
+
|
15
|
+
# Use a different logger for distributed setups
|
16
|
+
# config.logger = SyslogLogger.new
|
17
|
+
|
18
|
+
# Use a different cache store in production
|
19
|
+
# config.cache_store = :mem_cache_store
|
20
|
+
|
21
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
22
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
23
|
+
|
24
|
+
# Disable delivery errors, bad email addresses will be ignored
|
25
|
+
# config.action_mailer.raise_delivery_errors = false
|
26
|
+
|
27
|
+
# Enable threaded mode
|
28
|
+
# config.threadsafe!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
config.action_view.cache_template_loading = true
|
16
|
+
|
17
|
+
# Disable request forgery protection in test environment
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
19
|
+
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
22
|
+
# ActionMailer::Base.deliveries array.
|
23
|
+
config.action_mailer.delivery_method = :test
|
24
|
+
|
25
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
26
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
27
|
+
# like if you have constraints or database-specific column types
|
28
|
+
# config.active_record.schema_format = :sql
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# These settings change the behavior of Rails 2 apps and will be defaults
|
4
|
+
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
5
|
+
|
6
|
+
if defined?(ActiveRecord)
|
7
|
+
# Include Active Record class name as root for JSON serialized output.
|
8
|
+
ActiveRecord::Base.include_root_in_json = true
|
9
|
+
|
10
|
+
# Store the full class name (including module namespace) in STI type column.
|
11
|
+
ActiveRecord::Base.store_full_sti_class = true
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionController::Routing.generate_best_match = false
|
15
|
+
|
16
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
17
|
+
ActiveSupport.use_standard_json_time_format = true
|
18
|
+
|
19
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
20
|
+
# if you're including raw json in an HTML page.
|
21
|
+
ActiveSupport.escape_html_entities_in_json = false
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying cookie session data integrity.
|
4
|
+
# If you change this key, all old sessions will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
ActionController::Base.session = {
|
8
|
+
:key => '_stub_rails_session',
|
9
|
+
:secret => '3a182c6602a162a9ee6a1894a24eb4b8de5047ce3383bf3506c2b308b93b1715c75e14d3fa52e6c17350cd9d76f98b9479a1c9c45217e0f9bf0449ece5d7a542'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Use the database for sessions instead of the cookie-based default,
|
13
|
+
# which shouldn't be used to store highly confidential information
|
14
|
+
# (create the session table with "rake db:sessions:create")
|
15
|
+
# ActionController::Base.session_store = :active_record_store
|
@@ -0,0 +1,43 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
3
|
+
|
4
|
+
# Sample of regular route:
|
5
|
+
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
|
6
|
+
# Keep in mind you can assign values other than :controller and :action
|
7
|
+
|
8
|
+
# Sample of named route:
|
9
|
+
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
|
10
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
11
|
+
|
12
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
13
|
+
# map.resources :products
|
14
|
+
|
15
|
+
# Sample resource route with options:
|
16
|
+
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
|
17
|
+
|
18
|
+
# Sample resource route with sub-resources:
|
19
|
+
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
|
20
|
+
|
21
|
+
# Sample resource route with more complex sub-resources
|
22
|
+
# map.resources :products do |products|
|
23
|
+
# products.resources :comments
|
24
|
+
# products.resources :sales, :collection => { :recent => :get }
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Sample resource route within a namespace:
|
28
|
+
# map.namespace :admin do |admin|
|
29
|
+
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
|
30
|
+
# admin.resources :products
|
31
|
+
# end
|
32
|
+
|
33
|
+
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
|
34
|
+
# map.root :controller => "welcome"
|
35
|
+
|
36
|
+
# See how all your routes lay out with "rake routes"
|
37
|
+
|
38
|
+
# Install the default routes as the lowest priority.
|
39
|
+
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
40
|
+
# consider removing or commenting them out if you're using named routes and resources.
|
41
|
+
map.connect ':controller/:action/:id'
|
42
|
+
map.connect ':controller/:action/:id.:format'
|
43
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Major.create(:name => 'Daley', :city => cities.first)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
module SpecInstanceHelpers
|
2
|
+
def stub_instance_hash(*instance_names)
|
3
|
+
hash = {}
|
4
|
+
instance_names.each do |instance_name|
|
5
|
+
hash[instance_name] = stub_instance(instance_name)
|
6
|
+
end
|
7
|
+
hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def stub_string_hash(*instance_names)
|
11
|
+
hash = {}
|
12
|
+
instance_names.each do |instance_name|
|
13
|
+
hash[instance_name] = stub_string(instance_name)
|
14
|
+
end
|
15
|
+
hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_array_of_stubs(instance, count, stubbings)
|
19
|
+
stub_array = stub_array_instance(instance, count, instance.to_s.singularize)
|
20
|
+
stub_array.each do |stub|
|
21
|
+
stubbings.each do |key, value_lambda|
|
22
|
+
stub.stub!(key).and_return(value_lambda.call)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_instance(var_name, options={})
|
28
|
+
var_name = var_name.to_s.gsub(/[\?!]/, "")
|
29
|
+
the_stub = stub(var_name.to_s.humanize, options)
|
30
|
+
instance_variable_set("@#{var_name}", the_stub)
|
31
|
+
the_stub
|
32
|
+
end
|
33
|
+
|
34
|
+
def stub_array_instance(ivar_sym, count, label=nil)
|
35
|
+
label ||= ivar_sym.to_s.singularize
|
36
|
+
array = stub_array(count, label)
|
37
|
+
instance_variable_set("@#{ivar_sym}", array)
|
38
|
+
array
|
39
|
+
end
|
40
|
+
|
41
|
+
def stub_array(count, label)
|
42
|
+
array = []
|
43
|
+
1.upto(count) do |i|
|
44
|
+
array << stub("#{label} #{i}")
|
45
|
+
end
|
46
|
+
array
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_instances(*var_names)
|
50
|
+
var_names.map do |var_name|
|
51
|
+
stub_instance var_name
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def stub_params(*param_names)
|
56
|
+
@params = {}
|
57
|
+
param_names.each do |param_name|
|
58
|
+
instance_variable_set("@#{param_name}", "param #{param_name}")
|
59
|
+
@params[param_name.to_s] = "param #{param_name}"
|
60
|
+
end
|
61
|
+
@params
|
62
|
+
end
|
63
|
+
|
64
|
+
def stub_partial(partial, options={})
|
65
|
+
options = _prepare_stub_partial_options(partial, options)
|
66
|
+
template.stub!(:render).with(options).and_return(%|<p id="#{partial.gsub(/\//,'_')}_partial"></p>|)
|
67
|
+
end
|
68
|
+
|
69
|
+
def stub_partials(*partials)
|
70
|
+
partials.each &method(:stub_partial)
|
71
|
+
end
|
72
|
+
|
73
|
+
def stub_string(sym)
|
74
|
+
the_stub = sym.to_s.humanize
|
75
|
+
instance_variable_set("@#{sym}", the_stub)
|
76
|
+
the_stub
|
77
|
+
end
|
78
|
+
|
79
|
+
def stub_strings(*syms)
|
80
|
+
syms.each &method(:stub_string)
|
81
|
+
end
|
82
|
+
|
83
|
+
def stub_for_view(name, field_names)
|
84
|
+
the_stub = stub_instance(name)
|
85
|
+
_stub_methods_for_view(the_stub, field_names)
|
86
|
+
the_stub
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def expect_and_render_partial(partial,options={})
|
92
|
+
options = _prepare_stub_partial_options(partial, options)
|
93
|
+
template.should_receive(:render).with(options).and_return(%|<p id="#{partial.gsub(/\//,'_')}_partial"></p>|)
|
94
|
+
end
|
95
|
+
|
96
|
+
def _stub_methods_for_view(the_stub, field_names)
|
97
|
+
field_names.each do |fname|
|
98
|
+
case fname
|
99
|
+
when String, Symbol
|
100
|
+
field_name = fname.to_sym
|
101
|
+
field_value = block_given? ? yield(fname) : "The #{fname.to_s.humanize}"
|
102
|
+
the_stub.stub!(field_name).and_return(field_value)
|
103
|
+
when Hash
|
104
|
+
fname.each do |k,v|
|
105
|
+
the_stub.stub!(k.to_sym).and_return(v)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def _prepare_stub_partial_options(partial, options)
|
112
|
+
options.reverse_merge!(:partial => partial)
|
113
|
+
if options[:locals] == false
|
114
|
+
options.delete(:locals)
|
115
|
+
else
|
116
|
+
options.reverse_merge!(:locals => anything)
|
117
|
+
end
|
118
|
+
options
|
119
|
+
end
|
120
|
+
|
121
|
+
def stub_array_for_view(count, name_base, field_names)
|
122
|
+
the_array = []
|
123
|
+
count.times do |i|
|
124
|
+
i = i + 1 # one-based numbering
|
125
|
+
name = "#{name_base.to_s.singularize}#{i}"
|
126
|
+
the_stub = stub_instance(name)
|
127
|
+
_stub_methods_for_view(the_stub, field_names) do |fname|
|
128
|
+
"The #{fname.to_s.humanize} #{i}"
|
129
|
+
end
|
130
|
+
the_array << the_stub
|
131
|
+
end
|
132
|
+
instance_variable_set("@#{name_base}", the_array)
|
133
|
+
the_array
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
class NilClass
|
140
|
+
# Mocha:
|
141
|
+
|
142
|
+
def expects(*args)
|
143
|
+
raise "Don't expects(#{args.inspect}) on nil"
|
144
|
+
end
|
145
|
+
|
146
|
+
def stubs(*args)
|
147
|
+
raise "Don't stubs(#{args.inspect}) on nil"
|
148
|
+
end
|
149
|
+
|
150
|
+
# RSpec mocks:
|
151
|
+
#
|
152
|
+
def stub!(*args)
|
153
|
+
raise "Don't stub! on nil."
|
154
|
+
end
|
155
|
+
|
156
|
+
def should_receive(*args)
|
157
|
+
raise "Don't should_receive on nil."
|
158
|
+
end
|
159
|
+
|
160
|
+
def should_not_receive(*args)
|
161
|
+
raise "Don't should_not_receive on nil."
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: environment_configurable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Atomic Object
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-15 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.0
|
24
|
+
version:
|
25
|
+
description: A library that makes environment dependent configuration easy in rails.
|
26
|
+
email: github@atomicobject.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- Rakefile
|
37
|
+
- lib/environment_configurable.rb
|
38
|
+
- README.md
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/atomicobject/environment_configurable
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A library that makes environment dependent configuration easy in rails.
|
67
|
+
test_files:
|
68
|
+
- spec/environment_configurable_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- spec/stub_rails/app/controllers/application_controller.rb
|
71
|
+
- spec/stub_rails/app/helpers/application_helper.rb
|
72
|
+
- spec/stub_rails/config/boot.rb
|
73
|
+
- spec/stub_rails/config/environment.rb
|
74
|
+
- spec/stub_rails/config/environments/development.rb
|
75
|
+
- spec/stub_rails/config/environments/production.rb
|
76
|
+
- spec/stub_rails/config/environments/test.rb
|
77
|
+
- spec/stub_rails/config/initializers/backtrace_silencers.rb
|
78
|
+
- spec/stub_rails/config/initializers/inflections.rb
|
79
|
+
- spec/stub_rails/config/initializers/mime_types.rb
|
80
|
+
- spec/stub_rails/config/initializers/new_rails_defaults.rb
|
81
|
+
- spec/stub_rails/config/initializers/session_store.rb
|
82
|
+
- spec/stub_rails/config/routes.rb
|
83
|
+
- spec/stub_rails/db/seeds.rb
|
84
|
+
- spec/stub_rails/test/performance/browsing_test.rb
|
85
|
+
- spec/stub_rails/test/test_helper.rb
|
86
|
+
- spec/support/stub_helpers.rb
|