Created
May 14, 2011 06:18
-
-
Save okitan/971979 to your computer and use it in GitHub Desktop.
楽になったと言えるのか怪しくはあるw
This file contains hidden or 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
request_json 'POST /users/:user_id/articles' do # request_json is nicer than describe_jsonapi? | |
let(:user_id) { 1 } | |
let(:article_id) { 'hello' } | |
before(:all) { User.make!(:id => :user_id) } | |
after(:all) { DatabaseCleaner.clean } | |
context 'when user posts valid article' do | |
request_json do | |
Article.make(:user_id => id, :article_id => article_id) | |
end | |
after(:all) do { Article.delete } | |
it { status_code.should be_created } | |
response_headers do | |
its(['Location']) { should == url_for(:user_id => user_id, :id => article_id) } | |
end | |
response_body do | |
its(:article_id) { should == article_id } | |
its(:uri) { should == url_for(:user_id => user_id, :id => article_id) } | |
its(:body) { should_not be_nil } | |
end | |
request_json 'GET /users/:user_id/articles/:article_id' do | |
include_examples 'response for article' | |
end | |
end | |
context 'when user posts invalid article' do | |
request_json do | |
Article.make(:user_id => id, :article_id => article_id, :body => nil) | |
end | |
it { status_code.should be_bad_request } | |
response_headers { } | |
reponse_body do | |
member :errors do | |
element :first do | |
its(:message) { should == 'article needs body' } | |
end | |
end | |
end | |
end | |
end | |
__EOF__ | |
GET /users/:id | |
when user posts valid article | |
status code should be 201 Created | |
in response headers | |
Content-Type should start with application/json | |
Location should == http://example.com/users/1/hello | |
in response body | |
article_id should == 1 | |
uri should == http://example.com/users/1/hello | |
body should not be nil | |
and GET /users/:id/articles/:article_id | |
status code should be 200 OK | |
(...snip...) | |
when user posts invalid article | |
status code should be 400 Bad Request | |
in response headers | |
Content-Type should start with application/json | |
in response body | |
member errors | |
should be an aray | |
.first | |
message should == 'article needs body' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment