fixturex 0.1.1 → 0.1.2
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/Gemfile.lock +8 -8
- data/lib/fixturex/tree_builder.rb +26 -10
- data/lib/fixturex/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 969e8e5573328295b3bd63b0ec6ec2bef3f3462a613009f44ac5f8dfc9ba5c7d
         | 
| 4 | 
            +
              data.tar.gz: 02c925a94649f82fb08c7d5c1b555b10a95546054db19a864216717239da213d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6477664978fff4a5ee9ceee56decf5c96ceadacba17f02c81f15adde91e1678b72b4bf183b64ddfd3333396cf5a3691c1015f0095c9e93f69e9bc29fe051f53f
         | 
| 7 | 
            +
              data.tar.gz: d7f085be682df75a9dd849c7dd1473d97d56bea48090738def17095ec11f409fb23c43e32e33516f6c4158e546130de460ee3b332ebd83ee4db67045d8da9e71
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                fixturex (0.1. | 
| 4 | 
            +
                fixturex (0.1.2)
         | 
| 5 5 | 
             
                  rails (>= 6.0)
         | 
| 6 6 |  | 
| 7 7 | 
             
            GEM
         | 
| @@ -75,7 +75,7 @@ GEM | |
| 75 75 | 
             
                diff-lcs (1.4.4)
         | 
| 76 76 | 
             
                docile (1.4.0)
         | 
| 77 77 | 
             
                erubi (1.10.0)
         | 
| 78 | 
            -
                globalid (0. | 
| 78 | 
            +
                globalid (1.0.0)
         | 
| 79 79 | 
             
                  activesupport (>= 5.0)
         | 
| 80 80 | 
             
                i18n (1.8.10)
         | 
| 81 81 | 
             
                  concurrent-ruby (~> 1.0)
         | 
| @@ -84,9 +84,9 @@ GEM | |
| 84 84 | 
             
                  nokogiri (>= 1.5.9)
         | 
| 85 85 | 
             
                mail (2.7.1)
         | 
| 86 86 | 
             
                  mini_mime (>= 0.1.1)
         | 
| 87 | 
            -
                marcel (1.0. | 
| 87 | 
            +
                marcel (1.0.2)
         | 
| 88 88 | 
             
                method_source (1.0.0)
         | 
| 89 | 
            -
                mini_mime (1.1. | 
| 89 | 
            +
                mini_mime (1.1.2)
         | 
| 90 90 | 
             
                mini_portile2 (2.6.1)
         | 
| 91 91 | 
             
                minitest (5.14.4)
         | 
| 92 92 | 
             
                nio4r (2.5.8)
         | 
| @@ -169,12 +169,12 @@ GEM | |
| 169 169 | 
             
                  simplecov_json_formatter (~> 0.1)
         | 
| 170 170 | 
             
                simplecov-html (0.12.3)
         | 
| 171 171 | 
             
                simplecov_json_formatter (0.1.3)
         | 
| 172 | 
            -
                sprockets (4. | 
| 172 | 
            +
                sprockets (4.1.1)
         | 
| 173 173 | 
             
                  concurrent-ruby (~> 1.0)
         | 
| 174 174 | 
             
                  rack (> 1, < 3)
         | 
| 175 | 
            -
                sprockets-rails (3. | 
| 176 | 
            -
                  actionpack (>=  | 
| 177 | 
            -
                  activesupport (>=  | 
| 175 | 
            +
                sprockets-rails (3.4.2)
         | 
| 176 | 
            +
                  actionpack (>= 5.2)
         | 
| 177 | 
            +
                  activesupport (>= 5.2)
         | 
| 178 178 | 
             
                  sprockets (>= 3.0.0)
         | 
| 179 179 | 
             
                sqlite3 (1.4.2)
         | 
| 180 180 | 
             
                thor (1.1.0)
         | 
| @@ -11,30 +11,29 @@ module Fixturex | |
| 11 11 | 
             
              class ModelFixtures
         | 
| 12 12 | 
             
                Fixture = Struct.new(:name, :path, :attributes)
         | 
| 13 13 |  | 
| 14 | 
            -
                def self.load( | 
| 15 | 
            -
                  fixtures_paths( | 
| 14 | 
            +
                def self.load(model_class)
         | 
| 15 | 
            +
                  fixtures_paths(model_class).each_with_object([]) do |path, acc|
         | 
| 16 16 | 
             
                    fixtures = YAML.load_file(path)
         | 
| 17 17 | 
             
                    fixtures.select! do |_name, attributes|
         | 
| 18 18 | 
             
                      # if fixture has `type` - STI - then we only want type == class_name
         | 
| 19 | 
            -
                      attributes['type'].nil? || attributes['type'] ==  | 
| 19 | 
            +
                      attributes['type'].nil? || attributes['type'] == model_class.name
         | 
| 20 20 | 
             
                    end
         | 
| 21 21 | 
             
                    acc.concat(fixtures.map { |name, attributes| Fixture.new(name, path, attributes) })
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 | 
            -
                def self.fixtures_paths( | 
| 25 | 
            +
                def self.fixtures_paths(model_class)
         | 
| 26 26 | 
             
                  fixtures_paths = []
         | 
| 27 | 
            -
                  klass = class_name.constantize
         | 
| 28 27 | 
             
                  # TODO: is there a better way to find out fixtures root directory?
         | 
| 29 28 | 
             
                  fixtures_root = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
         | 
| 30 29 |  | 
| 31 | 
            -
                  while  | 
| 32 | 
            -
                    fixture_file = "#{ | 
| 30 | 
            +
                  while model_class < ActiveRecord::Base
         | 
| 31 | 
            +
                    fixture_file = "#{model_class.to_s.tableize}.yml"
         | 
| 33 32 | 
             
                    path = File.join(fixtures_root, *fixture_file.split('/'))
         | 
| 34 33 |  | 
| 35 34 | 
             
                    fixtures_paths << path if File.exist?(path)
         | 
| 36 35 |  | 
| 37 | 
            -
                     | 
| 36 | 
            +
                    model_class = model_class.superclass
         | 
| 38 37 | 
             
                  end
         | 
| 39 38 | 
             
                  fixtures_paths
         | 
| 40 39 | 
             
                end
         | 
| @@ -68,10 +67,12 @@ module Fixturex | |
| 68 67 |  | 
| 69 68 | 
             
                private
         | 
| 70 69 |  | 
| 70 | 
            +
                # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
         | 
| 71 71 | 
             
                def nested_fixtures_locations(parent_fixture_model_class, parent_fixture_name)
         | 
| 72 72 | 
             
                  associations_for_nested_models(parent_fixture_model_class).each_with_object([]) do |association, acc|
         | 
| 73 73 | 
             
                    belongs_to_attribute = belongs_to_attribute_for_association(association)
         | 
| 74 | 
            -
                     | 
| 74 | 
            +
                    child_model_class = association_model_class(association)
         | 
| 75 | 
            +
                    model_fixtures = self.class.cache[association.class_name] ||= ModelFixtures.load(child_model_class)
         | 
| 75 76 |  | 
| 76 77 | 
             
                    model_fixtures.each do |fixture|
         | 
| 77 78 | 
             
                      next if fixture.attributes.fetch(belongs_to_attribute, '').to_s.sub(/ .*/, '') != parent_fixture_name
         | 
| @@ -82,6 +83,18 @@ module Fixturex | |
| 82 83 | 
             
                    end
         | 
| 83 84 | 
             
                  end
         | 
| 84 85 | 
             
                end
         | 
| 86 | 
            +
                # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                def association_model_class(association)
         | 
| 89 | 
            +
                  class_name = association.class_name
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  unless Object.const_defined?(class_name)
         | 
| 92 | 
            +
                    namespace = association.active_record.name.split('::')[0..-2].join('::')
         | 
| 93 | 
            +
                    class_name = "#{namespace}::#{class_name}"
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                  class_name.constantize
         | 
| 97 | 
            +
                end
         | 
| 85 98 |  | 
| 86 99 | 
             
                def fixture_already_collected(list, fixture)
         | 
| 87 100 | 
             
                  list.find do |tree_entry|
         | 
| @@ -98,7 +111,10 @@ module Fixturex | |
| 98 111 | 
             
                  if association.type.present?
         | 
| 99 112 | 
             
                    association.type.sub('_type', '')
         | 
| 100 113 | 
             
                  else
         | 
| 101 | 
            -
                    association | 
| 114 | 
            +
                    child_model_class = association_model_class(association)
         | 
| 115 | 
            +
                    child_model_class.reflect_on_all_associations(:belongs_to).find do |belongs_to_association|
         | 
| 116 | 
            +
                      belongs_to_association.class_name == association.active_record.name
         | 
| 117 | 
            +
                    end.name.to_s
         | 
| 102 118 | 
             
                  end
         | 
| 103 119 | 
             
                end
         | 
| 104 120 | 
             
              end
         | 
    
        data/lib/fixturex/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fixturex
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - artemave
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-08-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |