summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/v1/licenses_controller.rb8
-rw-r--r--spec/controllers/v1/liceneses_controller_spec.rb9
2 files changed, 14 insertions, 3 deletions
diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb
index 86eb85e..e919663 100644
--- a/app/controllers/v1/licenses_controller.rb
+++ b/app/controllers/v1/licenses_controller.rb
@@ -1,8 +1,10 @@
class V1::LicensesController < ApplicationController
+ PER_PAGE = 10
+ DEFAULT_PAGE = 1
+
def index
- per_page = 10
- page = 1
- @licenses = License.most_recent(page, per_page)
+ page = params[:page].to_i || DEFAULT_PAGE
+ @licenses = License.most_recent(page, PER_PAGE)
render nothing: true
end
end
diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb
index fc4d7b3..7f1080c 100644
--- a/spec/controllers/v1/liceneses_controller_spec.rb
+++ b/spec/controllers/v1/liceneses_controller_spec.rb
@@ -12,5 +12,14 @@ describe V1::LicensesController do
response.should be_success
assigns(:licenses).should == licenses
end
+
+ it "returns the second page of licenses" do
+ License.stub(:most_recent).with(2, 10).and_return(licenses)
+
+ xhr :get, :index, page: 2
+
+ response.should be_success
+ assigns(:licenses).should == licenses
+ end
end
end