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

Add liquid resource assigns to tylium #1145

Merged
merged 14 commits into from
May 16, 2023
4 changes: 2 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[v#.#.#] ([month] [YYYY])
- [entity]:
- [future tense verb] [feature]
- Tylium:
- Add support for Liquid Dynamic Content
caitmich marked this conversation as resolved.
Show resolved Hide resolved
- Upgraded gems:
- [gem]
- Bugs fixes:
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/evidence_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def autogenerate_issue
track_created(@evidence.issue)
end

def liquid_resource_assigns
{
caitmich marked this conversation as resolved.
Show resolved Hide resolved
'evidence' => EvidenceDrop.new(@evidence),
'node' => NodeDrop.new(@evidence.node)
}
end

# Look for the Evidence we are going to be working with based on the :id
# passed by the user.
def set_or_initialize_evidence
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def import
end

private

def liquid_resource_assigns
{ 'issue' => IssueDrop.new(@issue) }
end

def set_affected_nodes
@affected_nodes = Node.joins(:evidence)
.select('nodes.id, label, type_id, count(evidence.id) as evidence_count, nodes.updated_at')
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/qa/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def issue_params
params.permit(:state)
end

def liquid_resource_assigns
{ 'issue' => IssueDrop.new(@issue) }
end

def set_issue
@issue = @issues.find(params[:id])
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/evidence/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</h4>

<div class="content-textile" data-behavior="content-textile">
<%= markup(@evidence.content) %>
<%= markup(@evidence.content, liquid: true) %>
</div>
<div class="author-info">
<span class="ml-auto">Author: <%= @evidence.author || 'n/a' %></span>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= render partial: 'actions' %>
</h4>
<div class="content-textile" data-behavior="content-textile">
<%= markup(@note.text) %>
<%= markup(@note.text, liquid: true) %>
</div>
<div class="author-info">
<span class="ml-auto">Author: <%= @note.author || 'n/a' %></span>
Expand Down
13 changes: 10 additions & 3 deletions spec/features/evidence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

example 'show page with wrong Node ID in URL' do
node = create(:node)
evidence = create(:evidence, node:)
evidence = create(:evidence, node: node)
wrong_node = create(:node)
expect do
visit project_node_evidence_path(current_project, wrong_node, evidence)
Expand All @@ -21,7 +21,7 @@

describe 'show page' do
before(:each) do
e_text = "#[Foobar]#\nBarfoo\n\n#[Fizzbuzz]#\nBuzzfizz"
e_text = "#[Foobar]#\nBarfoo\n\n#[Fizzbuzz]#\nBuzzfizz\n Liquid: {{evidence.title}}"
i_text = "#[Issue Title]#\nIssue info"
@issue = create(:issue, node: @node, text: i_text)
@evidence = create(:evidence, node: @node, issue: @issue, content: e_text)
Expand All @@ -45,6 +45,13 @@
should have_selector 'p', text: 'Issue info'
end

context 'with liquid dynamic content' do
it 'dynamically renders evidence properties' do
expect(find('.note-text-inner')).to have_content("Liquid: #{@evidence.title}")
expect(find('.note-text-inner')).not_to have_content('Liquid: {{evidence.title}}')
end
end

let(:commentable) { @evidence }
it_behaves_like 'a page with a comments feed'

Expand Down Expand Up @@ -86,7 +93,7 @@

before do
issue = create(:issue, node: issue_lib)
@evidence = create(:evidence, issue:, node: @node, updated_at: 2.seconds.ago)
@evidence = create(:evidence, issue: issue, node: @node, updated_at: 2.seconds.ago)
visit edit_project_node_evidence_path(current_project, @node, @evidence)
click_link 'Source'
end
Expand Down
9 changes: 8 additions & 1 deletion spec/features/issues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
@issue = issuelib.notes.create(
category: Category.issue,
author: 'rspec',
text: "#[Title]#\nMultiple Apache bugs\n\n",
text: "#[Title]#\nMultiple Apache bugs\n\n#[Description]#\nLiquid: {{issue.title}}",
node: create(:node, :with_project)
)
# @issue is currently loaded as a Note, not an Issue. Make sure it
Expand Down Expand Up @@ -402,6 +402,13 @@
expect(page).to have_text "(#{@issue.state.humanize})"
end
end

context 'with liquid dynamic content' do
it 'dynamically renders issue properties' do
expect(find('.note-text-inner')).to have_content("Liquid: #{@issue.title}")
expect(find('.note-text-inner')).not_to have_content('Liquid: {{issue.title}}')
end
end
end
end

Expand Down
13 changes: 10 additions & 3 deletions spec/features/note_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

example 'show page with wrong Node ID in URL' do
node = create(:node, project: current_project)
note = create(:note, node:)
note = create(:note, node: node)
wrong_node = create(:node, project: current_project)
expect do
visit project_node_note_path(current_project, wrong_node, note)
Expand All @@ -25,8 +25,8 @@

describe 'show page' do
before do
text = "#[Title]#\nMy note\n\n#[Description]#\nMy description"
@note = create(:note, node: @node, text:)
text = "#[Title]#\nMy note\n\n#[Description]#\nMy description\n Liquid: {{ project.name }}"
@note = create(:note, node: @node, text: text)
create_activities
create_comments
visit project_node_note_path(current_project, @node, @note)
Expand All @@ -42,6 +42,13 @@
should have_selector 'p', text: 'My description'
end

context 'with liquid dynamic content' do
it 'dynamically renders project properites' do
expect(find('.note-text-inner')).to have_content("Liquid: #{current_project.name}")
expect(find('.note-text-inner')).not_to have_content('Liquid: {{project.name}}')
end
end

let(:commentable) { @note }
it_behaves_like 'a page with a comments feed'

Expand Down
10 changes: 10 additions & 0 deletions spec/features/qa/issues_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
create_list(:issue, 10, state: :ready_for_review, node: current_project.issue_library)
end

context 'with liquid dynamic content' do
let(:issue) { create(:issue, state: :ready_for_review, node: current_project.issue_library, text: "#[Title]#\nIssue Title\n\n#[Description]#\nLiquid: {{issue.title}}") }

it 'dynamically renders issue properties' do
visit project_qa_issue_path(current_project, issue)
expect(find('.note-text-inner')).to have_content("Liquid: #{issue.title}")
expect(find('.note-text-inner')).not_to have_content('Liquid: {{issue.title}}')
end
end

include_examples 'qa pages', :issue
end
end