diff options
| author | mo khan <mo@mokhan.ca> | 2014-02-20 20:39:45 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-02-20 20:39:45 -0700 |
| commit | bd442141974a110a1647b01be919bf03de407ab9 (patch) | |
| tree | 05e605937fdc0a58ac423f43305047e23b6f961d | |
| parent | 9a094059fcb67a9f54ee73efbdecc2835a5fe0c6 (diff) | |
filter by license status and township
| -rw-r--r-- | app/controllers/v1/company_licenses_controller.rb | 3 | ||||
| -rw-r--r-- | app/models/license_status.rb | 3 | ||||
| -rw-r--r-- | spec/controllers/v1/company_licenses_controller_spec.rb | 14 |
3 files changed, 16 insertions, 4 deletions
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 |
