Added show action to page API and fixed some features

This commit is contained in:
Alex Sanford 2012-04-16 15:36:39 -03:00
parent 4f12c2cd10
commit 97edb0e4b7
3 changed files with 58 additions and 7 deletions

View File

@ -7,6 +7,11 @@ module Locomotive
respond_with(@pages)
end
def show
@page = current_site.pages.find(params[:id])
respond_with(@page)
end
def create
@page = current_site.pages.create(params[:page])
respond_with @page, :location => main_app.locomotive_api_pages_url

View File

@ -40,6 +40,41 @@ Feature: Pages
When I do an API GET request to pages.json
Then the JSON response should contain all pages
# showing page
Scenario: Accessing page as an Admin
Given I have an "admin" token
When I do an API GET request to pages/4f832c2cb0d86d3f42fffffe.json
Then the JSON response hash should contain:
"""
{
"id": "4f832c2cb0d86d3f42fffffe",
"slug": "hello-world"
}
"""
Scenario: Accessing page as a Designer
Given I have a "designer" token
When I do an API GET request to pages/4f832c2cb0d86d3f42fffffe.json
Then the JSON response hash should contain:
"""
{
"id": "4f832c2cb0d86d3f42fffffe",
"slug": "hello-world"
}
"""
Scenario: Accessing page as an Author
Given I have an "author" token
When I do an API GET request to pages/4f832c2cb0d86d3f42fffffe.json
Then the JSON response hash should contain:
"""
{
"id": "4f832c2cb0d86d3f42fffffe",
"slug": "hello-world"
}
"""
# create page
Scenario: Creating new page as an Admin
@ -101,11 +136,13 @@ Feature: Pages
When I do an API PUT to pages/4f832c2cb0d86d3f42fffffe.json with:
"""
{
"title": "Brand new updated title"
"page": {
"title": "Brand new updated title"
}
}
"""
When I do an API GET request to pages/4f832c2cb0d86d3f42fffffe.json
Then the JSON response should contain:
Then the JSON response hash should contain:
"""
{
"id": "4f832c2cb0d86d3f42fffffe",
@ -118,11 +155,13 @@ Feature: Pages
When I do an API PUT to pages/4f832c2cb0d86d3f42fffffe.json with:
"""
{
"title": "Brand new updated title"
"page": {
"title": "Brand new updated title"
}
}
"""
When I do an API GET request to pages/4f832c2cb0d86d3f42fffffe.json
Then the JSON response should contain:
Then the JSON response hash should contain:
"""
{
"id": "4f832c2cb0d86d3f42fffffe",
@ -135,7 +174,9 @@ Feature: Pages
When I do an API PUT to pages/4f832c2cb0d86d3f42fffffe.json with:
"""
{
"title": "Brand new updated title"
"page": {
"title": "Brand new updated title"
}
}
"""
Then the JSON response should be an access denied error

View File

@ -67,6 +67,11 @@ Then /^the JSON response should be an access denied error$/ do
@response['message'].should == 'You are not authorized to access this page'
end
Then /^the JSON response should contain:$/ do |json|
@response.merge(JSON.parse(json)).should == @response
Then /^the JSON response hash should contain:$/ do |json|
sub_response = {}
parsed_json = JSON.parse(json)
parsed_json.each do |k, v|
sub_response[k] = @response[k]
end
sub_response.should == parsed_json
end