Skip to content

Commit

Permalink
Update speaker profile if user has submitted proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
unasuke committed Sep 12, 2024
1 parent d371d4e commit 84c88a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def update
flash[:info] = I18n.t("devise.registrations.updated")
end

current_user.speakers.where(event: current_event).update_all(
bio: user_params[:bio], speaker_email: user_params[:email], speaker_name: user_params[:name]
)

redirect_to (session.delete(:target) || root_url)
else
flash.now[:danger] = "Unable to save profile. Please correct the following: #{current_user.errors.full_messages.join(', ')}."
Expand Down
37 changes: 34 additions & 3 deletions spec/controllers/profiles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,40 @@

before { allow(controller).to receive(:current_user).and_return(user) }

it "updates the user record" do
put :update, params: params
expect(response.code).to eq("302")
context 'simple case' do
it "updates the user record" do
put :update, params: params
expect(response.code).to eq("302")
end
end

context "when the user has submitted proposals" do
let(:event) { create(:event) }
let(:proposal) { create(:proposal_with_track, event: event) }
let(:speaker) {
create(:speaker, user: user, event: event, speaker_name: "old name", speaker_email: "[email protected]", bio: "old bio")
}
let(:speaker2) {
create(:speaker, event: event, speaker_name: "no effort speaker", speaker_email: "[email protected]", bio: "old bio2")
}
let(:params) {
{ user: { bio: "new bio", name: "new name", email: "[email protected]" } }
}

before do
allow(controller).to receive(:current_event).and_return(event)
proposal.speakers << [speaker, speaker2]
end

it "update submitted proposal speaker also" do
put :update, params: params
expect(response.code).to eq("302")
expect(proposal.speakers.first.bio).to eq("new bio")
expect(proposal.speakers.first.speaker_email).to eq("[email protected]")
expect(proposal.speakers.first.speaker_name).to eq("new name")
expect(proposal.speakers.last.speaker_name).to eq("no effort speaker")
end

end
end
end

0 comments on commit 84c88a9

Please sign in to comment.