diff options
| author | mo khan <mo@mokhan.ca> | 2014-02-20 18:52:21 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-02-20 18:52:21 -0700 |
| commit | b6635fb14d7935992aa004a477ac877804675794 (patch) | |
| tree | 1758aadace34794f33fd3f407393fd8230a64fd8 | |
| parent | 4f506a2366115e61c6f0cbb5ae154e2555b9d1ca (diff) | |
use named parameters for better readability and ensure a json response is returned.
| -rw-r--r-- | app/controllers/v1/licenses_controller.rb | 4 | ||||
| -rw-r--r-- | spec/controllers/v1/liceneses_controller_spec.rb | 13 |
2 files changed, 12 insertions, 5 deletions
diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index d8c16b6..36ae54c 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -4,8 +4,8 @@ class V1::LicensesController < ApplicationController before_filter :prepare_pagination def index - @licenses = License.most_recent(@page, @per_page) - render nothing: true + @licenses = License.most_recent(page: @page, per_page: @per_page) + render json: @licenses end private diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index 5964556..b2eb705 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -5,7 +5,7 @@ describe V1::LicensesController do let(:licenses) { [] } it "returns the first page of licenses" do - License.stub(:most_recent).with(1, 10).and_return(licenses) + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) xhr :get, :index @@ -14,7 +14,7 @@ describe V1::LicensesController do end it "returns the second page of licenses" do - License.stub(:most_recent).with(2, 10).and_return(licenses) + License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) xhr :get, :index, page: 2 @@ -23,11 +23,18 @@ describe V1::LicensesController do end it "returns the specified number of results" do - License.stub(:most_recent).with(1, 100).and_return(licenses) + 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 end |
