Technology and Software

Factory_girl and Globalize3

This is a quick one. I had to populate a test database with models with attributes translated with Globalize3. There are validations that fail if those attributes are not set before saving the record. This is the correct code:

record = Factory.build(:model)
I18n.available_locales.each do |locale|
  Globalize.with_locale(locale) do
    record.attribute = "Model_attribute_#{locale} #{n}"
  end
end
model.save


 

Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s