Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3363: 3363_binary_in_yaml_fixtures.diff

File 3363_binary_in_yaml_fixtures.diff, 0.9 kB (added by jamie@bravenet.com, 4 years ago)

ensures binary-encoded data in YAML fixtures makes it to the database as the intended binary data

  • activerecord/lib/active_record/fixtures.rb

    old new  
    293293          if yaml = YAML::load(erb_render(IO.read(yaml_file_path))) 
    294294            yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value) 
    295295            yaml.each do |name, data| 
     296              # Convert any binary fixtures to correct value before placing in database. 
     297              # Requires that the database field is binary-safe if binary fixtures are used. 
     298              data.each do |key, val| 
     299                if val.kind_of? YAML::Syck::PrivateType and val.type_id == 'binary' 
     300                  data[key] = Base64.decode64(val.value) 
     301                end 
     302              end 
    296303              self[name] = Fixture.new(data, @class_name) 
    297304            end 
    298305          end