Compare commits

...

1 Commits

Author SHA1 Message Date
bilal
94b417d4c4 do not show archived templates when importing contract templates 2020-06-17 15:08:01 +02:00
4 changed files with 36 additions and 2 deletions

View File

@@ -11,7 +11,9 @@ class ReleaseTemplateImportsController < ApplicationController
templates = []
filtered_contract_templates.each do |contract_template|
next if contract_template.duplicated? || contract_template.project == @project
next if contract_template.duplicated? ||
contract_template.archived? ||
contract_template.project == @project
already_imported = contract_template.duplicates.non_archived.pluck(:project_id).include?(@project.id)
templates << OpenStruct.new(template: contract_template, already_imported?: already_imported)

View File

@@ -51,6 +51,10 @@ class ContractTemplate < ApplicationRecord
parent.present?
end
def archived?
archived_at.present?
end
def archive
update(archived_at: Time.zone.now)
end

View File

@@ -8,6 +8,10 @@ FactoryBot.define do
guardian_clause "Is the signer a minor?"
fee "$0.00"
trait :archived do
archived_at Time.zone.now
end
factory :appearance_release_contract_template do
release_type "appearance"
end

View File

@@ -5,6 +5,7 @@ require 'rails_helper'
RSpec.feature 'User manages contract templates', type: :feature do
let(:current_user) { create(:user, :manager) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
let(:project2) { create(:project, members: current_user, account: current_user.primary_account, name: 'New project') }
before do
sign_in(current_user)
@@ -191,6 +192,21 @@ RSpec.feature 'User manages contract templates', type: :feature do
expect(page).not_to have_content('Test template')
end
scenario 'archived contract templates from other projects are not shown when importing contract templates' do
create(:contract_template, :archived, project: project2, name: 'Archived template')
create(:contract_template, project: project2, name: 'Active template')
create(:contract_template, project: project)
visit project_contract_templates_path(project)
expect(page).to have_content('Test template')
click_on import_template_button
expect(page).not_to have_content('Test template')
expect(page).not_to have_content('Archived template')
expect(page).to have_content('Active template')
end
context 'When the user is associate' do
let(:current_user) { create(:user, :associate) }
@@ -198,7 +214,7 @@ RSpec.feature 'User manages contract templates', type: :feature do
visit project_contract_templates_path(project)
expect(page).not_to have_content('Create New Release Template')
expect(page).not_to have_content('Import Release Template')
expect(page).not_to have_content(import_template_button)
expect(page).not_to have_content('Delete')
end
end
@@ -218,6 +234,14 @@ RSpec.feature 'User manages contract templates', type: :feature do
private
def import_template_button
t 'contract_templates.index.actions.import'
end
def import_selected_templates_button
t 'release_template_imports.new.actions.import'
end
def preview_heading
t 'blank_contracts.new.preview_heading'
end