From e05162bb0839a92a4b5d5c0542b3f55cc0be4931 Mon Sep 17 00:00:00 2001 From: Tim Fischbach Date: Mon, 18 Sep 2023 10:59:53 +0200 Subject: [PATCH] Pass entry type param in editor controller specs Required to find matching route. Also closer to real request. Entry type of fixture entry needs to match passed entry type to prevent `Pageflow::EditorController` from responding with bad reqest. REDMINE-19438 --- .../editor/chapters_controller_spec.rb | 47 +++++++---- .../content_elements_controller_spec.rb | 80 ++++++++++++------- .../editor/sections_controller_spec.rb | 39 +++++---- 3 files changed, 108 insertions(+), 58 deletions(-) diff --git a/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/chapters_controller_spec.rb b/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/chapters_controller_spec.rb index c527bfadf5..9bfad0fbd2 100644 --- a/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/chapters_controller_spec.rb +++ b/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/chapters_controller_spec.rb @@ -9,10 +9,11 @@ module PageflowScrolled describe '#create' do it 'requires authentication' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter: attributes_for(:scrolled_chapter) }, format: 'json') @@ -21,11 +22,12 @@ module PageflowScrolled end it 'succeeds for authorized user' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter: attributes_for(:scrolled_chapter) }, format: 'json') @@ -34,11 +36,12 @@ module PageflowScrolled end it 'allows setting the chapters configuration hash' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter: { configuration: {title: 'A chapter title'} @@ -50,11 +53,15 @@ module PageflowScrolled end it 'renders attributes as camel case' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') authorize_for_editor_controller(entry) post(:create, - params: {entry_id: entry, chapter: attributes_for(:scrolled_chapter)}, + params: { + entry_type: 'scrolled', + entry_id: entry, + chapter: attributes_for(:scrolled_chapter) + }, format: 'json') expect(json_response(path: [:permaId])).to be_present end @@ -62,12 +69,13 @@ module PageflowScrolled describe '#update' do it 'allows updating the chapters configuration hash' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) authorize_for_editor_controller(entry) patch(:update, params: { + entry_type: 'scrolled', entry_id: entry, id: chapter, chapter: { @@ -80,14 +88,15 @@ module PageflowScrolled end it 'does not allow updating a chapter from a different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') create(:scrolled_chapter, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') chapter_in_other_entry = create(:scrolled_chapter, revision: other_entry.draft) authorize_for_editor_controller(entry) patch(:update, params: { + entry_type: 'scrolled', entry_id: entry, id: chapter_in_other_entry, chapter: { @@ -101,13 +110,14 @@ module PageflowScrolled describe '#order' do it 'updates position of chapters according to given params order' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapters = create_list(:scrolled_chapter, 2, revision: entry.draft) storyline = chapters.first.storyline authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, storyline_id: storyline, ids: [chapters.last.id, chapters.first.id] @@ -118,12 +128,13 @@ module PageflowScrolled end it 'uses first storyline by default' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapters = create_list(:scrolled_chapter, 2, revision: entry.draft) authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, ids: [chapters.last.id, chapters.first.id] }, format: 'json') @@ -133,13 +144,14 @@ module PageflowScrolled end it 'allows moving a chapter from one storyline to another within the same entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) other_storyline = create(:scrolled_storyline, revision: entry.draft) authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, storyline_id: other_storyline, ids: [chapter.id] @@ -149,14 +161,15 @@ module PageflowScrolled end it 'does not allow moving a chapter to a storyline of different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') storyline_in_other_entry = create(:scrolled_storyline, revision: other_entry.draft) authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, storyline_id: storyline_in_other_entry, ids: [chapter.id] @@ -168,13 +181,14 @@ module PageflowScrolled describe '#destroy' do it 'deletes the chapter' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) storyline = chapter.storyline authorize_for_editor_controller(entry) delete(:destroy, params: { + entry_type: 'scrolled', entry_id: entry, id: chapter }, format: 'json') @@ -184,14 +198,15 @@ module PageflowScrolled end it 'does not allow deleting a chapter from a different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') create(:scrolled_chapter, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') chapter_in_other_entry = create(:scrolled_chapter, revision: other_entry.draft) authorize_for_editor_controller(entry) delete(:destroy, params: { + entry_type: 'scrolled', entry_id: entry, id: chapter_in_other_entry }, format: 'json') diff --git a/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/content_elements_controller_spec.rb b/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/content_elements_controller_spec.rb index d81e5f898d..7f00742f63 100644 --- a/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/content_elements_controller_spec.rb +++ b/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/content_elements_controller_spec.rb @@ -9,11 +9,12 @@ module PageflowScrolled describe '#batch' do it 'requires authentication' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [] @@ -23,13 +24,14 @@ module PageflowScrolled end it 'allows ordering content elements referenced by id' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_elements = create_list(:content_element, 2, section: section) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -43,7 +45,7 @@ module PageflowScrolled end it 'allows moving content elements to different section' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) other_section = create(:section, revision: entry.draft) content_element = create(:content_element, :text_block, section: section) @@ -51,6 +53,7 @@ module PageflowScrolled authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: other_section, content_elements: [ @@ -62,15 +65,16 @@ module PageflowScrolled end it 'does not allow moving content elements to different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') other_section = create(:section, revision: other_entry.draft) content_element = create(:content_element, section: section) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: other_section, content_elements: [ @@ -82,13 +86,14 @@ module PageflowScrolled end it 'allows setting content element configuration hashes' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_element = create(:content_element, section: section) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -100,7 +105,7 @@ module PageflowScrolled end it 'does not change configuration hash if not passed' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_element = create(:content_element, section: section, @@ -109,6 +114,7 @@ module PageflowScrolled authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -120,12 +126,13 @@ module PageflowScrolled end it 'allows creating content elements' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -139,13 +146,14 @@ module PageflowScrolled end it 'deletes content elements marked by _delete flag' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_elements = create_list(:content_element, 2, section: section) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -158,12 +166,13 @@ module PageflowScrolled end it 'responds with array of objects containging content element ids and perma ids' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -180,12 +189,13 @@ module PageflowScrolled end it 'does not create content elements if id is unknown' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -197,12 +207,13 @@ module PageflowScrolled end it 'rolls back other changes if one id is unknown' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -215,7 +226,7 @@ module PageflowScrolled end it 'allows performing a mix of update, create and delete operations' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_elements = create_list(:content_element, 3, @@ -225,6 +236,7 @@ module PageflowScrolled authorize_for_editor_controller(entry) post(:batch, params: { + entry_type: 'scrolled', entry_id: entry.id, section_id: section.id, content_elements: [ @@ -263,11 +275,12 @@ module PageflowScrolled describe '#create' do it 'requires authentication' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, content_element: attributes_for(:content_element, :text_block) @@ -277,12 +290,13 @@ module PageflowScrolled end it 'succeeds for authorized user' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, content_element: attributes_for(:content_element, :text_block) @@ -292,12 +306,13 @@ module PageflowScrolled end it 'allows setting the content elements configuration hash' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, content_element: { @@ -309,12 +324,13 @@ module PageflowScrolled end it 'allows setting the content elements type name' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, content_element: { @@ -326,12 +342,13 @@ module PageflowScrolled end it 'can handle camel case attributes' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, content_element: { @@ -343,12 +360,13 @@ module PageflowScrolled end it 'renders attributes as camel case' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, content_element: attributes_for(:content_element, :text_block) @@ -359,12 +377,13 @@ module PageflowScrolled describe '#update' do it 'allows updating the content elements configuration hash' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') content_element = create(:content_element, :text_block, revision: entry.draft) authorize_for_editor_controller(entry) patch(:update, params: { + entry_type: 'scrolled', entry_id: entry, id: content_element, content_element: { @@ -377,14 +396,15 @@ module PageflowScrolled end it 'does not allow updating a content element from a different entry' do - entry = create(:entry) - other_entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') + other_entry = create(:entry, type_name: 'scrolled') content_element_in_other_entry = create(:content_element, revision: other_entry.draft) authorize_for_editor_controller(entry) patch(:update, params: { + entry_type: 'scrolled', entry_id: entry, id: content_element_in_other_entry, content_element: { @@ -398,7 +418,7 @@ module PageflowScrolled describe '#order' do it 'updates position of content elements according to given params order' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_elements = create_list(:content_element, 2, :text_block, section: section) @@ -406,6 +426,7 @@ module PageflowScrolled put(:order, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section, ids: [content_elements.first.id, content_elements.last.id] @@ -416,14 +437,15 @@ module PageflowScrolled end it 'does not allow moving a content element to a section of a different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') content_element = create(:content_element, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') section_in_other_entry = create(:section, revision: other_entry.draft) authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, section_id: section_in_other_entry, ids: [content_element.id] @@ -435,13 +457,14 @@ module PageflowScrolled describe '#destroy' do it 'deletes the content element' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) content_element = create(:content_element, :text_block, section: section) authorize_for_editor_controller(entry) delete(:destroy, params: { + entry_type: 'scrolled', entry_id: entry, id: content_element }, format: 'json') @@ -451,13 +474,14 @@ module PageflowScrolled end it 'does not allow deleting a content element from a different entry' do - entry = create(:entry) - other_entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') + other_entry = create(:entry, type_name: 'scrolled') content_element_in_other_entry = create(:content_element, revision: other_entry.draft) authorize_for_editor_controller(entry) delete(:destroy, params: { + entry_type: 'scrolled', entry_id: entry, id: content_element_in_other_entry }, format: 'json') diff --git a/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/sections_controller_spec.rb b/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/sections_controller_spec.rb index b845d8d1ac..da1a3d817f 100644 --- a/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/sections_controller_spec.rb +++ b/entry_types/scrolled/spec/controllers/pageflow_scrolled/editor/sections_controller_spec.rb @@ -9,11 +9,12 @@ module PageflowScrolled describe '#create' do it 'requires authentication' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: chapter, section: attributes_for(:section) @@ -23,12 +24,13 @@ module PageflowScrolled end it 'succeeds for authorized user' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: chapter, section: attributes_for(:section) @@ -38,12 +40,13 @@ module PageflowScrolled end it 'allows setting the sections configuration hash' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: chapter, section: { @@ -55,12 +58,13 @@ module PageflowScrolled end it 'renders attributes as camel case' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) authorize_for_editor_controller(entry) post(:create, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: chapter, section: attributes_for(:section) @@ -71,12 +75,13 @@ module PageflowScrolled describe '#update' do it 'allows updating the sections configuration hash' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) authorize_for_editor_controller(entry) patch(:update, params: { + entry_type: 'scrolled', entry_id: entry, id: section, section: { @@ -89,14 +94,15 @@ module PageflowScrolled end it 'does not allow updating a section from a different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') create(:section, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') section_in_other_entry = create(:section, revision: other_entry.draft) authorize_for_editor_controller(entry) patch(:update, params: { + entry_type: 'scrolled', entry_id: entry, id: section_in_other_entry, chapter: { @@ -110,13 +116,14 @@ module PageflowScrolled describe '#order' do it 'updates position of sections according to given params order' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) sections = create_list(:section, 2, chapter: chapter) authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: chapter, ids: [sections.first.id, sections.last.id] @@ -127,7 +134,7 @@ module PageflowScrolled end it 'allows moving a section from one chapter to another within the same entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') revision = entry.draft chapter = create(:scrolled_chapter, revision: revision) section = create(:section, chapter: chapter) @@ -136,6 +143,7 @@ module PageflowScrolled authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: other_chapter, ids: [section.id] @@ -145,15 +153,16 @@ module PageflowScrolled end it 'does not allow moving a section to a chapter of another entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') chapter = create(:scrolled_chapter, revision: entry.draft) section = create(:section, chapter: chapter) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') chapter_in_other_entry = create(:scrolled_chapter, revision: other_entry.draft) authorize_for_editor_controller(entry) put(:order, params: { + entry_type: 'scrolled', entry_id: entry, chapter_id: chapter_in_other_entry, ids: [section.id] @@ -165,13 +174,14 @@ module PageflowScrolled describe '#destroy' do it 'deletes the section' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') section = create(:section, revision: entry.draft) chapter = section.chapter authorize_for_editor_controller(entry) delete(:destroy, params: { + entry_type: 'scrolled', entry_id: entry, id: section }, format: 'json') @@ -181,14 +191,15 @@ module PageflowScrolled end it 'does not allow deleting a section from a different entry' do - entry = create(:entry) + entry = create(:entry, type_name: 'scrolled') create(:section, revision: entry.draft) - other_entry = create(:entry) + other_entry = create(:entry, type_name: 'scrolled') section_in_other_entry = create(:section, revision: other_entry.draft) authorize_for_editor_controller(entry) delete(:destroy, params: { + entry_type: 'scrolled', entry_id: entry, id: section_in_other_entry }, format: 'json')