Commit 9e53cbea8ae30a0d7a7075c2a91a65e9f6d88cfc
Committed by
Leandro Santos
1 parent
415e0656
Exists in
staging
and in
32 other branches
Added boxes support for environment
Showing
2 changed files
with
20 additions
and
3 deletions
Show diff stats
lib/noosfero/api/v1/boxes.rb
| ... | ... | @@ -4,7 +4,7 @@ module Noosfero |
| 4 | 4 | |
| 5 | 5 | class Boxes < Grape::API |
| 6 | 6 | |
| 7 | - kinds = %w[profile community person enterprise] | |
| 7 | + kinds = %w[profile community person enterprise environment] | |
| 8 | 8 | kinds.each do |kind| |
| 9 | 9 | |
| 10 | 10 | resource kind.pluralize.to_sym do |
| ... | ... | @@ -12,8 +12,12 @@ module Noosfero |
| 12 | 12 | segment "/:#{kind}_id" do |
| 13 | 13 | resource :boxes do |
| 14 | 14 | get do |
| 15 | - profile = environment.send(kind.pluralize).find(params["#{kind}_id"]) | |
| 16 | - present profile.boxes, :with => Entities::Box | |
| 15 | + if (kind == "environment") | |
| 16 | + container = Environment.find(params["environment_id"]) | |
| 17 | + else | |
| 18 | + container = environment.send(kind.pluralize).find(params["#{kind}_id"]) | |
| 19 | + end | |
| 20 | + present container.boxes, :with => Entities::Box | |
| 17 | 21 | end |
| 18 | 22 | end |
| 19 | 23 | end | ... | ... |
test/unit/api/environment_test.rb
| ... | ... | @@ -33,4 +33,17 @@ class SearchTest < ActiveSupport::TestCase |
| 33 | 33 | json = JSON.parse(last_response.body) |
| 34 | 34 | assert_equal contextEnv.id, json['id'] |
| 35 | 35 | end |
| 36 | + | |
| 37 | + should 'return environment boxes' do | |
| 38 | + default = Environment.default | |
| 39 | + default.boxes << Box.new | |
| 40 | + default.boxes[0].blocks << Block.new | |
| 41 | + default.save! | |
| 42 | + assert !default.boxes.empty? | |
| 43 | + get "/api/v1/environments/#{default.id}/boxes" | |
| 44 | + json = JSON.parse(last_response.body) | |
| 45 | + assert_equal "boxes", json.first[0] | |
| 46 | + assert_not_equal [], json.first[1] | |
| 47 | + end | |
| 48 | + | |
| 36 | 49 | end |
| 37 | 50 | \ No newline at end of file | ... | ... |