From df4cd1ee6d18128c5109b232f4bae214e67dbf2d Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 30 Mar 2015 10:44:42 +0300 Subject: [PATCH] Add offset support for repp domains --- app/api/repp/domain_v1.rb | 6 ++++-- spec/requests/domain_spec.rb | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/api/repp/domain_v1.rb b/app/api/repp/domain_v1.rb index 7afb494c6..dbdcc778d 100644 --- a/app/api/repp/domain_v1.rb +++ b/app/api/repp/domain_v1.rb @@ -6,15 +6,17 @@ module Repp desc 'Return list of domains' params do optional :limit, type: Integer, values: (1..20).to_a + optional :offset, type: Integer end get '/' do limit = params[:limit] || 20 + offset = params[:offset] || 0 if params[:details] == 'true' - domains = current_user.registrar.domains.limit(limit) + domains = current_user.registrar.domains.limit(limit).offset(offset) else - domains = current_user.registrar.domains.limit(limit).pluck(:name) + domains = current_user.registrar.domains.limit(limit).offset(offset).pluck(:name) end @response = { diff --git a/spec/requests/domain_spec.rb b/spec/requests/domain_spec.rb index 97dd58ec5..74e697300 100644 --- a/spec/requests/domain_spec.rb +++ b/spec/requests/domain_spec.rb @@ -30,8 +30,27 @@ describe Repp::DomainV1 do log[:ip].should == '127.0.0.1' end - it 'returns domain names of the current registrar' do + it 'returns domain names with offset' do + get_with_auth '/repp/v1/domains', { offset: 1}, @api_user + response.status.should == 200 + body = JSON.parse(response.body) + body['total_number_of_records'].should == 2 + + # TODO: Maybe there is a way not to convert from and to json again + body['domains'].to_json.should == @api_user.reload.registrar.domains.offset(1).pluck(:name).to_json + + log = ApiLog::ReppLog.last + log[:request_path].should == '/repp/v1/domains' + log[:request_method].should == 'GET' + log[:request_params].should == '{"offset":1}' + log[:response_code].should == '200' + log[:api_user_name].should == 'gitlab' + log[:api_user_registrar].should == 'registrar1' + log[:ip].should == '127.0.0.1' + end + + it 'returns domain names of the current registrar' do get_with_auth '/repp/v1/domains', {}, @api_user response.status.should == 200