Sha256: 182e44b14a18411d413b14cb3ff22e5c6e49bd73fe6cb1e6105091ccd325f0c8
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
module DSL module Resource extend ActiveSupport::Concern module ClassMethods def self.define_action(verb) define_method verb do |route, args = {}, &block| rspec_api.merge! array: args.delete(:array), verb: verb, route: route args.merge! rspec_api_dsl: :route describe("#{verb.upcase} #{route}", args, &block) end end define_action :get define_action :put define_action :patch define_action :post define_action :delete def has_attribute(name, type, options = {}) parent = (@attribute_ancestors || []).inject(rspec_api) {|chain, step| chain[:attributes][step]} (parent[:attributes] ||= {})[name] = options.merge(type: type) nested_attribute(name, &Proc.new) if block_given? end def accepts_page(page_parameter) rspec_api[:page] = page_parameter end def accepts_sort(sort_parameter, options={}) rspec_api[:sort] = {parameter: sort_parameter, attribute: options[:on]} end # TODO: the second 'accepts_filter' should not override the first, but add def accepts_filter(filter_parameter, options={}) rspec_api[:filter] = options.merge(name: filter_parameter) end private def nested_attribute(name) (@attribute_ancestors ||= []).push name yield @attribute_ancestors.pop end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rspec-api-0.1.1 | lib/rspec-api/dsl/resource.rb |