Sha256: 61238b2b438652d5308b1aaad05e9adbe721719999ba9418b6d8cf80d793722f

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

module ShouldBeRestful # :nodoc:
  module Helpers # :nodoc:
    private # :enddoc:

    def get_existing_record(res) # :nodoc:
      returning(instance_variable_get("@#{res.object}")) do |record|
        assert(record, "This test requires you to set @#{res.object} in your setup block")
      end
    end

    def make_parent_params(resource, record = nil, parent_names = nil) # :nodoc:
      parent_names ||= resource.parents.reverse
      return {} if parent_names == [] # Base case
      parent_name = parent_names.shift
      parent = record ? record.send(parent_name) : parent_name.to_s.classify.constantize.find(:first)

      { :"#{parent_name}_id" => parent.to_param }.merge(make_parent_params(resource, parent, parent_names))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
khalsah-should_be_restful-1.0.0 lib/should_be_restful/helpers.rb