Created
April 15, 2021 12:53
-
-
Save adelahayepm/ec4e3f9e5e2eb0e5b6c2c1149589f907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module FactoryBot | |
module Syntax | |
module Default | |
class DSL | |
def spira_factory(name, options = {}, &block) | |
factory(name, options) do | |
instance_eval do | |
initialize_with do | |
RDF::Graph.new.tap do |g| | |
Spira.using_repository(g) do | |
new(attributes).save! | |
end | |
end | |
end | |
instance_eval(&block) if block | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyApp | |
class User < ::Spira::Base | |
configure base_uri: 'http://example.org/user' | |
property :bob, predicate: RDF::Vocab::DC.title, type: String | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryBot.define do | |
spira_factory :user, class: MyApp::User do | |
name { 'Bob' } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment