Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ GEM
aes_key_wrap (1.1.0)
ast (2.4.2)
aws-eventstream (1.3.1)
aws-partitions (1.1050.0)
aws-partitions (1.1052.0)
aws-record (2.13.2)
aws-sdk-dynamodb (~> 1, >= 1.85.0)
aws-sdk-core (3.218.1)
aws-sdk-core (3.219.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
Expand All @@ -137,7 +137,7 @@ GEM
aws-sessionstore-dynamodb (~> 2)
concurrent-ruby (~> 1.3, >= 1.3.1)
railties (>= 7.0.0)
aws-sdk-s3 (1.180.0)
aws-sdk-s3 (1.181.0)
aws-sdk-core (~> 3, >= 3.216.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -374,24 +374,24 @@ GEM
net-protocol
newrelic_rpm (9.17.0)
nio4r (2.7.4)
nokogiri (1.18.2)
nokogiri (1.18.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.18.2-aarch64-linux-gnu)
nokogiri (1.18.3-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.2-aarch64-linux-musl)
nokogiri (1.18.3-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.18.2-arm-linux-gnu)
nokogiri (1.18.3-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.2-arm-linux-musl)
nokogiri (1.18.3-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.18.2-arm64-darwin)
nokogiri (1.18.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.2-x86_64-darwin)
nokogiri (1.18.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.18.2-x86_64-linux-gnu)
nokogiri (1.18.3-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.2-x86_64-linux-musl)
nokogiri (1.18.3-x86_64-linux-musl)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
Expand Down Expand Up @@ -511,7 +511,7 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.4.0)
rexml (3.4.1)
rolify (6.0.1)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
Expand All @@ -532,7 +532,7 @@ GEM
rspec-support (3.13.2)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.72.0)
rubocop (1.72.2)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
Expand All @@ -545,13 +545,15 @@ GEM
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
rubocop-rails (2.29.1)
rubocop-rails (2.30.1)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (3.4.0)
rubocop (~> 1.61)
rubocop (>= 1.72.1, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rspec (3.5.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.13.0)
Expand All @@ -574,7 +576,7 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sidekiq (7.3.8)
sidekiq (7.3.9)
base64
connection_pool (>= 2.3.0)
logger
Expand Down Expand Up @@ -634,7 +636,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.7.1)
zeitwerk (2.7.2)

PLATFORMS
aarch64-linux
Expand Down
7 changes: 5 additions & 2 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Submission < ApplicationRecord

before_create :set_uuid
after_create :update_form
after_create :set_preview
after_commit :send_notifications, on: :create

scope :active, -> { where(flagged: false, spam: false, archived: false, deleted: false) }
Expand Down Expand Up @@ -69,6 +70,7 @@ def validate_custom_form
answered_questions.delete('spam')
answered_questions.delete('archived')
answered_questions.delete('deleted')
answered_questions.delete('preview')
answered_questions.delete('created_at')
answered_questions.delete('updated_at')
answered_questions.delete('deleted_at')
Expand Down Expand Up @@ -207,12 +209,13 @@ def organization_name
form.organization.present? ? form.organization.name : 'Org Name'
end

def preview
def set_preview
# only select the answer fields
fields = attributes.select { |attr| attr.include?("answer")}
# only select text fields
text_fields = fields.values.select { |v| v.is_a?(String) }
text_fields.join(" - ").truncate(120)
preview_text = text_fields.join(" - ").truncate(120)
self.update_attribute(:preview, preview_text)
end

def set_uuid
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/forms/_logo_display.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="display-logo-div">
<%= form_with(model: form, url: update_display_logo_admin_form_url(form, format: :js), html: { multipart: :true }, local: false) do |f| %>
<%= form_with(model: form, url: update_display_logo_admin_form_url(form, format: :js), html: { multipart: :true }, class: "usa-form--large", local: false) do |f| %>
<div class="grid-row grid-gap-md">
<div class="grid-col-12">
<div class="usa-form-group">
Expand Down
3 changes: 0 additions & 3 deletions app/views/admin/forms/responses.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<% end %>
</p>
<%= render 'admin/forms/nav', form: @form %>
<h3>
Customer Feedback Analysis
</h3>
<%- if admin_permissions? && @form.kind == "a11" %>
<div class="a11-analysis-widget"><span class="usa-label">Loading A11 Analysis...</span></div>
<% end %>
Expand Down
14 changes: 11 additions & 3 deletions app/views/components/_responses_by_status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,24 @@

