From 9a094059fcb67a9f54ee73efbdecc2835a5fe0c6 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:22:06 -0700 Subject: implement index action on company licenses controller. --- .../v1/company_licenses_controller_spec.rb | 23 +++++++++ spec/controllers/v1/liceneses_controller_spec.rb | 57 ---------------------- spec/controllers/v1/licenses_controller_spec.rb | 57 ++++++++++++++++++++++ 3 files changed, 80 insertions(+), 57 deletions(-) create mode 100644 spec/controllers/v1/company_licenses_controller_spec.rb delete mode 100644 spec/controllers/v1/liceneses_controller_spec.rb create mode 100644 spec/controllers/v1/licenses_controller_spec.rb (limited to 'spec/controllers') 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/liceneses_controller_spec.rb deleted file mode 100644 index e8538d0..0000000 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require "spec_helper" - -describe V1::LicensesController do - describe :index do - let(:licenses) { [] } - - it "returns the first page of licenses" do - License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) - - xhr :get, :index - - response.should be_success - assigns(:licenses).should == licenses - end - - it "returns the second page of licenses" do - License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) - - xhr :get, :index, page: 2 - - response.should be_success - assigns(:licenses).should == licenses - end - - it "returns the specified number of results" do - License.stub(:most_recent).with(page: 1, per_page: 100).and_return(licenses) - - xhr :get, :index, per_page: 100 - response.should be_success - assigns(:licenses).should == licenses - end - - it "returns a json response" do - License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) - - xhr :get, :index - -> { JSON.parse(response.body) }.should_not raise_error - end - end - - describe :show do - let(:license) { License.new(id: SecureRandom.uuid) } - - before :each do - License.stub(:find).with(license.id).and_return(license) - xhr :get, :show, id: license.id - end - - it "returns the correct license" do - assigns(:license).should == license - 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/licenses_controller_spec.rb b/spec/controllers/v1/licenses_controller_spec.rb new file mode 100644 index 0000000..e8538d0 --- /dev/null +++ b/spec/controllers/v1/licenses_controller_spec.rb @@ -0,0 +1,57 @@ +require "spec_helper" + +describe V1::LicensesController do + describe :index do + let(:licenses) { [] } + + it "returns the first page of licenses" do + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) + + xhr :get, :index + + response.should be_success + assigns(:licenses).should == licenses + end + + it "returns the second page of licenses" do + License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) + + xhr :get, :index, page: 2 + + response.should be_success + assigns(:licenses).should == licenses + end + + it "returns the specified number of results" do + License.stub(:most_recent).with(page: 1, per_page: 100).and_return(licenses) + + xhr :get, :index, per_page: 100 + response.should be_success + assigns(:licenses).should == licenses + end + + it "returns a json response" do + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) + + xhr :get, :index + -> { JSON.parse(response.body) }.should_not raise_error + end + end + + describe :show do + let(:license) { License.new(id: SecureRandom.uuid) } + + before :each do + License.stub(:find).with(license.id).and_return(license) + xhr :get, :show, id: license.id + end + + it "returns the correct license" do + assigns(:license).should == license + end + + it "returns a json response" do + expect(-> { JSON.parse(response.body) }).not_to raise_error + end + end +end -- cgit v1.2.3