From 8cc5ba134f6c5a1a06d91407aa78b962545c54ac Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 17 Apr 2014 11:42:13 +0200 Subject: initial commit for the service level api :api/service will return a hash of the current users service level This is failiing if the user is not logged in. Instead it should return the service description for an anonymous user. --- app/controllers/v1/services_controller.rb | 8 ++++++++ app/models/service_level.rb | 1 + config/routes.rb | 1 + test/functional/v1/services_controller_test.rb | 23 +++++++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 app/controllers/v1/services_controller.rb create mode 100644 test/functional/v1/services_controller_test.rb diff --git a/app/controllers/v1/services_controller.rb b/app/controllers/v1/services_controller.rb new file mode 100644 index 0000000..594940e --- /dev/null +++ b/app/controllers/v1/services_controller.rb @@ -0,0 +1,8 @@ +class V1::ServicesController < ApplicationController + + respond_to :json + + def show + respond_with current_user.effective_service_level + end +end diff --git a/app/models/service_level.rb b/app/models/service_level.rb index 299aaf1..31a713b 100644 --- a/app/models/service_level.rb +++ b/app/models/service_level.rb @@ -16,4 +16,5 @@ class ServiceLevel APP_CONFIG[:service_levels][@id] end + delegate :to_json, to: :config_hash end diff --git a/config/routes.rb b/config/routes.rb index b930bd1..f612b47 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,6 +25,7 @@ LeapWeb::Application.routes.draw do resources :users, :only => [:create, :update, :destroy, :index] resources :messages, :only => [:index, :update] resource :cert, :only => [:show] + resource :service, :only => [:show] end scope "(:locale)", :locale => MATCH_LOCALE do diff --git a/test/functional/v1/services_controller_test.rb b/test/functional/v1/services_controller_test.rb new file mode 100644 index 0000000..35a9de6 --- /dev/null +++ b/test/functional/v1/services_controller_test.rb @@ -0,0 +1,23 @@ +require 'test_helper' + +class V1::ServicesControllerTest < ActionController::TestCase + + test "anonymous user can request service info" do + get :show, format: :json + assert_json_response name: 'anonymous', + cert_prefix: 'LIMITED', + description: 'anonymous account, with rate limited VPN' + end + + test "user can see their service info" do + login + get :show, format: :json + assert_json_response name: 'free', + cert_prefix: 'LIMITED', + description: 'free account, with rate limited VPN', + cost: 0, + quota: 100 + end + +end + -- cgit v1.2.3