diff --git a/app/assets/stylesheets/events.css.sass b/app/assets/stylesheets/events.css.sass index fec4b5fc..4cacb8ed 100644 --- a/app/assets/stylesheets/events.css.sass +++ b/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 diff --git a/app/assets/stylesheets/moderations.css.sass b/app/assets/stylesheets/moderations.css.sass index 04e581d5..5e684ebc 100644 --- a/app/assets/stylesheets/moderations.css.sass +++ b/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 diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 4083e802..06d18139 100644 --- a/app/controllers/notes_controller.rb +++ b/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 diff --git a/app/models/note.rb b/app/models/note.rb index e7bf7fb8..8565d50f 100644 --- a/app/models/note.rb +++ b/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 diff --git a/app/views/moderations/index.html.haml b/app/views/moderations/index.html.haml index 903b6493..a295bc9c 100644 --- a/app/views/moderations/index.html.haml +++ b/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', diff --git a/app/views/notes/new.html.haml b/app/views/notes/new.html.haml index ed56de46..926c8f50 100644 --- a/app/views/notes/new.html.haml +++ b/app/views/notes/new.html.haml @@ -1,6 +1,5 @@ %h3 = link_to t('.back'), moderations_path - >>> =t '.title' .box= render 'form' diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index 994d65a1..5cabf28d 100644 --- a/test/controllers/notes_controller_test.rb +++ b/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 } + post :create, moderation_id: @note.event.id, note: { + author: @note.author, + contents: @note.contents, + date: @note.date + } 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 - end - - assert_redirected_to notes_path + assert_redirected_to moderations_path end end