Commit 7e0de97d authored by marcheing's avatar marcheing

Use the three inputs from date_select to generate birthdate

The date_select field on the form will generate three inputs that will
be sent with the post create request, but not in the birthdate key. With
this change, the day, month and year fields will be used to create a new
Date object which will be assigned as birthdate before the creation of a
new profile.
parent 389c3c7d
......@@ -77,7 +77,9 @@ class ProfilesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def profile_params
params.require(:profile).permit(:first_name, :last_name, :birthdate, :gender, :state, :city, :country, :school, :responsible_document, :responsible_name, :receive_mass_email, :phone, :user_id, :address, :zip_code, :occupation, :school_type)
complete_params = params.require(:profile).permit(:first_name, :last_name, :gender, :state, :city, :country, :school, :responsible_document, :responsible_name, :receive_mass_email, :phone, :user_id, :address, :zip_code, :occupation, :school_type)
complete_params[:birthdate] = Date.new params[:profile][:year].to_i, params[:profile][:month].to_i, params[:profile][:day].to_i
complete_params
end
def set_carmen_locale
......
......@@ -26,6 +26,15 @@ RSpec.describe ProfilesController, type: :controller do
# adjust the attributes here as well.
let(:valid_attributes) { attributes_for(:profile).merge(user_id: user.id) }
let(:valid_request_parameters) do
attributes = attributes_for(:profile)
birthdate = attributes.delete(:birthdate)
attributes[:day] = birthdate.day
attributes[:month] = birthdate.month
attributes[:year] = birthdate.year
attributes
end
let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
}
......@@ -76,18 +85,18 @@ RSpec.describe ProfilesController, type: :controller do
context "with valid params" do
it "creates a new Profile" do
expect {
post :create, params: {profile: valid_attributes}, session: valid_session
post :create, params: { profile: valid_request_parameters }, session: valid_session
}.to change(Profile, :count).by(1)
end
it "assigns a newly created profile as @profile" do
post :create, params: {profile: valid_attributes}, session: valid_session
post :create, params: { profile: valid_request_parameters }, session: valid_session
expect(assigns(:profile)).to be_a(Profile)
expect(assigns(:profile)).to be_persisted
end
it "redirects to the created profile" do
post :create, params: {profile: valid_attributes}, session: valid_session
post :create, params: { profile: valid_request_parameters }, session: valid_session
expect(response).to redirect_to(Profile.last)
end
end
......@@ -120,13 +129,13 @@ RSpec.describe ProfilesController, type: :controller do
it "assigns the requested profile as @profile" do
profile = Profile.create! valid_attributes
put :update, params: {id: profile.to_param, profile: valid_attributes}, session: valid_session
put :update, params: { id: profile.to_param, profile: valid_request_parameters }, session: valid_session
expect(assigns(:profile)).to eq(profile)
end
it "redirects to the profile" do
profile = Profile.create! valid_attributes
put :update, params: {id: profile.to_param, profile: valid_attributes}, session: valid_session
put :update, params: {id: profile.to_param, profile: valid_request_parameters }, session: valid_session
expect(response).to redirect_to(profile)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment