ualbertalib / acts_as_rdfable

MIT License
0 stars 1 forks source link

Modify to help us with seeding and testing our application #12

Closed pgwillia closed 2 years ago

pgwillia commented 3 years ago

I'm thinking about modifying acts_as_rdfable to help us with this.

Any of the add/remove/delete methods in ActsAsRdfable::MigrationAnnotations::RdfConfig could create/update a db/seeds/rdf_annotations.rb file in our application (maybe seed_dump) with the current dump of the database.

# lib/acts_as_rdfable/migration_annotations.rb
def dump_rdf_annotations
  SeedDump.dump(RdfAnnotation, file: 'db/seeds/rdf_annotations.rb')
end
# db/seeds/rdf_annotations.rb
RdfAnnotation.create!([
  {table: "items", column: "title", predicate: "http://purl.org/dc/terms/title"},
  {table: "items", column: "fedora3_uuid", predicate: "http://terms.library.ualberta.ca/fedora3UUID"},
  {table: "items", column: "depositor", predicate: "http://terms.library.ualberta.ca/depositor"},
...
  {table: "items", column: "alternative_title", predicate: "http://purl.org/dc/terms/alternative"}
])

We could check this in along with our db/schema.rb. Then load it from our db/seeds.rb

# db/seeds.rb
load('db/seeds/rdf_annotations.rb')

Right now in order to get all the RdfAnnotations we need to run all the migrations rather than being able to take advantage of something like rails db:setup.

And for our tests, There's Rails.application.load_seed which isn't exactly what we want but we could add

# test/test_helper.rb
class ActiveSupport::TestCase

  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all
  load('db/seeds/rdf_annotations.rb')

_Originally posted by @pgwillia in https://github.com/ualbertalib/jupiter/pull/2470#discussion_r701394557_