Skip to content

Commit cb13ed4

Browse files
committed
rspec stuff etc
1 parent ee62a75 commit cb13ed4

File tree

5 files changed

+68
-14
lines changed

5 files changed

+68
-14
lines changed

app/controllers/diy/diy_notification_preference_controller.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def edit
66

77
def update
88
diy_intake = current_diy_intake
9-
@form = DiyNotificationPreferenceForm.new(diy_intake)
9+
form_params = params.fetch(:diy_notification_preference_form, {}).permit(*DiyNotificationPreferenceForm.attribute_names)
10+
@form = DiyNotificationPreferenceForm.new(diy_intake, form_params)
1011
if @form.valid?
1112
@form.save
1213
session[:diy_intake_id] = diy_intake.id
@@ -15,15 +16,5 @@ def update
1516
render :edit
1617
end
1718
end
18-
19-
private
20-
21-
def tracking_data
22-
@form.attributes_for(:diy_intake)
23-
end
24-
25-
def illustration_path
26-
"contact-preference.svg"
27-
end
2819
end
2920
end

app/forms/diy_notification_preference_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize(diy_intake = nil, params = {})
99
end
1010

1111
def save
12-
diy_intake.update(attributes_for(:diy_intake))
12+
diy_intake.update!(attributes_for(:diy_intake))
1313
end
1414

1515
def self.existing_attributes(diy_intake)

app/views/diy/diy_notification_preference/edit.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<%= f.cfa_checkbox(:sms_notification_opt_in, t("views.questions.notification_preference.options.sms_notification_opt_in"), options: { checked_value: "yes", unchecked_value: "no", "data-follow-up": "#sms-opt-in" }) %>
2929
</div>
3030

31+
<!-- TODO add reveal widget -->
32+
<%= t('views.questions.notification_preference.reveal_header') %>
33+
<%= t('views.questions.notification_preference.below_reveal') %>
34+
3135
<p class="text--small spacing-above-25">
3236
<%= t("views.questions.notification_preference.note_html", terms_url: sms_terms_url, privacy_url: privacy_url) %>
3337
</p>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Diy::DiyNotificationPreferenceController do
4+
render_views
5+
6+
example_email_addr = 'example@example.test' # http://www.faqs.org/rfcs/rfc2606.html
7+
8+
let(:diy_intake) { create :diy_intake, email_address: example_email_addr }
9+
10+
before do
11+
allow(subject).to receive(:current_diy_intake).and_return(diy_intake)
12+
allow(subject).to receive(:send_mixpanel_event)
13+
end
14+
15+
describe "#edit" do
16+
let!(:diy_intake) { create :diy_intake, email_address: example_email_addr }
17+
18+
it "renders successfully" do
19+
get :edit
20+
expect(response).to be_successful
21+
end
22+
end
23+
24+
describe "#update" do
25+
context "with valid params" do
26+
let(:params) do
27+
{
28+
diy_notification_preference_form: {
29+
email_notification_opt_in: "yes",
30+
sms_notification_opt_in: "no",
31+
}
32+
}
33+
end
34+
35+
it "updates the diy_intake's notification preferences" do
36+
expect(diy_intake.sms_notification_opt_in).to eq("unfilled")
37+
expect(diy_intake.email_notification_opt_in).to eq("unfilled")
38+
39+
post :update, params: params
40+
41+
diy_intake.reload
42+
expect(diy_intake.sms_notification_opt_in).to eq("no")
43+
expect(diy_intake.email_notification_opt_in).to eq("yes")
44+
end
45+
46+
xit "sends an event to mixpanel with relevant data" do
47+
post :update, params: params
48+
49+
expect(subject).to have_received(:send_mixpanel_event).with(
50+
event_name: "question_answered",
51+
data: {
52+
email_notification_opt_in: "yes",
53+
sms_notification_opt_in: "no",
54+
}
55+
)
56+
end
57+
end
58+
end
59+
end

spec/controllers/diy/file_yourself_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@
8787
end
8888
end
8989

90-
it "redirects to the tax slayer link page" do
90+
it "redirects to the notification preference page" do
9191
post :update, params: params
9292

93-
expect(response).to redirect_to diy_continue_to_fsa_path
93+
expect(response).to redirect_to diy_diy_notification_preference_path
9494
end
9595
end
9696

0 commit comments

Comments
 (0)