source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/custom_validations_spec.rb | Ruby | mit | 9,984 | master | 7,440 | # frozen_string_literal: true
describe Grape::Validations do
describe 'using a custom length validator' do
subject do
Class.new(Grape::API) do
params do
requires :text, default_length: 140
end
get do
'bacon'
end
end
end
let(:default_length_... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/inherited_helpers_spec.rb | Ruby | mit | 9,984 | master | 2,476 | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:user) { 'Miguel Caneo' }
let(:id) { '42' }
let(:api_super_class) do
Class.new(Grape::API) do
helpers do
params(:superclass_params) { requires :id, type: String }
def current_user
params[:user]
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/router/greedy_route_spec.rb | Ruby | mit | 9,984 | master | 815 | # frozen_string_literal: true
RSpec.describe Grape::Router::GreedyRoute do
let(:instance) { described_class.new(pattern, endpoint:, allow_header:) }
let(:pattern) { :pattern }
let(:endpoint) { instance_double(Grape::Endpoint) }
let(:allow_header) { false }
describe 'inheritance' do
subject { instance }
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/integration/rack_sendfile_spec.rb | Ruby | mit | 9,984 | master | 1,049 | # frozen_string_literal: true
describe Rack::Sendfile do
subject do
content_object = file_object
app = Class.new(Grape::API) do
use Rack::Sendfile, 'X-Accel-Redirect'
format :json
get do
if content_object.is_a?(String)
sendfile content_object
else
stream ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/integration/global_namespace_function_spec.rb | Ruby | mit | 9,984 | master | 428 | # frozen_string_literal: true
# see https://github.com/ruby-grape/grape/issues/1348
def namespace
raise
end
describe Grape::API do
subject do
Class.new(Grape::API) do
format :json
get do
{ ok: true }
end
end
end
def app
subject
end
context 'with a global namespace ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/integration/rack_spec.rb | Ruby | mit | 9,984 | master | 2,623 | # frozen_string_literal: true
describe Rack do
describe 'from a Tempfile' do
subject { last_response.body }
let(:app) do
Class.new(Grape::API) do
format :json
params do
requires :file, type: File
end
post do
params[:file].then do |file|
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/endpoint/declared_spec.rb | Ruby | mit | 9,984 | master | 26,914 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe '#declared' do
before do
subject.format :json
subject.params do
requires :first
optional :second
optional :third, default: 'third-default'
o... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/registry_spec.rb | Ruby | mit | 9,984 | master | 5,254 | # frozen_string_literal: true
describe Grape::Util::Registry do
# Create a test class that includes the Registry module
subject { test_registry_class.new }
let(:test_registry_class) do
Class.new do
include Grape::Util::Registry
# Public methods to expose private functionality for testing
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/stackable_values_spec.rb | Ruby | mit | 9,984 | master | 3,508 | # frozen_string_literal: true
describe Grape::Util::StackableValues do
subject { described_class.new(parent) }
let(:parent) { described_class.new }
describe '#keys' do
it 'returns all keys' do
subject[:some_thing] = :foo_bar
subject[:some_thing_else] = :foo_bar
expect(subject.keys).to eq ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/reverse_stackable_values_spec.rb | Ruby | mit | 9,984 | master | 3,578 | # frozen_string_literal: true
describe Grape::Util::ReverseStackableValues do
subject { described_class.new(parent) }
let(:parent) { described_class.new }
describe '#keys' do
it 'returns all keys' do
subject[:some_thing] = :foo_bar
subject[:some_thing_else] = :foo_bar
expect(subject.keys)... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/media_type_spec.rb | Ruby | mit | 9,984 | master | 3,133 | # frozen_string_literal: true
RSpec.describe Grape::Util::MediaType do
shared_examples 'MediaType' do
it { is_expected.to eq(described_class.new(type:, subtype:)) }
end
describe '.parse' do
subject(:media_type) { described_class.parse(header) }
context 'when header blank?' do
let(:header) { n... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/deep_freeze_spec.rb | Ruby | mit | 9,984 | master | 2,278 | # frozen_string_literal: true
describe Grape::Util::DeepFreeze do
describe '.deep_freeze' do
subject { described_class.deep_freeze(obj) }
context 'with a String' do
let(:obj) { +'mutable' }
it { is_expected.to be_frozen }
end
context 'with an Array of strings' do
let(:obj) { [+'a... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/inheritable_setting_spec.rb | Ruby | mit | 9,984 | master | 9,258 | # frozen_string_literal: true
describe Grape::Util::InheritableSetting do
before do
described_class.reset_global!
subject.inherit_from parent
end
let(:parent) do
described_class.new.tap do |settings|
settings.global[:global_thing] = :global_foo_bar
settings.namespace[:namespace_thing] = ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/translation_spec.rb | Ruby | mit | 9,984 | master | 817 | # frozen_string_literal: true
describe Grape::Util::Translation do
subject(:translator) do
Class.new do
include Grape::Util::Translation
def translate_message(key, **opts)
translate(key, **opts)
end
end.new
end
describe '#translate_message' do
context 'when the translation... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/util/inheritable_values_spec.rb | Ruby | mit | 9,984 | master | 1,970 | # frozen_string_literal: true
describe Grape::Util::InheritableValues do
subject { described_class.new(parent) }
let(:parent) { described_class.new }
describe '#delete' do
it 'deletes a key' do
subject[:some_thing] = :new_foo_bar
subject.delete :some_thing
expect(subject[:some_thing]).to ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/invalid_versioner_option_spec.rb | Ruby | mit | 9,984 | master | 337 | # frozen_string_literal: true
describe Grape::Exceptions::InvalidVersionerOption do
describe '#message' do
let(:error) do
described_class.new('headers')
end
it 'contains the problem in the message' do
expect(error.message).to include(
'unknown :using for versioner: headers'
)
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/validation_errors_spec.rb | Ruby | mit | 9,984 | master | 2,690 | # frozen_string_literal: true
describe Grape::Exceptions::ValidationErrors do
let(:validation_message) { 'FooBar is invalid' }
let(:validation_error) { instance_double Grape::Exceptions::Validation, params: [validation_message], message: '' }
context 'initialize' do
subject do
described_class.new(erro... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/missing_group_type_spec.rb | Ruby | mit | 9,984 | master | 224 | # frozen_string_literal: true
RSpec.describe Grape::Exceptions::MissingGroupType do
describe '#message' do
subject { described_class.new.message }
it { is_expected.to include 'group type is required' }
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/invalid_accept_header_spec.rb | Ruby | mit | 9,984 | master | 10,543 | # frozen_string_literal: true
describe Grape::Exceptions::InvalidAcceptHeader do
shared_examples_for 'a valid request' do
it 'does return with status 200' do
expect(last_response.status).to eq 200
end
it 'does return the expected result' do
expect(last_response.body).to eq('beer received')
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/base_spec.rb | Ruby | mit | 9,984 | master | 2,509 | # frozen_string_literal: true
describe Grape::Exceptions::Base do
describe '#to_s' do
subject { described_class.new(message:).to_s }
let(:message) { 'a_message' }
it { is_expected.to eq(message) }
end
describe '#message' do
subject { described_class.new(message:).message }
let(:message) {... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/invalid_formatter_spec.rb | Ruby | mit | 9,984 | master | 326 | # frozen_string_literal: true
describe Grape::Exceptions::InvalidFormatter do
describe '#message' do
let(:error) do
described_class.new(String, 'xml')
end
it 'contains the problem in the message' do
expect(error.message).to include(
'cannot convert String to xml'
)
end
en... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/unsupported_group_type_spec.rb | Ruby | mit | 9,984 | master | 292 | # frozen_string_literal: true
RSpec.describe Grape::Exceptions::UnsupportedGroupType do
subject { described_class.new }
describe '#message' do
subject { described_class.new.message }
it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/body_parse_errors_spec.rb | Ruby | mit | 9,984 | master | 5,475 | # frozen_string_literal: true
describe Grape::Exceptions::ValidationErrors do
context 'api with rescue_from :all handler' do
subject { Class.new(Grape::API) }
before do
subject.rescue_from :all do |_e|
error! 'message was processed', 400
end
subject.params do
requires :beer... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/invalid_response_spec.rb | Ruby | mit | 9,984 | master | 269 | # frozen_string_literal: true
describe Grape::Exceptions::InvalidResponse do
describe '#message' do
let(:error) { described_class.new }
it 'contains the problem in the message' do
expect(error.message).to include('Invalid response')
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/unknown_validator_spec.rb | Ruby | mit | 9,984 | master | 316 | # frozen_string_literal: true
describe Grape::Exceptions::UnknownValidator do
describe '#message' do
let(:error) do
described_class.new('gt_10')
end
it 'contains the problem in the message' do
expect(error.message).to include(
'unknown validator: gt_10'
)
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/missing_mime_type_spec.rb | Ruby | mit | 9,984 | master | 477 | # frozen_string_literal: true
describe Grape::Exceptions::MissingMimeType do
describe '#message' do
let(:error) do
described_class.new('new_json')
end
it 'contains the problem in the message' do
expect(error.message).to include 'missing mime type for new_json'
end
it 'contains the r... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/exceptions/validation_spec.rb | Ruby | mit | 9,984 | master | 1,640 | # frozen_string_literal: true
describe Grape::Exceptions::Validation do
it 'fails when params are missing' do
expect { described_class.new(message: 'presence') }.to raise_error(ArgumentError, /missing keyword:.+?params/)
end
context 'when message is a Symbol' do
subject(:error) { described_class.new(par... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/params_scope_spec.rb | Ruby | mit | 9,984 | master | 51,635 | # frozen_string_literal: true
describe Grape::Validations::ParamsScope do
subject do
Class.new(Grape::API)
end
def app
subject
end
context 'when using custom types' do
let(:custom_type) do
Class.new do
attr_reader :value
def self.parse(value)
raise if value == '... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/param_scope_tracker_spec.rb | Ruby | mit | 9,984 | master | 3,940 | # frozen_string_literal: true
describe Grape::Validations::ParamScopeTracker do
describe '.current' do
it 'returns nil when no tracker is active' do
expect(described_class.current).to be_nil
end
end
describe '.track' do
it 'sets .current inside the block' do
described_class.track do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/types_spec.rb | Ruby | mit | 9,984 | master | 2,549 | # frozen_string_literal: true
describe Grape::Validations::Types do
let(:foo_type) do
Class.new do
def self.parse(_); end
end
end
let(:bar_type) do
Class.new do
def self.parse; end
end
end
describe '::primitive?' do
[
Integer, Float, Numeric, BigDecimal,
Grape::AP... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/params_documentation_spec.rb | Ruby | mit | 9,984 | master | 3,649 | # frozen_string_literal: true
describe Grape::Validations::ParamsDocumentation do
subject { klass.new(api_double) }
let(:api_double) do
Class.new do
include Grape::DSL::Settings
end.new
end
let(:klass) do
Class.new do
include Grape::Validations::ParamsDocumentation
attr_accesso... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/single_attribute_iterator_spec.rb | Ruby | mit | 9,984 | master | 1,865 | # frozen_string_literal: true
describe Grape::Validations::SingleAttributeIterator do
describe '#each' do
subject(:iterator) { described_class.new(%i[first second], scope, params) }
let(:scope) { Grape::Validations::ParamsScope.new(api: Class.new(Grape::API)) }
context 'when params is a hash' do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/multiple_attributes_iterator_spec.rb | Ruby | mit | 9,984 | master | 1,206 | # frozen_string_literal: true
describe Grape::Validations::MultipleAttributesIterator do
describe '#each' do
subject(:iterator) { described_class.new(validator, scope, params) }
let(:scope) { Grape::Validations::ParamsScope.new(api: Class.new(Grape::API)) }
let(:validator) { double(attrs: %i[first secon... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/types/set_coercer_spec.rb | Ruby | mit | 9,984 | master | 871 | # frozen_string_literal: true
describe Grape::Validations::Types::SetCoercer do
subject { described_class.new(type) }
describe '#call' do
context 'a set of primitives' do
let(:type) { Set[String] }
it 'coerces elements to the set' do
expect(subject.call([10, 20])).to eq(Set['10', '20'])
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/types/array_coercer_spec.rb | Ruby | mit | 9,984 | master | 907 | # frozen_string_literal: true
describe Grape::Validations::Types::ArrayCoercer do
subject { described_class.new(type) }
describe '#call' do
context 'an array of primitives' do
let(:type) { Array[String] }
it 'coerces elements in the array' do
expect(subject.call([10, 20])).to eq(%w[10 20]... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/types/primitive_coercer_spec.rb | Ruby | mit | 9,984 | master | 3,716 | # frozen_string_literal: true
describe Grape::Validations::Types::PrimitiveCoercer do
subject { described_class.new(type, strict:) }
let(:strict) { false }
describe '#call' do
context 'BigDecimal' do
let(:type) { BigDecimal }
it 'coerces to BigDecimal' do
expect(subject.call(5)).to eq(... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/base_i18n_spec.rb | Ruby | mit | 9,984 | master | 2,341 | # frozen_string_literal: true
describe Grape::Validations::Validators::Base do
describe 'i18n' do
subject { Class.new(Grape::API) }
let(:app) { subject }
let(:custom_i18n_validator) do
Class.new(Grape::Validations::Validators::Base) do
def validate_param!(attr_name, params)
retu... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/default_validator_spec.rb | Ruby | mit | 9,984 | master | 17,215 | # frozen_string_literal: true
describe Grape::Validations::Validators::DefaultValidator do
describe '/' do
let(:app) do
Class.new(Grape::API) do
default_format :json
params do
optional :id
optional :type, default: 'default-type'
end
get '/' do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/coerce_validator_spec.rb | Ruby | mit | 9,984 | master | 37,171 | # frozen_string_literal: true
describe Grape::Validations::Validators::CoerceValidator do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe 'coerce' do
let(:secure_uri_only) do
Class.new do
def self.parse(value)
URI.parse(value)
end
def self.parsed?(v... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/all_or_none_validator_spec.rb | Ruby | mit | 9,984 | master | 5,916 | # frozen_string_literal: true
describe Grape::Validations::Validators::AllOrNoneOfValidator do
describe '#validate!' do
subject(:validate) { post path, params }
describe '/' do
let(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
er... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/except_values_validator_spec.rb | Ruby | mit | 9,984 | master | 8,831 | # frozen_string_literal: true
describe Grape::Validations::Validators::ExceptValuesValidator do
describe 'IncompatibleOptionValues' do
subject { api }
context 'when a default value is set' do
let(:api) do
ev = except_values
dv = default_value
Class.new(Grape::API) do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/at_least_one_of_validator_spec.rb | Ruby | mit | 9,984 | master | 7,382 | # frozen_string_literal: true
describe Grape::Validations::Validators::AtLeastOneOfValidator do
describe '#validate!' do
subject(:validate) { post path, params }
describe '/' do
let(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
e... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/length_validator_spec.rb | Ruby | mit | 9,984 | master | 11,146 | # frozen_string_literal: true
describe Grape::Validations::Validators::LengthValidator do
describe '/with_min_max' do
let(:app) do
Class.new(Grape::API) do
params do
requires :list, length: { min: 2, max: 3 }
end
post 'with_min_max' do
end
end
end
co... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/regexp_validator_spec.rb | Ruby | mit | 9,984 | master | 5,612 | # frozen_string_literal: true
describe Grape::Validations::Validators::RegexpValidator do
describe '#bad encoding' do
let(:app) do
Class.new(Grape::API) do
default_format :json
params do
requires :name, regexp: { value: /^[a-z]+$/ }
end
get '/bad_encoding'
e... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/mutually_exclusive_spec.rb | Ruby | mit | 9,984 | master | 7,866 | # frozen_string_literal: true
describe Grape::Validations::Validators::MutuallyExclusiveValidator do
describe '#validate!' do
subject(:validate) { post path, params }
describe '/' do
let(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/presence_validator_spec.rb | Ruby | mit | 9,984 | master | 9,077 | # frozen_string_literal: true
describe Grape::Validations::Validators::PresenceValidator do
subject do
Class.new(Grape::API) do
format :json
end
end
def app
subject
end
context 'without validation' do
before do
subject.resource :bacons do
get do
'All the bacon'... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/allow_blank_validator_spec.rb | Ruby | mit | 9,984 | master | 22,002 | # frozen_string_literal: true
describe Grape::Validations::Validators::AllowBlankValidator do
describe 'bad encoding' do
let(:app) do
Class.new(Grape::API) do
default_format :json
params do
requires :name, type: String, allow_blank: false
end
get '/bad_encoding'
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/values_validator_spec.rb | Ruby | mit | 9,984 | master | 23,022 | # frozen_string_literal: true
describe Grape::Validations::Validators::ValuesValidator do
let(:values_model) do
Class.new do
class << self
def values
@values ||= []
[default_values + @values].flatten.uniq
end
def add_value(value)
@values ||= []
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/same_as_validator_spec.rb | Ruby | mit | 9,984 | master | 2,447 | # frozen_string_literal: true
describe Grape::Validations::Validators::SameAsValidator do
describe '/' do
let(:app) do
Class.new(Grape::API) do
params do
requires :password
requires :password_confirmation, same_as: :password
end
post do
end
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations/validators/exactly_one_of_validator_spec.rb | Ruby | mit | 9,984 | master | 8,273 | # frozen_string_literal: true
describe Grape::Validations::Validators::ExactlyOneOfValidator do
describe '#validate!' do
subject(:validate) { post path, params }
describe '/' do
let(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
e... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/presenters/presenter_spec.rb | Ruby | mit | 9,984 | master | 1,427 | # frozen_string_literal: true
describe Grape::Presenters::Presenter do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::InsideRoute
attr_reader :env, :request, :new_settings
def initialize
@env = {}
@header = {}
@new_settings = { nam... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/validations_spec.rb | Ruby | mit | 9,984 | master | 2,549 | # frozen_string_literal: true
describe Grape::DSL::Validations do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Settings
extend Grape::DSL::Validations
end
end
describe '.params' do
subject { dummy_class.params { :my_block } }
it 'creates a proper G... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/callbacks_spec.rb | Ruby | mit | 9,984 | master | 1,083 | # frozen_string_literal: true
describe Grape::DSL::Callbacks do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Settings
extend Grape::DSL::Callbacks
end
end
let(:proc) { -> {} }
describe '.before' do
it 'adds a block to "before"' do
subject.befor... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/inside_route_spec.rb | Ruby | mit | 9,984 | master | 11,270 | # frozen_string_literal: true
describe Grape::DSL::InsideRoute do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::InsideRoute
include Grape::DSL::Settings
attr_reader :env, :request, :new_settings
def initialize
@env = {}
@header = {}... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/desc_spec.rb | Ruby | mit | 9,984 | master | 2,804 | # frozen_string_literal: true
describe Grape::DSL::Desc do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Desc
extend Grape::DSL::Settings
end
end
describe '.desc' do
it 'sets a description' do
desc_text = 'The description'
options = { message... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/settings_spec.rb | Ruby | mit | 9,984 | master | 4,985 | # frozen_string_literal: true
describe Grape::DSL::Settings do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::Settings
def with_namespace(&block)
within_namespace(&block)
end
def reset_validations!; end
end
end
describe '#global_set... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/headers_spec.rb | Ruby | mit | 9,984 | master | 1,493 | # frozen_string_literal: true
describe Grape::DSL::Headers do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::Headers
end
end
let(:header_data) do
{ 'first key' => 'First Value',
'second key' => 'Second Value' }
end
context 'when headers are set'... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/helpers_spec.rb | Ruby | mit | 9,984 | master | 2,142 | # frozen_string_literal: true
describe Grape::DSL::Helpers do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Helpers
extend Grape::DSL::Settings
def self.mods
inheritable_setting.namespace_stackable[:helpers]
end
def self.first_mod
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/routing_spec.rb | Ruby | mit | 9,984 | master | 8,697 | # frozen_string_literal: true
describe Grape::DSL::Routing do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Routing
extend Grape::DSL::Settings
extend Grape::DSL::Validations
class << self
attr_reader :instance, :base
attr_accessor :confi... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/middleware_spec.rb | Ruby | mit | 9,984 | master | 1,705 | # frozen_string_literal: true
describe Grape::DSL::Middleware do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Middleware
extend Grape::DSL::Settings
end
end
let(:proc) { -> {} }
let(:foo_middleware) { Class.new }
let(:bar_middleware) { Class.new }
de... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/logger_spec.rb | Ruby | mit | 9,984 | master | 822 | # frozen_string_literal: true
describe Grape::DSL::Logger do
let(:dummy_logger) do
Class.new do
extend Grape::DSL::Logger
extend Grape::DSL::Settings
end
end
describe '.logger' do
context 'when setting a logger' do
subject { dummy_logger.logger :my_logger }
it { is_expected.... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/request_response_spec.rb | Ruby | mit | 9,984 | master | 9,008 | # frozen_string_literal: true
describe Grape::DSL::RequestResponse do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::RequestResponse
extend Grape::DSL::Settings
end
end
let(:c_type) { 'application/json' }
let(:format) { 'txt' }
describe '.default_format'... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/dsl/parameters_spec.rb | Ruby | mit | 9,984 | master | 9,209 | # frozen_string_literal: true
describe Grape::DSL::Parameters do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::Parameters
attr_accessor :api, :element, :parent
def initialize
@validate_attributes = []
end
def validate_attributes(*arg... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/params_builder/hash_spec.rb | Ruby | mit | 9,984 | master | 2,520 | # frozen_string_literal: true
describe Grape::ParamsBuilder::Hash do
subject { app }
let(:app) do
Class.new(Grape::API)
end
describe 'in an endpoint' do
describe '#params' do
before do
subject.params do
build_with :hash
end
subject.get do
params.clas... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/params_builder/hash_with_indifferent_access_spec.rb | Ruby | mit | 9,984 | master | 3,431 | # frozen_string_literal: true
describe Grape::ParamsBuilder::HashWithIndifferentAccess do
subject { app }
let(:app) do
Class.new(Grape::API)
end
describe 'in an endpoint' do
describe '#params' do
before do
subject.params do
build_with :hash_with_indifferent_access
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/globals_spec.rb | Ruby | mit | 9,984 | master | 918 | # frozen_string_literal: true
describe Grape::Middleware::Globals do
subject { described_class.new(blank_app) }
before { allow(subject).to receive(:dup).and_return(subject) }
let(:blank_app) { ->(_env) { [200, {}, 'Hi there.'] } }
it 'calls through to the app' do
expect(subject.call({})).to eq([200, {},... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/formatter_spec.rb | Ruby | mit | 9,984 | master | 18,005 | # frozen_string_literal: true
describe Grape::Middleware::Formatter do
subject { described_class.new(app) }
before { allow(subject).to receive(:dup).and_return(subject) }
let(:body) { { 'foo' => 'bar' } }
let(:app) { ->(_env) { [200, {}, [body]] } }
context 'serialization' do
let(:body) { { 'abc' => '... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/exception_spec.rb | Ruby | mit | 9,984 | master | 7,315 | # frozen_string_literal: true
describe Grape::Middleware::Error do
let(:exception_app) do
Class.new do
class << self
def call(_env)
raise 'rain!'
end
end
end
end
let(:other_exception_app) do
Class.new do
class << self
def call(_env)
raise... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/base_spec.rb | Ruby | mit | 9,984 | master | 6,336 | # frozen_string_literal: true
describe Grape::Middleware::Base do
subject { described_class.new(blank_app) }
let(:blank_app) { ->(_) { [200, {}, 'Hi there.'] } }
before do
# Keep it one object for testing.
allow(subject).to receive(:dup).and_return(subject)
end
it 'has the app as an accessor' do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/error_spec.rb | Ruby | mit | 9,984 | master | 1,576 | # frozen_string_literal: true
describe Grape::Middleware::Error do
let(:err_app) do
Class.new do
class << self
attr_accessor :error, :format
def call(_env)
throw :error, error
end
end
end
end
let(:options) { { default_message: 'Aww, hamburgers.' } }
let(:... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/stack_spec.rb | Ruby | mit | 9,984 | master | 5,145 | # frozen_string_literal: true
describe Grape::Middleware::Stack do
subject { described_class.new }
let(:foo_middleware) { Class.new }
let(:bar_middleware) { Class.new }
let(:block_middleware) do
Class.new do
attr_reader :block
def initialize(&block)
@block = block
end
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/versioner_spec.rb | Ruby | mit | 9,984 | master | 943 | # frozen_string_literal: true
describe Grape::Middleware::Versioner do
subject { described_class.using(strategy) }
context 'when :path' do
let(:strategy) { :path }
it { is_expected.to eq(Grape::Middleware::Versioner::Path) }
end
context 'when :header' do
let(:strategy) { :header }
it { is_e... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/versioner/header_spec.rb | Ruby | mit | 9,984 | master | 11,949 | # frozen_string_literal: true
describe Grape::Middleware::Versioner::Header do
subject { described_class.new(app, **@options) }
let(:app) { ->(env) { [200, env, env] } }
before do
@options = {
version_options: {
using: :header,
vendor: 'vendor'
}
}
end
context 'api.type... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/versioner/param_spec.rb | Ruby | mit | 9,984 | master | 5,370 | # frozen_string_literal: true
describe Grape::Middleware::Versioner::Param do
subject { described_class.new(app, **options) }
let(:app) { ->(env) { [200, env, env[Grape::Env::API_VERSION]] } }
let(:options) { {} }
it 'sets the API version based on the default param (apiver)' do
env = Rack::MockRequest.en... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/versioner/path_spec.rb | Ruby | mit | 9,984 | master | 1,988 | # frozen_string_literal: true
describe Grape::Middleware::Versioner::Path do
subject { described_class.new(app, **options) }
let(:app) { ->(env) { [200, env, env[Grape::Env::API_VERSION]] } }
let(:options) { {} }
it 'sets the API version based on the first path' do
expect(subject.call(Rack::PATH_INFO => ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/versioner/accept_version_header_spec.rb | Ruby | mit | 9,984 | master | 3,603 | # frozen_string_literal: true
describe Grape::Middleware::Versioner::AcceptVersionHeader do
subject { described_class.new(app, **@options) }
let(:app) { ->(env) { [200, env, env] } }
before do
@options = {
version_options: {
using: :accept_version_header
}
}
end
describe '#bad ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/auth/base_spec.rb | Ruby | mit | 9,984 | master | 732 | # frozen_string_literal: true
describe Grape::Middleware::Auth::Base do
subject do
Class.new(Grape::API) do
http_basic realm: 'my_realm' do |user, password|
user && password && user == password
end
get '/authorized' do
'DONE'
end
end
end
let(:app) { subject }
i... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/auth/strategies_spec.rb | Ruby | mit | 9,984 | master | 2,347 | # frozen_string_literal: true
describe Grape::Middleware::Auth::Strategies do
describe 'Basic Auth' do
let(:app) do
proc = ->(u, p) { u && p && u == p }
Rack::Builder.app do
use Grape::Middleware::Error
use(Grape::Middleware::Auth::Base, type: :http_basic, proc:)
run ->(_env) ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/middleware/auth/dsl_spec.rb | Ruby | mit | 9,984 | master | 2,105 | # frozen_string_literal: true
describe Grape::Middleware::Auth::DSL do
subject { Class.new(Grape::API) }
let(:block) { -> {} }
let(:settings) do
{
opaque: 'secret',
proc: block,
realm: 'API Authorization',
type: :http_digest
}
end
describe '.auth' do
it 'sets auth parame... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | activeadmin.gemspec | Ruby | mit | 9,684 | master | 1,929 | # frozen_string_literal: true
require File.join(__dir__, "lib", "active_admin", "version")
Gem::Specification.new do |s|
s.name = "activeadmin"
s.license = "MIT"
s.version = ActiveAdmin::VERSION
s.homepage = "https://activeadmin.info"
s.authors = ["Charles Maresh", "David Rodríguez", "Greg Bell", "Igor Fedor... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | Gemfile | Ruby | mit | 9,684 | master | 1,013 | # frozen_string_literal: true
source "https://rubygems.org"
group :development, :test do
gem "rake"
gem "cancancan"
gem "pundit"
gem "draper"
gem "devise"
gem "rails", "~> 8.1.0"
gem "sprockets-rails"
gem "ransack", ">= 4.2.0"
gem "formtastic", ">= 6.0.0"
gem "cssbundling-rails"
gem "importm... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | Rakefile | Ruby | mit | 9,684 | master | 398 | # frozen_string_literal: true
require "bundler/gem_tasks"
import "tasks/local.rake"
import "tasks/test.rake"
import "tasks/dependencies.rake"
gemfile = ENV["BUNDLE_GEMFILE"]
if gemfile.nil? || File.expand_path(gemfile) == File.expand_path("Gemfile")
import "tasks/release.rake"
end
task default: :test
task :conso... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/base_controller.rb | Ruby | mit | 9,684 | master | 3,220 | # frozen_string_literal: true
module ActiveAdmin
# BaseController for ActiveAdmin.
# It implements ActiveAdmin controllers core features.
class BaseController < ::InheritedResources::Base
helper MethodOrProcHelper
helper LayoutHelper
helper FormHelper
helper BreadcrumbHelper
helper AutoLinkHel... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/page_controller.rb | Ruby | mit | 9,684 | master | 563 | # frozen_string_literal: true
module ActiveAdmin
# All Pages controllers inherit from this controller.
class PageController < BaseController
# Active admin actions don't require layout. All custom actions do.
ACTIVE_ADMIN_ACTIONS = [:index]
actions :index
before_action :authorize_access!
d... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller.rb | Ruby | mit | 9,684 | master | 3,290 | # frozen_string_literal: true
require "active_admin/collection_decorator"
module ActiveAdmin
# All Resources Controller inherits from this controller.
# It implements actions and helpers for resources.
class ResourceController < BaseController
respond_to :html, :xml, :json
respond_to :csv, only: :index
... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/base_controller/menu.rb | Ruby | mit | 9,684 | master | 1,153 | # frozen_string_literal: true
module ActiveAdmin
class BaseController < ::InheritedResources::Base
module Menu
extend ActiveSupport::Concern
included do
before_action :set_current_menu_item
helper_method :current_menu
helper_method :current_menu_item?
end
protect... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/base_controller/authorization.rb | Ruby | mit | 9,684 | master | 4,330 | # frozen_string_literal: true
module ActiveAdmin
class BaseController < ::InheritedResources::Base
module Authorization
extend ActiveSupport::Concern
ACTIONS_DICTIONARY = {
index: ActiveAdmin::Authorization::READ,
show: ActiveAdmin::Authorization::READ,
new: ActiveAdmin::Autho... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/action_builder.rb | Ruby | mit | 9,684 | master | 721 | # frozen_string_literal: true
module ActiveAdmin
class ResourceController < BaseController
module ActionBuilder
extend ActiveSupport::Concern
module ClassMethods
def clear_member_actions!
remove_action_methods(:member)
active_admin_config.clear_member_actions!
en... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/decorators.rb | Ruby | mit | 9,684 | master | 2,205 | # frozen_string_literal: true
module ActiveAdmin
class ResourceController < BaseController
module Decorators
protected
def apply_decorator(resource)
decorate? ? decorator_class.new(resource) : resource
end
def apply_collection_decorator(collection)
if decorate?
... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/resource_class_methods.rb | Ruby | mit | 9,684 | master | 669 | # frozen_string_literal: true
module ActiveAdmin
class ResourceController < BaseController
module ResourceClassMethods
# Override the default `resource_class` class and instance
# methods to only return the class defined in the instance
# of ActiveAdmin::Resource
def override_resource_cla... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/polymorphic_routes.rb | Ruby | mit | 9,684 | master | 1,185 | # frozen_string_literal: true
require "active_admin/resource"
require "active_admin/resource/model"
module ActiveAdmin
class ResourceController < BaseController
module PolymorphicRoutes
def polymorphic_url(record_or_hash_or_array, options = {})
super(map_named_resources_for(record_or_hash_or_array)... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/scoping.rb | Ruby | mit | 9,684 | master | 1,047 | # frozen_string_literal: true
module ActiveAdmin
class ResourceController < BaseController
# This module deals with scoping entire controllers to a relation
module Scoping
extend ActiveSupport::Concern
protected
# Override the default InheritedResource #begin_of_association_chain to allow... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/streaming.rb | Ruby | mit | 9,684 | master | 1,322 | # frozen_string_literal: true
require "csv"
module ActiveAdmin
class ResourceController < BaseController
# This module overrides CSV responses to allow large data downloads.
# Could be expanded to JSON and XML in the future.
#
module Streaming
def index
super do |format|
for... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/controllers/active_admin/resource_controller/data_access.rb | Ruby | mit | 9,684 | master | 10,880 | # frozen_string_literal: true
module ActiveAdmin
class ResourceController < BaseController
# This module overrides most of the data access methods in Inherited
# Resources to provide Active Admin with it's data.
#
# The module also deals with authorization and resource callbacks.
#
module Dat... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/helpers/active_admin/display_helper.rb | Ruby | mit | 9,684 | master | 3,698 | # frozen_string_literal: true
module ActiveAdmin
module DisplayHelper
DISPLAY_NAME_FALLBACK = -> {
klass = self.class
name = if klass.respond_to?(:model_name)
if klass.respond_to?(:primary_key)
"#{klass.model_name.human} ##{send(klass.primary_key)}"
else
... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/helpers/active_admin/layout_helper.rb | Ruby | mit | 9,684 | master | 1,679 | # frozen_string_literal: true
module ActiveAdmin
module LayoutHelper
# Returns the current Active Admin application instance
def active_admin_application
ActiveAdmin.application
end
def set_page_title(title)
@page_title = title
end
def site_title
# Prioritize namespace and ... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/helpers/active_admin/breadcrumb_helper.rb | Ruby | mit | 9,684 | master | 1,657 | # frozen_string_literal: true
module ActiveAdmin
module BreadcrumbHelper
ID_FORMAT_REGEXP = /\A(\d+|[a-f0-9]{24}|(?:[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}))\z/.freeze
# Returns an array of links to use in a breadcrumb
def build_breadcrumb_links(path = request.path, html_options = {})
config = ... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/helpers/active_admin/form_helper.rb | Ruby | mit | 9,684 | master | 3,032 | # frozen_string_literal: true
module ActiveAdmin
module FormHelper
RESERVED_PARAMS = %w(controller action commit utf8).freeze
def active_admin_form_for(resource, options = {}, &block)
Arbre::Context.new({}, self) do
active_admin_form_for resource, options, &block
end.content
end
... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/helpers/active_admin/auto_link_helper.rb | Ruby | mit | 9,684 | master | 2,426 | # frozen_string_literal: true
module ActiveAdmin
module AutoLinkHelper
# Automatically links objects to their resource controllers. If
# the resource has not been registered, a string representation of
# the object is returned.
#
# The default content in the link is returned from ActiveAdmin::Disp... |
github | activeadmin/activeadmin | https://github.com/activeadmin/activeadmin | app/helpers/active_admin/index_helper.rb | Ruby | mit | 9,684 | master | 1,038 | # frozen_string_literal: true
module ActiveAdmin
module IndexHelper
def scope_name(scope)
case scope.name
when Proc then
self.instance_exec(&scope.name).to_s
else
scope.name.to_s
end
end
def batch_actions_to_display
@batch_actions_to_display ||= begin
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.