-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove `ATHA::QueryParam` and `ATHA::RequestParam` * Remove `ATH::Exception::InvalidParamete` * Remove everything in `ATH::Params` namespace, including `ATH::Action#params` * Add `ATH::Exception.from_status`
- Loading branch information
1 parent
b09a847
commit 339336e
Showing
33 changed files
with
233 additions
and
1,511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/components/framework/spec/controller/value_resolvers/query_parameter_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require "../../spec_helper" | ||
|
||
private def parameter( | ||
klass : T.class = String, | ||
*, | ||
name : String? = nil, | ||
validation_failed_status : HTTP::Status = :not_found, | ||
default : T? = nil | ||
) forall T | ||
ATH::Controller::ParameterMetadata(T).new( | ||
"foo", | ||
default_value: default, | ||
has_default: !default.nil?, | ||
annotation_configurations: ADI::AnnotationConfigurations.new({ | ||
ATHA::MapQueryParameter => [ | ||
ATHA::MapQueryParameterConfiguration.new(name, validation_failed_status), | ||
] of ADI::AnnotationConfigurations::ConfigurationBase, | ||
} of ADI::AnnotationConfigurations::Classes => Array(ADI::AnnotationConfigurations::ConfigurationBase)) | ||
) | ||
end | ||
|
||
describe ATHR::QueryParameter do | ||
describe "#resolve" do | ||
it "does not have the annotation" do | ||
parameter = ATH::Controller::ParameterMetadata(String).new "foo" | ||
ATHR::QueryParameter.new.resolve(new_request, parameter).should be_nil | ||
end | ||
|
||
it "valid scalar parameter" do | ||
ATHR::QueryParameter.new.resolve(new_request(query: "foo=bar"), parameter).should eq "bar" | ||
end | ||
|
||
it "custom param name" do | ||
ATHR::QueryParameter.new.resolve(new_request(query: "blah=bar"), parameter name: "blah").should eq "bar" | ||
end | ||
|
||
it "valid array parameter" do | ||
ATHR::QueryParameter.new.resolve(new_request(query: "foo=1&foo=2"), parameter(Array(Int32))).should eq [1, 2] | ||
end | ||
|
||
it "missing nilable" do | ||
ATHR::QueryParameter.new.resolve(new_request, parameter(Float64?)).should be_nil | ||
end | ||
|
||
it "non-nilable with default" do | ||
ATHR::QueryParameter.new.resolve(new_request, parameter(Bool, default: false)).should be_nil | ||
end | ||
|
||
it "missing non-nilable no default" do | ||
expect_raises ATH::Exception::NotFound, "Missing query parameter: 'foo'." do | ||
ATHR::QueryParameter.new.resolve new_request, parameter | ||
end | ||
end | ||
|
||
it "missing non-nilable no default custom status" do | ||
expect_raises ATH::Exception::UnprocessableEntity, "Missing query parameter: 'foo'." do | ||
ATHR::QueryParameter.new.resolve new_request, parameter(validation_failed_status: :unprocessable_entity) | ||
end | ||
end | ||
|
||
it "invalid" do | ||
expect_raises ATH::Exception::NotFound, "Invalid query parameter: 'foo'." do | ||
ATHR::QueryParameter.new.resolve new_request(query: "foo=bar"), parameter(Int32) | ||
end | ||
end | ||
|
||
it "missing non-nilable no default custom status" do | ||
expect_raises ATH::Exception::UnprocessableEntity, "Invalid query parameter: 'foo'." do | ||
ATHR::QueryParameter.new.resolve new_request(query: "foo=bar"), parameter(Int32, validation_failed_status: :unprocessable_entity) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 0 additions & 87 deletions
87
src/components/framework/spec/controllers/query_param_controller.cr
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/components/framework/spec/exceptions/invalid_parameter_spec.cr
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/components/framework/spec/listeners/param_fetcher_spec.cr
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.