spec/middleware_spec.rb in rack-reducer-0.1.0 vs spec/middleware_spec.rb in rack-reducer-0.1.1

- old
+ new

@@ -1,22 +1,30 @@ require 'spec_helper' -require_relative 'fixtures' 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 - def self.app + 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] } } + ] + } + + def self.app(options = {}, key = options[:key] || 'rack.reduction') Rack::Builder.new do - use Rack::Reducer, dataset: ARTISTS, 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] } } - ] - run ->(env) { [200, {}, [env['rack.reduction'].to_json]] } + 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