diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-04 01:24:55 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-04 01:24:55 +0200 |
| commit | 206dc5c50a73c5402b90d7fdc8945d3ba9356758 (patch) | |
| tree | b2c98c48248c878da4344e61734bfa89130f18d1 /test/controllers/events_controller_test.rb | |
| parent | d9461bae0b6232d618dde118360b44bb80f962b8 (diff) | |
Add self-service event creation from nodes#show
nodes#show's events table now renders unconditionally (previously
hidden entirely for a zero-event node) and gains an "add event" link.
The suggested tag_list is derived from the page's own category tags
via NodesHelper::DEFAULT_EVENT_TAG_BY_PAGE_TAG (erfa-detail/
chaostreff-detail -> open-day) rather than hardcoded, and degrades to
a blank field for any node whose tags don't match - deliberately
universal, not chapter-specific, since Updates have historically
carried event dates the same way.
events#new surfaces *why* the tag was pre-filled via flash.now (not
flash - this is a same-request render, not a redirect), using an
explicit auto_tag_source param passed alongside tag_list rather than
having the controller re-derive the reason from node_id.
No destroy link added to nodes#show's events list - deliberate, per
existing subnav-semantics convention (destructive actions live on the
resource's own views). Covered directly by test.
Adds real coverage for EventsController, previously 100% commented-out
scaffold, plus unit tests for the new tag-mapping helper and the
weekday-abbreviation helpers from the prior commit.
Diffstat (limited to 'test/controllers/events_controller_test.rb')
| -rw-r--r-- | test/controllers/events_controller_test.rb | 167 |
1 files changed, 126 insertions, 41 deletions
diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb index 14e534e..9371ca7 100644 --- a/test/controllers/events_controller_test.rb +++ b/test/controllers/events_controller_test.rb | |||
| @@ -1,45 +1,130 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class EventsControllerTest < ActionController::TestCase | 3 | class EventsControllerTest < ActionController::TestCase |
| 4 | # test "should get index" do | 4 | |
| 5 | # get :index | 5 | test "should get index" do |
| 6 | # assert_response :success | 6 | login_as :quentin |
| 7 | # assert_not_nil assigns(:events) | 7 | get :index |
| 8 | # end | 8 | assert_response :success |
| 9 | # | 9 | assert_not_nil assigns(:events) |
| 10 | # test "should get new" do | 10 | end |
| 11 | # get :new | 11 | |
| 12 | # assert_response :success | 12 | test "should get new" do |
| 13 | # end | 13 | login_as :quentin |
| 14 | # | 14 | get :new |
| 15 | # test "should create event" do | 15 | assert_response :success |
| 16 | # assert_difference('Event.count') do | 16 | end |
| 17 | # post :create, params: { :event => { } } | 17 | |
| 18 | # end | 18 | test "new pre-fills tag_list and explains it via flash when auto_tag_source is given" do |
| 19 | # | 19 | login_as :quentin |
| 20 | # assert_redirected_to event_path(assigns(:event)) | 20 | node = create_node_with_published_page |
| 21 | # end | 21 | |
| 22 | # | 22 | get :new, params: { node_id: node.id, tag_list: "open-day", auto_tag_source: "erfa-detail" } |
| 23 | # test "should show event" do | 23 | |
| 24 | # get :show, params: { :id => events(:one).to_param } | 24 | assert_response :success |
| 25 | # assert_response :success | 25 | assert_equal "open-day", assigns(:event).tag_list.to_s |
| 26 | # end | 26 | assert_match "open-day", flash[:notice] |
| 27 | # | 27 | assert_match "erfa-detail", flash[:notice] |
| 28 | # test "should get edit" do | 28 | end |
| 29 | # get :edit, params: { :id => events(:one).to_param } | 29 | |
| 30 | # assert_response :success | 30 | test "new does not flash without an auto_tag_source" do |
| 31 | # end | 31 | login_as :quentin |
| 32 | # | 32 | |
| 33 | # test "should update event" do | 33 | get :new, params: { tag_list: "open-day" } |
| 34 | # put :update, params: { :id => events(:one).to_param, :event => { } } | 34 | |
| 35 | # assert_redirected_to event_path(assigns(:event)) | 35 | assert_response :success |
| 36 | # end | 36 | assert_nil flash[:notice] |
| 37 | # | 37 | end |
| 38 | # test "should destroy event" do | 38 | |
| 39 | # assert_difference('Event.count', -1) do | 39 | test "new with no params renders a blank, unflashed form" do |
| 40 | # delete :destroy, params: { :id => events(:one).to_param } | 40 | login_as :quentin |
| 41 | # end | 41 | |
| 42 | # | 42 | get :new |
| 43 | # assert_redirected_to events_path | 43 | |
| 44 | # end | 44 | assert_response :success |
| 45 | assert_nil assigns(:event).tag_list.presence | ||
| 46 | assert_nil flash[:notice] | ||
| 47 | end | ||
| 48 | |||
| 49 | test "should show event" do | ||
| 50 | login_as :quentin | ||
| 51 | node = create_node_with_published_page | ||
| 52 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 53 | |||
| 54 | get :show, params: { id: event.id } | ||
| 55 | assert_response :success | ||
| 56 | end | ||
| 57 | |||
| 58 | test "should get edit" do | ||
| 59 | login_as :quentin | ||
| 60 | node = create_node_with_published_page | ||
| 61 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 62 | |||
| 63 | get :edit, params: { id: event.id } | ||
| 64 | assert_response :success | ||
| 65 | end | ||
| 66 | |||
| 67 | test "should create event attached to a node" do | ||
| 68 | login_as :quentin | ||
| 69 | node = create_node_with_published_page | ||
| 70 | |||
| 71 | assert_difference('Event.count') do | ||
| 72 | post :create, params: { | ||
| 73 | event: { | ||
| 74 | node_id: node.id, | ||
| 75 | start_time: Time.now, | ||
| 76 | end_time: Time.now + 1.hour, | ||
| 77 | tag_list: "open-day" | ||
| 78 | } | ||
| 79 | } | ||
| 80 | end | ||
| 81 | |||
| 82 | assert_redirected_to edit_node_path(node) | ||
| 83 | assert_equal 'Event was successfully created.', flash[:notice] | ||
| 84 | end | ||
| 85 | |||
| 86 | test "should not create an event without a title or a node_id" do | ||
| 87 | login_as :quentin | ||
| 88 | |||
| 89 | assert_no_difference('Event.count') do | ||
| 90 | post :create, params: { event: { start_time: Time.now, end_time: Time.now + 1.hour } } | ||
| 91 | end | ||
| 92 | |||
| 93 | assert_response :success # re-renders :new, not a redirect | ||
| 94 | end | ||
| 95 | |||
| 96 | test "should honour return_to on create" do | ||
| 97 | login_as :quentin | ||
| 98 | node = create_node_with_published_page | ||
| 99 | |||
| 100 | post :create, params: { | ||
| 101 | event: { node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour }, | ||
| 102 | return_to: node_path(node) | ||
| 103 | } | ||
| 104 | |||
| 105 | assert_redirected_to node_path(node) | ||
| 106 | end | ||
| 107 | |||
| 108 | test "should update event" do | ||
| 109 | login_as :quentin | ||
| 110 | node = create_node_with_published_page | ||
| 111 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 112 | |||
| 113 | put :update, params: { id: event.id, event: { title: "Updated title" } } | ||
| 114 | |||
| 115 | assert_redirected_to events_path | ||
| 116 | assert_equal "Updated title", event.reload.title | ||
| 117 | end | ||
| 118 | |||
| 119 | test "should destroy event" do | ||
| 120 | login_as :quentin | ||
| 121 | node = create_node_with_published_page | ||
| 122 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 123 | |||
| 124 | assert_difference('Event.count', -1) do | ||
| 125 | delete :destroy, params: { id: event.id } | ||
| 126 | end | ||
| 127 | |||
| 128 | assert_redirected_to events_url | ||
| 129 | end | ||
| 45 | end | 130 | end |
