From beb69e33a16bf6d11155f1e8e0599ff4a8a2f39c Mon Sep 17 00:00:00 2001 From: Luca Lee Date: Mon, 1 Apr 2024 17:23:16 -0500 Subject: [PATCH 1/4] add profile on home page and fix history responses --- rails_root/app/controllers/home_controller.rb | 6 ++++-- rails_root/app/views/home/index.html.erb | 3 +++ .../app/views/survey_profiles/_survey_profile.html.erb | 4 ---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rails_root/app/controllers/home_controller.rb b/rails_root/app/controllers/home_controller.rb index 2c39734..8525938 100644 --- a/rails_root/app/controllers/home_controller.rb +++ b/rails_root/app/controllers/home_controller.rb @@ -4,7 +4,9 @@ class HomeController < ApplicationController def index @survey_responses = SurveyResponse.where(profile_id: 2) # FIXME: use code below when other part works - # @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]["sub"]) - # @survey_responses = SurveyResponse.where(profile_id: session[:userinfo]["sub"]) + if !session[:userinfo].nil? + @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]["sub"]) + @survey_responses = SurveyResponse.where(profile_id: @survey_profile.id) + end end end diff --git a/rails_root/app/views/home/index.html.erb b/rails_root/app/views/home/index.html.erb index 4e8f468..1ccbc05 100644 --- a/rails_root/app/views/home/index.html.erb +++ b/rails_root/app/views/home/index.html.erb @@ -4,6 +4,9 @@ <% if session[:userinfo].present? %>

<%= session[:userinfo]['name'] %> - Welcome to Our Rails App

+
+

Your Profile

+ <%= render @survey_profile%>

Your History Responses

diff --git a/rails_root/app/views/survey_profiles/_survey_profile.html.erb b/rails_root/app/views/survey_profiles/_survey_profile.html.erb index dfb371e..7093f46 100644 --- a/rails_root/app/views/survey_profiles/_survey_profile.html.erb +++ b/rails_root/app/views/survey_profiles/_survey_profile.html.erb @@ -1,8 +1,4 @@
-

- User: - <%= survey_profile.user_id %> -

First name: From 8102c189db49c3d948c0ef3fa7f9210e84d1ecb3 Mon Sep 17 00:00:00 2001 From: Luca Lee Date: Thu, 4 Apr 2024 15:40:04 -0500 Subject: [PATCH 2/4] fix rspec --- rails_root/app/views/home/index.html.erb | 4 +++- rails_root/spec/views/home/index.html.erb_spec.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rails_root/app/views/home/index.html.erb b/rails_root/app/views/home/index.html.erb index 1ccbc05..0244e7d 100644 --- a/rails_root/app/views/home/index.html.erb +++ b/rails_root/app/views/home/index.html.erb @@ -6,7 +6,9 @@

<%= session[:userinfo]['name'] %> - Welcome to Our Rails App


Your Profile

- <%= render @survey_profile%> + <% if @survey_profile.present? %> + <%= render @survey_profile%> + <%end%>

Your History Responses

diff --git a/rails_root/spec/views/home/index.html.erb_spec.rb b/rails_root/spec/views/home/index.html.erb_spec.rb index e4c0596..0038cd2 100644 --- a/rails_root/spec/views/home/index.html.erb_spec.rb +++ b/rails_root/spec/views/home/index.html.erb_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'home/index.html.erb', type: :view do it 'displays the welcome message with name' do - session[:userinfo] = { 'name' => 'Peter', 'sub' => 'testestest' } + session[:userinfo] = { 'name' => 'Peter', 'sub' => 1 } render expect(rendered).to have_text('Peter - Welcome to Our Rails App') end From 3c88b0b9f719e9c1fea51a9e0a40b5e81d84f516 Mon Sep 17 00:00:00 2001 From: jacobtoddmathes Date: Tue, 9 Apr 2024 17:06:36 -0500 Subject: [PATCH 3/4] changing logic to pass tests --- rails_root/app/controllers/home_controller.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rails_root/app/controllers/home_controller.rb b/rails_root/app/controllers/home_controller.rb index 8525938..4ace803 100644 --- a/rails_root/app/controllers/home_controller.rb +++ b/rails_root/app/controllers/home_controller.rb @@ -3,10 +3,13 @@ # Controller for the home page class HomeController < ApplicationController def index - @survey_responses = SurveyResponse.where(profile_id: 2) # FIXME: use code below when other part works - if !session[:userinfo].nil? - @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]["sub"]) - @survey_responses = SurveyResponse.where(profile_id: @survey_profile.id) - end + # @survey_responses = SurveyResponse.where(profile_id: 2) # FIXME: use code below when other part works + return if session[:userinfo].nil? + + @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]['sub']) + puts session[:userinfo]['sub'].to_json + return if @survey_profile.nil? + + @survey_responses = SurveyResponse.where(profile_id: @survey_profile.id) end end From f1d8eb623ad7972c558ac2558df4f296ad3a92f3 Mon Sep 17 00:00:00 2001 From: jacobtoddmathes Date: Tue, 9 Apr 2024 17:07:32 -0500 Subject: [PATCH 4/4] removing logs --- rails_root/app/controllers/home_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/rails_root/app/controllers/home_controller.rb b/rails_root/app/controllers/home_controller.rb index 4ace803..997387c 100644 --- a/rails_root/app/controllers/home_controller.rb +++ b/rails_root/app/controllers/home_controller.rb @@ -3,11 +3,9 @@ # Controller for the home page class HomeController < ApplicationController def index - # @survey_responses = SurveyResponse.where(profile_id: 2) # FIXME: use code below when other part works return if session[:userinfo].nil? @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]['sub']) - puts session[:userinfo]['sub'].to_json return if @survey_profile.nil? @survey_responses = SurveyResponse.where(profile_id: @survey_profile.id)