Sha256: 43ec5eada9dbe5694905e1c8e8b5589d504dbdb4f3f3946a9fc805c92ec35e1c

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# Attach a file
#
# Example:
#
#   Company.new.logo = File.new…
#
#   Given the file "…" was attached as logo to the company above
#
#
# Example:
#
#   class Gallery
#     has_many :images, :as => :owner
#   end
#
#   class Image
#     belongs_to :owner, polymorphic: true
#   end
#
#   # so container = Image.new; container.file = File.new… , container.owner = object
#
#   Given the file "…" was attached as Image/file to the company above
#
#
# Example:
#
#   Set updated_at with
#
#     Given … 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?

  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

7 entries across 7 versions & 1 rubygems

Version Path
spreewald-0.9.0 lib/spreewald/file_attachment_steps.rb
spreewald-0.8.6 lib/spreewald/file_attachment_steps.rb
spreewald-0.8.5 lib/spreewald/file_attachment_steps.rb
spreewald-0.8.4 lib/spreewald/file_attachment_steps.rb
spreewald-0.8.3 lib/spreewald/file_attachment_steps.rb
spreewald-0.8.2 lib/spreewald/file_attachment_steps.rb
spreewald-0.8.1 lib/spreewald/file_attachment_steps.rb