WorkPackage mapper changes

pull/1435/head
Marek Takac 11 years ago
parent 622ebd04eb
commit 00f3b7a291
  1. 2
      app/api/api.rb
  2. 4
      app/api/work_packages/work_package_mapper.rb
  3. 9
      app/api/work_packages/work_packages.rb
  4. 10
      spec/api/api_spec.rb
  5. 3
      spec/spec_helper.rb

@ -33,7 +33,7 @@ class API < Grape::API
end
get do
"Entry point"
{ test: 'test' }.to_json
end
get :search do

@ -1,5 +1,9 @@
module WorkPackages
class WorkPackageMapper < Yaks::Mapper
def initialize(object, embedded)
super(object)
end
link :self, '/api/v3/work_packages/{id}'
link :createChildren, '/api/v3/work_packages?parent_id={id}', method: :post
link :update, '/api/v3/work_packages/{id}', method: :patch

@ -5,9 +5,9 @@ module WorkPackages
params do
optional :page, type: Integer, default: 1
optional :per_page, type: Integer, default: 100
optional :filters, type: Array
optional :filters, type: String
optional :sort_expression, type: String
optional :extend, type: String
optional :embedded, type: String
end
get do
work_packages = WorkPackage.all
@ -16,8 +16,9 @@ module WorkPackages
get ':id' do
work_package = WorkPackage.find(params[:id])
authorize work_package, :show?
resource = WorkPackageMapper.new(work_package).to_resource
Yaks::HalSerializer.new(resource).serialize.to_json
resource = WorkPackageMapper.new(work_package, 'rest').to_resource
binding.pry
Yaks::HalSerializer.new(resource).to_hal.to_json
end
patch ':id' do

@ -0,0 +1,10 @@
require 'spec_helper'
describe API do
describe "GET /api/v3" do
it "should be success" do
get "/api/v3"
response.status.should == 200
end
end
end

@ -112,6 +112,9 @@ RSpec.configure do |config|
raise "your specs leave a #{cls} in the DB\ndid you use before(:all) instead of before or forget to kill the instances in a after(:all)?" if cls.count > 0
end
end
# include spec/api for API request specs
config.include RSpec::Rails::RequestExampleGroup, type: :request, example_group: { file_path: /spec\/api/ }
end
# load disable_specs.rbs from plugins

Loading…
Cancel
Save