heart_seed 0.0.4 → 0.0.5

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: cf94922ae1a0a622269943b4598ac461fabb7f11
4
- data.tar.gz: 84bb1c58325c03d3472656e763a27b892428b6f0
3
+ metadata.gz: 3eac8531ec734a730680e223a8bb7a58a43dac84
4
+ data.tar.gz: d8f9f23f4759928cc439363f198292ccc849d900
5
5
  SHA512:
6
- metadata.gz: 53da2afdc2b19b6cd23a2d299b0540cf221738f5ca09e36cecf06f955e73d9049971b9ed0e4d4277f8227fcfb26fd75175c207262a14214a71c2607b37cf5f00
7
- data.tar.gz: 22f75929ad85617f9516b714fe6c2672fdd1cce5de61e52186272438e5ce6d4ceff36b339d8bb0e36cc6c9cdf1548207cbf1b0ba4e23a8a145221fd1e1be96d8
6
+ metadata.gz: d47173b69ed309859fb0df2e1f28e2ca4e6651c765534bfe2c1fd37b46d057ceae9a6eed19125e836152a6ddd7eaee39b79d3cfda8799849e81f24c9eddfebce
7
+ data.tar.gz: 1fc16baceacbb9a16ae967250e84c391d077dd87be4b97ec42d38d8be0979a3cdd40687f289905fedefebb645fe48a18ff090d1f2483e59ce23537634ef39eff
@@ -1,5 +1,14 @@
1
1
  ## master
