Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket 282996,afficher une consigne dans la description générée #33

Merged
merged 8 commits into from
Jan 9, 2024
2 changes: 1 addition & 1 deletion app/models/issue_template_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def self.short_name
end

def rendered_value(section_attributes, textile: true, value_only: false)
'' # Nothing to render
"\n p(wiki-class-#{instruction_type}). #{text}\n"
end
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce qu'il ne faudrait pas gérer 2 cas ici ? Pour prendre en compte le cas où show_in_generated_issue est désactivé ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dans le controller , il y a une condition

if (section.type == "IssueTemplateSectionInstruction") && !section.display_mode.to_i.zero?
             @issue.description.present? ? @issue.description += section.rendered_value([]) : @issue.description = section.rendered_value([])
end

Donc, la méthode n'est pas appelée dans ce cas


Expand Down
2 changes: 1 addition & 1 deletion app/overrides/issues/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
rows.left l(:label_issue_template), link_to_issue_template(@issue.issue_template), :class => 'template'
end
end %>
}
}
3 changes: 3 additions & 0 deletions app/views/issue_templates/sections/_instruction_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<%= wikitoolbar_for textarea_id unless template %>

</p>
<p>
<%= form.check_box :display_mode, label: :show_in_generated_issue %>
</p>
</div>
<% end %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ en:
add_repeatable_bloc_label: Custom text for block add button (optional)
delete_repeatable_bloc_label: Custom text for block delete button (optional)
field_assignable_projects: "Template projects"
show_in_generated_issue: Show in the generated issue
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ fr:
add_repeatable_bloc_label: Texte personnalisé pour le bouton d'ajout du bloc (facultatif)
delete_repeatable_bloc_label: Texte personnalisé pour le bouton de suppression du bloc (facultatif)
field_assignable_projects: "Projets"
show_in_generated_issue: Afficher dans la demande générée
14 changes: 13 additions & 1 deletion lib/redmine_templates/issues_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,21 @@ def update_description_with_sections
end
end
@issue.description = @issue.substituted(issue_description, @sections_attributes)

end
end

if @issue.issue_template.present?
# integrate the instructions into the generated description.
@issue.issue_template.section_groups.each do |group|
group.sections.each do |section|
if (section.type == "IssueTemplateSectionInstruction") && !section.display_mode.to_i.zero?
@issue.description.present? ? @issue.description += section.rendered_value([]) : @issue.description = section.rendered_value([])
end
end
end
end
end

def update_subject_when_autocomplete
issue_template = @issue.issue_template
if issue_template.present? && issue_template.autocomplete_subject && issue_template.subject.present?
Expand Down
29 changes: 29 additions & 0 deletions spec/controllers/issue_templates_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,35 @@
expect(template_with_instruction.sections.third.text).to eq "New warning!"
expect(template_with_instruction.sections.third.position).to eq 3
end

it "should successfully select (option show in the generated issue)" do
expect do
post :create, params: {
:issue_template => {
:template_title => "New template",
:template_enabled => "1",
:template_project_ids => ["1"],
:tracker_id => 1,
:status_id => 1,
section_groups_attributes: [
{ "position" => "1",
"title" => "",
"repeatable" => "0",
sections_attributes: [
{ "position" => "1",
"type" => "IssueTemplateSectionInstruction",
"instruction_type" => "info",
"text" => "New instruction",
"display_mode" => "1",
},
]
}
]
}
}
end.to change { IssueTemplate.count }.by(1)
expect(IssueTemplate.last.section_groups.first.sections.first.display_mode).to eq("1")
end
end

describe "issue creation" do
Expand Down
42 changes: 27 additions & 15 deletions spec/controllers/issues_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,32 @@
expect(issue.description).to eq("\r\n-----\r\n\r\n*Section title :* \r\nTest text\r\n\r\n*Second section title without Toolbar :* \r\nNothing to say\r\n")
end

it "does not join instructions into description" do
it "does not join instructions into description when the option (Show in the generated issue)is unselected" do
section_test = IssueTemplateSection.find(6)
assert_difference('Issue.count', 1) do
post :create, :params => {
:project_id => 1,
:issue => {
:tracker_id => 3,
:status_id => 2,
:subject => 'This is the test_new issue',
:description => 'Ignore default description',
:priority_id => 5,
:issue_template_id => template_with_instruction.id,
}
}
end

issue = Issue.last
expect(issue).not_to be_nil
expect(issue.description).to_not include(section_test.text)
end

it "Should join instructions into description when the option (Show in the generated issue)is selected" do
section_test = IssueTemplateSection.find(6)
section_test.display_mode = "1"
section_test.save

assert_difference('Issue.count', 1) do
post :create, :params => {
:project_id => 1,
Expand All @@ -358,26 +383,13 @@
:description => 'Ignore default description',
:priority_id => 5,
:issue_template_id => template_with_instruction.id,
:issue_template => {
:section_groups_attributes => {
"4" => {
"0" => {
:sections_attributes => {
"6" => {
text: "Text in a section field"
}
}
}
}
}
}
}
}
end

issue = Issue.last
expect(issue).not_to be_nil
expect(issue.description).to eq("\r\n-----\r\n")
expect(issue.description).to include(section_test.text)
end

it "sends a notification by mail with multiple sections concatenated into one description" do
Expand Down
14 changes: 14 additions & 0 deletions spec/models/issue_template_section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@
expect(t.value_from_text_attribute(attributes)).to eq("a,b,c")
end
end

describe "rendered_value of instruction type" do
it "Should return the correct value" do
section = IssueTemplateSection.new(text: 'new info', type: "IssueTemplateSectionInstruction", instruction_type: "note")
expect(section.rendered_value([])).to eq("\n p(wiki-class-note). new info\n")
end

it "Should return the correct wiki class" do
IssueTemplateDescriptionInstruction::TYPES.each do |type|
section = IssueTemplateSection.new(text: 'new info', type: "IssueTemplateSectionInstruction", instruction_type: type)
expect(section.rendered_value([])).to include("\n p(wiki-class-#{type}). new info\n")
end
end
end
end
Loading