Sha256: 68b6737449061b600436cb7346d981201a599e54ffbb007315aa074e39268583

Contents?: true

Size: 1.38 KB

Versions: 34

Compression:

Stored size: 1.38 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

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
spreewald-1.4.0 lib/spreewald/file_attachment_steps.rb
spreewald-1.3.3 lib/spreewald/file_attachment_steps.rb
spreewald-1.3.2 lib/spreewald/file_attachment_steps.rb
spreewald-1.3.1 lib/spreewald/file_attachment_steps.rb
spreewald-1.3.0 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.14 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.13 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.12 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.11 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.10 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.9 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.8 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.7 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.6 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.5 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.4 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.3 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.2 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.1 lib/spreewald/file_attachment_steps.rb
spreewald-1.2.0 lib/spreewald/file_attachment_steps.rb