diff options
| -rw-r--r-- | app/controllers/v1/company_licenses_controller.rb | 14 | ||||
| -rw-r--r-- | app/models/company.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/v1/company_licenses_controller_spec.rb | 23 | ||||
| -rw-r--r-- | spec/controllers/v1/licenses_controller_spec.rb (renamed from spec/controllers/v1/liceneses_controller_spec.rb) | 0 |
4 files changed, 38 insertions, 1 deletions
diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index aa52b26..06d2145 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -1,2 +1,14 @@ -class V1::CompanyLicensesController +class V1::CompanyLicensesController < ApplicationController + before_filter :load_company + + def index + @active_licenses = @company.active_licenses + render json: @active_licenses + end + + private + + def load_company + @company = Company.find(params[:company_id]) + end end diff --git a/app/models/company.rb b/app/models/company.rb new file mode 100644 index 0000000..bff819b --- /dev/null +++ b/app/models/company.rb @@ -0,0 +1,2 @@ +class Company +end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb new file mode 100644 index 0000000..fb0972a --- /dev/null +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -0,0 +1,23 @@ +require "spec_helper" + +describe V1::CompanyLicensesController do + describe :index do + let(:company) { Object.new } + let(:company_id) { SecureRandom.uuid } + let(:active_licenses) { [] } + + before :each do + Company.stub(:find).with(company_id).and_return(company) + company.stub(:active_licenses).and_return(active_licenses) + xhr :get, :index, company_id: company_id + end + + it "returns the active licenses" do + assigns(:active_licenses).should == active_licenses + end + + it "returns a json response" do + expect(-> { JSON.parse(response.body) }).not_to raise_error + end + end +end diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/licenses_controller_spec.rb index e8538d0..e8538d0 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/licenses_controller_spec.rb |
