migration_data 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5eb9b4e4b05f034db9b1052abe2d70acf918eef0
4
- data.tar.gz: b40491e6124d7666732164bd79e1dbe5f5dea0a2
3
+ metadata.gz: fd17cf47cfa0baf42b5c1d2352959ec3157a975b
4
+ data.tar.gz: de896217509a426ff6c4e937d84f761783807623
5
5
  SHA512:
6
- metadata.gz: 002d97ddc5b91de8d3430b04991dbe8e6f5d3d431a87897b539935a53433eb4778d3c63a972825bfdf7a9f8201cf5607592f4e49028f288e65a8da3f799cb0c6
7
- data.tar.gz: a8121c8c39a8f0970dfb7055b2ac402f50eafb71db4ca7bcd8fd758ff491e54cd2134cf7ccab3c73009ca276bb9e6633096c0c356847a7438eedc90e40fd246a
6
+ metadata.gz: a95485cd38bf813737a1b8d2608b2fd98086b79c60f220be527228e4417580a41bc627a27a87ef07355198722ccfee9fb9876bb3be66fb1b88bc64234aff429f
7
+ data.tar.gz: ee4b11882e2439e0ba09baccb514ca95bad1400a7200f6865655e64788bdbc9386f1719a4091330a38648db1655722d930f1bb4478d3549ff061c5db9ee6f92e
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # MigrationData
2
2
 
3
+ [![Build Status](https://travis-ci.org/ka8725/migration_data.png?branch=master)](https://travis-ci.org/ka8725/migration_data)
4
+
3
5
  This gem provides functionality to write any code in migrations safely without regression.
4
6
 
5
7
  Sometimes we have to write some Rails code in the migrations and it's hard to
@@ -8,7 +10,9 @@ some techniques which help to avoid these pitfalls. For example, define model
8
10
  classes in the migrations or write raw SQL. But they don't help in 100% cases anyway.
9
11
  This gem promises to solve the problem in a simple way.
10
12
 
11
- Currently the gem supports Rails 4 and Ruby >= 2.0.
13
+ Currently the gem supports Rails 4.
14
+
15
+ If you still don't understand what for this gem please check out [this blob post](http://railsguides.net/2014/01/30/change-data-in-migrations-like-a-boss/).
12
16
 
13
17
  ## Installation
14
18
 
@@ -46,7 +50,7 @@ NOTE: it's not run on `down`. If you have any reason to do it please fell free t
46
50
 
47
51
  ## Testing migrations
48
52
 
49
- To keep your migrations working don't forget to write test foe them.
53
+ To keep your migrations working don't forget to write tests for them.
50
54
  Possible `RSpec` test for the migration looks like this:
51
55
 
52
56
  ```ruby
@@ -0,0 +1,17 @@
1
+ module MigrationData
2
+ module ActiveRecord
3
+ module Migration
4
+ def self.included(base)
5
+ base.class_eval do
6
+ def exec_migration_with_data(conn, direction)
7
+ origin_exec_migration(conn, direction)
8
+ data if direction == :up && respond_to?(:data)
9
+ end
10
+
11
+ alias origin_exec_migration exec_migration
12
+ alias exec_migration exec_migration_with_data
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ require 'rails'
2
+
1
3
  def require_migration(migration_name)
2
4
  path = ActiveRecord::Migrator.migrations_path
3
5
  all_migrations = ActiveRecord::Migrator.migrations(path)
@@ -1,3 +1,3 @@
1
1
  module MigrationData
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -1,12 +1,5 @@
1
+ require 'active_record'
1
2
  require 'migration_data/version'
3
+ require 'migration_data/active_record/migration'
2
4
 
3
- module MigrationData
4
- def exec_migration(conn, direction)
5
- super
6
- if direction == :up && respond_to?(:data)
7
- data
8
- end
9
- end
10
- end
11
-
12
- ActiveRecord::Migration.prepend(MigrationData)
5
+ ActiveRecord::Migration.send(:include, MigrationData::ActiveRecord::Migration)
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1.5'
26
26
  spec.add_development_dependency 'rake'
27
27
  spec.add_development_dependency 'sqlite3'
28
- spec.add_dependency 'activerecord', '>= 4.0.0.rc1'
28
+ spec.add_dependency 'rails', '>= 4.0.0.rc1'
29
29
  end
@@ -4,12 +4,14 @@ require 'migration_data/testing'
4
4
  describe '#require_migration' do
5
5
  let(:db_path) do
6
6
  test_dir = File.expand_path(File.dirname(__FILE__))
7
- File.join(test_dir, 'db')
7
+ Pathname(File.join(test_dir, 'db'))
8
8
  end
9
9
 
10
10
  it 'loads existed migation' do
11
- ActiveRecord::Migrator.stub(:migrations_path, db_path) do
12
- require_migration 'test_migration'
11
+ Rails.stub(:root, db_path) do
12
+ ActiveRecord::Migrator.stub(:migrations_path, db_path) do
13
+ require_migration 'test_migration'
14
+ end
13
15
  end
14
16
  end
15
17
 
data/test/test_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'minitest/autorun'
2
- require 'active_record'
3
2
  require 'migration_data'
4
3
 
5
4
  ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'tmp/test.sqlite3')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Koleshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: activerecord
56
+ name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -79,11 +79,13 @@ extensions: []
79
79
  extra_rdoc_files: []
80
80
  files:
81
81
  - ".gitignore"
82
+ - ".travis.yml"
82
83
  - Gemfile
83
84
  - LICENSE.txt
84
85
  - README.md
85
86
  - Rakefile
86
87
  - lib/migration_data.rb
88
+ - lib/migration_data/active_record/migration.rb
87
89
  - lib/migration_data/testing.rb
88
90
  - lib/migration_data/version.rb
89
91
  - migration_data.gemspec