</td>
<td>
<%= link_to responses_admin_form_path(@form, flagged: 1) do %>
<%= number_with_delimiter(responses_by_status["flagged"]) %>
<% end %>
</td>
<td>
<%= number_with_delimiter(responses_by_status["marked"]) %>
<%= link_to responses_admin_form_path(@form, spam: 1) do %>
<%= number_with_delimiter(responses_by_status["marked"]) %>
<% end %>
</td>
<td>
<%= number_with_delimiter(responses_by_status["archived"]) %>
<%= link_to responses_admin_form_path(@form, archived: 1) do %>
<%= number_with_delimiter(responses_by_status["archived"]) %>
<% end %>
</td>
<td>
<%= number_with_delimiter(responses_by_status["deleted"]) %>
<%= link_to responses_admin_form_path(@form, deleted: 1) do %>
<%= number_with_delimiter(responses_by_status["deleted"]) %>
<% end %>
</td>
<td>
</td>
Expand Down
3 changes: 0 additions & 3 deletions app/views/user_mailer/form_feedback.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<p>
Please take this <%= link_to "short survey", @feedback_url %>
to provide feedback regarding the Touchpoints application and/or the Touchpoints team.
<br>
<br>
<%= link_to @feedback_url, @feedback_url %>
</p>
<p>
We want to know what you thought of Touchpoints and how CX feedback is going.
Expand Down
1 change: 1 addition & 0 deletions config/newrelic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ common: &default_settings
development:
<<: *default_settings
app_name: touchpoints-development
monitor_mode: false

test:
<<: *default_settings
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20250214194816_cache_submission_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CacheSubmissionPreview < ActiveRecord::Migration[7.2]
def change
add_column :submissions, :preview, :string, default: ""

Submission.unscoped.in_batches(of: 10_000) do |batch|
batch.each do |submission|
submission.set_preview
end
end
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2025_02_11_191435) do
ActiveRecord::Schema[7.2].define(version: 2025_02_14_194816) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -651,6 +651,7 @@
t.boolean "archived", default: false
t.boolean "deleted", default: false
t.datetime "deleted_at"
t.string "preview", default: ""
t.index ["archived"], name: "index_submissions_on_archived"
t.index ["created_at"], name: "index_submissions_on_created_at"
t.index ["flagged"], name: "index_submissions_on_flagged"
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,19 @@
after(:create) do |f, _evaluator|
FactoryBot.create(:question,
form: f,
answer_field: :answer_01,
question_type: 'textarea',
form_section: f.form_sections.first,
text: 'Body')
FactoryBot.create(:question,
form: f,
answer_field: :answer_02,
question_type: 'textarea',
form_section: f.form_sections.first,
text: 'Name')
FactoryBot.create(:question,
form: f,
answer_field: :answer_03,
question_type: 'textarea',
form_section: f.form_sections.first,
text: 'Email')
Expand Down
1 change: 0 additions & 1 deletion spec/features/admin/forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@
end

it 'display table list of Responses and Export responses dropdown' do
expect(page).to have_content('Customer Feedback Analysis')
expect(page).to have_content('RESPONSES BY STATUS')
expect(page).to have_content('Responses per day')
expect(page).to have_content('Total submissions received over period')
Expand Down
38 changes: 38 additions & 0 deletions spec/models/submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,42 @@
expect(submission.spam_score).to eq(0)
end
end

describe "callbacks" do
describe "after_create :set_preview" do
let(:open_ended_contact_form) { FactoryBot.create(:form, :open_ended_form_with_contact_information, organization:, notification_emails: "#{admin.email}, second@example.gov") }

it "sets preview from answer fields" do
new_submission = Submission.create(
form: open_ended_contact_form,
answer_01: "First answer",
answer_02: "Second answer",
answer_03: "Third answer",
)
expect(new_submission.preview).to eq("First answer - Second answer - Third answer")
end

it "ignores non-answer fields" do
new_submission = Submission.create(
form: open_ended_contact_form,
answer_01: "First answer",
answer_02: "Second answer",
language: "en"
)
expect(new_submission.preview).to eq("First answer - Second answer")
end

it "truncates the preview to 120 characters" do
long_text = "A" * 150
new_submission = Submission.create(
form: open_ended_contact_form,
answer_01: long_text,
answer_02: "Another answer"
)
expect(new_submission.preview.length).to be <= 120
expect(new_submission.preview).to end_with("...")
end
end
end

end
Loading