fourthbase 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +24 -0
  4. data/.yardopts +1 -0
  5. data/Appraisals +19 -0
  6. data/CHANGELOG.md +37 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +191 -0
  10. data/Rakefile +24 -0
  11. data/VERSION +1 -0
  12. data/fourthbase.gemspec +25 -0
  13. data/gemfiles/rails40.gemfile +8 -0
  14. data/gemfiles/rails41.gemfile +8 -0
  15. data/gemfiles/rails42.gemfile +8 -0
  16. data/gemfiles/rails50.gemfile +8 -0
  17. data/lib/fourth_base.rb +20 -0
  18. data/lib/fourth_base/base.rb +8 -0
  19. data/lib/fourth_base/databases.rake +121 -0
  20. data/lib/fourth_base/databases_rails_five.rake +22 -0
  21. data/lib/fourth_base/databases_rails_four.rake +22 -0
  22. data/lib/fourth_base/forced.rb +21 -0
  23. data/lib/fourth_base/on_base.rb +36 -0
  24. data/lib/fourth_base/railtie.rb +52 -0
  25. data/lib/fourth_base/test_help.rb +11 -0
  26. data/lib/fourth_base/version.rb +3 -0
  27. data/lib/fourthbase.rb +1 -0
  28. data/lib/rails/fourth_base/generators/migration_generator.rb +25 -0
  29. data/test/cases/dbtask_test.rb +248 -0
  30. data/test/cases/forced_test.rb +49 -0
  31. data/test/cases/generator_test.rb +64 -0
  32. data/test/cases/on_base_test.rb +35 -0
  33. data/test/cases/railtie_test.rb +31 -0
  34. data/test/cases/rake_test.rb +0 -0
  35. data/test/dummy_apps/rails_five/Rakefile +2 -0
  36. data/test/dummy_apps/rails_five/app/controllers/application_controller.rb +7 -0
  37. data/test/dummy_apps/rails_five/app/helpers/application_helper.rb +3 -0
  38. data/test/dummy_apps/rails_five/app/models/application_record.rb +3 -0
  39. data/test/dummy_apps/rails_five/app/models/comment.rb +6 -0
  40. data/test/dummy_apps/rails_five/app/models/comment_forced.rb +6 -0
  41. data/test/dummy_apps/rails_five/app/models/post.rb +7 -0
  42. data/test/dummy_apps/rails_five/app/models/user.rb +6 -0
  43. data/test/dummy_apps/rails_five/bin/rails +5 -0
  44. data/test/dummy_apps/rails_five/config/database.yml +13 -0
  45. data/test/dummy_apps/rails_five/config/routes.rb +3 -0
  46. data/test/dummy_apps/rails_five/db/migrate/20141209165002_create_users.rb +11 -0
  47. data/test/dummy_apps/rails_five/db/migrate/20141214142700_create_posts.rb +12 -0
  48. data/test/dummy_apps/rails_five/db/secondbase/migrate/20151202075826_create_comments.rb +11 -0
  49. data/test/dummy_apps/rails_five/init.rb +42 -0
  50. data/test/dummy_apps/rails_five/log/.keep +0 -0
  51. data/test/dummy_apps/rails_five/tmp/.keep +0 -0
  52. data/test/dummy_apps/rails_four/Rakefile +2 -0
  53. data/test/dummy_apps/rails_four/app/controllers/application_controller.rb +7 -0
  54. data/test/dummy_apps/rails_four/app/helpers/application_helper.rb +3 -0
  55. data/test/dummy_apps/rails_four/app/models/comment.rb +6 -0
  56. data/test/dummy_apps/rails_four/app/models/comment_forced.rb +6 -0
  57. data/test/dummy_apps/rails_four/app/models/post.rb +7 -0
  58. data/test/dummy_apps/rails_four/app/models/user.rb +6 -0
  59. data/test/dummy_apps/rails_four/bin/rails +5 -0
  60. data/test/dummy_apps/rails_four/config/database.yml +14 -0
  61. data/test/dummy_apps/rails_four/config/routes.rb +3 -0
  62. data/test/dummy_apps/rails_four/db/migrate/20141209165002_create_users.rb +11 -0
  63. data/test/dummy_apps/rails_four/db/migrate/20141214142700_create_posts.rb +12 -0
  64. data/test/dummy_apps/rails_four/db/secondbase/migrate/20151202075826_create_comments.rb +11 -0
  65. data/test/dummy_apps/rails_four/init.rb +42 -0
  66. data/test/dummy_apps/rails_four/log/.keep +0 -0
  67. data/test/dummy_apps/rails_four/tmp/.keep +0 -0
  68. data/test/test_helper.rb +46 -0
  69. data/test/test_helpers/dummy_app_helpers.rb +94 -0
  70. data/test/test_helpers/rails_version_helpers.rb +29 -0
  71. data/test/test_helpers/stream_helpers.rb +40 -0
  72. data/thirdbase-2.1.1.gem +0 -0
  73. data/thirdbase-2.1.2.gem +0 -0
  74. metadata +206 -0
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class ForcedTest < FourthBase::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 FourthBase::Base.connection_pool.object_id,
13
+ CommentForced.connection_pool.object_id
14
+ end
15
+
16
+ def test_shared_connection
17
+ assert_equal FourthBase::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 = FourthBase::Base.connection.raw_connection.object_id
23
+ new_base_connection_id, new_forced_connection_id = Thread.new {
24
+ [ FourthBase::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 FourthBase::Base.connected?
33
+ assert CommentForced.connected?
34
+ CommentForced.clear_all_connections!
35
+ refute FourthBase::Base.connected?
36
+ refute CommentForced.connected?
37
+ end
38
+
39
+ def test_can_remove_connection_properly
40
+ base_connection = FourthBase::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 < FourthBase::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(/fourth_base\:migration/, output)
13
+ end
14
+
15
+ def test_description_uses_rails_base
16
+ output = Dir.chdir(dummy_root) { `rails g fourth_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 fourth_base:migration CreateFavorites post_id:integer count:integer` }
22
+ assert_match %r{create.*db/fourthbase/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}/fourthbase/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 < FourthBase::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 FourthBase.is_on_base
13
+ FourthBase.on_base do
14
+ assert FourthBase.is_on_base
15
+ assert_equal FourthBase::Base.connection.class, ActiveRecord::Base.connection.class
16
+ assert_equal [FourthBase::Railtie.fullpath('migrate')], ActiveRecord::Tasks::DatabaseTasks.migrations_paths
17
+ assert_equal FourthBase::Railtie.fullpath, ActiveRecord::Tasks::DatabaseTasks.db_dir
18
+ end
19
+ refute FourthBase.is_on_base
20
+ end
21
+
22
+ def test_on_base_nested
23
+ refute FourthBase.is_on_base
24
+ FourthBase.on_base do
25
+ assert FourthBase.is_on_base
26
+ FourthBase.on_base do
27
+ assert FourthBase.is_on_base
28
+ end
29
+ assert FourthBase.is_on_base
30
+ end
31
+ refute FourthBase.is_on_base
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class RailtieTest < FourthBase::TestCase
4
+
5
+ def test_config
6
+ expected_path = 'db/fourthbase'
7
+ assert_equal expected_path, railtie_inst.config.fourth_base.path
8
+ assert_equal expected_path, railtie_klass.config.fourth_base.path
9
+ expected_config_key = 'fourthbase'
10
+ assert_equal expected_config_key, railtie_inst.config.fourth_base.config_key
11
+ assert_equal expected_config_key, railtie_klass.config.fourth_base.config_key
12
+ end
13
+
14
+ def test_fullpath
15
+ expected = dummy_db.join('fourthbase').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
+ FourthBase::Railtie
29
+ end
30
+
31
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ require File.expand_path '../init', __FILE__
2
+ Dummy::Application.load_tasks
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ def index
4
+ render :html => '<h1>Dummy::Application</h1>'.html_safe, :layout => false
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module ApplicationHelper
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,6 @@
1
+ class Comment < FourthBase::Base
2
+
3
+ belongs_to :user
4
+
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ class CommentForced < ApplicationRecord
2
+ self.table_name = 'comments'
3
+ belongs_to :user
4
+ end
5
+
6
+ CommentForced.extend FourthBase::Forced
@@ -0,0 +1,7 @@
1
+ class Post < ApplicationRecord
2
+
3
+ belongs_to :user
4
+ has_many :comments
5
+
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ class User < ApplicationRecord
2
+
3
+ has_many :posts
4
+
5
+
6
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_PATH = File.expand_path('../../init', __FILE__)
4
+ require APP_PATH
5
+ require 'rails/commands'
@@ -0,0 +1,13 @@
1
+
2
+ test:
3
+ adapter: sqlite3
4
+ database: ./db/base.sqlite3
5
+
6
+ fourthbase:
7
+
8
+ test:
9
+ adapter: mysql2
10
+ database: 'fourthbase_test'
11
+ username: root
12
+ password:
13
+ host: localhost
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do
2
+ root :to => 'application#index'
3
+ end
@@ -0,0 +1,11 @@
1
+ class CreateUsers < ActiveRecord::Migration[4.2]
2
+
3
+ def change
4
+ create_table :users, force: true do |t|
5
+ t.string :name
6
+ t.string :email
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePosts < ActiveRecord::Migration[4.2]
2
+
3
+ def change
4
+ create_table :posts, force: true do |t|
5
+ t.text :title
6
+ t.text :body
7
+ t.references :user, index: true
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateComments < ActiveRecord::Migration[4.2]
2
+
3
+ def change
4
+ create_table :comments, force: true do |t|
5
+ t.text :body
6
+ t.references :user, index: true
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+
11
+ end
@@ -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_FOURTHBASE_TASKS'].present?
37
+ config.fourth_base.run_with_db_tasks = ENV['WITH_FOURTHBASE_TASKS'] == 'true'
38
+ end
39
+ end
40
+ end
41
+
42
+ Dummy::Application.initialize!
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ require File.expand_path '../init', __FILE__
2
+ Dummy::Application.load_tasks
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ def index
4
+ render :html => '<h1>Dummy::Application</h1>'.html_safe, :layout => false
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module ApplicationHelper
2
+
3
+ end
@@ -0,0 +1,6 @@
1
+ class Comment < FourthBase::Base
2
+
3
+ belongs_to :user
4
+
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ class CommentForced < ActiveRecord::Base
2
+ self.table_name = 'comments'
3
+ belongs_to :user
4
+ end
5
+
6
+ CommentForced.extend FourthBase::Forced
@@ -0,0 +1,7 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+ has_many :comments
5
+
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_many :posts
4
+
5
+
6
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_PATH = File.expand_path('../../init', __FILE__)
4
+ require APP_PATH
5
+ require 'rails/commands'
@@ -0,0 +1,14 @@
1
+
2
+ test:
3
+ adapter: sqlite3
4
+ database: ./db/base.sqlite3
5
+
6
+ fourthbase:
7
+
8
+ test:
9
+ adapter: mysql
10
+ database: 'fourthbase_test'
11
+ username: root
12
+ password:
13
+ host: localhost
14
+
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do
2
+ root :to => 'application#index'
3
+ end
@@ -0,0 +1,11 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table :users, force: true do |t|
5
+ t.string :name
6
+ t.string :email
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+
11
+ end