Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aledustet committed Aug 2, 2019
1 parent 94a10ad commit bb18150
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
14 changes: 14 additions & 0 deletions lib/factory_bot/definition_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ def association(name, *options)
end
end

# Creates a copy of the file passed to attach to the attribute
#
# Arguments:
# filepath: (String)
# The path for the file that will be loaded. Should be a valid path
# for a file that exists at that location.
#
# Returns:
# An instance of the file loader class pointing to the file at the
# provided path.
def file_fixture(file_path)
FileLoader.new(file_path)
end

def to_create(&block)
@definition.to_create(&block)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/factory_bot/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def instance=(object_instance)
@instance = object_instance
end

def file_fixture(file_path)
FileLoader.new(file_path)
end

def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissing
if @instance.respond_to?(method_name)
@instance.send(method_name, *args, &block)
Expand Down
14 changes: 0 additions & 14 deletions lib/factory_bot/syntax/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,6 @@ def generate_list(name, count)
Internal.sequence_by_name(name).next
end
end

# Creates a copy of the file passed to attach to the attribute
#
# Arguments:
# filepath: (String)
# The path for the file that will be loaded. Should be a valid path
# for a file that exists at that location.
#
# Returns:
# An instance of the file loader class pointing to the file at the
# provided path.
def file_fixture(file_path)
FileLoader.new(file_path)
end
end
end
end
4 changes: 2 additions & 2 deletions spec/acceptance/file_attributes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe "file attributes" do
context "when an attribute uses a file" do
it "assigns an file to the attribute" do
define_class("Post") do |_class|
attr_accessor :attachment
define_model("Post") do
has_one_attached :attachment
end
filename = File.expand_path("spec/support/text_file.txt")
file_contents = File.read(filename)
Expand Down

0 comments on commit bb18150

Please sign in to comment.