storey 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +83 -0
- data/Rakefile +7 -0
- data/lib/storey/duplicator.rb +61 -0
- data/lib/storey/exceptions.rb +6 -0
- data/lib/storey/migrator.rb +28 -0
- data/lib/storey/railtie.rb +47 -0
- data/lib/storey/version.rb +3 -0
- data/lib/storey.rb +161 -0
- data/lib/tasks/storey.rake +57 -0
- data/spec/config/database.yml.sample +6 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/company.rb +2 -0
- data/spec/dummy/app/models/fake.rb +2 -0
- data/spec/dummy/app/models/post.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml.sample +6 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20120115060713_create_companies.rb +8 -0
- data/spec/dummy/db/migrate/20120115060728_create_posts.rb +8 -0
- data/spec/dummy/db/schema.rb +25 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/fixtures/.gitkeep +0 -0
- data/spec/migrator_spec.rb +63 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/storey/configuration_spec.rb +13 -0
- data/spec/storey/create_spec.rb +87 -0
- data/spec/storey/drop_spec.rb +31 -0
- data/spec/storey/duplicate_spec.rb +49 -0
- data/spec/storey/excluded_models_spec.rb +15 -0
- data/spec/storey/schema_spec.rb +31 -0
- data/spec/storey/schemas_spec.rb +51 -0
- data/spec/storey/switch_spec.rb +102 -0
- data/spec/tasks/storey_rake_spec.rb +106 -0
- data/storey.gemspec +27 -0
- metadata +204 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
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.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
+
config.serve_static_assets = false
|
13
|
+
|
14
|
+
# Compress JavaScripts and CSS
|
15
|
+
config.assets.compress = true
|
16
|
+
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to Rails.root.join("public/assets")
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
26
|
+
# Specifies the header that your server uses for sending files
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
+
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
+
# config.force_ssl = true
|
32
|
+
|
33
|
+
# See everything in the log (default is :info)
|
34
|
+
# config.log_level = :debug
|
35
|
+
|
36
|
+
# Use a different logger for distributed setups
|
37
|
+
# config.logger = SyslogLogger.new
|
38
|
+
|
39
|
+
# Use a different cache store in production
|
40
|
+
# config.cache_store = :mem_cache_store
|
41
|
+
|
42
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
43
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
44
|
+
|
45
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
46
|
+
# config.assets.precompile += %w( search.js )
|
47
|
+
|
48
|
+
# Disable delivery errors, bad email addresses will be ignored
|
49
|
+
# config.action_mailer.raise_delivery_errors = false
|
50
|
+
|
51
|
+
# Enable threaded mode
|
52
|
+
# config.threadsafe!
|
53
|
+
|
54
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
55
|
+
# the I18n.default_locale when a translation can not be found)
|
56
|
+
config.i18n.fallbacks = true
|
57
|
+
|
58
|
+
# Send deprecation notices to registered listeners
|
59
|
+
config.active_support.deprecation = :notify
|
60
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
33
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
34
|
+
# like if you have constraints or database-specific column types
|
35
|
+
# config.active_record.schema_format = :sql
|
36
|
+
|
37
|
+
# Print deprecation notices to the stderr
|
38
|
+
config.active_support.deprecation = :stderr
|
39
|
+
end
|
@@ -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 to debug a problem that might stem 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,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies 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
|
+
Dummy::Application.config.secret_token = '3c7189c1f30529d45de484bae0827fdb06924842af16ddefa69a11f63286cd745aa5659049f5e4889458c1745770a7bcec7630b42450051cb1cc0b9bc24667d9'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters :format => [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20120115060728) do
|
14
|
+
|
15
|
+
create_table "companies", :force => true do |t|
|
16
|
+
t.string "name"
|
17
|
+
t.string "schema_name"
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table "posts", :force => true do |t|
|
21
|
+
t.string "name"
|
22
|
+
t.text "body"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
File without changes
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey::Migrator do
|
4
|
+
before do
|
5
|
+
@original_schema = ActiveRecord::Base.connection.schema_search_path
|
6
|
+
@schema_1 = "first_schema"
|
7
|
+
Storey.create @schema_1
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#migrate" do
|
11
|
+
it "should connect to new db, then reset when done" do
|
12
|
+
ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(@schema_1).once
|
13
|
+
ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(@original_schema).once
|
14
|
+
Storey::Migrator.migrate(@schema_1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should migrate db" do
|
18
|
+
ActiveRecord::Migrator.should_receive(:migrate)
|
19
|
+
Storey::Migrator.migrate(@schema_1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#run" do
|
24
|
+
before do
|
25
|
+
@migration_version_1 = 20120115060713
|
26
|
+
@migration_version_2 = 20120115060728
|
27
|
+
end
|
28
|
+
|
29
|
+
context "up" do
|
30
|
+
it "should connect to new db, then reset when done" do
|
31
|
+
ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(@schema_1).once
|
32
|
+
ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(@original_schema).once
|
33
|
+
Storey::Migrator.run(:up, @schema_1, @migration_version_2)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should migrate to a version" do
|
37
|
+
ActiveRecord::Migrator.should_receive(:run).with(:up, anything, @migration_version_1)
|
38
|
+
Storey::Migrator.run(:up, @schema_1, @migration_version_1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "down" do
|
43
|
+
it "should connect to new db, then reset when done" do
|
44
|
+
ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(@schema_1).once
|
45
|
+
ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(@original_schema).once
|
46
|
+
Storey::Migrator.run(:down, @schema_1, @migration_version_2)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should migrate to a version" do
|
50
|
+
ActiveRecord::Migrator.should_receive(:run).with(:down, anything, @migration_version_1)
|
51
|
+
Storey::Migrator.run(:down, @schema_1, @migration_version_1)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#rollback" do
|
56
|
+
it "should rollback the db" do
|
57
|
+
@steps = 2
|
58
|
+
ActiveRecord::Migrator.should_receive(:rollback).with(anything, @steps)
|
59
|
+
Storey::Migrator.rollback(@schema_1, @steps)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
|
6
|
+
# So we can clean the database before each test
|
7
|
+
require 'database_cleaner'
|
8
|
+
|
9
|
+
# Include rake so we can instantiate the @rake variable and call rake tasks
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'ruby-debug'
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.before(:each) do
|
16
|
+
# We don't want configuration to leak into other tests
|
17
|
+
Storey.reload_config!
|
18
|
+
|
19
|
+
# Always switch back to the default search path
|
20
|
+
# Some tests that didn't switch back broke the following tests
|
21
|
+
Storey.switch
|
22
|
+
|
23
|
+
# Delete all schemas except public
|
24
|
+
Storey.schemas(:public => false, :suffix => true).each do |schema|
|
25
|
+
Storey.drop schema
|
26
|
+
end
|
27
|
+
|
28
|
+
# How to call rake from within your app:
|
29
|
+
# http://www.philsergi.com/2009/02/testing-rake-tasks-with-rspec.html
|
30
|
+
@rake = Rake::Application.new
|
31
|
+
Rake.application = @rake
|
32
|
+
Dummy::Application.load_tasks
|
33
|
+
|
34
|
+
# It seems when instantiating our own rake object, misc.rake
|
35
|
+
# isn't loaded. We get the following error if we don't load misc.rake:
|
36
|
+
# RuntimeError: Don't know how to build task 'rails_env'
|
37
|
+
load "rails/tasks/misc.rake"
|
38
|
+
|
39
|
+
# we don't want any test that has set this to keep it hanging around
|
40
|
+
# screwing with our migration
|
41
|
+
ENV['STEP'] = ENV['VERSION'] = nil
|
42
|
+
@rake["db:migrate"].invoke
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Load support files
|
47
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey, "configuration" do
|
4
|
+
it "should allow setting of suffix" do
|
5
|
+
Storey.suffix = "_hello"
|
6
|
+
Storey.suffix.should == "_hello"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should allow setting of excluded_models" do
|
10
|
+
Storey.excluded_models = %w(Company)
|
11
|
+
Storey.excluded_models.should == %w(Company)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey, "#create" do
|
4
|
+
it "should load the schema.rb into the new schema" do
|
5
|
+
public_tables = Storey.switch { ActiveRecord::Base.connection.tables }.sort
|
6
|
+
Storey.create "foobar" do
|
7
|
+
foobar_tables = ActiveRecord::Base.connection.tables.sort
|
8
|
+
foobar_tables.should == public_tables
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should copy the schema_migrations over" do
|
13
|
+
Storey.create "foobar"
|
14
|
+
public_schema_migrations = Storey.switch { ActiveRecord::Migrator.get_all_versions }
|
15
|
+
Storey.switch "foobar" do
|
16
|
+
ActiveRecord::Migrator.get_all_versions.should == public_schema_migrations
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context ":load_database_schema => false" do
|
21
|
+
it "should not load the schema.rb" do
|
22
|
+
Storey.should_not_receive(:load_database_schema)
|
23
|
+
Storey.create "foobar", :load_database_schema => false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when no string is passed" do
|
28
|
+
it "should raise argument error" do
|
29
|
+
expect {Storey.create}.to raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when a blank string is passed" do
|
34
|
+
it "should raise an argument error about an invalid schema name" do
|
35
|
+
expect {Storey.create ""}.to raise_error(ArgumentError, "Must pass in a valid schema name")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when suffix is set" do
|
40
|
+
before do
|
41
|
+
Storey.suffix = "_rock"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create a schema with the suffix" do
|
45
|
+
Storey.create "foobar"
|
46
|
+
Storey.schemas(:suffix => true).should include("foobar_rock")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when suffix is not set" do
|
51
|
+
it "should create a schema without a suffix" do
|
52
|
+
Storey.create "foobar"
|
53
|
+
Storey.schemas.should include("foobar")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the schema already exists" do
|
58
|
+
it "should raise an error" do
|
59
|
+
Storey.create "foobar"
|
60
|
+
expect {
|
61
|
+
Storey.create "foobar"
|
62
|
+
}.to raise_error(Storey::SchemaExists, %{The schema "foobar" already exists.})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when a block is passed" do
|
67
|
+
it "should create the schema and execute that block in the newly created schema's context" do
|
68
|
+
Storey.create "foo" do
|
69
|
+
Post.create :name => "Hello"
|
70
|
+
end
|
71
|
+
|
72
|
+
Post.count.should be_zero
|
73
|
+
|
74
|
+
Storey.switch "foo" do
|
75
|
+
Post.count.should == 1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when creating a record in a table that doesn't exist" do
|
80
|
+
it "should re-raise the original error" do
|
81
|
+
Storey.create "foo" do
|
82
|
+
expect {Fake.create}.to raise_error(ActiveRecord::StatementInvalid)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey, "#drop" do
|
4
|
+
context "when suffix is set" do
|
5
|
+
before do
|
6
|
+
Storey.suffix = "bar"
|
7
|
+
Storey.create "foo"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should drop the schema with the suffix" do
|
11
|
+
Storey.drop "foo"
|
12
|
+
Storey.schemas.should_not include("foo")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when suffix is not set" do
|
17
|
+
it "should drop the schema without the suffix" do
|
18
|
+
Storey.create "foobar"
|
19
|
+
Storey.drop "foobar"
|
20
|
+
Storey.schemas.should_not include("foobar")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the schema does not exist" do
|
25
|
+
it "should raise an error" do
|
26
|
+
expect {
|
27
|
+
Storey.drop "foobar"
|
28
|
+
}.to raise_error(Storey::SchemaNotFound, %{The schema "foobar" cannot be found.})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey, "#duplicate!" do
|
4
|
+
before do
|
5
|
+
# Always clear the tmp file of the Rails app
|
6
|
+
FileUtils.rm_rf(Storey::Duplicator::DUMP_PATH)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when there's no suffix set" do
|
10
|
+
before do
|
11
|
+
Storey.create 'ricky' do
|
12
|
+
Post.create :name => "Hi"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should create a schema with the same data under a new name" do
|
17
|
+
Storey.duplicate! 'ricky', 'bobby'
|
18
|
+
Storey.schemas.should include('bobby')
|
19
|
+
Storey.switch 'bobby' do
|
20
|
+
Post.count.should == 1
|
21
|
+
Post.find_by_name("Hi").should_not be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should clear the PGPASSWORD environment variable" do
|
27
|
+
Storey.create 'ricky'
|
28
|
+
Storey.duplicate! 'ricky', 'bobby'
|
29
|
+
ENV['PGPASSWORD'].should be_blank
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when a suffix is set" do
|
33
|
+
before do
|
34
|
+
Storey.suffix = "_shakenbake"
|
35
|
+
Storey.create 'ricky' do
|
36
|
+
Post.create :name => "Hi"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should create a schema with the suffix" do
|
41
|
+
Storey.duplicate! "ricky", "bobby"
|
42
|
+
Storey.schemas(:suffix => true).should include("bobby_shakenbake")
|
43
|
+
Storey.switch 'bobby' do
|
44
|
+
Post.count.should == 1
|
45
|
+
Post.find_by_name("Hi").should_not be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey, "dealing with excluded_models" do
|
4
|
+
before do
|
5
|
+
Storey.excluded_models = %w(Company)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should always reference these models in the public schema" do
|
9
|
+
Storey.create("foo") { Company.create :name => "company_1" }
|
10
|
+
Company.create :name => "company_2"
|
11
|
+
|
12
|
+
Company.count.should == 2
|
13
|
+
Storey.switch("foo") {Company.count.should == 2}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Storey, "#schema" do
|
4
|
+
it "should return the current schema" do
|
5
|
+
Storey.schema.should == %{"$user",public}
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when a suffix is set" do
|
9
|
+
before do
|
10
|
+
Storey.suffix = "_rock"
|
11
|
+
Storey.create "hello"
|
12
|
+
Storey.switch "hello"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return the schema without the suffix by default" do
|
16
|
+
Storey.schema.should == "hello"
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when :suffix => true" do
|
20
|
+
it "should return the schema with the suffix" do
|
21
|
+
Storey.schema(:suffix => true).should include("hello_rock")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when :suffix => false" do
|
26
|
+
it "should return the schema without the suffix" do
|
27
|
+
Storey.schema(:suffix => false).should include("hello")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|