Sha256: 0867f4781ef7e149bcb25c38ebf344350a5850191c80f301654b466300bbb537
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require 'rspec-api/requests' require 'rspec-api/resource/options' module RSpecApi module Resource module Actions [:get, :put, :patch, :post, :delete].each do |action| define_method action do |route, rspec_api_options = {}, &block| options = rspec_api_options.merge route: route, action: action options = rspec_api_resource.merge options describe description_for(options), rspec_api_params: options do extend RSpecApi::Requests instance_eval &block if block end end end private def description_for(params = {}) action, name, plural = params.values_at(:action, :resource_name, :collection) [verb_for(action), object_for(name.to_s, plural)].compact.join ' ' end def verb_for(action) case action when :get then 'Getting' when :put then 'Editing' when :patch then 'Editing' when :post then 'Creating' when :delete then 'Deleting' end end def object_for(name, plural) plural ? "a list of #{name.pluralize}" : "one #{name}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec-api-0.7.1 | lib/rspec-api/resource/actions.rb |
rspec-api-0.7.0 | lib/rspec-api/resource/actions.rb |