Commit 9e53cbea8ae30a0d7a7075c2a91a65e9f6d88cfc
Committed by
Leandro Santos
1 parent
415e0656
Exists in
web_steps_improvements
and in
8 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,7 +4,7 @@ module Noosfero | ||
| 4 | 4 | ||
| 5 | class Boxes < Grape::API | 5 | class Boxes < Grape::API |
| 6 | 6 | ||
| 7 | - kinds = %w[profile community person enterprise] | 7 | + kinds = %w[profile community person enterprise environment] |
| 8 | kinds.each do |kind| | 8 | kinds.each do |kind| |
| 9 | 9 | ||
| 10 | resource kind.pluralize.to_sym do | 10 | resource kind.pluralize.to_sym do |
| @@ -12,8 +12,12 @@ module Noosfero | @@ -12,8 +12,12 @@ module Noosfero | ||
| 12 | segment "/:#{kind}_id" do | 12 | segment "/:#{kind}_id" do |
| 13 | resource :boxes do | 13 | resource :boxes do |
| 14 | get do | 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 | end | 21 | end |
| 18 | end | 22 | end |
| 19 | end | 23 | end |
test/unit/api/environment_test.rb
| @@ -33,4 +33,17 @@ class SearchTest < ActiveSupport::TestCase | @@ -33,4 +33,17 @@ class SearchTest < ActiveSupport::TestCase | ||
| 33 | json = JSON.parse(last_response.body) | 33 | json = JSON.parse(last_response.body) |
| 34 | assert_equal contextEnv.id, json['id'] | 34 | assert_equal contextEnv.id, json['id'] |
| 35 | end | 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 | end | 49 | end |
| 37 | \ No newline at end of file | 50 | \ No newline at end of file |