Merge pull request #1943 from tchak/clone-notice

Clone procedure notice
This commit is contained in:
Paul Chavard 2018-05-22 17:55:58 +02:00 committed by GitHub
commit de6638c7a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 2 deletions

View file

@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
before_action :reject, if: -> { Flipflop.maintenance_mode? }
before_action :staging_authenticate
before_action :set_active_storage_host
def staging_authenticate
if StagingAuthService.enabled? && !authenticate_with_http_basic { |username, password| StagingAuthService.authenticate(username, password) }
@ -57,6 +58,10 @@ class ApplicationController < ActionController::Base
private
def set_active_storage_host
ActiveStorage::Current.host = request.base_url
end
def logged_users
@logged_users ||= [
current_user,

View file

@ -135,6 +135,16 @@ class Procedure < ApplicationRecord
procedure.logo_secure_token = nil
procedure.remote_logo_url = self.logo_url
if notice.attached?
response = Typhoeus.get(notice.service_url, timeout: 5)
if response.success?
procedure.notice.attach(
io: StringIO.new(response.body),
filename: notice.filename
)
end
end
procedure.administrateur = admin
procedure.initiated_mail = initiated_mail.try(:dup)
procedure.received_mail = received_mail.try(:dup)

View file

@ -455,10 +455,15 @@ describe Admin::ProceduresController, type: :controller do
end
describe 'PUT #clone' do
let!(:procedure) { create(:procedure, administrateur: admin) }
let!(:procedure) { create(:procedure, :with_notice, administrateur: admin) }
let(:params) { { procedure_id: procedure.id } }
subject { put :clone, params: params }
before do
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
Typhoeus.stub(/active_storage\/disk/).and_return(response)
end
it { expect { subject }.to change(Procedure, :count).by(1) }
context 'when admin is the owner of the procedure' do
@ -466,7 +471,8 @@ describe Admin::ProceduresController, type: :controller do
it 'creates a new procedure and redirect to it' do
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
expect(Procedure.last.cloned_from_library).to be(false)
expect(Procedure.last.cloned_from_library).to be_falsey
expect(Procedure.last.notice.attached?).to be_truthy
expect(flash[:notice]).to have_content 'Procédure clonée'
end

View file

@ -111,6 +111,15 @@ FactoryBot.define do
end
end
trait :with_notice do
after(:create) do |procedure, _evaluator|
procedure.notice.attach(
io: StringIO.new('Hello World'),
filename: 'hello.txt'
)
end
end
trait :with_all_champs_mandatory do
after(:build) do |procedure, _evaluator|
tdcs = []

View file

@ -64,6 +64,7 @@ VCR.configure do |c|
c.hook_into :webmock
c.cassette_library_dir = 'spec/fixtures/cassettes'
c.configure_rspec_metadata!
c.ignore_hosts 'test.host'
end
DatabaseCleaner.strategy = :transaction
@ -119,6 +120,8 @@ RSpec.configure do |config|
config.before(:all) {
Warden.test_mode!
Typhoeus::Expectation.clear
if Flipflop.remote_storage?
VCR.use_cassette("ovh_storage_init") do
CarrierWave.configure do |config|