From 0625a941bd12932a8a835f43a4f74c84bb55ab00 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 7 Apr 2015 22:43:40 +0300 Subject: [PATCH] #465: Update specs --- app/controllers/autocompletes_controller.rb | 2 +- app/controllers/search_controller.rb | 1 + app/controllers/sitemap_controller.rb | 3 ++- app/models/build_list.rb | 2 +- spec/controllers/advisories_controller_spec.rb | 4 ++-- .../controllers/api/v1/products_controller_spec.rb | 2 +- spec/controllers/autocompletes_controller_spec.rb | 14 +++++++------- .../platforms/repositories_controller_spec.rb | 2 +- .../projects/git/git_trees_controller_spec.rb | 2 +- spec/controllers/search_controller_spec.rb | 6 +++--- spec/controllers/sitemap_controller_spec.rb | 10 +++++----- spec/support/shared_examples/admin_examples.rb | 8 ++++---- 12 files changed, 29 insertions(+), 27 deletions(-) diff --git a/app/controllers/autocompletes_controller.rb b/app/controllers/autocompletes_controller.rb index 9f76e8555..17798401e 100644 --- a/app/controllers/autocompletes_controller.rb +++ b/app/controllers/autocompletes_controller.rb @@ -37,7 +37,7 @@ class AutocompletesController < ApplicationController def autocomplete_extra_repositories # Only personal and build for platform repositories can be attached to the build - platforms = PlatformPolicy::Scope.new(current_user, Platform).related. + platforms = PlatformPolicy::Scope.new(current_user, Platform).show. includes(:repositories).search(params[:term]).search_order.limit(5). where("platforms.platform_type = 'personal' OR platforms.id = ?", params[:build_for_platform_id]) platforms.each do |platform| diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ac635b79f..7f2d2111e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -2,6 +2,7 @@ class SearchController < ApplicationController include PaginateHelper before_action :authenticate_user! unless APP_CONFIG['anonymous_access'] + skip_after_action :verify_authorized def index @type = Search::TYPES.find{ |t| t == params[:type] } || Search::TYPES.first diff --git a/app/controllers/sitemap_controller.rb b/app/controllers/sitemap_controller.rb index 521a6bee3..a5527a2db 100644 --- a/app/controllers/sitemap_controller.rb +++ b/app/controllers/sitemap_controller.rb @@ -1,4 +1,5 @@ class SitemapController < ApplicationController + skip_after_action :verify_authorized def show redirect_to "/sitemaps/#{request.host_with_port.gsub(/www./, '')}/sitemap.xml.gz" @@ -8,4 +9,4 @@ class SitemapController < ApplicationController render file: 'sitemap/robots', layout: false, content_type: Mime::TEXT end -end \ No newline at end of file +end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index f0a9b4d8d..0b914be79 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -132,7 +132,7 @@ class BuildList < ActiveRecord::Base scope :recent, -> { order(updated_at: :desc) } scope :for_extra_build_lists, ->(ids, save_to_platform) { - s = s.where(id: ids) + s = where(id: ids, container_status: BuildList::BUILD_PUBLISHED) s = s.where(save_to_platform_id: save_to_platform.id) if save_to_platform && save_to_platform.main? s } diff --git a/spec/controllers/advisories_controller_spec.rb b/spec/controllers/advisories_controller_spec.rb index d41c8b41e..9ebbaa467 100644 --- a/spec/controllers/advisories_controller_spec.rb +++ b/spec/controllers/advisories_controller_spec.rb @@ -4,7 +4,7 @@ describe AdvisoriesController, type: :controller do context 'for all' do it "should be able to perform search action" do get :search - response.should_not redirect_to(forbidden_path) + expect(response).to_not redirect_to(forbidden_path) end end -end \ No newline at end of file +end diff --git a/spec/controllers/api/v1/products_controller_spec.rb b/spec/controllers/api/v1/products_controller_spec.rb index f165bf737..07532687b 100644 --- a/spec/controllers/api/v1/products_controller_spec.rb +++ b/spec/controllers/api/v1/products_controller_spec.rb @@ -114,7 +114,7 @@ shared_examples_for 'api user with admin rights' do #[:update, :destroy].each do |action| # it "ensures that return correct answer for wrong #{action} action" do # put action, id: nil, format: :json - # response.status.should == 404 + # expect(response.status).to eq 404 # end #end end diff --git a/spec/controllers/autocompletes_controller_spec.rb b/spec/controllers/autocompletes_controller_spec.rb index b4c0bba85..ad380aa44 100644 --- a/spec/controllers/autocompletes_controller_spec.rb +++ b/spec/controllers/autocompletes_controller_spec.rb @@ -11,12 +11,12 @@ describe AutocompletesController, type: :controller do it 'should be able to perform autocomplete_user_or_group action' do get :autocomplete_user_or_group - response.should be_success + expect(response).to be_success end it 'should be able to perform autocomplete_user_uname action' do get :autocomplete_user_uname - response.should be_success + expect(response).to be_success end context 'autocomplete_extra_build_list' do @@ -26,13 +26,13 @@ describe AutocompletesController, type: :controller do it 'no data when build_list without container' do get :autocomplete_extra_build_list, params - response.body.should == '[]' + expect(response.body).to eq '[]' end it 'shows data when build_list with container' do build_list.update_column(:container_status, BuildList::BUILD_PUBLISHED) get :autocomplete_extra_build_list, params - response.body.should_not == '[]' + expect(response.body).to_not eq '[]' end end @@ -47,13 +47,13 @@ describe AutocompletesController, type: :controller do it 'no data when repository of main platform' do get :autocomplete_extra_repositories, params - response.body.should == '[]' + expect(response.body).to eq '[]' end it 'shows data when repository of personal platform' do Platform.update_all(platform_type: 'personal') get :autocomplete_extra_repositories, params - response.body.should_not == '[]' + expect(response.body).to_not eq '[]' end end @@ -73,7 +73,7 @@ describe AutocompletesController, type: :controller do ].each do |action| it "should not be able to perform #{action} action" do get action - response.should redirect_to(new_user_session_path) + expect(response).to redirect_to(new_user_session_path) end end diff --git a/spec/controllers/platforms/repositories_controller_spec.rb b/spec/controllers/platforms/repositories_controller_spec.rb index 20e0752e5..220128530 100644 --- a/spec/controllers/platforms/repositories_controller_spec.rb +++ b/spec/controllers/platforms/repositories_controller_spec.rb @@ -267,7 +267,7 @@ describe Platforms::RepositoriesController, type: :controller do it 'should not be able to perform projects_list action', anonymous_access: false do get :projects_list, id: @repository, platform_id: @platform, format: :json - response.response_code.should == 401 + expect(response.response_code).to eq 401 end end diff --git a/spec/controllers/projects/git/git_trees_controller_spec.rb b/spec/controllers/projects/git/git_trees_controller_spec.rb index 577613d2b..39625d9a9 100644 --- a/spec/controllers/projects/git/git_trees_controller_spec.rb +++ b/spec/controllers/projects/git/git_trees_controller_spec.rb @@ -30,7 +30,7 @@ describe Projects::Git::TreesController, type: :controller do it "should not be able to perform archive action without anonymous acccess", anonymous_access: false do get :archive, @params.merge(format: 'tar.gz') - response.code.should == '401' + expect(response.code).to eq '401' end it 'should not be able to perform destroy action' do diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 9d359e2a9..1196b72b2 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' shared_examples_for 'able search' do it 'should be able to search' do get :index - response.should be_success - response.should render_template(:index) + expect(response).to be_success + expect(response).to render_template(:index) end end shared_examples_for 'not able search' do it 'should not be able to search' do get :index - response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path) + expect(response).to redirect_to(controller.current_user ? forbidden_path : new_user_session_path) end end diff --git a/spec/controllers/sitemap_controller_spec.rb b/spec/controllers/sitemap_controller_spec.rb index 539a21eaa..b97193f27 100644 --- a/spec/controllers/sitemap_controller_spec.rb +++ b/spec/controllers/sitemap_controller_spec.rb @@ -5,8 +5,8 @@ describe SitemapController, type: :controller do it 'is successful' do get :robots - response.should be_success - response.should render_template('sitemap/robots') + expect(response).to be_success + expect(response).to render_template('sitemap/robots') end context 'validate robots.txt' do @@ -14,12 +14,12 @@ describe SitemapController, type: :controller do it 'ensures that Host is correct' do get :robots - response.body.should match(/^Host: http:\/\/test.host$/) + expect(response.body).to match(/^Host: http:\/\/test.host$/) end it 'ensures that Sitemap is correct' do get :robots - response.body.should match(/^Sitemap: http:\/\/test.host\/sitemap.xml.gz$/) + expect(response.body).to match(/^Sitemap: http:\/\/test.host\/sitemap.xml.gz$/) end end end @@ -28,7 +28,7 @@ describe SitemapController, type: :controller do it 'is successful' do get :show - response.should redirect_to("/sitemaps/test.host/sitemap.xml.gz") + expect(response).to redirect_to("/sitemaps/test.host/sitemap.xml.gz") end end diff --git a/spec/support/shared_examples/admin_examples.rb b/spec/support/shared_examples/admin_examples.rb index 4e8535a41..9463f9c61 100644 --- a/spec/support/shared_examples/admin_examples.rb +++ b/spec/support/shared_examples/admin_examples.rb @@ -2,21 +2,21 @@ shared_examples_for 'an admin controller' do it 'redirects to login when accessed unauthorised' do get :index - response.should redirect_to(new_user_session_path) + expect(response).to redirect_to(new_user_session_path) end it 'raises a 404 for non-admin users' do user = User.first || FactoryGirl.create(:user) sign_in user get :index - response.should render_template(file: "#{Rails.root}/public/404.html") + expect(response).to render_template(file: "#{Rails.root}/public/404.html") end it 'is successful for admin users' do user = FactoryGirl.create(:admin) sign_in user get :index - response.should be_success + expect(response).to be_success end -end \ No newline at end of file +end