Commit 5cb7c0ab4f7648fcdfbb8d9803daeb3d21dc33f5
1 parent
1fe6b276
Exists in
api-homepage
Added environment endpoints and tests
Showing
2 changed files
with
52 additions
and
1 deletions
Show diff stats
lib/noosfero/api/v1/environments.rb
... | ... | @@ -9,7 +9,21 @@ module Noosfero |
9 | 9 | get '/signup_person_fields' do |
10 | 10 | present environment.signup_person_fields |
11 | 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 | 27 | end |
14 | 28 | |
15 | 29 | end | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
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 | + puts "Return: #{last_response.body}" | |
34 | + json = JSON.parse(last_response.body) | |
35 | + assert_equal contextEnv.id, json['id'] | |
36 | + end | |
37 | +end | |
0 | 38 | \ No newline at end of file | ... | ... |