Skip to content

Commit

Permalink
Merge pull request #11 from tamu-edu-students/adding-rspec-tests
Browse files Browse the repository at this point in the history
tests for survey_responses implemented and passing. Rubocop autoforma…
  • Loading branch information
Andres-L-Santiago authored Feb 16, 2024
2 parents 2fe49d6 + e339ea5 commit 55e409f
Show file tree
Hide file tree
Showing 64 changed files with 548 additions and 370 deletions.
4 changes: 3 additions & 1 deletion rails_root/.simplecov
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

SimpleCov.start 'rails' do
enable_coverage :branch # see https://github.com/colszowka/simplecov#branch-coverage-ruby--25
end
end
2 changes: 2 additions & 0 deletions rails_root/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

ruby '3.3.0'
Expand Down
2 changes: 2 additions & 0 deletions rails_root/Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand Down
2 changes: 2 additions & 0 deletions rails_root/app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions rails_root/app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
2 changes: 2 additions & 0 deletions rails_root/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
end
37 changes: 21 additions & 16 deletions rails_root/app/controllers/survey_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# frozen_string_literal: true

class SurveyProfilesController < ApplicationController
before_action :set_survey_profile, only: %i[ show edit update destroy ]
before_action :set_survey_profile, only: %i[show edit update destroy]

# GET /survey_profiles or /survey_profiles.json
def index
@survey_profiles = SurveyProfile.all
end

# GET /survey_profiles/1 or /survey_profiles/1.json
def show
end
def show; end

# GET /survey_profiles/new
def new
@survey_profile = SurveyProfile.new
end

# GET /survey_profiles/1/edit
def edit
end
def edit; end

# POST /survey_profiles or /survey_profiles.json
def create
@survey_profile = SurveyProfile.new(survey_profile_params)

respond_to do |format|
if @survey_profile.save
format.html { redirect_to survey_profile_url(@survey_profile), notice: "Survey profile was successfully created." }
format.html do
redirect_to survey_profile_url(@survey_profile), notice: 'Survey profile was successfully created.'
end
format.json { render :show, status: :created, location: @survey_profile }
else
format.html { render :new, status: :unprocessable_entity }
Expand All @@ -38,7 +40,9 @@ def create
def update
respond_to do |format|
if @survey_profile.update(survey_profile_params)
format.html { redirect_to survey_profile_url(@survey_profile), notice: "Survey profile was successfully updated." }
format.html do
redirect_to survey_profile_url(@survey_profile), notice: 'Survey profile was successfully updated.'
end
format.json { render :show, status: :ok, location: @survey_profile }
else
format.html { render :edit, status: :unprocessable_entity }
Expand All @@ -52,19 +56,20 @@ def destroy
@survey_profile.destroy!

respond_to do |format|
format.html { redirect_to survey_profiles_url, notice: "Survey profile was successfully destroyed." }
format.html { redirect_to survey_profiles_url, notice: 'Survey profile was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_survey_profile
@survey_profile = SurveyProfile.find(params[:id])
end

# Only allow a list of trusted parameters through.
def survey_profile_params
params.require(:survey_profile).permit(:user_id, :first_name, :last_name, :campus_name, :district_name)
end
# Use callbacks to share common setup or constraints between actions.
def set_survey_profile
@survey_profile = SurveyProfile.find(params[:id])
end

# Only allow a list of trusted parameters through.
def survey_profile_params
params.require(:survey_profile).permit(:user_id, :first_name, :last_name, :campus_name, :district_name)
end
end
78 changes: 49 additions & 29 deletions rails_root/app/controllers/survey_responses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,66 @@
# frozen_string_literal: true

class SurveyResponsesController < ApplicationController
before_action :set_survey_response, only: %i[ show edit update destroy ]
before_action :set_survey_response, only: %i[show edit update destroy]

# GET /survey_responses or /survey_responses.json
def index
@survey_responses = SurveyResponse.all
end

# GET /survey_responses/1 or /survey_responses/1.json
def show
end
def show; end

# GET /survey_responses/new
def new
@survey_response = SurveyResponse.new
end

# GET /survey_responses/1/edit
def edit
end
def edit; end

# POST /survey_responses or /survey_responses.json
def create
@survey_response = SurveyResponse.new(survey_response_params)
if survey_response_params.values.any?(&:nil?)
respond_to do |format|
format.html do
redirect_to new_survey_response_url, notice: 'invalid form', status: :unprocessable_entity
end
format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity }
end
else
@survey_response = SurveyResponse.new(survey_response_params)

