feat(announce): can destroy a note and add at the same date
This commit is contained in:
parent
5df6997fa3
commit
e49436aa5d
8 changed files with 47 additions and 5 deletions
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
delete: Delete this note
|
||||
new: New note
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
fr:
|
||||
delete: Supprimer cette note
|
||||
new: Ajouter une note
|
|
@ -40,4 +40,14 @@
|
|||
|
||||
|
||||
.fr-fieldset__element
|
||||
= f.submit "Valider", class: "fr-btn fr-btn--lg"
|
||||
%ul.fr-btns-group.fr-btns-group--inline.fr-btns-group--icon-left
|
||||
%li= f.button "Valider", class: "fr-btn fr-icon-check-line"
|
||||
|
||||
- if release_note.persisted?
|
||||
%li= link_to t(".new"), new_super_admins_release_note_path(date: release_note.released_on), class: "fr-btn fr-btn--secondary fr-icon-add-line"
|
||||
|
||||
- if release_note.persisted?
|
||||
%li
|
||||
= link_to t('.delete'), super_admins_release_note_path(release_note),
|
||||
class: "fr-btn fr-btn--secondary fr-icon-delete-line",
|
||||
data: { method: :delete, confirm: "Supprimer cette note ?" }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class SuperAdmins::ReleaseNotesController < ApplicationController
|
||||
before_action :authenticate_super_admin!
|
||||
before_action :set_note, only: [:edit, :update]
|
||||
before_action :set_note, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@release_notes = ReleaseNote
|
||||
|
@ -14,7 +14,7 @@ class SuperAdmins::ReleaseNotesController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@release_note = ReleaseNote.new(released_on: Date.current)
|
||||
@release_note = ReleaseNote.new(released_on: params[:date].presence || Date.current, published: true)
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -40,6 +40,12 @@ class SuperAdmins::ReleaseNotesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@release_note.destroy!
|
||||
|
||||
redirect_to super_admins_release_notes_path, notice: t('.success')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def release_note_params
|
||||
|
|
|
@ -14,6 +14,8 @@ en:
|
|||
error: Release note was not saved.
|
||||
update:
|
||||
<<: *save
|
||||
destroy:
|
||||
success: Release note was successfully deleted.
|
||||
activerecord:
|
||||
attributes:
|
||||
release_note:
|
||||
|
|
|
@ -14,6 +14,8 @@ fr:
|
|||
error: L’annonce n’a pas pu être sauvegardée.
|
||||
update:
|
||||
<<: *save
|
||||
destroy:
|
||||
success: La note a été supprimée.
|
||||
activerecord:
|
||||
attributes:
|
||||
release_note:
|
||||
|
|
|
@ -126,7 +126,7 @@ Rails.application.routes.draw do
|
|||
}
|
||||
|
||||
namespace :super_admins do
|
||||
resources :release_notes, only: [:index, :new, :create, :edit, :update, :show]
|
||||
resources :release_notes
|
||||
end
|
||||
|
||||
get 'super_admins/edit_otp', to: 'super_admins#edit_otp', as: 'edit_super_admin_otp'
|
||||
|
|
|
@ -39,16 +39,24 @@ describe SuperAdmins::ReleaseNotesController, type: :controller do
|
|||
expect(response.status).to eq(302)
|
||||
expect(flash[:alert]).to be_present
|
||||
end
|
||||
|
||||
it 'is not allowed to destroy' do
|
||||
delete :destroy, params: { id: release_note.id }
|
||||
expect(response.status).to eq(302)
|
||||
expect(flash[:alert]).to be_present
|
||||
expect(release_note.reload).to be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is signed as super admin' do
|
||||
let(:release_note) { create(:release_note, published: false) }
|
||||
|
||||
it 'is allowed to post' do
|
||||
expect { post :create, params: { release_note: { categories: ['api'], released_on: Date.current, published: "0", body: "bam" } } }.to change(ReleaseNote, :count).by(1)
|
||||
expect(flash[:notice]).to be_present
|
||||
end
|
||||
|
||||
it 'is allowed to put' do
|
||||
release_note = create(:release_note, published: false)
|
||||
put :update, params: {
|
||||
id: release_note.id,
|
||||
release_note: {
|
||||
|
@ -63,6 +71,12 @@ describe SuperAdmins::ReleaseNotesController, type: :controller do
|
|||
expect(release_note.body.to_plain_text).to eq("new body")
|
||||
expect(release_note.published).to be_truthy
|
||||
end
|
||||
|
||||
it 'is allowed to destroy' do
|
||||
delete :destroy, params: { id: release_note.id }
|
||||
expect(flash[:notice]).to be_present
|
||||
expect { release_note.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue