Sha256: e9ca2a9ca0d1f213f62d40ad8b80ba7cae07a74540228f460739936bc3a00a8f

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

# Attach a file to the given model's last record.
#
# Example (Company has a `file` attribute):
#
#     Given the file "image.png" was attached to the company above
#
# You may specify the attribute under which the file is stored …
#
# Example (Company has a `logo` attribute):
#
#     Given the file "image.png" was attached as logo to the company above
#
# … or both a container class and its attribute name
#
# Example (Company has many `Image`s, `Image` has a `file` attribute)
#
#     Given the file "image.png" was attached as Image/file to the company above
#
# To simultaneously set the `updated_at` timestamp:
#
#     Given the file "some_file" was attached to the profile above at "2011-11-11 11:11"
#
Given /^the file "([^"]*)" was attached(?: as (?:([^"]*)\/)?([^"]*))? to the ([^"]*) above(?: at "([^"]*)")?$/ do
  |path_to_file, container_name, relation_name, model_name, time_string|

  object = model_name.camelize.constantize.last
  time = Time.parse(time_string) if time_string.present?
  relation_name ||= 'file'

  if container_name.present?
    container = container_name.camelize.constantize.new # Image.file = File... owner: gallery
    container.owner = object
    container.created_at = time if time
  else
    container = object # Person.avatar = File...
  end

  container.send("#{relation_name}=", File.new(path_to_file))
  container.updated_at = time if time
  container.save!
end.overridable

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spreewald-1.6.0 lib/spreewald/file_attachment_steps.rb
spreewald-1.5.5 lib/spreewald/file_attachment_steps.rb
spreewald-1.5.4 lib/spreewald/file_attachment_steps.rb
spreewald-1.5.3 lib/spreewald/file_attachment_steps.rb
spreewald-1.5.2 lib/spreewald/file_attachment_steps.rb
spreewald-1.5.1 lib/spreewald/file_attachment_steps.rb
spreewald-1.5.0 lib/spreewald/file_attachment_steps.rb