enrar 1.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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTk4NDVmMzQ0OTA1NGM5MWEzYjdlMDVmYzQ4Y2JlMmM5NWExODJlYw==
5
+ data.tar.gz: !binary |-
6
+ ZTJkODMxMzQ0ZTExMzU3Yjg4YzdiYjJhZjQ3YjE2MDMxODVhNDhlYw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MTAzMDcyNTgyNmRlY2Y4YTZkN2MwY2E4YjJiMzBmMjAwNTc5N2NhNmU0NGM4
10
+ MThmYWY2NDgzNzZkYWEyYjAyMjE5MTk0NTdhMDRkNTNkYWJmZWIyYWM4ZThk
11
+ NmQ5YTc4MDU3YWExYTY4MjVjYmE4ZmY5ZDExZTA0MzRkMTBhYmI=
12
+ data.tar.gz: !binary |-
13
+ NTNmYTE2OTEzYWRmOGQyZjRmMmY1N2YwM2Q3OWVhZGRjMTZlNjVlNWUzMGRj
14
+ ZjE5MWEwN2FmMTI1M2E4NWQyYjAyYTQ0NjU2ZTc4ZjdkNGE2M2I1MTliMWQ5
15
+ NTg5NWU3NmQxZjY2Yjg0YjljZGQ1MzEwM2U4ZmE3MTVlMzc1MDg=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ /lib/tasks/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enrar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TJ Taylor
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Enrar
2
+
3
+ Who doesn't love the simplicity of working with Rails and ActiveRecord when you have to touch a database? Unfortunately, there are times that you have to use a database and _don't_ get to work in Rails. This gem tries to make your life a little bit easier by providing a lot of the Rails-y/ActiveRecord goodness without all the Rails.
4
+
5
+ There are a few opinions that Enrar holds onto from Rails that tend to not be a problem, but that you should be aware of:
6
+
7
+ 1. The default location for you database configuration is in PROJECT\_ROOT/config/database.yml. If that's where you've got it, you're all set from the get-go.
8
+ 2. Your migrations will get placed in PROJECT\_ROOT/db/migrate. This is non-negotiable at the moment.
9
+ 3. Your schema.rb will get placed in PROJECT\_ROOT/db. This is also non-negotiable.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'enrar'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install enrar
24
+
25
+ ## Usage
26
+
27
+ After you've added Ernar to your project, add the following lines to your Rakefile:
28
+
29
+ require 'enrar/task'
30
+ Enrar::Task.new
31
+
32
+ Then you can run around almost as if you're in Rails-land.
33
+
34
+ $ rake 'enrar:db:migrations:generate[migration_name]'
35
+ $ # The quotes are necessary if you're in zsh. You can leave them off in you're in bash.
36
+
37
+ $ rake 'enrar:db:migrate'
38
+ $ rake 'enrar:db:version'
39
+
40
+ Additionally, you can use Enrar in your code to manage the ActiveRecord configurations.
41
+
42
+ #!/usr/bin/env ruby
43
+ require 'enrar'
44
+
45
+ Enrar.initialize!
46
+ # From here on out, ActiveRecord::Base is setup with ENRAR_ENV as the environment
47
+ # and ActiveRecord::Base.configurations is defined as expected.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/enrar.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enrar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enrar"
8
+ spec.version = Enrar::VERSION
9
+ spec.authors = ["TJ Taylor"]
10
+ spec.email = ["Thomas_Taylor2@cable.comcast.com"]
11
+ spec.description = %q{No Rails ActiveRecord}
12
+ spec.summary = %q{Primarily for ActiveRecord Migrations outside rails}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "sqlite3"
24
+
25
+ spec.add_dependency 'activerecord', '>= 3.2'
26
+ end
data/lib/enrar.rb ADDED
@@ -0,0 +1,74 @@
1
+ require "enrar/version"
2
+ require 'pathname'
3
+
4
+ require 'active_record'
5
+ require 'active_support/core_ext/string'
6
+
7
+ require 'rake'
8
+
9
+ require 'enrar/db'
10
+ require 'enrar/migrator'
11
+ require 'enrar/migration'
12
+ require 'enrar/schema'
13
+
14
+ module Enrar
15
+ def self.env
16
+ @@env ||= (ENV['ENRAR_ENV'] || 'development')
17
+ end
18
+
19
+ def self.gem_root
20
+ @@gem_root ||= Pathname(File.expand_path('../', __FILE__))
21
+ end
22
+
23
+ def self.db_config
24
+ @@db_config ||= root.join('config', 'database.yml')
25
+ end
26
+
27
+ def self.root=(path)
28
+ @@root = Pathname(path)
29
+ end
30
+
31
+ def self.root
32
+ @@root ||= begin
33
+ root_path = Dir.pwd
34
+
35
+ while not_in_a_project_root?(root_path)
36
+ parent = File.dirname(root_path)
37
+ root_path = parent != root_path && parent
38
+ end
39
+
40
+ root = File.exist?("#{root_path}/#{flag}") ? root_path : nil
41
+ raise "Could not find root path for #{self}" unless root
42
+
43
+ RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ?
44
+ Pathname.new(root).expand_path : Pathname.new(root).realpath
45
+ end
46
+ end
47
+
48
+ def self.not_in_a_project_root?(root_path)
49
+ root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
50
+ end
51
+
52
+ def self.clear_config!
53
+ @@env = nil
54
+ @@root = nil
55
+ @@db_config = nil
56
+ @@rake_tasks = nil
57
+ end
58
+
59
+ # This is a file that designates the top-level of a project
60
+ def self.flag
61
+ 'Gemfile'
62
+ end
63
+
64
+ def self.initialize!
65
+ ActiveRecord::Base.configurations = YAML::load_file(db_config.to_s)
66
+ ActiveRecord::Base.establish_connection ActiveRecord::Base.configurations[env]
67
+ true
68
+ end
69
+
70
+ def self.setup!
71
+ initialize!
72
+ ActiveRecord::Base.connection
73
+ end
74
+ end
data/lib/enrar/db.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'enrar'
2
+
3
+ module Enrar
4
+ class DB
5
+ def create!
6
+ FileUtils.mkdir_p path
7
+ ActiveRecord::Base.connection
8
+ end
9
+
10
+ def path
11
+ Enrar.root.join('db').to_s
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'erb'
2
+
3
+ module Enrar
4
+ class Migration
5
+ attr_reader :migration_class_name
6
+
7
+ def initialize(name)
8
+ @migration_class_name = name.underscore.camelize
9
+ end
10
+
11
+ def generate!
12
+ FileUtils.mkdir_p path.dirname
13
+ File.write(path.to_s, ERB.new(TEMPLATE).result(binding))
14
+ self
15
+ end
16
+
17
+ def path
18
+ Enrar.root.join('db/migrate', filename)
19
+ end
20
+
21
+ def filename
22
+ "#{version}_#{@migration_class_name.underscore}.rb"
23
+ end
24
+
25
+ def version
26
+ @version ||= Time.now.strftime('%Y%m%d%H%M%S%L').to_i
27
+ end
28
+
29
+ TEMPLATE = <<-MIGRATION.strip_heredoc
30
+ class <%= @migration_class_name %> < ActiveRecord::Migration
31
+ def change
32
+ # insert your migration stuffs here
33
+ end
34
+ end
35
+ MIGRATION
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'enrar'
2
+
3
+ module Enrar
4
+ class Migrator
5
+ def initialize(to_version = nil, options = {})
6
+ @verbose = options[:verbose].nil? ? true : options[:verbose]
7
+ @version = to_version
8
+ end
9
+
10
+ def migrate!
11
+ ActiveRecord::Migration.verbose = @verbose
12
+ ActiveRecord::Migrator.migrate migrations_dir, @version
13
+ end
14
+
15
+ def migrations_dir
16
+ Enrar.root.join('db', 'migrate')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ require 'enrar'
2
+
3
+ module Enrar
4
+ class Schema
5
+ def version
6
+ ActiveRecord::Migrator.current_version
7
+ end
8
+ end
9
+ end
data/lib/enrar/task.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'enrar'
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+
5
+ module Enrar
6
+
7
+ # Create the Enrar Rake tasks programmatically.
8
+ # This code was shamelessly stolen and modified from the Rake library.
9
+ class Task < Rake::TaskLib
10
+
11
+ # Name of test task. (default is :enrar)
12
+ attr_accessor :name
13
+
14
+ # The path to your database.yml file. (default is config/database.yml)
15
+ attr_accessor :database_config
16
+
17
+ # Do you want me to be noisy?
18
+ attr_accessor :verbose
19
+
20
+ # Create the Enrar tasks
21
+ def initialize(name=:enrar)
22
+ @name = name
23
+ @database_config = 'config/database.yml'
24
+ @verbose = verbose
25
+ yield self if block_given?
26
+ define
27
+ end
28
+
29
+ # Create the tasks defined by this task lib.
30
+ def define
31
+ desc "Generate a migration (don't forget to pass the migration name)"
32
+ task "#{@name}:migrations:generate", [:name] do |t, args|
33
+ raise 'Need a migration name' unless args[:name]
34
+ Enrar::Migration.new(args[:name]).generate!
35
+ end
36
+
37
+ desc "Create the db"
38
+ task "#{@name}:db:create" do
39
+ Enrar::DB.new.create!
40
+ end
41
+
42
+ desc "Migrate the database (VERBOSE=true)"
43
+ task "#{@name}:db:migrate", [:version] do |t, args|
44
+ Enrar::Migrator.new(args[:version], verbose: ENV['VERBOSE']).migrate!
45
+ end
46
+ self
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Enrar
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :text
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class CreateTests < ActiveRecord::Migration
2
+ def change
3
+ create_table :tests do |t|
4
+ t.string :stuff
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :username
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test_project.gemspec
4
+ gemspec
5
+
6
+ gem 'enrar', path: File.expand_path('../../../../', __FILE__)
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'enrar'
4
+ Enrar.initialize!
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'enrar'
4
+
5
+ Enrar.setup!
6
+
7
+ puts ActiveRecord::Base.connected?
@@ -0,0 +1,4 @@
1
+ development:
2
+ adapter: sqlite3
3
+ pool: 5
4
+ database: db/development.sqlite3
@@ -0,0 +1,5 @@
1
+ require "test_project/version"
2
+
3
+ module TestProject
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module TestProject
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test_project/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "test_project"
8
+ spec.version = TestProject::VERSION
9
+ spec.authors = ["TJ Taylor"]
10
+ spec.email = ["Thomas_Taylor2@cable.comcast.com"]
11
+ spec.description = %q{TODO: Write a gem description}
12
+ spec.summary = %q{TODO: Write a gem summary}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir['lib/**/*.rb']
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'enrar'
25
+ spec.add_dependency 'sqlite3'
26
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Enrar used in code' do
4
+ before(:each) { setup_test_project! }
5
+ after(:each) { teardown_test_project! }
6
+
7
+ it 'should fully setup ActiveRecord via config' do
8
+ `bundle exec bin/connection-test 2>&1`.must_match /true/i
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Rake tasks' do
4
+ before(:each) do
5
+ setup_test_project!
6
+ end
7
+
8
+ after(:each) do
9
+ teardown_test_project!
10
+ end
11
+
12
+ describe 'enrar:migrations:generate' do
13
+ it 'generates a migration' do
14
+ i_call_rake_task 'enrar:migrations:generate', 'create_test_table'
15
+ Dir[@test_directory + '/db/migrate/*_create_test_table.rb'].wont_be_empty
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'test_helpers/rake_testing'
4
+ require 'test_helpers/test_project'
5
+
6
+ require File.expand_path '../../lib/enrar', __FILE__
@@ -0,0 +1,26 @@
1
+ class MiniTest::Unit::TestCase
2
+ def i_call_rake_task(task_name, *args)
3
+ rake= nil
4
+ Dir.chdir(Enrar.gem_root) do
5
+ # Get an instance of rake
6
+ rake = Rake::Application.new
7
+ Rake.application = rake
8
+ end
9
+
10
+ Rake.application.rake_require rake_task_path(task_name),
11
+ [Enrar.gem_root.to_s],
12
+ loaded_files_excluding_current_rake_file(task_name)
13
+
14
+ task = rake[task_name]
15
+ assert task, "No rake task defined: #{task_name}"
16
+ task.invoke *args
17
+ end
18
+
19
+ def loaded_files_excluding_current_rake_file(file)
20
+ $".reject {|file| file == Enrar.gem_root.join("#{rake_task_path(file)}.rake").to_s }
21
+ end
22
+
23
+ def rake_task_path(name)
24
+ "tasks/#{name.split(":").first}"
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class MiniTest::Unit::TestCase
4
+ def setup_test_project!
5
+ @test_directory = File.expand_path('../../fixtures/test_project', __FILE__)
6
+ @old_directory = Dir.pwd
7
+ ENV['ENRAR_ENV'] = 'development'
8
+
9
+ Enrar.clear_config!
10
+ Enrar.root = @test_directory
11
+ Dir.chdir @test_directory
12
+ Enrar.initialize!
13
+
14
+ @migration_versions = %w(create_tests create_posts create_users).map do |migration_name|
15
+ sample = File.read(File.expand_path("../../fixtures/#{migration_name}.rb", __FILE__))
16
+ migration = Enrar::Migration.new(migration_name).generate!
17
+ File.write(migration.path, sample)
18
+ sleep 0.001
19
+ migration.version
20
+ end
21
+ end
22
+
23
+ def teardown_test_project!
24
+ Enrar.clear_config!
25
+ FileUtils.rm_r @test_directory + '/db'
26
+ Dir.chdir @old_directory
27
+ end
28
+ end
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ describe 'configurations' do
4
+ describe Enrar, '.root' do
5
+ it "points to the user's project's root" do
6
+ Enrar.root.to_s.must_equal File.expand_path('../../../', __FILE__)
7
+ end
8
+ end
9
+
10
+ describe Enrar, '.gem_root' do
11
+ it "points to Enrar's root" do
12
+ Enrar.root.to_s.must_equal File.expand_path('../../../', __FILE__)
13
+ end
14
+
15
+ it "stays the same even if I change directory" do
16
+ old_root = Enrar.root
17
+ Dir.chdir('/') do
18
+ Enrar.root.must_equal old_root
19
+ end
20
+ end
21
+ end
22
+
23
+ describe Enrar, '.root=' do
24
+ def new_root
25
+ File.expand_path('../../fixtures/test_project', __FILE__)
26
+ end
27
+
28
+ it "sets the location of the user's project's root" do
29
+ Enrar.root = new_root
30
+ Enrar.root.to_s.must_equal new_root
31
+ end
32
+
33
+ it "creates it as a Pathname" do
34
+ Enrar.root = new_root
35
+ Enrar.root.must_be_kind_of Pathname
36
+ end
37
+ end
38
+
39
+ describe Enrar, '.db_config' do
40
+ it 'defaults to Enrar.root.join(config/database.yml)' do
41
+ Enrar.db_config.must_equal Enrar.root.join('config', 'database.yml')
42
+ end
43
+
44
+ it 'is a Pathname object' do
45
+ Enrar.db_config.must_be_kind_of Pathname
46
+ end
47
+
48
+ it 'is a YAML file' do
49
+ Enrar.db_config.basename.to_s.must_match /ya?ml/i
50
+ end
51
+ end
52
+
53
+ describe Enrar do
54
+ before(:each) { Enrar.clear_config! }
55
+
56
+ describe '.clear_config' do
57
+ it 'clears out all the configuration settings' do
58
+ default_root = Enrar.root
59
+ Enrar.root = '/lib/some/where'
60
+ Enrar.clear_config!
61
+ Enrar.root.must_equal default_root
62
+ end
63
+ end
64
+
65
+ describe '.env' do
66
+ it 'defaults to "development"' do
67
+ ENV['ENRAR_ENV'] = nil
68
+ Enrar.env.must_equal 'development'
69
+ end
70
+
71
+ it 'is set-able via CLI option ENRAR_ENV' do
72
+ ENV['ENRAR_ENV'] = 'production'
73
+ Enrar.env.must_equal 'production'
74
+ end
75
+ end
76
+ end
77
+
78
+ describe 'a test project' do
79
+ before(:each) do
80
+ ENV['ENRAR_ENV'] = 'development'
81
+ Enrar.clear_config!
82
+ Enrar.root = File.expand_path('../../fixtures/test_project', __FILE__)
83
+ Enrar.initialize!
84
+ end
85
+
86
+ describe Enrar, '.initialize!' do
87
+ it 'loads the environment and sets up ActiveRecord' do
88
+ end
89
+ end
90
+
91
+ describe ActiveRecord::Base, '.configurations' do
92
+ it 'is set with Enrar.db_config' do
93
+ parsed_yaml = YAML::load_file(Enrar.db_config)
94
+ ActiveRecord::Base.configurations.must_equal parsed_yaml
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ describe Enrar::DB do
4
+ describe 'creating the databse' do
5
+ before(:each) do
6
+ setup_test_project!
7
+ end
8
+
9
+ after(:each) do
10
+ teardown_test_project!
11
+ end
12
+
13
+ it 'creates a migration file' do
14
+ Enrar::DB.new.create!
15
+ File.exist?(@test_directory + '/db/development.sqlite3').must_equal true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ describe Enrar do
4
+ before(:each) do
5
+ setup_test_project!
6
+ end
7
+
8
+ after(:each) do
9
+ teardown_test_project!
10
+ end
11
+
12
+ describe '.setup!' do
13
+ it 'works like initialize!, but it creates and migrates the db first' do
14
+ Enrar.setup!
15
+ ActiveRecord::Base.connected?.must_equal true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ describe Enrar::Migration do
4
+ it 'accepts an underscored name' do
5
+ Enrar::Migration.new('create_test_table').migration_class_name.must_equal 'CreateTestTable'
6
+ end
7
+
8
+ it 'accepts a camelized name' do
9
+ Enrar::Migration.new('CreateTestTable').migration_class_name.must_equal 'CreateTestTable'
10
+ end
11
+
12
+ it 'has a version' do
13
+ Enrar::Migration.new('CreateTestTable').version.to_i.must_be_within_delta Time.now.strftime('%Y%m%d%H%M%S%L').to_i, 2000
14
+ end
15
+
16
+ describe 'generating a migration' do
17
+ before(:each) do
18
+ @test_directory = File.expand_path('../../fixtures/test_project', __FILE__)
19
+ ENV['ENRAR_ENV'] = 'development'
20
+ Enrar.clear_config!
21
+ Enrar.root = @test_directory
22
+ Enrar.initialize!
23
+ end
24
+
25
+ after(:each) do
26
+ FileUtils.rm_r @test_directory + '/db'
27
+ end
28
+
29
+ it 'creates a migration file' do
30
+ migration = Enrar::Migration.new('create_test_table')
31
+ migration.generate!
32
+ File.exist?(migration.path).must_equal true
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ describe Enrar::Migrator do
4
+ describe 'migrating the database' do
5
+ before(:each) do
6
+ setup_test_project!
7
+ end
8
+
9
+ after(:each) do
10
+ teardown_test_project!
11
+ end
12
+
13
+ it 'runs all migrations in the migration_dir' do
14
+ Enrar::Migrator.new(nil, verbose: false).migrate!
15
+ ActiveRecord::Base.connection.table_exists?('tests').must_equal true
16
+ end
17
+
18
+ it 'accepts a migration version' do
19
+ Enrar::Migrator.new(@migration_versions.first.to_i, verbose: false).migrate!
20
+ ActiveRecord::Base.connection.table_exists?('tests').must_equal true
21
+ ActiveRecord::Base.connection.table_exists?('posts').must_equal false, 'Posts WAS created'
22
+ ActiveRecord::Base.connection.table_exists?('users').must_equal false, 'Users WAS created'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Sanity' do
4
+ it 'passes' do
5
+ true.must_equal true
6
+ end
7
+
8
+ describe 'secretfile:generate', 'A test that rake testing works' do
9
+ after(:each) do
10
+ File.delete '.super-secret'
11
+ end
12
+
13
+ it 'generates the secret file' do
14
+ i_call_rake_task 'secretfile:generate'
15
+ File.exists?('.super-secret').must_equal true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ describe Enrar::Schema do
4
+ before(:each) do
5
+ setup_test_project!
6
+ Enrar::Migrator.new(nil, verbose: false).migrate!
7
+ end
8
+
9
+ after(:each) { teardown_test_project! }
10
+
11
+ it 'knows the version number' do
12
+ Enrar::Schema.new.version.must_equal @migration_versions.last
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enrar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TJ Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ prerelease: false
15
+ name: bundler
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: '1.3'
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ prerelease: false
29
+ name: rake
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ prerelease: false
43
+ name: sqlite3
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ prerelease: false
57
+ name: activerecord
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '3.2'
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '3.2'
68
+ type: :runtime
69
+ description: No Rails ActiveRecord
70
+ email:
71
+ - Thomas_Taylor2@cable.comcast.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - enrar.gemspec
82
+ - lib/enrar.rb
83
+ - lib/enrar/db.rb
84
+ - lib/enrar/migration.rb
85
+ - lib/enrar/migrator.rb
86
+ - lib/enrar/schema.rb
87
+ - lib/enrar/task.rb
88
+ - lib/enrar/version.rb
89
+ - test/fixtures/create_posts.rb
90
+ - test/fixtures/create_tests.rb
91
+ - test/fixtures/create_users.rb
92
+ - test/fixtures/test_project/Gemfile
93
+ - test/fixtures/test_project/Rakefile
94
+ - test/fixtures/test_project/bin/connection-test
95
+ - test/fixtures/test_project/config/database.yml
96
+ - test/fixtures/test_project/lib/test_project.rb
97
+ - test/fixtures/test_project/lib/test_project/version.rb
98
+ - test/fixtures/test_project/test_project.gemspec
99
+ - test/integrations/enrar_in_code_test.rb
100
+ - test/integrations/rake_test.rb
101
+ - test/test_helper.rb
102
+ - test/test_helpers/rake_testing.rb
103
+ - test/test_helpers/test_project.rb
104
+ - test/units/configuration_test.rb
105
+ - test/units/db_test.rb
106
+ - test/units/enrar_setup_test.rb
107
+ - test/units/migration_test.rb
108
+ - test/units/migrator_test.rb
109
+ - test/units/sanity_test.rb
110
+ - test/units/schema_test.rb
111
+ homepage: ''
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Primarily for ActiveRecord Migrations outside rails
135
+ test_files:
136
+ - test/fixtures/create_posts.rb
137
+ - test/fixtures/create_tests.rb
138
+ - test/fixtures/create_users.rb
139
+ - test/fixtures/test_project/Gemfile
140
+ - test/fixtures/test_project/Rakefile
141
+ - test/fixtures/test_project/bin/connection-test
142
+ - test/fixtures/test_project/config/database.yml
143
+ - test/fixtures/test_project/lib/test_project.rb
144
+ - test/fixtures/test_project/lib/test_project/version.rb
145
+ - test/fixtures/test_project/test_project.gemspec
146
+ - test/integrations/enrar_in_code_test.rb
147
+ - test/integrations/rake_test.rb
148
+ - test/test_helper.rb
149
+ - test/test_helpers/rake_testing.rb
150
+ - test/test_helpers/test_project.rb
151
+ - test/units/configuration_test.rb
152
+ - test/units/db_test.rb
153
+ - test/units/enrar_setup_test.rb
154
+ - test/units/migration_test.rb
155
+ - test/units/migrator_test.rb
156
+ - test/units/sanity_test.rb
157
+ - test/units/schema_test.rb