Sha256: 270111301d42913301b041a7255f3763bc6046f509e445bae671afd9ab9da2c8

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

Contents

When /^I(\sstrict\s|\s)update the '(.+)' for '(.+)' to '(.+)'$/ do |strict, attr, doc_name, value|
  doc = instance_variable_get("@#{doc_name}")
  attrs = {attr => value}
  attrs.merge!(:__strict__ => true) unless strict.blank?
  @last_return = doc.update_attributes(attrs)
end

When /^someone else changes the (.+?) '(.+)' of '(.+)' to$/ do |assoc_klass, assoc_name, name, table|
  orig = instance_variable_get("@#{name}")
  doc = orig.class.find_one(orig._id)
  obj = assoc_klass.constantize.new
  table.hashes.each do |hash|
    hash.each do |key, value|
      obj.send("#{key.underscore.gsub(' ', '_')}=", value)
    end
  end
  doc.send("#{assoc_name.underscore.gsub(' ', '_')}=", obj)
  doc.save
end

When /^someone else changes the (.+) of '(.+)':$/ do |assoc_name, name, table|
  orig = instance_variable_get("@#{name}")
  doc = orig.class.find_one(orig._id)
  doc.send(assoc_name).clear
  table.hashes.each do |hash|
    doc.send(assoc_name) << hash.inject({}) do |attrs, (attr, value)|
      attrs["#{attr.underscore.gsub(' ', '_')}"] = value
      attrs
    end
  end
  doc.save
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mongo_doc-0.4.1 features/step_definitions/partial_update_steps.rb
mongo_doc-0.4.0 features/step_definitions/partial_update_steps.rb
mongo_doc-0.3.2 features/step_definitions/partial_update_steps.rb
mongo_doc-0.3.1 features/step_definitions/partial_update_steps.rb
mongo_doc-0.3.0 features/step_definitions/partial_update_steps.rb
mongodoc-0.2.4 features/step_definitions/partial_update_steps.rb
mongodoc-0.2.2 features/step_definitions/partial_update_steps.rb
mongodoc-0.2.1 features/step_definitions/partial_update_steps.rb
mongodoc-0.2.0 features/step_definitions/partial_update_steps.rb