diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 35e3c0b0..8f1dd1fa 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -2,7 +2,7 @@ module Admin class ProjectsController < Admin::ApplicationController - before_action :set_host_for_local_storage + include ActiveStorage::SetCurrent def scoped_resource resource_class.internal_projects @@ -13,11 +13,5 @@ def destroy_image image.purge redirect_back(fallback_location: requested_resource) end - - private - - def set_host_for_local_storage - ActiveStorage::Current.host = request.base_url if Rails.application.config.active_storage.service == :local - end end end diff --git a/spec/factories/project.rb b/spec/factories/project.rb index e1da4476..ab6fbd5e 100644 --- a/spec/factories/project.rb +++ b/spec/factories/project.rb @@ -33,5 +33,9 @@ content_type: 'image/png') end end + + factory :internal_project do + user_id { nil } + end end end diff --git a/spec/features/admin/admin_projects_spec.rb b/spec/features/admin/admin_projects_spec.rb new file mode 100644 index 00000000..b4527ee2 --- /dev/null +++ b/spec/features/admin/admin_projects_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin projects', type: :request do + let(:admin_user) { create(:admin_user) } + + describe 'GET /projects' do + it 'responds 200' do + create(:project) + + sign_in_as admin_user + + get "/admin/projects" + expect(response).to have_http_status(:success) + end + end + + describe 'GET /projects/:id' do + it 'responds 200 for an internal project' do + project = create(:internal_project) + + sign_in_as admin_user + + get "/admin/projects/#{project.id}" + + expect(response).to have_http_status(:success) + end + + it 'responds 404 for a user created project' do + project = create(:project) + + sign_in_as admin_user + + get "/admin/projects/#{project.id}" + + expect(response).to have_http_status(:not_found) + end + end + + private + + def sign_in_as(user) + allow(User).to receive(:from_omniauth).and_return(admin_user) + get '/auth/callback' + end +end