database_rewinder 0.0.2 → 0.0.3

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: db7ed1dc6ce9a93cb75fcbb82baf3e02654f9242
4
- data.tar.gz: 5be39f4a597442871bc8e70d1d9fd2a5a4dceaf3
3
+ metadata.gz: b36e1dc99cdb3e75821ed24db79120cac63d3268
4
+ data.tar.gz: 8d125b3188fe1613c09b889a3d8570c757ab227b
5
5
  SHA512:
6
- metadata.gz: 0f8b1ffbc5cc58969aaf7f028e70e1d87f67a6bf48597d2b97b9e80f2ee06fd0d1e1f2f490a7b12860bf7d4c04f58323606f579c5e019c515ae655785829cccd
7
- data.tar.gz: ecf4ec4b7450800d551965fe1bf213023b11ed3bbf41ae7be3d9780fc088d5ba9c5b03db7bc235f9a8d6d451e18c376f6e1fdc7b44ba5059fd8ae3e0631178b7
6
+ metadata.gz: 182d904250271fe18edeec5f9484ea1a8412e99bf558b55e8a5f492afc8735ea74a1e07b335713d88b2f2bacd0b391eeebd6f276da32ae8bc30bcfca1262cc10
7
+ data.tar.gz: 99cfc24b2918823a43ec6678f95ac59096bb15fd9e5cc3ff385778af24d6a239ad74017cd8309dd9ecd143c21089a2a8a7ddc19a205c7e8da928e37a9dc633c1
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
1
3
  require "bundler/gem_tasks"
2
4
  require 'rspec/core'
3
5
  require 'rspec/core/rake_task'
@@ -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 = "database_rewinder"
7
- spec.version = '0.0.2'
7
+ spec.version = '0.0.3'
8
8
  spec.authors = ["Akira Matsuda"]
9
9
  spec.email = ["ronnie@dio.jp"]
10
10
  spec.description = "A minimalist's tiny and ultra-fast database cleaner"
@@ -7,7 +7,7 @@ module DatabaseRewinder
7
7
  class << self
8
8
  def init
9
9
  @cleaners, @table_names_cache, @clean_all, @only, @except = [], {}, false
10
- @db_config = YAML::load(ERB.new(IO.read(Rails.root.join 'config/database.yml')).result)
10
+ @db_config = YAML::load(ERB.new(Rails.root.join('config/database.yml').read).result)
11
11
  end
12
12
 
13
13
  def create_cleaner(connection_name)
@@ -71,14 +71,15 @@ module DatabaseRewinder
71
71
 
72
72
  # for database_cleaner compat
73
73
  def start; end
74
- def strategy=(_strategy, only: nil, except: nil, **)
75
- @only, @except = only, except
74
+ def strategy=(args)
75
+ options = args.is_a?(Array) ? args.extract_options! : {}
76
+ @only, @except = options[:only], options[:except]
76
77
  end
77
78
 
78
79
  # cache AR connection.tables
79
80
  def all_table_names(connection)
80
81
  db = connection.instance_variable_get(:'@config')[:database]
81
- @table_names_cache[db] ||= connection.tables
82
+ @table_names_cache[db] ||= connection.tables.reject{|t| t == ActiveRecord::Migrator.schema_migrations_table_name }
82
83
  end
83
84
  end
84
85
  end
@@ -29,9 +29,10 @@ module DatabaseRewinder
29
29
  end
30
30
 
31
31
  # for database_cleaner compat
32
- def strategy=(_strategy, only: nil, except: nil, **)
33
- @only += Array(only) unless only.blank?
34
- @except += Array(except) unless except.blank?
32
+ def strategy=(args)
33
+ options = args.is_a?(Array) ? args.extract_options! : {}
34
+ @only += Array(options[:only]) unless options[:only].blank?
35
+ @except += Array(options[:except]) unless options[:except].blank?
35
36
  end
36
37
 
