diff --git a/lib/noosfero/api/v1/environments.rb b/lib/noosfero/api/v1/environments.rb index 909deea..695dea0 100644 --- a/lib/noosfero/api/v1/environments.rb +++ b/lib/noosfero/api/v1/environments.rb @@ -9,7 +9,21 @@ module Noosfero get '/signup_person_fields' do present environment.signup_person_fields end - + + # Returns the given environment + get ':id' do + id = params[:id] + if (id == "default") + present Environment.default + else + if (id == "context") + present Environment.find_by_name(request.host) + else + present Environment.find(params[:id]) + end + end + end + end end diff --git a/test/unit/api/environment_test.rb b/test/unit/api/environment_test.rb new file mode 100644 index 0000000..f048fb9 --- /dev/null +++ b/test/unit/api/environment_test.rb @@ -0,0 +1,36 @@ +require_relative 'test_helper' + +class SearchTest < ActiveSupport::TestCase + + def setup + @person = create_user('testing').person + end + attr_reader :person + + should 'return the default environment' do + default = Environment.default + get "/api/v1/environment/default" + json = JSON.parse(last_response.body) + assert_equal default.id, json['id'] + end + + should 'return created environment' do + other = fast_create(Environment) + default = Environment.default + assert_not_equal other.id, default.id + get "/api/v1/environment/#{other.id}" + json = JSON.parse(last_response.body) + assert_equal other.id, json['id'] + end + + should 'return context environment' do + contextEnv = fast_create(Environment) + contextEnv.name = "example.org" + contextEnv.save + default = Environment.default + assert_not_equal contextEnv.id, default.id + get "/api/v1/environment/context" + json = JSON.parse(last_response.body) + assert_equal contextEnv.id, json['id'] + end +end \ No newline at end of file -- libgit2 0.21.2