Sha256: 0f22daa7d87069ab2a46eb59dad91466f83efbf40ff4d7a810232d884334b60d

Contents?: true

Size: 1.39 KB

Versions: 36

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

36 entries across 36 versions & 1 rubygems

Version Path
spreewald-2.2.4 lib/spreewald/file_attachment_steps.rb
spreewald-2.2.3 lib/spreewald/file_attachment_steps.rb
spreewald-2.2.2 lib/spreewald/file_attachment_steps.rb
spreewald-2.2.1 lib/spreewald/file_attachment_steps.rb
spreewald-2.2.0 lib/spreewald/file_attachment_steps.rb
spreewald-2.1.3 lib/spreewald/file_attachment_steps.rb
spreewald-2.1.2 lib/spreewald/file_attachment_steps.rb
spreewald-2.1.1 lib/spreewald/file_attachment_steps.rb
spreewald-2.1.0 lib/spreewald/file_attachment_steps.rb
spreewald-2.0.0 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.6 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.5 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.4 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.3 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.2 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.1 lib/spreewald/file_attachment_steps.rb
spreewald-1.12.0 lib/spreewald/file_attachment_steps.rb
spreewald-1.11.6 lib/spreewald/file_attachment_steps.rb
spreewald-1.11.5 lib/spreewald/file_attachment_steps.rb
spreewald-1.11.4 lib/spreewald/file_attachment_steps.rb