Sha256: 0e3cf1e98e0eb73da813f54e4120f0d173b994fa50654c1ac92b692021eb710c
Contents?: true
Size: 795 Bytes
Versions: 1
Compression:
Stored size: 795 Bytes
Contents
require 'spec_helper' require_relative 'fixtures' require 'sinatra/base' require 'json' class SinatraFunctional < Sinatra::Base class Artist < Sequel::Model plugin :json_serializer end get '/artists' do @artists = Rack::Reducer.call(params, dataset: Artist, filters: [ ->(genre:) { grep(:genre, "%#{genre}%", case_insensitive: true) }, ->(name:) { grep(:name, "%#{name}%", case_insensitive: true) }, ->(order: 'genre') { order(order.to_sym) } ]) @artists.all.to_json end end describe SinatraFunctional do let(:app) { described_class } it_behaves_like Rack::Reducer it 'applies a default order' do get '/artists' do |response| genre = JSON.parse(response.body).dig(0, 'genre') expect(genre).to eq('alt-soul') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-reducer-0.1.0 | spec/sinatra_functional_spec.rb |