Skip to content

Commit

Permalink
Merge pull request #35 from tamu-edu-students/updating-readme
Browse files Browse the repository at this point in the history
updating readme, tweaking controller logic
  • Loading branch information
jacobtoddmathes authored Feb 17, 2024
2 parents 47d9c0d + cd4a321 commit 3d5f068
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 51 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/62f4dd4fb092b4211973/maintainability)](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/maintainability)
![rubocop](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/barnden/c7b2d5e19079e12445b300407e383294/raw/badge.json)

**All project files in rails_root**

Links
- Deployed Application
- https://elrc-app-dfcfc7cd862b.herokuapp.com/
Expand Down
1 change: 1 addition & 0 deletions rails_root/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# ignore migration files

AllCops:
DisabledByDefault: false
Exclude:
- 'db/**/*'
- 'config/**/*'
Expand Down
4 changes: 3 additions & 1 deletion rails_root/app/controllers/survey_responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ def edit

# POST /survey_responses or /survey_responses.json
def create
if survey_response_params.values.any? { |value| value.nil? || value.empty? }
# If any of the survey_response_params values are nil, then the form is invalid
if survey_response_params.values.any? { |value| value.nil? || value.empty? || survey_response_params.keys.length != SurveyResponse.column_names.length - 3 }
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)

Expand Down
85 changes: 35 additions & 50 deletions rails_root/spec/requests/survey_responses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,9 @@

require 'rails_helper'

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to test the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.

# rubocop:disable Metrics/BlockLength
RSpec.describe '/survey_responses', type: :request do
# This should return the minimal set of attributes required to create a valid
# SurveyResponse. As you add validations to SurveyResponse, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
# skip('Add a hash of attributes valid for your model')
{
user_id: 1,
leads_by_example: 1,
Expand All @@ -35,8 +19,6 @@
end

let(:invalid_attributes) do
# skip('Add a hash of attributes invalid for your model')
# any value in form is null
{
user_id: 1,
leads_by_example: 1,
Expand All @@ -50,110 +32,113 @@
}
end

let(:new_attributes) do
{
leads_by_example: 5
}
end

let!(:survey_response) { SurveyResponse.create! valid_attributes }

describe 'GET /index' do
before { get survey_responses_url }

it 'renders a successful response' do
SurveyResponse.create! valid_attributes
get survey_responses_url
expect(response).to be_successful
end
end

describe 'GET /show' do
before { get survey_response_url(survey_response) }

it 'renders a successful response' do
survey_response = SurveyResponse.create! valid_attributes
get survey_response_url(survey_response)
expect(response).to be_successful
end
end

describe 'GET /new' do
before { get new_survey_response_url }

it 'renders a successful response' do
get new_survey_response_url
expect(response).to be_successful
end
end

describe 'GET /edit' do
before { get edit_survey_response_url(survey_response) }

it 'renders a successful response' do
survey_response = SurveyResponse.create! valid_attributes
get edit_survey_response_url(survey_response)
expect(response).to be_successful
end
end

describe 'POST /create' do
context 'with valid parameters' do
def post_request
post survey_responses_url, params: { survey_response: valid_attributes }
end

it 'creates a new SurveyResponse' do
expect do
post survey_responses_url, params: { survey_response: valid_attributes }
end.to change(SurveyResponse, :count).by(1)
expect { post_request }.to change(SurveyResponse, :count).by(1)
end

it 'redirects to the created survey_response' do
post survey_responses_url, params: { survey_response: valid_attributes }
post_request
expect(response).to redirect_to(survey_response_url(SurveyResponse.last))
end
end

context 'with invalid parameters' do
def post_request
post survey_responses_url, params: { survey_response: invalid_attributes }
end

it 'does not create a new SurveyResponse' do
expect do
post survey_responses_url, params: { survey_response: invalid_attributes }
end.to_not change(SurveyResponse, :count)
expect { post_request }.to_not change(SurveyResponse, :count)
end

it 'returns a failure response (i.e., to display the "new" template)' do
post survey_responses_url, params: { survey_response: invalid_attributes }
post_request
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

describe 'PATCH /update' do
context 'with valid parameters' do
let(:new_attributes) do
# skip('Add a hash of attributes valid for your model')

{
leads_by_example: 5
}
before do
patch survey_response_url(survey_response), params: { survey_response: new_attributes }
survey_response.reload
end

it 'updates the requested survey_response' do
survey_response = SurveyResponse.create! valid_attributes
patch survey_response_url(survey_response), params: { survey_response: new_attributes }
survey_response.reload
# skip('Add assertions for updated state')
expect(survey_response.leads_by_example).to eq(5)
end

it 'redirects to the survey_response' do
survey_response = SurveyResponse.create! valid_attributes
patch survey_response_url(survey_response), params: { survey_response: new_attributes }
survey_response.reload
expect(response).to redirect_to(survey_response_url(survey_response))
end
end

context 'with invalid parameters' do
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
survey_response = SurveyResponse.create! valid_attributes
before do
patch survey_response_url(survey_response), params: { survey_response: invalid_attributes }
end

it "renders a response with 422 status (i.e. to display the 'edit' template)" do
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

describe 'DELETE /destroy' do
it 'destroys the requested survey_response' do
survey_response = SurveyResponse.create! valid_attributes
expect do
delete survey_response_url(survey_response)
end.to change(SurveyResponse, :count).by(-1)
end

it 'redirects to the survey_responses list' do
survey_response = SurveyResponse.create! valid_attributes
delete survey_response_url(survey_response)
expect(response).to redirect_to(survey_responses_url)
end
Expand Down

0 comments on commit 3d5f068

Please sign in to comment.