kostyantyn / hydra_attribute

Implementation of EAV pattern for ActiveRecord models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to properly test a Rails application using hydra_attributes?

paulepanter opened this issue · comments

Using hydra_attributes in a Ruby on Rails application and setting up a RSpec request spec for testing, we always hit a no attribute error because the database is always emptied before each run and it looks like hydra_attribute has not been initialized yet. Are there helper methods or ways to deal with that?

if i understood you correctly, you truncate data before every test. If yes, you can re-create your attributes before each test. For example:

# spec/spec_helper.rb
RSpec.configure do |config|
  config.before do
    Product.hydra_attributes.create(name: 'price', backend_type: 'float')
  end
end

Thank you for the quick reply. We tried that already, but it is already too late for hydra_attributes in our tests. We try to get a minimal example set up. But this will take at least two weeks. Thanks again.