seedomatic 0.6.0 → 0.6.1
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 +4 -4
- data/lib/seedomatic/seeder.rb +12 -3
- data/lib/seedomatic/version.rb +1 -1
- data/spec/lib/seeder_spec.rb +15 -1
- data/spec/support/my_model.rb +7 -1
- metadata +13 -13
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ded7e5f21770ef24d3bd1c70c5715b8416c793d7
         | 
| 4 | 
            +
              data.tar.gz: 5ba7d227b09e773386f166e220b9cf2cfd0747c4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8b566bacf4a664a78a235c1cf50cd21c4ceaba23f371ded06c3a8e7fe344c3b44628b94dd6f5ac82d3f4d8d9df63508aef503035df2cfc39df3d500a79338ebc
         | 
| 7 | 
            +
              data.tar.gz: 46df87a18a26175401a561d5382736fb2354ef84c9c80116ff071baa65f70da57cbabc4fffa212e68e3ca5e199c5da5e640818e7d8bbf43fbc8528dd37f1f9c9
         | 
    
        data/lib/seedomatic/seeder.rb
    CHANGED
    
    | @@ -52,9 +52,18 @@ module SeedOMatic | |
| 52 52 | 
             
                    attrs.delete(key)
         | 
| 53 53 |  | 
| 54 54 | 
             
                    association = key.gsub("_lookup", "").to_sym
         | 
| 55 | 
            -
                     | 
| 56 | 
            -
             | 
| 57 | 
            -
                     | 
| 55 | 
            +
                    reflection = model_class.reflect_on_association(association)
         | 
| 56 | 
            +
                    lookup_class = reflection.klass
         | 
| 57 | 
            +
                    association_type = reflection.macro
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    if association_type == :has_many
         | 
| 60 | 
            +
                      attrs[association] = []
         | 
| 61 | 
            +
                      value.each do |v|
         | 
| 62 | 
            +
                        attrs[association] << lookup_class.where(v).first
         | 
| 63 | 
            +
                      end
         | 
| 64 | 
            +
                    else
         | 
| 65 | 
            +
                      attrs[association] = lookup_class.where(value).first
         | 
| 66 | 
            +
                    end
         | 
| 58 67 | 
             
                  end
         | 
| 59 68 | 
             
                  attrs
         | 
| 60 69 | 
             
                end
         | 
    
        data/lib/seedomatic/version.rb
    CHANGED
    
    
    
        data/spec/lib/seeder_spec.rb
    CHANGED
    
    | @@ -46,13 +46,27 @@ describe SeedOMatic::Seeder do | |
| 46 46 | 
             
                    let(:items) { [{'name' => 'foo', 'category_lookup' => { 'code' => 'bar' }}]}
         | 
| 47 47 | 
             
                    let(:category) { MyCategory.new }
         | 
| 48 48 | 
             
                    specify {
         | 
| 49 | 
            -
                      MyModel.should_receive(:reflect_on_association).with(:category).and_return(OpenStruct.new(:klass => MyCategory))
         | 
| 49 | 
            +
                      MyModel.should_receive(:reflect_on_association).with(:category).and_return(OpenStruct.new(:klass => MyCategory, :macro => :has_one))
         | 
| 50 50 | 
             
                      MyCategory.should_receive(:where).with(hash_including('code' => 'bar')).and_return(OpenStruct.new(:first => category))
         | 
| 51 51 | 
             
                      subject
         | 
| 52 52 | 
             
                      MyModel[0].category.should == category
         | 
| 53 53 | 
             
                      MyModel[0].category_lookup.should be_nil
         | 
| 54 54 | 
             
                    }
         | 
| 55 55 | 
             
                  end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  context "has many lookup fields" do
         | 
| 58 | 
            +
                    let(:items) {[{'name' => 'foo', 'things_lookup' => [{'name' => 'thingy'}, {'code' => 'broom'}]}]}
         | 
| 59 | 
            +
                    let(:thing1) { MyThing.new }
         | 
| 60 | 
            +
                    let(:thing2) { MyThing.new }
         | 
| 61 | 
            +
                    specify {
         | 
| 62 | 
            +
                      MyModel.should_receive(:reflect_on_association).with(:things).and_return(OpenStruct.new(:klass => MyThing, :macro => :has_many))
         | 
| 63 | 
            +
                      MyThing.should_receive(:where).with(hash_including('name' => 'thingy')).and_return(OpenStruct.new(:first => thing1))
         | 
| 64 | 
            +
                      MyThing.should_receive(:where).with(hash_including('code' => 'broom')).and_return(OpenStruct.new(:first => thing2))
         | 
| 65 | 
            +
                      subject
         | 
| 66 | 
            +
                      MyModel[0].things.should == [thing1, thing2]
         | 
| 67 | 
            +
                      MyModel[0].things_lookup.should be_nil
         | 
| 68 | 
            +
                    }
         | 
| 69 | 
            +
                  end
         | 
| 56 70 | 
             
                end
         | 
| 57 71 |  | 
| 58 72 | 
             
                describe "checking uniqueness on a specified field" do
         | 
    
        data/spec/support/my_model.rb
    CHANGED
    
    | @@ -2,8 +2,12 @@ class MyCategory | |
| 2 2 |  | 
| 3 3 | 
             
            end
         | 
| 4 4 |  | 
| 5 | 
            +
            class MyThing
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            end
         | 
| 8 | 
            +
             | 
| 5 9 | 
             
            class MyModel
         | 
| 6 | 
            -
              attr_accessor :name, :new_record, :category, :category_lookup
         | 
| 10 | 
            +
              attr_accessor :name, :new_record, :category, :things, :category_lookup, :things_lookup
         | 
| 7 11 |  | 
| 8 12 | 
             
              @@models = []
         | 
| 9 13 |  | 
| @@ -31,7 +35,9 @@ class MyModel | |
| 31 35 | 
             
                attr = attr.with_indifferent_access
         | 
| 32 36 | 
             
                self.name = attr['name']
         | 
| 33 37 | 
             
                self.category = attr['category']
         | 
| 38 | 
            +
                self.things = attr['things']
         | 
| 34 39 | 
             
                self.category_lookup = attr['category_lookup']
         | 
| 40 | 
            +
                self.things_lookup = attr['things_lookup']
         | 
| 35 41 | 
             
              end
         | 
| 36 42 |  | 
| 37 43 | 
             
              def save!
         | 
    
        metadata
    CHANGED
    
    | @@ -1,55 +1,55 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: seedomatic
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ryan Brunner
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-09-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: 2.9.0
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - ~>
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: 2.9.0
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: pry
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 31 | 
            +
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: '0'
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 38 | 
            +
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: activesupport
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 45 | 
            +
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: '0'
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 52 | 
            +
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '0'
         | 
| 55 55 | 
             
            description: Create repeatable seed fixtures that you can continually use and deploy
         | 
| @@ -60,8 +60,8 @@ executables: [] | |
| 60 60 | 
             
            extensions: []
         | 
| 61 61 | 
             
            extra_rdoc_files: []
         | 
| 62 62 | 
             
            files:
         | 
| 63 | 
            -
            - .gitignore
         | 
| 64 | 
            -
            - .rspec
         | 
| 63 | 
            +
            - ".gitignore"
         | 
| 64 | 
            +
            - ".rspec"
         | 
| 65 65 | 
             
            - Gemfile
         | 
| 66 66 | 
             
            - Rakefile
         | 
| 67 67 | 
             
            - lib/seedomatic.rb
         | 
| @@ -90,17 +90,17 @@ require_paths: | |
| 90 90 | 
             
            - lib
         | 
| 91 91 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 92 92 | 
             
              requirements:
         | 
| 93 | 
            -
              - -  | 
| 93 | 
            +
              - - ">="
         | 
| 94 94 | 
             
                - !ruby/object:Gem::Version
         | 
| 95 95 | 
             
                  version: '0'
         | 
| 96 96 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 97 97 | 
             
              requirements:
         | 
| 98 | 
            -
              - -  | 
| 98 | 
            +
              - - ">="
         | 
| 99 99 | 
             
                - !ruby/object:Gem::Version
         | 
| 100 100 | 
             
                  version: '0'
         | 
| 101 101 | 
             
            requirements: []
         | 
| 102 102 | 
             
            rubyforge_project: seedomatic
         | 
| 103 | 
            -
            rubygems_version: 2. | 
| 103 | 
            +
            rubygems_version: 2.2.2
         | 
| 104 104 | 
             
            signing_key: 
         | 
| 105 105 | 
             
            specification_version: 4
         | 
| 106 106 | 
             
            summary: Seed-O-Matic makes seeding easier.
         |