Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
composerinteralia committed Jul 16, 2020
1 parent 37bc11d commit 8d9bcda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def self.build_stubbed_starting_id=(starting_id)
end

class << self
attr_accessor :file_fixture_path

delegate :factories,
:register_strategy,
:rewind_sequences,
Expand Down
16 changes: 16 additions & 0 deletions lib/factory_bot/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ def association(factory_name, *traits_and_overrides)
@build_strategy.association(runner)
end

# TODO: only define this if Rack::Test::UploadedFile exists
def file_fixture(filename)
if FactoryBot.file_fixture_path.present?
path = Pathname.new(File.join(FactoryBot.file_fixture_path, filename))

if path.exist?
Rack::Test::UploadedFile.new(path)
else
msg = "the directory '%s' does not contain a file named '%s'"
Kernel.raise ArgumentError, msg % [file_fixture_path, filename]
end
else
Kernel.raise "to use the file_fixture helper you must set FactoryBot.file_fixture_path='path/to/fixture_files'"
end
end

attr_accessor :instance

if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
Expand Down

0 comments on commit 8d9bcda

Please sign in to comment.