Browse Source

La gestion des notes de modération est en place, sans l'envoi de mail

recurrent
echarp 8 years ago
parent
commit
b1f1b00f79
  1. 2
      app/assets/stylesheets/events.css.sass
  2. 2
      app/assets/stylesheets/moderations.css.sass
  3. 14
      app/controllers/notes_controller.rb
  4. 5
      app/models/note.rb
  5. 2
      app/views/moderations/index.html.haml
  6. 1
      app/views/notes/new.html.haml
  7. 41
      test/controllers/notes_controller_test.rb

2
app/assets/stylesheets/events.css.sass

@ -145,7 +145,7 @@ table.calendar
a
color: #8F4900
.events form
.events form, .moderations form
.field, .actions
text-align: left
margin-left: 2px

2
app/assets/stylesheets/moderations.css.sass

@ -9,6 +9,8 @@
padding-bottom: 0.5em
&.empty
background-color: white
&.note
text-align: left
pre
width: 70%
margin: auto

14
app/controllers/notes_controller.rb

@ -1,9 +1,19 @@
class NotesController < InheritedResources::Base
belongs_to :event
belongs_to :moderation
def create
create! do |format|
format.html {
@note.author = current_user
create!(notice: 'Dude! Nice job creating that note.') { moderations_url }
}
end
end
private
def begin_of_association_chain
@event = Event.unscoped.find params[:moderation_id]
@moderation = Event.unscoped.find params[:moderation_id]
@event = @moderation
end
def permitted_params

5
app/models/note.rb

@ -1,4 +1,9 @@
class Note < ActiveRecord::Base
belongs_to :event
belongs_to :author, class_name: User
# Setup the magic time stamp so it uses the "date" column
def timestamp_attributes_for_create
super << :date
end
end

2
app/views/moderations/index.html.haml

@ -45,7 +45,7 @@
- event.notes.each do |note|
%tr
%td.empty/
%td(colspan="5")
%td.note(colspan="5")
=raw note.contents
%em.author
=t '.posted_by',

1
app/views/notes/new.html.haml

@ -1,6 +1,5 @@
%h3
= link_to t('.back'), moderations_path
>>>
=t '.title'
.box= render 'form'

41
test/controllers/notes_controller_test.rb

@ -1,49 +1,28 @@
require 'test_helper'
class NotesControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@note = notes(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:notes)
sign_in users(:one)
end
test "should get new" do
get :new
get :new, moderation_id: @note.event.id
assert_response :success
end
test "should create note" do
assert_difference('Note.count') do
post :create, note: { author: @note.author, contents: @note.contents, date: @note.date, event: @note.event }
end
assert_redirected_to note_path(assigns(:note))
end
test "should show note" do
get :show, id: @note
assert_response :success
end
test "should get edit" do
get :edit, id: @note
assert_response :success
end
test "should update note" do
patch :update, id: @note, note: { author: @note.author, contents: @note.contents, date: @note.date, event: @note.event }
assert_redirected_to note_path(assigns(:note))
end
test "should destroy note" do
assert_difference('Note.count', -1) do
delete :destroy, id: @note
post :create, moderation_id: @note.event.id, note: {
author: @note.author,
contents: @note.contents,
date: @note.date
}
end
assert_redirected_to notes_path
assert_redirected_to moderations_path
end
end

Loading…
Cancel
Save