thirdbase 2.1.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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +24 -0
- data/.yardopts +1 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +37 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +191 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/gemfiles/rails40.gemfile +8 -0
- data/gemfiles/rails41.gemfile +8 -0
- data/gemfiles/rails42.gemfile +8 -0
- data/gemfiles/rails50.gemfile +8 -0
- data/lib/rails/second_base/generators/migration_generator.rb +25 -0
- data/lib/third_base.rb +20 -0
- data/lib/third_base/base.rb +8 -0
- data/lib/third_base/databases.rake +121 -0
- data/lib/third_base/databases_rails_five.rake +22 -0
- data/lib/third_base/databases_rails_four.rake +22 -0
- data/lib/third_base/forced.rb +21 -0
- data/lib/third_base/on_base.rb +36 -0
- data/lib/third_base/railtie.rb +52 -0
- data/lib/third_base/test_help.rb +11 -0
- data/lib/third_base/version.rb +3 -0
- data/lib/thirdbase.rb +1 -0
- data/test/cases/dbtask_test.rb +248 -0
- data/test/cases/forced_test.rb +49 -0
- data/test/cases/generator_test.rb +64 -0
- data/test/cases/on_base_test.rb +35 -0
- data/test/cases/railtie_test.rb +31 -0
- data/test/cases/rake_test.rb +0 -0
- data/test/dummy_apps/rails_five/Rakefile +2 -0
- data/test/dummy_apps/rails_five/app/controllers/application_controller.rb +7 -0
- data/test/dummy_apps/rails_five/app/helpers/application_helper.rb +3 -0
- data/test/dummy_apps/rails_five/app/models/application_record.rb +3 -0
- data/test/dummy_apps/rails_five/app/models/comment.rb +6 -0
- data/test/dummy_apps/rails_five/app/models/comment_forced.rb +6 -0
- data/test/dummy_apps/rails_five/app/models/post.rb +7 -0
- data/test/dummy_apps/rails_five/app/models/user.rb +6 -0
- data/test/dummy_apps/rails_five/bin/rails +5 -0
- data/test/dummy_apps/rails_five/config/database.yml +13 -0
- data/test/dummy_apps/rails_five/config/routes.rb +3 -0
- data/test/dummy_apps/rails_five/db/migrate/20141209165002_create_users.rb +11 -0
- data/test/dummy_apps/rails_five/db/migrate/20141214142700_create_posts.rb +12 -0
- data/test/dummy_apps/rails_five/db/secondbase/migrate/20151202075826_create_comments.rb +11 -0
- data/test/dummy_apps/rails_five/init.rb +42 -0
- data/test/dummy_apps/rails_five/log/.keep +0 -0
- data/test/dummy_apps/rails_five/tmp/.keep +0 -0
- data/test/dummy_apps/rails_four/Rakefile +2 -0
- data/test/dummy_apps/rails_four/app/controllers/application_controller.rb +7 -0
- data/test/dummy_apps/rails_four/app/helpers/application_helper.rb +3 -0
- data/test/dummy_apps/rails_four/app/models/comment.rb +6 -0
- data/test/dummy_apps/rails_four/app/models/comment_forced.rb +6 -0
- data/test/dummy_apps/rails_four/app/models/post.rb +7 -0
- data/test/dummy_apps/rails_four/app/models/user.rb +6 -0
- data/test/dummy_apps/rails_four/bin/rails +5 -0
- data/test/dummy_apps/rails_four/config/database.yml +14 -0
- data/test/dummy_apps/rails_four/config/routes.rb +3 -0
- data/test/dummy_apps/rails_four/db/migrate/20141209165002_create_users.rb +11 -0
- data/test/dummy_apps/rails_four/db/migrate/20141214142700_create_posts.rb +12 -0
- data/test/dummy_apps/rails_four/db/secondbase/migrate/20151202075826_create_comments.rb +11 -0
- data/test/dummy_apps/rails_four/init.rb +42 -0
- data/test/dummy_apps/rails_four/log/.keep +0 -0
- data/test/dummy_apps/rails_four/tmp/.keep +0 -0
- data/test/test_helper.rb +46 -0
- data/test/test_helpers/dummy_app_helpers.rb +94 -0
- data/test/test_helpers/rails_version_helpers.rb +29 -0
- data/test/test_helpers/stream_helpers.rb +40 -0
- data/thirdbase.gemspec +25 -0
- metadata +247 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ForcedTest < ThirdBase::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
run_db :create
|
7
|
+
run_db :migrate
|
8
|
+
establish_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_shared_pool
|
12
|
+
assert_equal ThirdBase::Base.connection_pool.object_id,
|
13
|
+
CommentForced.connection_pool.object_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_shared_connection
|
17
|
+
assert_equal ThirdBase::Base.connection.raw_connection.object_id,
|
18
|
+
CommentForced.connection.raw_connection.object_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_shared_new_connection_in_a_different_thread
|
22
|
+
current_base_connection_id = ThirdBase::Base.connection.raw_connection.object_id
|
23
|
+
new_base_connection_id, new_forced_connection_id = Thread.new {
|
24
|
+
[ ThirdBase::Base.connection.raw_connection.object_id,
|
25
|
+
CommentForced.connection.raw_connection.object_id ]
|
26
|
+
}.value
|
27
|
+
refute_equal new_base_connection_id, current_base_connection_id
|
28
|
+
assert_equal new_base_connection_id, new_forced_connection_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_shared_connected_query
|
32
|
+
assert ThirdBase::Base.connected?
|
33
|
+
assert CommentForced.connected?
|
34
|
+
CommentForced.clear_all_connections!
|
35
|
+
refute ThirdBase::Base.connected?
|
36
|
+
refute CommentForced.connected?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_can_remove_connection_properly
|
40
|
+
base_connection = ThirdBase::Base.connection
|
41
|
+
forced_connection = CommentForced.connection
|
42
|
+
assert base_connection.active?
|
43
|
+
assert forced_connection.active?
|
44
|
+
CommentForced.remove_connection
|
45
|
+
refute base_connection.active?
|
46
|
+
refute forced_connection.active?
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GeneratorTest < ThirdBase::TestCase
|
4
|
+
|
5
|
+
teardown do
|
6
|
+
generated_migration_delete
|
7
|
+
generated_migration_base_delete
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialization_via_help
|
11
|
+
output = Dir.chdir(dummy_root) { `rails g -h` }
|
12
|
+
assert_match(/third_base\:migration/, output)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_description_uses_rails_base
|
16
|
+
output = Dir.chdir(dummy_root) { `rails g third_base:migration -h` }
|
17
|
+
assert_match %r{db/migrate/20080514090912_add_ssl_flag\.rb}, output
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_migration
|
21
|
+
output = Dir.chdir(dummy_root) { `rails g third_base:migration CreateFavorites post_id:integer count:integer` }
|
22
|
+
assert_match %r{create.*db/thirdbase/migrate/.*create_favorites\.rb}, output
|
23
|
+
migration = generated_migration_data
|
24
|
+
assert_match %r{create_table :favorites}, migration
|
25
|
+
assert_match %r{t.integer :post_id}, migration
|
26
|
+
assert_match %r{t.integer :count}, migration
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_base_migration_generator
|
30
|
+
output = Dir.chdir(dummy_root) { `rails g migration AddBaseColumn` }
|
31
|
+
assert_match %r{create.*db/migrate/.*add_base_column\.rb}, output
|
32
|
+
migration = generated_migration_base_data
|
33
|
+
assert_match %r{class AddBaseColumn}, migration
|
34
|
+
assert_match %r{def change}, migration
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def generated_migration
|
41
|
+
Dir["#{dummy_db}/thirdbase/migrate/*favorites.{rb}"].first
|
42
|
+
end
|
43
|
+
|
44
|
+
def generated_migration_data
|
45
|
+
generated_migration ? File.read(generated_migration) : ''
|
46
|
+
end
|
47
|
+
|
48
|
+
def generated_migration_delete
|
49
|
+
FileUtils.rm_rf(generated_migration) if generated_migration
|
50
|
+
end
|
51
|
+
|
52
|
+
def generated_migration_base
|
53
|
+
Dir["#{dummy_db}/migrate/*add_base*.{rb}"].first
|
54
|
+
end
|
55
|
+
|
56
|
+
def generated_migration_base_data
|
57
|
+
generated_migration_base ? File.read(generated_migration_base) : ''
|
58
|
+
end
|
59
|
+
|
60
|
+
def generated_migration_base_delete
|
61
|
+
FileUtils.rm_rf(generated_migration_base) if generated_migration_base
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OnBaseTest < ThirdBase::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
run_db :create
|
7
|
+
run_db :migrate
|
8
|
+
establish_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_on_base
|
12
|
+
refute ThirdBase.is_on_base
|
13
|
+
ThirdBase.on_base do
|
14
|
+
assert ThirdBase.is_on_base
|
15
|
+
assert_equal ThirdBase::Base.connection.class, ActiveRecord::Base.connection.class
|
16
|
+
assert_equal [ThirdBase::Railtie.fullpath('migrate')], ActiveRecord::Tasks::DatabaseTasks.migrations_paths
|
17
|
+
assert_equal ThirdBase::Railtie.fullpath, ActiveRecord::Tasks::DatabaseTasks.db_dir
|
18
|
+
end
|
19
|
+
refute ThirdBase.is_on_base
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_on_base_nested
|
23
|
+
refute ThirdBase.is_on_base
|
24
|
+
ThirdBase.on_base do
|
25
|
+
assert ThirdBase.is_on_base
|
26
|
+
ThirdBase.on_base do
|
27
|
+
assert ThirdBase.is_on_base
|
28
|
+
end
|
29
|
+
assert ThirdBase.is_on_base
|
30
|
+
end
|
31
|
+
refute ThirdBase.is_on_base
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RailtieTest < ThirdBase::TestCase
|
4
|
+
|
5
|
+
def test_config
|
6
|
+
expected_path = 'db/thirdbase'
|
7
|
+
assert_equal expected_path, railtie_inst.config.third_base.path
|
8
|
+
assert_equal expected_path, railtie_klass.config.third_base.path
|
9
|
+
expected_config_key = 'thirdbase'
|
10
|
+
assert_equal expected_config_key, railtie_inst.config.third_base.config_key
|
11
|
+
assert_equal expected_config_key, railtie_klass.config.third_base.config_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_fullpath
|
15
|
+
expected = dummy_db.join('thirdbase').to_s
|
16
|
+
assert_equal expected, railtie_inst.fullpath
|
17
|
+
assert_equal expected, railtie_klass.fullpath
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def railtie_inst
|
24
|
+
dummy_app.railties.grep(railtie_klass).first
|
25
|
+
end
|
26
|
+
|
27
|
+
def railtie_klass
|
28
|
+
ThirdBase::Railtie
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __FILE__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rails/all'
|
5
|
+
Bundler.require(:default, Rails.env)
|
6
|
+
|
7
|
+
module Dummy
|
8
|
+
class Application < ::Rails::Application
|
9
|
+
|
10
|
+
# Basic Engine
|
11
|
+
config.root = File.join __FILE__, '..'
|
12
|
+
config.cache_store = :memory_store
|
13
|
+
config.assets.enabled = false
|
14
|
+
config.secret_token = '012345678901234567890123456789'
|
15
|
+
config.active_support.test_order = :random
|
16
|
+
|
17
|
+
# Mimic Test Environment Config.
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
config.action_dispatch.show_exceptions = false
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
config.action_mailer.delivery_method = :test
|
23
|
+
config.active_support.deprecation = :stderr
|
24
|
+
config.allow_concurrency = true
|
25
|
+
config.cache_classes = true
|
26
|
+
config.dependency_loading = true
|
27
|
+
config.preload_frameworks = true
|
28
|
+
config.eager_load = true
|
29
|
+
config.secret_key_base = '012345678901234567890123456789'
|
30
|
+
|
31
|
+
# Keep pending test:prepare via pending migrations from running.
|
32
|
+
config.active_record.maintain_test_schema = false if ActiveRecord::Base.respond_to?(:maintain_test_schema)
|
33
|
+
|
34
|
+
config.active_record.schema_format = ENV['SCHEMA_FORMAT'] ? :sql : :ruby
|
35
|
+
|
36
|
+
if ENV['WITH_SECONDBASE_TASKS'].present?
|
37
|
+
config.third_base.run_with_db_tasks = ENV['WITH_SECONDBASE_TASKS'] == 'true'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Dummy::Application.initialize!
|
File without changes
|
File without changes
|