2
- [full changelog](https://github.com/sue445/heart_seed/compare/v0.0.4...master)
2
+ [full changelog](https://github.com/sue445/heart_seed/compare/v0.0.5...master)
3
+
4
+ ## 0.0.5 (2015/02/09)
5
+ [full changelog](https://github.com/sue445/heart_seed/compare/v0.0.4...v0.0.5)
6
+
7
+ * Stop db:seed When invalid fixture
8
+ * https://github.com/sue445/heart_seed/issues/22
9
+ * https://github.com/sue445/heart_seed/issues/23
10
+ * execute seed do follow the order in catalog file
11
+ * https://github.com/sue445/heart_seed/issues/24
3
12
 
4
13
  ## 0.0.4 (2015/01/16)
5
14
  [full changelog](https://github.com/sue445/heart_seed/compare/v0.0.3...v0.0.4)
@@ -25,10 +25,10 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "activesupport", ">= 3.0.0"
26
26
  spec.add_dependency "roo", ">= 1.13.2"
27
27
 
28
- spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "bundler"
29
29
  spec.add_development_dependency "codeclimate-test-reporter"
30
30
  spec.add_development_dependency "coveralls"
31
- spec.add_development_dependency "database_rewinder", "> 0.2.0"
31
+ spec.add_development_dependency "database_rewinder", ">= 0.4.2"
32
32
  spec.add_development_dependency "pry"
33
33
  spec.add_development_dependency "pry-nav"
34
34
  spec.add_development_dependency "pry-remote"
@@ -28,7 +28,7 @@ module HeartSeed
28
28
  model_class.transaction do
29
29
  model_class.delete_all
30
30
  fixtures.each do |fixture|
31
- model_class.create(fixture)
31
+ model_class.create!(fixture)
32
32
  end
33
33
  end
34
34
  end
@@ -52,16 +52,31 @@ module HeartSeed
52
52
  raise "require TABLES or CATALOGS if production" if HeartSeed::Helper.production? && target_table_names.empty?
53
53
 
54
54
  ActiveRecord::Migration.verbose = true
55
- Dir.glob(File.join(seed_dir, "*.yml")) do |file_path|
56
- table_name = File.basename(file_path, '.*')
57
- next unless target_table?(table_name, target_table_names)
58
55
 
59
- ActiveRecord::Migration.say_with_time("#{file_path} -> #{table_name}") do
60
- begin
56
+ if target_table_names.empty?
57
+ # seed all tables
58
+ Dir.glob(File.join(seed_dir, "*.yml")) do |file_path|
59
+ table_name = File.basename(file_path, '.*')
60
+
61
+ ActiveRecord::Migration.say_with_time("#{file_path} -> #{table_name}") do
62
+ insert_seed(file_path: file_path, table_name: table_name, mode: mode)
63
+ ActiveRecord::Migration.say("[INFO] success", true)
64
+ end
65
+ end
66
+
67
+ else
68
+ # seed specified tables (follow the order)
69
+ target_table_names.each do |table_name|
70
+ file_path = File.join(seed_dir, "#{table_name}.yml")
71
+
72
+ unless File.exists?(file_path)
73
+ ActiveRecord::Migration.say("[WARN] #{file_path} is not exists")
74
+ next
75
+ end
76
+
77
+ ActiveRecord::Migration.say_with_time("#{file_path} -> #{table_name}") do
61
78
  insert_seed(file_path: file_path, table_name: table_name, mode: mode)
62
79
  ActiveRecord::Migration.say("[INFO] success", true)
63
- rescue => e
64
- ActiveRecord::Migration.say("[ERROR] #{e.message}", true)
65
80
  end
66
81
  end
67
82
  end
@@ -118,12 +133,6 @@ module HeartSeed
118
133
  tables.compact
119
134
  end
120
135
 
121
- def self.target_table?(source_table, target_tables)
122
- return true if target_tables.empty?
123
- target_tables.include?(source_table)
124
- end
125
- private_class_method :target_table?
126
-
127
136
  # insert yaml file to table
128
137
  # @param file_path [String] source seed yaml file
129
138
  # @param table_name [String] output destination table
@@ -1,3 +1,3 @@
1
1
  module HeartSeed
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -5,26 +5,26 @@ ActiveRecord::Schema.define(version: 1) do
5
5
  t.string :title
6
6
  t.text :description
7
7
 
8
- t.timestamps
8
+ t.timestamps null: false
9
9
  end
10
10
 
11
11
  create_table :comments do |t|
12
12
  t.references :article, index: true
13
13
  t.text :message
14
14
 
15
- t.timestamps
15
+ t.timestamps null: false
16
16
  end
17
17
 
18
18
  create_table :likes do |t|
19
19
  t.references :article, index: true
20
20
 
21
- t.timestamps
21
+ t.timestamps null: false
22
22
  end
23
23
 
24
24
  create_table :shard_articles do |t|
25
25
  t.string :title
26
26
  t.text :description
27
27
 
28
- t.timestamps
28
+ t.timestamps null: false
29
29
  end
30
30
  end
@@ -10,7 +10,7 @@ SHARD_NAMES.each do |shard_name|
10
10
  # database: ":memory:",
11
11
  database: db_file,
12
12
  timeout: 500
13
- }
13
+ }.with_indifferent_access
14
14
 
15
15
  DatabaseRewinder.create_cleaner(shard_name)
16
16
  ActiveRecord::Base.establish_connection(shard_name.to_sym)
@@ -4,6 +4,8 @@ end
4
4
 
5
5
  class Comment < ActiveRecord::Base
6
6
  establish_connection(:test)
7
+
8
+ validates_numericality_of :article_id, greater_than: 0
7
9
  end
8
10
 
9
11
  class Like < ActiveRecord::Base
@@ -0,0 +1,9 @@
1
+ ---
2
+ comments_1:
3
+ id: 1
4
+ article_id: 1
5
+ message: message1
6
+ comments_2:
7
+ id: 2
8
+ article_id: 0 # this is invalid!
9
+ message: message2
@@ -11,10 +11,20 @@ describe HeartSeed::DbSeed do
11
11
  describe "#insert" do
12
12
  subject { HeartSeed::DbSeed.insert(file_path: file_path, model_class: model_class) }
13
13
 
14
- let(:file_path) { "#{FIXTURE_DIR}/comments.yml" }
15
14
  let(:model_class) { Comment }
16
15
 
17
- it{ expect{ subject }.to change(Comment, :count).by(2) }
16
+ context "When valid data" do
17
+ let(:file_path) { "#{FIXTURE_DIR}/comments.yml" }
18
+
19
+ it{ expect{ subject }.to change(Comment, :count).by(2) }
20
+ end
21
+
22
+ context "When invalid data" do
23
+ let(:file_path) { "#{FIXTURE_DIR}/invalid/invalid_comments.yml" }
24
+
25
+ it{ expect{ subject }.to raise_error ActiveRecord::RecordInvalid }
26
+ it{ expect{ subject rescue nil }.to change(Comment, :count).by(0) }
27
+ end
18
28
  end
19
29
 
20
30
  describe "#import_all" do
@@ -25,16 +35,6 @@ describe HeartSeed::DbSeed do
25
35
  let(:catalogs) { [] }
26
36
  let(:mode){}
27
37
 
28
- before do
29
- # FIXME can not clear if using `DatabaseRewinder.clean`
30
- DatabaseRewinder.clean_all
31
- end
32
-
33
- after do
34
- # FIXME can not clear if using `DatabaseRewinder.clean`
35
- DatabaseRewinder.clean_all
36
- end
37
-
38
38
  context "When empty tables" do
39
39
  it{ expect{ subject }.to change(Article, :count).by(2) }
40
40
  it{ expect{ subject }.to change(Comment, :count).by(2) }
@@ -54,10 +54,17 @@ describe HeartSeed::DbSeed do
54
54
 
55
55
  before do
56
56
  allow(HeartSeed::Helper).to receive(:catalogs){
57
- { "article" => ["articles", "likes"] }
57
+ { "article" => ["articles", "likes", "missing_table"] }
58
58
  }
59
59
  end
60
60
 
61
+ it "should execute seed do follow the order in catalog file" do
62
+ expect(HeartSeed::DbSeed).to receive(:insert_seed).with(hash_including(table_name: "articles")).ordered
63
+ expect(HeartSeed::DbSeed).to receive(:insert_seed).with(hash_including(table_name: "likes")).ordered
64
+ expect(HeartSeed::DbSeed).not_to receive(:insert_seed).with(hash_including(table_name: "missing_table")).ordered
65
+ subject
66
+ end
67
+
61
68
  it{ expect{ subject }.to change(Article, :count).by(2) }
62
69
  it{ expect{ subject }.to change(Comment, :count).by(0) }
63
70
  it{ expect{ subject }.to change(Like , :count).by(1) }
@@ -16,11 +16,15 @@
16
16
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
17
 
18
18
  if ENV["COVERAGE"]
19
+ require "simplecov"
20
+ require "coveralls"
19
21
  require "codeclimate-test-reporter"
20
- CodeClimate::TestReporter.start
21
22
 
22
- require 'coveralls'
23
- Coveralls.wear!
23
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
24
+ CodeClimate::TestReporter::Formatter,
25
+ Coveralls::SimpleCov::Formatter
26
+ ]
27
+ SimpleCov.start
24
28
  end
25
29
 
26
30
  $LOAD_PATH.unshift(File.join(__dir__, "..", "lib"))
@@ -120,6 +124,12 @@ RSpec.configure do |config|
120
124
 
121
125
  # database_rewinder
122
126
  config.before :suite do
127
+ # FIXME: fool automatic_reconnect ...
128
+ # https://github.com/rails/rails/blob/v4.2.0/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L444
129
+ SHARD_NAMES.each do |shard_name|
130
+ DatabaseRewinder[nil, connection: shard_name].pool.automatic_reconnect = true
131
+ end
132
+
123
133
  DatabaseRewinder.clean_all
124
134
  # or
125
135
  # DatabaseRewinder.clean_with :any_arg_that_would_be_actually_ignored_anyway
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heart_seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '1.6'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '1.6'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: codeclimate-test-reporter
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: database_rewinder
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.2.0
117
+ version: 0.4.2
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.2.0
124
+ version: 0.4.2
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pry
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -379,6 +379,7 @@ files:
379
379
  - spec/dummy/vendor/assets/stylesheets/.keep
380
380
  - spec/fixtures/articles.yml
381
381
  - spec/fixtures/comments.yml
382
+ - spec/fixtures/invalid/invalid_comments.yml
382
383
  - spec/fixtures/likes.yml
383
384
  - spec/fixtures/shard_articles.yml
384
385
  - spec/heart_seed/converter_spec.rb
@@ -386,9 +387,6 @@ files:
386
387
  - spec/heart_seed/tasks/heart_seed_rake_spec.rb
387
388
  - spec/heart_seed_spec.rb
388
389
  - spec/spec_helper.rb
389
- - spec/support/models/article.rb
390
- - spec/support/models/comment.rb
391
- - spec/support/models/like.rb
392
390
  - spec/support/shared_contexts/rake_in_app_dir.rb
393
391
  homepage: https://github.com/sue445/heart_seed
394
392
  licenses:
@@ -477,6 +475,7 @@ test_files:
477
475
  - spec/dummy/vendor/assets/stylesheets/.keep
478
476
  - spec/fixtures/articles.yml
479
477
  - spec/fixtures/comments.yml
478
+ - spec/fixtures/invalid/invalid_comments.yml
480
479
  - spec/fixtures/likes.yml
481
480
  - spec/fixtures/shard_articles.yml
482
481
  - spec/heart_seed/converter_spec.rb
@@ -484,8 +483,5 @@ test_files:
484
483
  - spec/heart_seed/tasks/heart_seed_rake_spec.rb
485
484
  - spec/heart_seed_spec.rb
486
485
  - spec/spec_helper.rb
487
- - spec/support/models/article.rb
488
- - spec/support/models/comment.rb
489
- - spec/support/models/like.rb
490
486
  - spec/support/shared_contexts/rake_in_app_dir.rb
491
487
  has_rdoc:
File without changes
File without changes
File without changes