Looking for a way for DRY fixtures. Say we have some data. There is a part that can be referenced from $ LABEL. Here is an example:
DEFAULTS: &DEFAULTS state: $LABEL score: 99 one: <<: *DEFAULTS uuid: <%= ActiveRecord::FixtureSet.identify(:one, :uuid) %> two: <<: *DEFAULTS uuid: <%= ActiveRecord::FixtureSet.identify(:two, :uuid) %>
Is there a DRY way of doing this. I want something like this:
DEFAULTS: &DEFAULTS state: $LABEL score: 99 uuid: <%= ActiveRecord::FixtureSet.identify($LABEL, :uuid) %> one: <<: *DEFAULTS two: <<: *DEFAULTS
But this is not possible because $ LABEL is not evaluated here. Any suggestions?
I just struggled with the same problem and really don't want to switch to factories for only a few cases where it would be useful.
, , uuid , ? uuids ( Postgres), , , , Rails . primary_key , uuid, , , $LABEL .
primary_key
, ERB $LABEL.
$LABEL
ActiveRecord:
https://github.com/rails/rails/blob/d514ce9199fac58e569482dc901e53d0526abdf7/activerecord/lib/active_record/fixtures.rb#L656
663 , , $PRIMARY_KEY YAML, $LABEL.
$PRIMARY_KEY
# interpolate the primary key row.each do |key, value| row[key] = value.gsub("$PRIMARY_KEY", row[primary_key_name].to_s) if value.is_a?(String) end
, , , - .
Source: https://habr.com/ru/post/1681097/More articles:Count counts in Python unittests separately - pythonLINQ OrderBy based on string values - c #Spark SQL change number format - scalaHow to set display accuracy in PySpark Dataframe show - pysparkKapt generatestubs - невозможно инициализировать объект с помощью внутреннего конструктора из unit-test - constructorUse project link in Debug and Nuget in release - c #Why does initscr () after delwin () return undef? - perl6How to make a convolution with maxout activation? - pythonLaravel 5.4 using Mail fake with Mail :: queue, Mail :: assertSent not working - emailError predicted with mlr: - rAll Articles