diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
| commit | 8eab68f2c5a3c126e2fec2ecdfa7ace87ce0937b (patch) | |
| tree | f446ebc26a7707c7b64a937aa51a155df146c80a /test/controllers/events_controller_test.rb | |
| parent | 42714c697273a7117c6b355fab26c8c35e336ad1 (diff) | |
| parent | cdf5d9941ca866d437612d2f863eac6eb0b3db12 (diff) | |
Merge branch 'erdgeist-revive-events'
Diffstat (limited to 'test/controllers/events_controller_test.rb')
| -rw-r--r-- | test/controllers/events_controller_test.rb | 170 |
1 files changed, 129 insertions, 41 deletions
diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb index 14e534e..46f3f4f 100644 --- a/test/controllers/events_controller_test.rb +++ b/test/controllers/events_controller_test.rb | |||
| @@ -1,45 +1,133 @@ | |||
| 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 | node = create_node_with_published_page |
| 8 | # end | 8 | Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) |
| 9 | # | 9 | |
| 10 | # test "should get new" do | 10 | get :index |
| 11 | # get :new | 11 | assert_response :success |
| 12 | # assert_response :success | 12 | assert_not_nil assigns(:events) |
| 13 | # end | 13 | end |
| 14 | # | 14 | |
| 15 | # test "should create event" do | 15 | test "should get new" do |
| 16 | # assert_difference('Event.count') do | 16 | login_as :quentin |
| 17 | # post :create, params: { :event => { } } | 17 | get :new |
| 18 | # end | 18 | assert_response :success |
| 19 | # | 19 | end |
| 20 | # assert_redirected_to event_path(assigns(:event)) | 20 | |
| 21 | # end | 21 | test "new pre-fills tag_list and explains it via flash when auto_tag_source is given" do |
| 22 | # | 22 | login_as :quentin |
| 23 | # test "should show event" do | 23 | node = create_node_with_published_page |
| 24 | # get :show, params: { :id => events(:one).to_param } | 24 | |
| 25 | # assert_response :success | 25 | get :new, params: { node_id: node.id, tag_list: "open-day", auto_tag_source: "erfa-detail" } |
| 26 | # end | 26 | |
| 27 | # | 27 | assert_response :success |
| 28 | # test "should get edit" do | 28 | assert_equal "open-day", assigns(:event).tag_list.to_s |
| 29 | # get :edit, params: { :id => events(:one).to_param } | 29 | assert_match "open-day", flash[:notice] |
| 30 | # assert_response :success | 30 | assert_match "erfa-detail", flash[:notice] |
| 31 | # end | 31 | end |
| 32 | # | 32 | |
| 33 | # test "should update event" do | 33 | test "new does not flash without an auto_tag_source" do |
| 34 | # put :update, params: { :id => events(:one).to_param, :event => { } } | 34 | login_as :quentin |
| 35 | # assert_redirected_to event_path(assigns(:event)) | 35 | |
| 36 | # end | 36 | get :new, params: { tag_list: "open-day" } |
| 37 | # | 37 | |
| 38 | # test "should destroy event" do | 38 | assert_response :success |
| 39 | # assert_difference('Event.count', -1) do | 39 | assert_nil flash[:notice] |
| 40 | # delete :destroy, params: { :id => events(:one).to_param } | 40 | end |
| 41 | # end | 41 | |
| 42 | # | 42 | test "new with no params renders a blank, unflashed form" do |
| 43 | # assert_redirected_to events_path | 43 | login_as :quentin |
| 44 | # end | 44 | |
| 45 | get :new | ||
| 46 | |||
| 47 | assert_response :success | ||
| 48 | assert_nil assigns(:event).tag_list.presence | ||
| 49 | assert_nil flash[:notice] | ||
| 50 | end | ||
| 51 | |||
| 52 | test "should show event" do | ||
| 53 | login_as :quentin | ||
| 54 | node = create_node_with_published_page | ||
| 55 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 56 | |||
| 57 | get :show, params: { id: event.id } | ||
| 58 | assert_response :success | ||
| 59 | end | ||
| 60 | |||
| 61 | test "should get edit" do | ||
| 62 | login_as :quentin | ||
| 63 | node = create_node_with_published_page | ||
| 64 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 65 | |||
| 66 | get :edit, params: { id: event.id } | ||
| 67 | assert_response :success | ||
| 68 | end | ||
| 69 | |||
| 70 | test "should create event attached to a node" do | ||
| 71 | login_as :quentin | ||
| 72 | node = create_node_with_published_page | ||
| 73 | |||
| 74 | assert_difference('Event.count') do | ||
| 75 | post :create, params: { | ||
| 76 | event: { | ||
| 77 | node_id: node.id, | ||
| 78 | start_time: Time.now, | ||
| 79 | end_time: Time.now + 1.hour, | ||
| 80 | tag_list: "open-day" | ||
| 81 | } | ||
| 82 | } | ||
| 83 | end | ||
| 84 | |||
| 85 | assert_redirected_to edit_node_path(node) | ||
| 86 | assert_equal 'Event was successfully created.', flash[:notice] | ||
| 87 | end | ||
| 88 | |||
| 89 | test "should not create an event without a title or a node_id" do | ||
| 90 | login_as :quentin | ||
| 91 | |||
| 92 | assert_no_difference('Event.count') do | ||
| 93 | post :create, params: { event: { start_time: Time.now, end_time: Time.now + 1.hour } } | ||
| 94 | end | ||
| 95 | |||
| 96 | assert_response :success # re-renders :new, not a redirect | ||
| 97 | end | ||
| 98 | |||
| 99 | test "should honour return_to on create" do | ||
| 100 | login_as :quentin | ||
| 101 | node = create_node_with_published_page | ||
| 102 | |||
| 103 | post :create, params: { | ||
| 104 | event: { node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour }, | ||
| 105 | return_to: node_path(node) | ||
| 106 | } | ||
| 107 | |||
| 108 | assert_redirected_to node_path(node) | ||
| 109 | end | ||
| 110 | |||
| 111 | test "should update event" do | ||
| 112 | login_as :quentin | ||
| 113 | node = create_node_with_published_page | ||
| 114 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 115 | |||
| 116 | put :update, params: { id: event.id, event: { title: "Updated title" } } | ||
| 117 | |||
| 118 | assert_redirected_to events_path | ||
| 119 | assert_equal "Updated title", event.reload.title | ||
| 120 | end | ||
| 121 | |||
| 122 | test "should destroy event" do | ||
| 123 | login_as :quentin | ||
| 124 | node = create_node_with_published_page | ||
| 125 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | ||
| 126 | |||
| 127 | assert_difference('Event.count', -1) do | ||
| 128 | delete :destroy, params: { id: event.id } | ||
| 129 | end | ||
| 130 | |||
| 131 | assert_redirected_to events_url | ||
| 132 | end | ||
| 45 | end | 133 | end |
