-
Notifications
You must be signed in to change notification settings - Fork 3
Permitir cambiar carrera de un usuario con FeatureFlag #972
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4121bc0
allow to change degree
RenzoMinelli e7ba8c9
update styles
RenzoMinelli 6a1ac3a
move responsability to feature class
RenzoMinelli b7592f2
redirect to root path
RenzoMinelli 91d961c
fix tabs
RenzoMinelli 5e1665b
remove tools version
RenzoMinelli 7069e4a
change degree path and remove user id
RenzoMinelli 2561098
reorder actions
RenzoMinelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| module Users | ||
| class DegreesController < ApplicationController | ||
| before_action :authenticate_user! | ||
| before_action :ensure_feature_enabled! | ||
|
|
||
| def edit; end | ||
|
|
||
| def update | ||
| current_user.degree = Degree.find(params[:degree_id]) | ||
|
|
||
| if current_user.save | ||
| redirect_to root_path, notice: "Tu carrera ha sido actualizada correctamente." | ||
| else | ||
| redirect_to edit_user_degree_path, alert: "Hubo un error actualizando tu carrera." | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def ensure_feature_enabled! | ||
| redirect_to root_path unless Features::ChangingDegrees.enabled? | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module Features | ||
| module ChangingDegrees | ||
| module_function | ||
|
|
||
| def enabled? | ||
| ENV['ENABLE_CHANGING_DEGREES'].present? | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <div class="flex flex-col justify-center items-center p-6 space-y-6"> | ||
| <h2 class="text-3xl/9 text-neutral-700">Cambiar Carrera</h2> | ||
|
|
||
| <%= form_with(url: user_degree_path(current_user), method: :put, class: "flex flex-col w-full max-w-md space-y-6") do |f| %> | ||
| <div> | ||
| <%= f.label :degree_id, "Carrera de Grado", class: "text-sm/6 font-medium text-gray-700 with-error:text-red-600" %> | ||
| <%= f.select( | ||
| :degree_id, | ||
| options_for_select( | ||
| Degree.ids.map { |id| [id.humanize, id] }, | ||
| selected: current_user.degree_id | ||
| ), | ||
| { | ||
| include_blank: "Selecciona tu carrera de grado", | ||
| }, | ||
| { | ||
| class: %w[ | ||
| bg-white | ||
| w-full | ||
| rounded-md | ||
| px-3 | ||
| py-1.5 | ||
| outline-1 | ||
| outline-gray-300 | ||
| focus:outline-2 | ||
| focus:outline-indigo-600 | ||
| with-error:outline-red-500 | ||
| with-error:focus:outline-red-600 | ||
| ].join(" "), | ||
| required: true | ||
| }, | ||
| ) %> | ||
| </div> | ||
| <%= render ButtonComponent.new(form: f, label: "Guardar") %> | ||
| <% end %> | ||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Features::ChangingDegrees do | ||
| describe '.enabled?' do | ||
| after do | ||
| ENV.delete('ENABLE_CHANGING_DEGREES') | ||
| end | ||
|
|
||
| it 'returns true when the ENABLE_CHANGING_DEGREES env var is set' do | ||
| ENV['ENABLE_CHANGING_DEGREES'] = 'true' | ||
|
|
||
| expect(described_class.enabled?).to be true | ||
| end | ||
|
|
||
| it 'returns false when the ENABLE_CHANGING_DEGREES env var is not set' do | ||
| ENV['ENABLE_CHANGING_DEGREES'] = nil | ||
|
|
||
| expect(described_class.enabled?).to be false | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe 'Changing degrees', type: :system do | ||
| let!(:computacion_degree) { degrees(:computacion) } | ||
| let!(:sistemas_degree) { create(:degree, id: 'sistemas', current_plan: '2025', include_inco_subjects: false) } | ||
| let!(:user) { create(:user, degree: computacion_degree) } | ||
|
|
||
| before do | ||
| sign_in user | ||
| end | ||
|
|
||
| context 'when feature is enabled' do | ||
| before do | ||
| allow(Features::ChangingDegrees).to receive(:enabled?).and_return(true) | ||
| end | ||
|
|
||
| it 'allows user to change their degree successfully' do | ||
| visit root_path | ||
|
|
||
| click_user_menu | ||
| click_on 'Cambiar Carrera' | ||
|
|
||
| expect(page).to have_text('Cambiar Carrera') | ||
| expect(page).to have_select('degree_id', selected: 'Computacion') | ||
|
|
||
| select 'Sistemas', from: 'degree_id' | ||
| click_on 'Guardar' | ||
|
|
||
| expect(page).to have_text('Tu carrera ha sido actualizada correctamente.') | ||
| expect(current_path).to eq(root_path) | ||
|
|
||
| user.reload | ||
| expect(user.degree_id).to eq('sistemas') | ||
| end | ||
| end | ||
|
|
||
| context 'when feature is disabled' do | ||
| before do | ||
| allow(Features::ChangingDegrees).to receive(:enabled?).and_return(false) | ||
| end | ||
|
|
||
| it 'does not show the change degree link in user menu' do | ||
| visit root_path | ||
|
|
||
| click_user_menu | ||
|
|
||
| expect(page).not_to have_link('Cambiar Carrera') | ||
| end | ||
|
|
||
| it 'redirects to root path when trying to access edit page directly' do | ||
| visit edit_user_degree_path(user) | ||
|
|
||
| expect(current_path).to eq(root_path) | ||
| end | ||
| end | ||
|
|
||
| context 'when user is not authenticated' do | ||
| before do | ||
| allow(Features::ChangingDegrees).to receive(:enabled?).and_return(true) | ||
| sign_out :user | ||
| end | ||
|
|
||
| it 'redirects to login page when accessing edit page' do | ||
| visit edit_user_degree_path(user) | ||
|
|
||
| expect(current_path).to eq(new_user_session_path) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def click_user_menu | ||
| find("#user-menu[data-controller-connected='true']").click | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.