37
38
  private
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ module DatabaseRewinder
4
+ describe Cleaner do
5
+ describe '#strategy=' do
6
+ before { @cleaner = described_class.new }
7
+
8
+ context 'when only strategy is given' do
9
+ before { @cleaner.strategy = :truncation }
10
+
11
+ it 'should ignore strategy' do
12
+ expect(@cleaner.instance_variable_get(:@only)).to eq([])
13
+ expect(@cleaner.instance_variable_get(:@except)).to eq([])
14
+ end
15
+ end
16
+
17
+ context 'when only option is given' do
18
+ before { @cleaner.strategy = :truncation, { only: ['foos'] } }
19
+
20
+ it 'should set only option' do
21
+ expect(@cleaner.instance_variable_get(:@only)).to eq(['foos'])
22
+ expect(@cleaner.instance_variable_get(:@except)).to eq([])
23
+ end
24
+ end
25
+
26
+ context 'when except option is given' do
27
+ before { @cleaner.strategy = :truncation, { except: ['foos'] } }
28
+
29
+ it 'should set only option' do
30
+ expect(@cleaner.instance_variable_get(:@only)).to eq([])
31
+ expect(@cleaner.instance_variable_get(:@except)).to eq(['foos'])
32
+ end
33
+ end
34
+
35
+ context 'when only and except option are given' do
36
+ before { @cleaner.strategy = :truncation, { only: ['foos'], except: ['bars'] } }
37
+
38
+ it 'should set only option' do
39
+ expect(@cleaner.instance_variable_get(:@only)).to eq(['foos'])
40
+ expect(@cleaner.instance_variable_get(:@except)).to eq(['bars'])
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -36,4 +36,52 @@ describe DatabaseRewinder do
36
36
  Bar.count.should == 0
37
37
  end
38
38
  end
39
+
40
+ describe '.clean_all' do
41
+ before do
42
+ ActiveRecord::SchemaMigration.create_table
43
+ ActiveRecord::SchemaMigration.create! version: '001'
44
+ Foo.create! name: 'foo1'
45
+ DatabaseRewinder.clean_all
46
+ end
47
+ after { ActiveRecord::SchemaMigration.drop_table }
48
+ it 'should clean except schema_migrations' do
49
+ Foo.count.should == 0
50
+ ActiveRecord::SchemaMigration.count.should == 1
51
+ end
52
+ end
53
+
54
+ describe '.strategy=' do
55
+ context 'when no option is specified' do
56
+ before { described_class.strategy = :truncate }
57
+ it 'should set strategy' do
58
+ expect(described_class.instance_variable_get(:@only)).to be_nil
59
+ expect(described_class.instance_variable_get(:@except)).to be_nil
60
+ end
61
+ end
62
+
63
+ context 'when only option is specified' do
64
+ before { described_class.strategy = :truncate, { only: %w{foos} } }
65
+ it 'should set only option' do
66
+ expect(described_class.instance_variable_get(:@only)).to eq(['foos'])
67
+ expect(described_class.instance_variable_get(:@except)).to be_nil
68
+ end
69
+ end
70
+
71
+ context 'when except option is specified' do
72
+ before { described_class.strategy = :truncate, { except: %w{foos} } }
73
+ it 'should set except option' do
74
+ expect(described_class.instance_variable_get(:@only)).to be_nil
75
+ expect(described_class.instance_variable_get(:@except)).to eq(['foos'])
76
+ end
77
+ end
78
+
79
+ context 'when only and except option are specified' do
80
+ before { described_class.strategy = :truncate, { only: %w{foos}, except: %w{bars} } }
81
+ it 'should set only and except options' do
82
+ expect(described_class.instance_variable_get(:@only)).to eq(['foos'])
83
+ expect(described_class.instance_variable_get(:@except)).to eq(['bars'])
84
+ end
85
+ end
86
+ end
39
87
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_rewinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-27 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,7 @@ files:
98
98
  - lib/database_rewinder/cleaner.rb
99
99
  - lib/database_rewinder/railtie.rb
100
100
  - spec/active_record_monkey_spec.rb
101
+ - spec/cleaner_spec.rb
101
102
  - spec/config/database.yml
102
103
  - spec/database_rewinder_spec.rb
103
104
  - spec/fake_app.rb
@@ -122,14 +123,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  version: '0'
123
124
  requirements: []
124
125
  rubyforge_project:
125
- rubygems_version: 2.0.3
126
+ rubygems_version: 2.2.1
126
127
  signing_key:
127
128
  specification_version: 4
128
129
  summary: A minimalist's tiny and ultra-fast database cleaner
129
130
  test_files:
130
131
  - spec/active_record_monkey_spec.rb
132
+ - spec/cleaner_spec.rb
131
133
  - spec/config/database.yml
132
134
  - spec/database_rewinder_spec.rb
133
135
  - spec/fake_app.rb
134
136
  - spec/spec_helper.rb
135
- has_rdoc: