-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change HTTP DELETE status code and body logic, use nil for HTTP 204 #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,11 +111,42 @@ def initialize | |
expect(subject.status).to eq 204 | ||
end | ||
|
||
it 'defaults to 200 on DELETE with a body present' do | ||
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE')) | ||
subject.body 'content here' | ||
expect(subject).to receive(:request).and_return(request) | ||
expect(subject.status).to eq 200 | ||
describe 'what is regarded as content on DELETE' do | ||
it 'regards a string as content' do | ||
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE')) | ||
subject.body 'content here' | ||
expect(subject).to receive(:request).and_return(request) | ||
expect(subject.status).to eq 200 | ||
end | ||
|
||
it 'regards an empty string as content' do | ||
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE')) | ||
subject.body '' | ||
expect(subject).to receive(:request).and_return(request) | ||
expect(subject.status).to eq 200 | ||
end | ||
|
||
it 'regards an empty hash as content' do | ||
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE')) | ||
subject.body({}) # Use brackets, because it's a block otherwise | ||
expect(subject).to receive(:request).and_return(request) | ||
expect(subject.status).to eq 200 | ||
end | ||
|
||
it 'regards an empty array as content' do | ||
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE')) | ||
subject.body [] | ||
expect(subject).to receive(:request).and_return(request) | ||
expect(subject.status).to eq 200 | ||
end | ||
|
||
# Still failing for some weird kind of reason. | ||
it 'regards a nil as no content' do | ||
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE')) | ||
subject.body nil | ||
expect(subject).to receive(:request).and_return(request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't work because there is wrong code in using You don't need test this expectation. Please remove this line. |
||
expect(subject.status).to eq 204 | ||
end | ||
end | ||
|
||
it 'returns status set' do | ||
|
@@ -184,9 +215,9 @@ def initialize | |
end | ||
end | ||
|
||
describe 'false' do | ||
describe 'nil' do | ||
before do | ||
subject.body false | ||
subject.body nil | ||
end | ||
|
||
it 'sets status to 204' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the text is not required, just
raise ArgumentError
.What if value is
nil
, what'snil.length
?This needs a test.
You can also turn this into a separate PR if you want.