From eed99c4599cc7f0c218ecc45e126acfafd33360a Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 17 Jun 2013 23:14:20 +0400 Subject: [PATCH 1/2] #70: updated Api::V1::MaintainersController, added specs --- .../api/v1/maintainers_controller.rb | 2 +- .../api/v1/maintainers_controller_spec.rb | 53 ++++++++++++++----- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/maintainers_controller.rb b/app/controllers/api/v1/maintainers_controller.rb index cda1761f1..c6596ca69 100644 --- a/app/controllers/api/v1/maintainers_controller.rb +++ b/app/controllers/api/v1/maintainers_controller.rb @@ -5,7 +5,7 @@ class Api::V1::MaintainersController < Api::V1::BaseController def index @maintainers = BuildList::Package.includes(:project) .actual.by_platform(@platform) - .like_name(params[:filter].try(:[], :package_name)) + .like_name(params[:package_name]) .paginate(paginate_params) end end diff --git a/spec/controllers/api/v1/maintainers_controller_spec.rb b/spec/controllers/api/v1/maintainers_controller_spec.rb index 837539ec9..c653a499d 100644 --- a/spec/controllers/api/v1/maintainers_controller_spec.rb +++ b/spec/controllers/api/v1/maintainers_controller_spec.rb @@ -1,22 +1,48 @@ require 'spec_helper' +shared_examples_for 'api maintainers user with reader rights' do + it 'should be able to perform index action' do + get :index, :platform_id => package.platform_id, :format => :json + should render_template(:index) + end + + it 'loads all of the maintainers into @maintainers' do + get :index, :platform_id => package.platform_id, :format => :json + assigns(:maintainers).should have(2).items + assigns(:maintainers).should include(package, package2) + end + + it 'loads all of the maintainers into @maintainers when search by name' do + get :index, :platform_id => package.platform_id, :package_name => 'package1', :format => :json + assigns(:maintainers).should have(1).item + assigns(:maintainers).should include(package) + end + +end + describe Api::V1::MaintainersController do before do stub_symlink_methods + FactoryGirl.create(:build_list_package, :platform => package.platform) end + let(:package) { FactoryGirl.create(:build_list_package, :name => 'package1', :actual => true) } + let!(:package2) { FactoryGirl.create(:build_list_package, :platform => package.platform, :actual => true) } - let(:package) { FactoryGirl.create(:build_list_package) } context 'for guest' do - it "should be able to perform index action", :anonymous_access => true do - get :index, :platform_id => package.platform_id, :format => :json - should render_template(:index) + if APP_CONFIG['anonymous_access'] + it_should_behave_like 'api maintainers user with reader rights' + else + it 'should not be able to perform index action', :anonymous_access => false do + get :index, :platform_id => package.platform_id, :format => :json + response.status.should == 401 + end end + # it 'should be able to perform index action', :anonymous_access => true do + # get :index, :platform_id => package.platform_id, :format => :json + # should render_template(:index) + # end - it 'should be able to perform get_id action', :anonymous_access => false do - get :index, :platform_id => package.platform_id, :format => :json - response.status.should == 401 - end end context 'for simple user' do @@ -24,9 +50,12 @@ describe Api::V1::MaintainersController do http_login(FactoryGirl.create(:user)) end - it "should be able to perform index action" do - get :index, :platform_id => package.platform_id, :format => :json - should render_template(:index) - end + it_should_behave_like 'api maintainers user with reader rights' + # it 'should be able to perform index action' do + # get :index, :platform_id => package.platform_id, :format => :json + # should render_template(:index) + # end + + # it '' end end From 13842c2791bc0808e3d28a4813fec5b91b9513d9 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 17 Jun 2013 23:16:14 +0400 Subject: [PATCH 2/2] #70: removed unnecessary code --- .../controllers/api/v1/maintainers_controller_spec.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/spec/controllers/api/v1/maintainers_controller_spec.rb b/spec/controllers/api/v1/maintainers_controller_spec.rb index c653a499d..6d28e2aad 100644 --- a/spec/controllers/api/v1/maintainers_controller_spec.rb +++ b/spec/controllers/api/v1/maintainers_controller_spec.rb @@ -38,11 +38,6 @@ describe Api::V1::MaintainersController do response.status.should == 401 end end - # it 'should be able to perform index action', :anonymous_access => true do - # get :index, :platform_id => package.platform_id, :format => :json - # should render_template(:index) - # end - end context 'for simple user' do @@ -51,11 +46,5 @@ describe Api::V1::MaintainersController do end it_should_behave_like 'api maintainers user with reader rights' - # it 'should be able to perform index action' do - # get :index, :platform_id => package.platform_id, :format => :json - # should render_template(:index) - # end - - # it '' end end