respond_to do |format|
if @survey_response.save
format.html { redirect_to survey_response_url(@survey_response), notice: "Survey response was successfully created." }
format.json { render :show, status: :created, location: @survey_response }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @survey_response.errors, status: :unprocessable_entity }
respond_to do |format|
if @survey_response.save
format.html do
redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully created.'
end
format.json { render :show, status: :created, location: @survey_response }

end
end
end
end

# PATCH/PUT /survey_responses/1 or /survey_responses/1.json
def update
respond_to do |format|
if @survey_response.update(survey_response_params)
format.html { redirect_to survey_response_url(@survey_response), notice: "Survey response was successfully updated." }
format.json { render :show, status: :ok, location: @survey_response }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @survey_response.errors, status: :unprocessable_entity }
if survey_response_params.values.any?(&:nil?)
respond_to do |format|
format.html do
redirect_to edit_survey_response_url(@survey_response), notice: 'invalid form', status: :unprocessable_entity
end
format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity }
end
else
respond_to do |format|
if @survey_response.update(survey_response_params)
format.html do
redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully updated.'
end
format.json { render :show, status: :ok, location: @survey_response }

end
end
end
end
Expand All @@ -52,19 +70,21 @@ def destroy
@survey_response.destroy!

respond_to do |format|
format.html { redirect_to survey_responses_url, notice: "Survey response was successfully destroyed." }
format.html { redirect_to survey_responses_url, notice: 'Survey response was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_survey_response
@survey_response = SurveyResponse.find(params[:id])
end

# Only allow a list of trusted parameters through.
def survey_response_params
params.require(:survey_response).permit(:user_id, :leads_by_example, :ability_to_juggle, :communicator, :lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented)
end
# Use callbacks to share common setup or constraints between actions.
def set_survey_response
@survey_response = SurveyResponse.find(params[:id])
end

# Only allow a list of trusted parameters through.
def survey_response_params
params.require(:survey_response).permit(:user_id, :leads_by_example, :ability_to_juggle, :communicator,
:lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented)
end
end
2 changes: 2 additions & 0 deletions rails_root/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
2 changes: 2 additions & 0 deletions rails_root/app/helpers/survey_profiles_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module SurveyProfilesHelper
end
2 changes: 2 additions & 0 deletions rails_root/app/helpers/survey_responses_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module SurveyResponsesHelper
end
2 changes: 2 additions & 0 deletions rails_root/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
Expand Down
6 changes: 4 additions & 2 deletions rails_root/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout "mailer"
default from: '[email protected]'
layout 'mailer'
end
2 changes: 2 additions & 0 deletions rails_root/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
2 changes: 2 additions & 0 deletions rails_root/app/models/survey_profile.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class SurveyProfile < ApplicationRecord
end
2 changes: 2 additions & 0 deletions rails_root/app/models/survey_response.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class SurveyResponse < ApplicationRecord
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
json.extract! survey_profile, :id, :user_id, :first_name, :last_name, :campus_name, :district_name, :created_at, :updated_at
# frozen_string_literal: true

json.extract! survey_profile, :id, :user_id, :first_name, :last_name, :campus_name, :district_name, :created_at,
:updated_at
json.url survey_profile_url(survey_profile, format: :json)
4 changes: 3 additions & 1 deletion rails_root/app/views/survey_profiles/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
json.array! @survey_profiles, partial: "survey_profiles/survey_profile", as: :survey_profile
# frozen_string_literal: true

json.array! @survey_profiles, partial: 'survey_profiles/survey_profile', as: :survey_profile
4 changes: 3 additions & 1 deletion rails_root/app/views/survey_profiles/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
json.partial! "survey_profiles/survey_profile", survey_profile: @survey_profile
# frozen_string_literal: true

json.partial! 'survey_profiles/survey_profile', survey_profile: @survey_profile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
json.extract! survey_response, :id, :user_id, :leads_by_example, :ability_to_juggle, :communicator, :lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented, :created_at, :updated_at
# frozen_string_literal: true

json.extract! survey_response, :id, :user_id, :leads_by_example, :ability_to_juggle, :communicator, :lifelong_learner,
:high_expectations, :cooperative, :empathetic, :people_oriented, :created_at, :updated_at
json.url survey_response_url(survey_response, format: :json)
4 changes: 3 additions & 1 deletion rails_root/app/views/survey_responses/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
json.array! @survey_responses, partial: "survey_responses/survey_response", as: :survey_response
# frozen_string_literal: true

json.array! @survey_responses, partial: 'survey_responses/survey_response', as: :survey_response
4 changes: 3 additions & 1 deletion rails_root/app/views/survey_responses/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
json.partial! "survey_responses/survey_response", survey_response: @survey_response
# frozen_string_literal: true

json.partial! 'survey_responses/survey_response', survey_response: @survey_response
Loading

0 comments on commit 55e409f

Please sign in to comment.