Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add start_date and end_date to surveys #179

Merged
merged 27 commits into from
Oct 13, 2024

Conversation

Ahmedhossamdev
Copy link
Member

No description provided.

Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty solid! I'd like to see one more test added that validates that only surveys that meet the filter_currently_active scope's criteria are included in the API output.

module Filterable
extend ActiveSupport::Concern

module ClassMethods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this end up getting used anywhere? if not, please delete. if so, please include a doc comment that explains what it does and how it works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Filterable module was intended to reduce repetitive code when applying multiple scopes in the controller. It dynamically applied filters based on provided parameters, but it's not currently in use, so I’m removing it to clean up the codebase

here is the full document:

https://www.justinweiss.com/articles/search-and-filter-rails-models-without-bloating-your-controller/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is added now

@aaronbrethorst

Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is looking really good! I have a couple questions and some minor changes that I would like to see made before merging.

@@ -36,4 +43,20 @@ def require_stop_id_sensibility

errors.add(:require_stop_id_in_response, 'is only valid if Show on Map is false')
end

def validate_date_presence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole method is very idiomatic Ruby. Great work!

app/views/admins/surveys/_form.html.erb Outdated Show resolved Hide resolved
spec/factories/factories.rb Show resolved Hide resolved
RSpec.describe Survey, type: :model do
let(:study) { Study.create } # Assuming you have a Study model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need it I forgot to remove it

spec/models/survey_spec.rb Outdated Show resolved Hide resolved
spec/models/survey_spec.rb Outdated Show resolved Hide resolved
spec/models/survey_spec.rb Outdated Show resolved Hide resolved
@@ -31,6 +31,12 @@
post admin_study_surveys_path(study), params: { survey: attributes_for(:survey) }
expect(response).to redirect_to(admin_study_survey_path(study, Survey.last))
end

it "does not create a new survey end_date is before start_date" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this is testing. I would think based upon the use of the invalid trait and this text does not create a new survey end_date is before start_date that Survey.count wouldn't change. what am I misunderstanding?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is that when we create a study, it automatically creates a survey, so the initial Survey.count is set to 1. This is why the count changes in the test even when we expect it not to, so if we will create a new survey the with study the count will be 2 not 1

spec/requests/admins/surveys_spec.rb Outdated Show resolved Hide resolved
Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good!

@aaronbrethorst aaronbrethorst merged commit 8486053 into main Oct 13, 2024
2 checks passed
@aaronbrethorst aaronbrethorst deleted the feature/survey-date-range-availability branch October 13, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants