Sha256: 29711f4c66652cb34a57e14f2b4b807ee93bf215c9ae4d9f2d440828561d37d4
Contents?: true
Size: 921 Bytes
Versions: 3
Compression:
Stored size: 921 Bytes
Contents
require 'spec_helper' require 'json' # mount Rack::Reducer as middleware, let it filter data into env['rack.reduction'], # and respond with env['rack.reduction'].to_json module MiddlewareTest DEFAULTS = { dataset: DB[:artists].all, filters: [ ->(genre:) { select { |item| item[:genre].match(/#{genre}/i) } }, ->(name:) { select { |item| item[:name].match(/#{name}/i) } }, ->(order:) { sort_by { |item| item[order.to_sym] } }, ->(releases:) { select { |item| item[:release_count] == releases.to_i } }, ] } def self.app(options = {}, key = options[:key] || 'rack.reduction') Rack::Builder.new do use Rack::Reducer, DEFAULTS.merge(options) run ->(env) { [200, {}, [env[key].to_json]] } end end end describe MiddlewareTest.app do it_behaves_like Rack::Reducer end describe MiddlewareTest.app(key: 'some.custom.key') do it_behaves_like Rack::Reducer end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rack-reducer-1.0.1 | spec/middleware_spec.rb |
rack-reducer-1.0.0 | spec/middleware_spec.rb |
rack-reducer-0.1.2 | spec/middleware_spec.rb |