Commit 415e0656bad8829048f59aeb89b62fc17cac1bd5
Committed by
Leandro Santos
1 parent
dbb2c156
Exists in
web_steps_improvements
and in
8 other branches
Added environment api tests and endpoints
Showing
2 changed files
with
51 additions
and
1 deletions
Show diff stats
lib/noosfero/api/v1/environments.rb
@@ -9,7 +9,21 @@ module Noosfero | @@ -9,7 +9,21 @@ module Noosfero | ||
9 | get '/signup_person_fields' do | 9 | get '/signup_person_fields' do |
10 | present environment.signup_person_fields | 10 | present environment.signup_person_fields |
11 | end | 11 | end |
12 | - | 12 | + |
13 | + # Returns the given environment | ||
14 | + get ':id' do | ||
15 | + id = params[:id] | ||
16 | + if (id == "default") | ||
17 | + present Environment.default | ||
18 | + else | ||
19 | + if (id == "context") | ||
20 | + present Environment.find_by_name(request.host) | ||
21 | + else | ||
22 | + present Environment.find(params[:id]) | ||
23 | + end | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
13 | end | 27 | end |
14 | 28 | ||
15 | end | 29 | end |
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +require_relative 'test_helper' | ||
2 | + | ||
3 | +class SearchTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @person = create_user('testing').person | ||
7 | + end | ||
8 | + attr_reader :person | ||
9 | + | ||
10 | + should 'return the default environment' do | ||
11 | + default = Environment.default | ||
12 | + get "/api/v1/environment/default" | ||
13 | + json = JSON.parse(last_response.body) | ||
14 | + assert_equal default.id, json['id'] | ||
15 | + end | ||
16 | + | ||
17 | + should 'return created environment' do | ||
18 | + other = fast_create(Environment) | ||
19 | + default = Environment.default | ||
20 | + assert_not_equal other.id, default.id | ||
21 | + get "/api/v1/environment/#{other.id}" | ||
22 | + json = JSON.parse(last_response.body) | ||
23 | + assert_equal other.id, json['id'] | ||
24 | + end | ||
25 | + | ||
26 | + should 'return context environment' do | ||
27 | + contextEnv = fast_create(Environment) | ||
28 | + contextEnv.name = "example.org" | ||
29 | + contextEnv.save | ||
30 | + default = Environment.default | ||
31 | + assert_not_equal contextEnv.id, default.id | ||
32 | + get "/api/v1/environment/context" | ||
33 | + json = JSON.parse(last_response.body) | ||
34 | + assert_equal contextEnv.id, json['id'] | ||
35 | + end | ||
36 | +end | ||
0 | \ No newline at end of file | 37 | \ No newline at end of file |