Save syndication sources to posts
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
require_relative "db/helpers"
|
||||
require_relative "db/database_cleaner"
|
||||
require_relative "db/factory"
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before :suite do
|
||||
@@ -11,5 +12,5 @@ RSpec.configure do |config|
|
||||
|
||||
config.include Test::DB::Helpers, :db
|
||||
|
||||
# config.include(Test::DB::FactoryHelper.new, factory: nil)
|
||||
config.include(Test::DB::FactoryHelper.new, factory: nil)
|
||||
end
|
||||
|
@@ -5,6 +5,10 @@ require_relative "helpers"
|
||||
DatabaseCleaner[:sequel].strategy = :transaction
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before :suite do
|
||||
DatabaseCleaner[:sequel].clean_with :truncation
|
||||
end
|
||||
|
||||
config.prepend_before :each, type: :db do |example|
|
||||
strategy = example.metadata[:js] ? :truncation : :transaction
|
||||
DatabaseCleaner[:sequel].strategy = strategy
|
||||
|
42
spec/support/db/factory.rb
Normal file
42
spec/support/db/factory.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
require "rom-factory"
|
||||
require_relative "helpers"
|
||||
|
||||
module Test
|
||||
Factory = ROM::Factory.configure { |config|
|
||||
config.rom = Test::DB::Helpers.rom
|
||||
}
|
||||
|
||||
module DB
|
||||
class FactoryHelper < Module
|
||||
ENTITIES_MODULE_NAME = :Entities
|
||||
|
||||
attr_reader :slice_name
|
||||
|
||||
def initialize(slice_name = nil)
|
||||
@slice_name = slice_name
|
||||
|
||||
factory = entity_namespace ? Test::Factory.struct_namespace(entity_namespace) : Factory
|
||||
|
||||
define_method(:factory) do
|
||||
factory
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def entity_namespace
|
||||
return @entity_namespace if instance_variable_defined?(:@entity_namespace)
|
||||
|
||||
slice = slice_name ? Hanami.app.slices[slice_name] : Hanami.app
|
||||
slice_namespace = slice.namespace
|
||||
|
||||
@entity_namespace =
|
||||
if slice_namespace.const_defined?(ENTITIES_MODULE_NAME)
|
||||
slice_namespace.const_get(ENTITIES_MODULE_NAME)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Dir[SPEC_ROOT.join("support/factories/**/*.rb")].each { require(_1) }
|
7
spec/support/factories/posts.rb
Normal file
7
spec/support/factories/posts.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
Test::Factory.define(:post) do |f|
|
||||
f.name "post_name"
|
||||
f.content "post_content"
|
||||
f.slug "post-slug"
|
||||
f.published_at Time.now
|
||||
f.syndication_sources {}
|
||||
end
|
20
spec/support/feature_loader.rb
Normal file
20
spec/support/feature_loader.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "dry/system"
|
||||
|
||||
RSpec.configure do |config|
|
||||
Dir[File.join(__dir__, "*.rb")].sort.each do |file|
|
||||
options = Dry::System::MagicCommentsParser.call(file)
|
||||
tag_name = options[:require_with_metadata]
|
||||
|
||||
next unless tag_name
|
||||
|
||||
tag_name = File.basename(file, File.extname(file)) if tag_name.eql?(true)
|
||||
|
||||
config.when_first_matching_example_defined(tag_name.to_sym) do
|
||||
require file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Dir[SPEC_ROOT.join("support", "**", "global_config.rb")].each { require _1 }
|
Reference in New Issue
Block a user