squasher 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bf39c604130d794f42f29a6a71328154c55c60e
4
- data.tar.gz: 448ea347111fe23d91f500c43a9f1ecc86047f17
3
+ metadata.gz: 4e3e107d6711573cf3fc5acd9b237fde3186c5b0
4
+ data.tar.gz: 0a710e069d472696efd9802c3427b6b2f463af83
5
5
  SHA512:
6
- metadata.gz: c8960b288cfc369f217f51705a7c8827f3d223343f3c055eafb030a48887657a2dbd90d9bbe50e7b5f2a8a915cd585bb8365e99f6ad2f4b49f6126c0a9b47967
7
- data.tar.gz: 05e4a577fb8b698713b1c181f65e8ae3316608acb1e6dbe604eafce00030f423a02960bc632e497365623ad0128baf4366be81706fe013d40c6053be00fb43ac
6
+ metadata.gz: d4ea404426d7555d6c0564578990be8d76140b1c27b5a96bf11c737252359b45904844df57c4f1ca5bfb8a56816e353ad7702b73b68b213d2fe89f20fd3383ce
7
+ data.tar.gz: 4eea8c07ec83255821bea140e655fddebc85d03c6c10cff2d51f7a16a44e10031fc6a2487799d81f03869b5788a707dec1e48217e968d0c8b3c659c329ed5714
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  /.bundle
4
4
  /.config
5
5
  /.rspec
6
+ Gemfile.custom
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -1,9 +1,8 @@
1
- before_install:
2
- - gem update bundler
1
+ cache: bundler
3
2
  language: ruby
4
3
  rvm:
5
- - 2.1.0
6
- - 2.0.0
7
- - 1.9.3
8
- - jruby-19mode
9
- - rbx
4
+ - ruby-head
5
+ - 2.2
6
+ - 2.1
7
+ - 2.0
8
+ - jruby
data/Gemfile CHANGED
@@ -3,9 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in squasher.gemspec
4
4
  gemspec
5
5
 
6
- platforms :rbx do
7
- gem 'json'
8
- gem 'racc'
9
- gem 'rubysl', '~> 2.0'
10
- gem 'psych'
11
- end
6
+ eval(File.read('Gemfile.custom')) if File.exist?('Gemfile.custom')
data/README.md CHANGED
@@ -36,12 +36,28 @@ You can tell `squasher` a more detailed date, for example:
36
36
  $ squasher 2013/12 #prior to December 2013
37
37
  $ squasher 2013/12/19 #prior to 19 December 2013
38
38
 
39
+ ### Options
40
+
41
+ `-d` - execute in **dry** mode - test a squashing process without deleting old migrations. The final output will be
42
+ printed in the console.
43
+
44
+ `-r` - reuse a database from previous squashing process. The option can be used in the next cases:
45
+ - you've run squasher in **dry** mode before and there were no errors
46
+ - you're squashing migrations gradually. For example, you want to squash migrations from 2013 till 2015, but the
47
+ process breaks in a migration from 2014. In this situation you squash till 2014, save the squasher's
48
+ database at the end, make a patch in the broken migration and run again the suite with `-r` option. As the result
49
+ squasher will not need to create the db schema and all data from the previous migrations will be there.
50
+
39
51
  ## Requirements
40
52
 
41
- It works and was tested on Ruby 1.9.3+ and Rails 3.1+. It also requires a valid configuration in `config/database.yml` and using Ruby format in `db/schema.rb` (default Rails use-case).
53
+ It works and was tested on Ruby 2.0+ and Rails 3.1+. It also requires a valid configuration in `config/database.yml` and using Ruby format in `db/schema.rb` (default Rails use-case).
42
54
  If an old migration inserted data (created ActiveRecord model records) you will lose this code in the squashed migration, **BUT** `squasher` will ask you to leave a tmp database which will have all data that was inserted while migrating. Using this database you could add that data as another migration, or into `config/seed.rb` (the expected place for this stuff).
43
55
 
44
56
  ## Changelog
57
+ - 0.2.0
58
+ - add **dry** mode and ability to reuse the previous squasher database
59
+ - improve database config processing
60
+ - raise the minimum supported version of Ruby
45
61
  - 0.1.7
46
62
  - a regression fix of the log output ([@lime](https://github.com/lime))
47
63
  - improve a multi-platform support ([@johncarney](https://github.com/johncarney))
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'squasher'
3
3
 
4
- case ARGV[0]
5
- when 'clean' then Squasher.clean
6
- when /\A\d{4}/ then Squasher.squash(ARGV[0])
4
+ if ARGV[0] == 'clean'
5
+ Squasher.clean
6
+ elsif ARGV[-1] =~ /\A\d{4}/
7
+ Squasher.squash(ARGV[-1], ARGV[0...-1])
7
8
  else
8
9
  Squasher.tell(:usage)
9
10
  end
@@ -6,10 +6,19 @@ module Squasher
6
6
  autoload :Render, 'squasher/render'
7
7
  autoload :Worker, 'squasher/worker'
8
8
 
9
- def squash(raw_date)
9
+ def squash(raw_date, raw_options)
10
10
  parts = raw_date.to_s.split('/').map(&:to_i)
11
11
  date = Time.new(*parts)
12
- Worker.process(date)
12
+
13
+ options = raw_options.map do |o|
14
+ o = o.gsub('-', '').to_sym
15
+ unless Worker::OPTIONS.include?(o)
16
+ tell(:wrong_option, o: o)
17
+ error(:usage)
18
+ end
19
+ o
20
+ end
21
+ Worker.process(date, options)
13
22
  end
14
23
 
15
24
  def clean
@@ -28,9 +37,9 @@ module Squasher
28
37
 
29
38
  def tell(key, options = {})
30
39
  message = messages.fetch(key.to_s)
40
+ message = message.join("\n") if message.is_a?(Array)
31
41
  message = colorize(message)
32
- message = message % options
33
- puts message
42
+ puts message % options
34
43
  end
35
44
 
36
45
  def error(*args)
@@ -48,10 +57,9 @@ module Squasher
48
57
  @messages = JSON.load(File.open(path))
49
58
  end
50
59
 
60
+ COLORS = ['red', 'green', 'yellow', 'blue'].each_with_index.inject({}) { |r, (k, i)| r.merge!(k => "03#{ i + 1 }") }
61
+
51
62
  def colorize(message)
52
- message.gsub(/\:(\w+)\<([^>]+)\>/) do |match|
53
- color_code = { "red" => "031", "green" => "032", "yellow" => "033" }[$1]
54
- "\033[#{ color_code }m#{ $2 }\033[039m"
55
- end
63
+ message.gsub(/\:(\w+)\<([^>]+)\>/) { |_| "\033[#{ COLORS[$1] }m#{ $2 }\033[039m" }
56
64
  end
57
65
  end
@@ -4,12 +4,14 @@ require 'erb'
4
4
 
5
5
  module Squasher
6
6
  class Config
7
+ attr_reader :schema_file
8
+
7
9
  def initialize
8
- @root_path = Dir.pwd
9
- end
10
+ root_path = Dir.pwd
10
11
 
11
- def schema_file
12
- @schema_file ||= from_root('db', 'schema.rb')
12
+ @schema_file = File.join(root_path, 'db', 'schema.rb')
13
+ @migrations_folder = File.join(root_path, 'db', 'migrate')
14
+ @dbconfig_file = File.join(root_path, 'config', 'database.yml')
13
15
  end
14
16
 
15
17
  def migration_files
@@ -34,52 +36,38 @@ module Squasher
34
36
  list = [dbconfig_file, schema_file]
35
37
  list.each do |file|
36
38
  next unless File.exists?(file)
37
- FileUtils.mv file, "#{ file }.sbackup"
39
+ FileUtils.mv file, "#{ file }.sq"
38
40
  end
39
- update_dbconfig_file
41
+
42
+ File.open(dbconfig_file, 'wb') { |stream| stream.write dbconfig.to_yaml }
40
43
 
41
44
  yield
42
45
 
43
46
  ensure
44
47
  list.each do |file|
45
- next unless File.exists?("#{ file }.sbackup")
46
- FileUtils.mv "#{ file }.sbackup", file
48
+ next unless File.exists?("#{ file }.sq")
49
+ FileUtils.mv "#{ file }.sq", file
47
50
  end
48
51
  end
49
52
 
50
53
  private
51
54
 
52
- attr_reader :root_path
53
-
54
- def from_root(*subfolders)
55
- File.join(root_path, *subfolders)
56
- end
57
-
58
- def migrations_folder
59
- @migrations_folder ||= from_root('db', 'migrate')
60
- end
61
-
62
- def dbconfig_file
63
- @dbconfig_file ||= from_root('config', 'database.yml')
64
- end
55
+ attr_reader :migrations_folder, :dbconfig_file
65
56
 
66
57
  def dbconfig
67
58
  return @dbconfig if defined?(@dbconfig)
68
59
  return @dbconfig = nil unless File.exists?(dbconfig_file)
69
60
 
61
+ @dbconfig = nil
62
+
70
63
  begin
71
- content = File.read(dbconfig_file).gsub(/database: (.+)/, 'database: squasher')
72
- parsed_content = ERB.new(content).result(binding)
73
- @dbconfig = YAML.load(parsed_content)
74
- @dbconfig = nil unless @dbconfig.keys.include?('development')
64
+ content = YAML.load(ERB.new(File.read(dbconfig_file)).result(binding))
65
+ if content.has_key?('development')
66
+ @dbconfig = { 'development' => content['development'].merge('database' => 'squasher') }
67
+ end
75
68
  rescue
76
- @dbconfig = nil
77
69
  end
78
70
  @dbconfig
79
71
  end
80
-
81
- def update_dbconfig_file
82
- File.open(dbconfig_file, 'wb') { |stream| stream.write dbconfig.to_yaml }
83
- end
84
72
  end
85
73
  end
@@ -1,9 +1,17 @@
1
1
  {
2
- "keep_database" : "Squasher's created the `:green<squasher>` database for its needs.\nIt might be useful if to keep it if any of your deleted migrations inserted data into database.\nKeep it (:green<yes> / :red<no>)?",
2
+ "keep_database" : [
3
+ "Squasher's created the `:green<squasher>` database for its needs.",
4
+ "It might be useful to keep it if any of your deleted migrations inserts data or",
5
+ "you squash migrations in few steps (look at -r option).",
6
+ "Keep it (:green<yes> / :red<no>)?"
7
+ ],
3
8
 
4
9
  "apply_clean": "Do you want to clean your database from the old schema migration records(:red<yes>/:green<no>)?",
5
10
 
6
- "migration_folder_missing" : "The folder with migrations is missing.\nAre you sure that you're in the :red<root of a rails> application?",
11
+ "migration_folder_missing" : [
12
+ "The folder with migrations is missing.",
13
+ "Are you sure that you're in the :red<root of a rails> application?"
14
+ ],
7
15
 
8
16
  "no_migrations" : "There are no migrations in the folder prior to :red<%{date}>",
9
17
 
@@ -15,5 +23,20 @@
15
23
 
16
24
  "db_cleaning": "Squasher is applying the clean migration",
17
25
 
18
- "usage": "Example usage:\n :green<squasher> :yellow<year[/month][/day]> #squash migrations prior to a specified date\n :green<squasher> :yellow<clean> #generate or update a cleaning migration and apply it\n :green<squasher> :yellow<info> #show this message"
26
+ "db_reuse": "Squasher is reusing the database from the previous squashing",
27
+
28
+ "usage": [
29
+ "Example usage:",
30
+ " :green<squasher> [options] :yellow<year[/month][/day]> => squash migrations prior to a specified date",
31
+ " :green<squasher> :yellow<clean> => generate or update a cleaning migration and apply it",
32
+ " :green<squasher> :yellow<info> => show the message",
33
+ "",
34
+ "Options:",
35
+ " :yellow<-d> => execute in :blue<`dry`> mode - test a squashing process without removing old migrations",
36
+ " :yellow<-r> => reuse a database from the previous squashing"
37
+ ],
38
+
39
+ "wrong_option": "You provided a wrong option :red<%{o}>",
40
+
41
+ "dry_mode_finished": "The `dry` mode is finished. Below the init schema's content:"
19
42
  }
@@ -6,6 +6,6 @@ class InitSchema < ActiveRecord::Migration
6
6
  end
7
7
 
8
8
  def down
9
- raise "Can not revert initial migration"
9
+ raise ActiveRecord::IrreversibleMigration, "The initial migration is not revertable"
10
10
  end
11
11
  end
@@ -2,28 +2,35 @@ require 'fileutils'
2
2
 
3
3
  module Squasher
4
4
  class Worker
5
- attr_reader :date
5
+ OPTIONS = [:d, :r]
6
+
7
+ attr_reader :date, :options
6
8
 
7
9
  def self.process(*args)
8
10
  new(*args).process
9
11
  end
10
12
 
11
- def initialize(date)
13
+ def initialize(date, options = [])
12
14
  @date = date
15
+ @options = options
13
16
  end
14
17
 
15
18
  def process
16
19
  check!
17
20
 
18
21
  result = under_squash_env do
19
- File.open(config.migration_file(finish_timestamp, :init_schema), 'wb') do |stream|
20
- stream << ::Squasher::Render.render(:init_schema, config)
22
+ if options.include?(:d)
23
+ Squasher.tell(:dry_mode_finished)
24
+ puts Render.render(:init_schema, config)
25
+ else
26
+ path = config.migration_file(finish_timestamp, :init_schema)
27
+ File.open(path, 'wb') { |io| io << Render.render(:init_schema, config) }
28
+ migrations.each { |file| FileUtils.rm(file) }
21
29
  end
22
30
 
23
- migrations.each { |file| FileUtils.rm(file) }
24
-
25
31
  Squasher.rake("db:drop") unless Squasher.ask(:keep_database)
26
32
  end
33
+
27
34
  Squasher.clean if result && Squasher.ask(:apply_clean)
28
35
  end
29
36
 
@@ -64,10 +71,17 @@ module Squasher
64
71
 
65
72
  def under_squash_env
66
73
  config.stub_dbconfig do
67
- if Squasher.rake("db:drop db:create", :db_create) &&
68
- Squasher.rake("db:migrate VERSION=#{ finish_timestamp }", :db_migrate)
69
- yield
74
+ if options.include?(:r)
75
+ Squasher.tell(:db_reuse)
76
+ else
77
+ return unless Squasher.rake("db:drop db:create", :db_create)
70
78
  end
79
+
80
+ return unless Squasher.rake("db:migrate VERSION=#{ finish_timestamp }", :db_migrate)
81
+
82
+ yield
83
+
84
+ true
71
85
  end
72
86
  end
73
87
  end
@@ -5,8 +5,8 @@ describe Squasher::Cleaner do
5
5
  let(:expected_file) { File.join(fake_root, 'db', 'migrate', '20140102030405_squasher_clean.rb') }
6
6
 
7
7
  before do
8
- Time.stub(:now => Time.new(2014, 1, 2, 3, 4, 5))
9
- Squasher.stub(:rake).with("db:migrate", :db_cleaning)
8
+ allow(Time).to receive(:now).and_return(Time.new(2014, 1, 2, 3, 4, 5))
9
+ allow(Squasher).to receive(:rake).with("db:migrate", :db_cleaning)
10
10
  end
11
11
 
12
12
  after do
@@ -14,7 +14,7 @@ describe Squasher::Cleaner do
14
14
  end
15
15
 
16
16
  it 'create a new migration' do
17
- Squasher::Cleaner.any_instance.stub(:prev_migration => nil)
17
+ allow_any_instance_of(Squasher::Cleaner).to receive(:prev_migration).and_return(nil)
18
18
  Squasher.clean
19
19
 
20
20
  expect(clean_migrations).to include(expected_file)
@@ -7,19 +7,19 @@ describe Squasher::Config do
7
7
  subject(:result) { config.dbconfig? }
8
8
 
9
9
  it 'a file is exists and it has a valid content' do
10
- expect(result).to be_true
10
+ expect(result).to be_truthy
11
11
  end
12
12
 
13
13
  it 'a file is exists but doesnt have a valid content' do
14
- config.stub(:dbconfig_file => File.join(fake_root, 'config', 'invalid_database.yml'))
14
+ allow(config).to receive(:dbconfig_file).and_return(File.join(fake_root, 'config', 'invalid_database.yml'))
15
15
 
16
- expect(result).to be_false
16
+ expect(result).to be_falsey
17
17
  end
18
18
 
19
19
  it 'a file is not exists' do
20
- config.stub(:dbconfig_file => File.join(fake_root, 'config', 'not_existed.yml'))
20
+ allow(config).to receive(:dbconfig_file).and_return(File.join(fake_root, 'config', 'not_existed.yml'))
21
21
 
22
- expect(result).to be_false
22
+ expect(result).to be_falsey
23
23
  end
24
24
  end
25
25
 
@@ -30,8 +30,7 @@ describe Squasher::Config do
30
30
  content = YAML.load(stream.read)
31
31
  expect(content["development"]["database"]).to eq("squasher")
32
32
  expect(content["development"]["encoding"]).to eq("utf-8")
33
- expect(content["another_development"]["database"]).to eq("squasher")
34
- expect(content["another_development"]["encoding"]).to eq("utf-8")
33
+ expect(content).not_to have_key("another_development")
35
34
  end
36
35
  end
37
36
  end
@@ -39,14 +38,14 @@ describe Squasher::Config do
39
38
  it 'recover original schema and db config files if some error raised' do
40
39
  begin
41
40
  config.stub_dbconfig do
42
- expect(file_exists?('config', 'database.yml')).to be_true
43
- expect(file_exists?('config', 'database.yml.sbackup')).to be_true
41
+ expect(file_exists?('config', 'database.yml')).to be_truthy
42
+ expect(file_exists?('config', 'database.yml.sq')).to be_truthy
44
43
 
45
44
  raise RuntimeError, "Unexpected system error"
46
45
  end
47
46
  rescue RuntimeError
48
- expect(file_exists?('config', 'database.yml')).to be_true
49
- expect(file_exists?('config', 'database.yml.sbackup')).to be_false
47
+ expect(file_exists?('config', 'database.yml')).to be_truthy
48
+ expect(file_exists?('config', 'database.yml.sq')).to be_falsey
50
49
  end
51
50
  end
52
51
 
@@ -6,8 +6,8 @@ describe Squasher do
6
6
  specify { expected_covert("2013", Time.new(2013, 1, 1)) }
7
7
 
8
8
  def expected_covert(input, expected)
9
- expect(Squasher::Worker).to receive(:process).with(expected)
10
- Squasher.squash(input)
9
+ expect(Squasher::Worker).to receive(:process).with(expected, [])
10
+ Squasher.squash(input, [])
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe Squasher::Worker do
5
+ context 'failed on #check!' do
6
+ let(:worker) { described_class.new(Time.new(2012, 6, 20)) }
7
+
8
+ specify 'command was run not in application root' do
9
+ allow_any_instance_of(Squasher::Config).to receive(:migrations_folder?).and_return(false)
10
+
11
+ expect_exit_with(:migration_folder_missing)
12
+ end
13
+
14
+ specify 'db configuration is invalid' do
15
+ allow_any_instance_of(Squasher::Config).to receive(:dbconfig?).and_return(false)
16
+
17
+ expect_exit_with(:dbconfig_invalid)
18
+ end
19
+
20
+ specify 'matched migrations was not found' do
21
+ expect_exit_with(:no_migrations, :date => "2012/06/20")
22
+ end
23
+
24
+ def expect_exit_with(*args)
25
+ expect(Squasher).to receive(:error).with(*args).and_call_original
26
+ expect { worker.process }.to raise_error(SystemExit)
27
+ end
28
+ end
29
+
30
+ it 'creates a new squashed migration & remove selected migrations' do
31
+ worker = described_class.new(Time.new(2014))
32
+ allow(worker).to receive(:under_squash_env).and_yield.and_return(true)
33
+ new_migration_path = File.join(Dir.tmpdir, 'init_schema.rb')
34
+ allow_any_instance_of(Squasher::Config).to receive(:migration_file).with('20131213090719', :init_schema).and_return(new_migration_path)
35
+
36
+ expect(FileUtils).to receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131205160936_first_migration.rb'))
37
+ expect(FileUtils).to receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131213090719_second_migration.rb'))
38
+ expect(Squasher).to receive(:ask).with(:keep_database).and_return(false)
39
+ expect(Squasher).to receive(:rake).with("db:drop")
40
+ expect(Squasher).to receive(:ask).with(:apply_clean).and_return(true)
41
+ expect(Squasher).to receive(:clean)
42
+
43
+ worker.process
44
+
45
+ expect(File.exists?(new_migration_path)).to be_truthy
46
+ File.open(new_migration_path) do |stream|
47
+ content = stream.read
48
+ expect(content).to include("InitSchema")
49
+ expect(content).to include('create_table "managers", :force => true do |t|')
50
+ end
51
+ end
52
+
53
+ specify 'the dry mode' do
54
+ worker = described_class.new(Time.new(2014), [:d])
55
+ allow(worker).to receive(:under_squash_env).and_yield.and_return(true)
56
+ expect(Squasher).to receive(:tell).with(:dry_mode_finished).and_call_original
57
+ expect(Squasher).to receive(:ask).with(:keep_database).and_return(false)
58
+ expect(Squasher).to receive(:rake).with("db:drop")
59
+ expect(Squasher).to receive(:ask).with(:apply_clean).and_return(false)
60
+ worker.process
61
+ end
62
+
63
+ specify 'reuse of an existing database' do
64
+ worker = described_class.new(Time.new(2014), [:r])
65
+ expect(Squasher).to receive(:tell).with(:db_reuse).and_call_original
66
+ expect(Squasher).not_to receive(:rake).with("db:drop db:create", :db_create)
67
+ allow(Squasher).to receive(:rake).with("db:migrate VERSION=20131213090719", :db_migrate).and_return(false)
68
+ worker.process
69
+ end
70
+ end
@@ -1,13 +1,22 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.require
3
3
 
4
- def fake_root
5
- @fake_root ||= File.join(File.dirname(__FILE__), 'fake_app')
4
+
5
+ module SpecHelpers
6
+ def fake_root
7
+ File.join(File.dirname(__FILE__), 'fake_app')
8
+ end
9
+ end
10
+
11
+ module Squasher
12
+ class Dir < ::Dir
13
+ def self.pwd
14
+ File.join(File.dirname(__FILE__), 'fake_app')
15
+ end
16
+ end
6
17
  end
7
18
 
8
19
  RSpec.configure do |config|
9
20
  config.order = 'random'
10
- config.before do
11
- Squasher::Config.any_instance.stub(:root_path => fake_root)
12
- end
21
+ config.include SpecHelpers
13
22
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "squasher"
7
- spec.version = "0.1.7"
7
+ spec.version = "0.2.0"
8
8
  spec.authors = ["Sergey Pchelintsev"]
9
9
  spec.email = ["mail@sergeyp.me"]
10
10
  spec.description = %q{Squash your old migrations}
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", ">= 1.3"
21
21
  spec.add_development_dependency "rake"
22
- spec.add_development_dependency "rspec", "~> 2.14.0"
22
+ spec.add_development_dependency "rspec", ">= 3.3.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pchelintsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.0
47
+ version: 3.3.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.0
54
+ version: 3.3.0
55
55
  description: Squash your old migrations
56
56
  email:
57
57
  - mail@sergeyp.me
@@ -82,10 +82,10 @@ files:
82
82
  - spec/fake_app/db/migrate/20140101010101_squasher_clean.rb
83
83
  - spec/fake_app/db/migrate/20140103124257_third_migration.rb
84
84
  - spec/fake_app/db/schema.rb
85
- - spec/lib/squasher/cleaner_spec.rb
86
- - spec/lib/squasher/config_spec.rb
87
- - spec/lib/squasher/worker_spec.rb
85
+ - spec/lib/cleaner_spec.rb
86
+ - spec/lib/config_spec.rb
88
87
  - spec/lib/squasher_spec.rb
88
+ - spec/lib/worker_spec.rb
89
89
  - spec/spec_helper.rb
90
90
  - squasher.gemspec
91
91
  homepage: https://github.com/jalkoby/squasher
@@ -120,8 +120,9 @@ test_files:
120
120
  - spec/fake_app/db/migrate/20140101010101_squasher_clean.rb
121
121
  - spec/fake_app/db/migrate/20140103124257_third_migration.rb
122
122
  - spec/fake_app/db/schema.rb
123
- - spec/lib/squasher/cleaner_spec.rb
124
- - spec/lib/squasher/config_spec.rb
125
- - spec/lib/squasher/worker_spec.rb
123
+ - spec/lib/cleaner_spec.rb
124
+ - spec/lib/config_spec.rb
126
125
  - spec/lib/squasher_spec.rb
126
+ - spec/lib/worker_spec.rb
127
127
  - spec/spec_helper.rb
128
+ has_rdoc:
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
- require 'tempfile'
3
-
4
- describe Squasher::Worker do
5
- context 'failed on #check!' do
6
- let(:worker) { described_class.new(Time.new(2012, 6, 20)) }
7
-
8
- it 'command was run not in application root' do
9
- Squasher::Config.any_instance.stub(:migrations_folder? => false)
10
-
11
- expect_exit_with(:migration_folder_missing)
12
- end
13
-
14
- it 'db configuration is invalid' do
15
- Squasher::Config.any_instance.stub(:dbconfig? => false)
16
-
17
- expect_exit_with(:dbconfig_invalid)
18
- end
19
-
20
- it 'matched migrations was not found' do
21
- expect_exit_with(:no_migrations, :date => "2012/06/20")
22
- end
23
-
24
- def expect_exit_with(*args)
25
- expect(Squasher).to receive(:error).with(*args).and_call_original
26
- expect { worker.process }.to raise_error(SystemExit)
27
- end
28
- end
29
-
30
- it 'create a new squashed migration & remove selected migrations' do
31
- worker = described_class.new(Time.new(2014))
32
- worker.stub(:under_squash_env).and_yield.and_return(true)
33
- new_migration_path = File.join(Dir.tmpdir, 'init_schema.rb')
34
- Squasher::Config.any_instance.stub(:migration_file).with('20131213090719', :init_schema).and_return(new_migration_path)
35
-
36
- FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131205160936_first_migration.rb'))
37
- FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131213090719_second_migration.rb'))
38
- Squasher.should_receive(:ask).with(:keep_database).and_return(false)
39
- Squasher.should_receive(:rake).with("db:drop")
40
- Squasher.should_receive(:ask).with(:apply_clean).and_return(true)
41
- Squasher.should_receive(:clean)
42
-
43
- worker.process
44
-
45
- expect(File.exists?(new_migration_path)).to be_true
46
- File.open(new_migration_path) do |stream|
47
- content = stream.read
48
- expect(content).to include("InitSchema")
49
- expect(content).to include('create_table "managers", :force => true do |t|')
50
- end
51
- end
52
- end