From bd442141974a110a1647b01be919bf03de407ab9 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:39:45 -0700 Subject: filter by license status and township --- app/controllers/v1/company_licenses_controller.rb | 3 ++- app/models/license_status.rb | 3 +++ spec/controllers/v1/company_licenses_controller_spec.rb | 14 +++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 app/models/license_status.rb diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 06d2145..963423a 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -2,7 +2,8 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company def index - @active_licenses = @company.active_licenses + @active_licenses = @company.status(LicenseStatus::ACTIVE) + @active_licenses = @active_licenses.township(params[:township]) if params[:township].present? render json: @active_licenses end diff --git a/app/models/license_status.rb b/app/models/license_status.rb new file mode 100644 index 0000000..abe54b1 --- /dev/null +++ b/app/models/license_status.rb @@ -0,0 +1,3 @@ +module LicenseStatus + ACTIVE="active" +end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index fb0972a..2784a1d 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -4,20 +4,28 @@ describe V1::CompanyLicensesController do describe :index do let(:company) { Object.new } let(:company_id) { SecureRandom.uuid } - let(:active_licenses) { [] } + let(:active_licenses) { ["active"] } + let(:active_licenses_in_township) { ["active township"] } 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 + company.stub(:status).with(LicenseStatus::ACTIVE).and_return(active_licenses) + active_licenses.stub(:township).with("123").and_return(active_licenses_in_township) end it "returns the active licenses" do + xhr :get, :index, company_id: company_id assigns(:active_licenses).should == active_licenses end it "returns a json response" do + xhr :get, :index, company_id: company_id expect(-> { JSON.parse(response.body) }).not_to raise_error end + + it "returns the active licenses for a given township" do + xhr :get, :index, company_id: company_id, township: "123" + assigns(:active_licenses).should == active_licenses_in_township + end end end -- cgit v1.2.3