seedomatic 0.1.2 → 0.2.0

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.
@@ -10,8 +10,10 @@ module SeedOMatic
10
10
  files_to_import(opts).each do |file|
11
11
  file_info = load_file(file)
12
12
 
13
- if should_import?(opts, file_info)
14
- results[file_info[:model_name]] = Seeder.new(file_info).import
13
+ file_info.each do |f|
14
+ if should_import?(opts, f)
15
+ results[f[:model_name]] = Seeder.new(f).import
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -35,12 +37,9 @@ module SeedOMatic
35
37
  end
36
38
 
37
39
  def load_file(file)
38
- data = YAML.load_file(file)
39
- {
40
- :model_name => data.keys.first,
41
- :match_on => data.first[1]['match_on'],
42
- :items => data.first[1]['items']
43
- }
40
+ data = YAML.load_file(file).map do |k, v|
41
+ v.merge(:model_name => k).with_indifferent_access
42
+ end
44
43
  end
45
44
 
46
45
  end
@@ -1,3 +1,3 @@
1
1
  module Seedomatic
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/readme.markdown CHANGED
@@ -1,9 +1,7 @@
1
1
  # Seed-O-Matic
2
2
  *Run repeatable seeds across a variety of environments*
3
3
 
4
- Seeds are great, but they're usually written in a way that they can only be used on an initial deploy. Seed-O-Matic gives
5
- you tools to specify seed data in a way that's repeatable across environments, allowing you to change seed data in a safe
6
- way between all of your environments.
4
+ Seeds and db:fixture:load are great, but they're usually written in a way that they can only be used on an initial deploy. Seed-O-Matic gives you tools to specify seed data in a way that's repeatable across environments, allowing you to change seed data in a safe way between all of your environments.
7
5
 
8
6
  ## Seed Files
9
7
  Seed files are set up as YAML files. By default, Seed-O-Matic will look for seed files in `config/seeds`, although you can
@@ -17,6 +15,15 @@ specify another directory when you run your seeds. Here's the structure of a typ
17
15
  code: my_model
18
16
  - name: My Model 2
19
17
  code: my_model_2
18
+ other_model:
19
+ match_on: [code, category]
20
+ items:
21
+ - name: Other Model 1
22
+ code: om_1
23
+ category: a
24
+ - name: Other Model 2
25
+ code: om_2
26
+ category: b
20
27
 
21
28
  * The seed file starts with a *model name*. This should match the name of a model in your application.
22
29
  * The *items* array lists all the items you'd like to seed. Attribute names should match the name of your attributes.
@@ -30,6 +30,27 @@ describe SeedOMatic do
30
30
  context "no options (assumed config / seeds directory)" do
31
31
 
32
32
  end
33
+
34
+ describe "multiple records in a file" do
35
+ let(:opts) { { :file => 'spec/support/multiple_models.yml'} }
36
+
37
+ specify {
38
+ SeedOMatic::Seeder.should_receive(:new).with(hash_including(:model_name => 'model_1')).and_return(mock_seeder)
39
+ SeedOMatic::Seeder.should_receive(:new).with(hash_including(:model_name => 'model_2')).and_return(mock_seeder)
40
+
41
+ subject
42
+ }
43
+ end
44
+
45
+ describe "json data" do
46
+ let(:opts) { { :file => 'spec/support/single_model.json' } }
47
+
48
+ specify {
49
+ SeedOMatic::Seeder.should_receive(:new).with(hash_including(:model_name => 'model_name',
50
+ :items => ['name' => 'Name 1', 'code' => 'code_1'])).and_return(mock_seeder)
51
+ subject
52
+ }
53
+ end
33
54
  end
34
55
 
35
56
  describe "should_import?" do
@@ -0,0 +1,8 @@
1
+ model_1:
2
+ items:
3
+ - name: test
4
+ - name: test2
5
+ model_2:
6
+ items:
7
+ - name: test
8
+ - name: test2
@@ -0,0 +1,7 @@
1
+ {
2
+ "model_name": {
3
+ "items": [
4
+ { "name": "Name 1", "code": "code_1" }
5
+ ]
6
+ }
7
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seedomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70148779022620 !ruby/object:Gem::Requirement
16
+ requirement: &70143477327600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.9.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70148779022620
24
+ version_requirements: *70143477327600
25
25
  description: Create repeatable seed fixtures that you can continually use and deploy
26
26
  to multiple environments and tenants.
27
27
  email:
@@ -43,9 +43,11 @@ files:
43
43
  - spec/lib/seed_o_matic_spec.rb
44
44
  - spec/lib/seeder_spec.rb
45
45
  - spec/spec_helper.rb
46
+ - spec/support/multiple_models.yml
46
47
  - spec/support/my_model.rb
47
48
  - spec/support/seed_directory/dir1.yml
48
49
  - spec/support/seed_directory/dir2.yml
50
+ - spec/support/single_model.json
49
51
  - spec/support/single_model.yml
50
52
  homepage: http://github.com/ryanbrunner/seedomatic
51
53
  licenses: []
@@ -75,7 +77,9 @@ test_files:
75
77
  - spec/lib/seed_o_matic_spec.rb
76
78
  - spec/lib/seeder_spec.rb
77
79
  - spec/spec_helper.rb
80
+ - spec/support/multiple_models.yml
78
81
  - spec/support/my_model.rb
79
82
  - spec/support/seed_directory/dir1.yml
80
83
  - spec/support/seed_directory/dir2.yml
84
+ - spec/support/single_model.json
81
85
  - spec/support/single_model.yml