diff --git a/CHANGELOG.md b/CHANGELOG.md index fb1cb10f16..5376e2338a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 4.0.0 (unreleased) + +* Deprecated controller requests test helpers [#1284](https://github.com/AlchemyCMS/alchemy_cms/pull/1284) by [tvdeyen](https://github.com/tvdeyen) + ## 4.0.0.beta (2017-06-20) * Rails 5 diff --git a/lib/alchemy/deprecation.rb b/lib/alchemy/deprecation.rb new file mode 100644 index 0000000000..74a57e5d03 --- /dev/null +++ b/lib/alchemy/deprecation.rb @@ -0,0 +1,3 @@ +module Alchemy + Deprecation = ActiveSupport::Deprecation.new('5.0', 'Alchemy') +end diff --git a/lib/alchemy/test_support/controller_requests.rb b/lib/alchemy/test_support/controller_requests.rb index d66084b380..cd84514f29 100644 --- a/lib/alchemy/test_support/controller_requests.rb +++ b/lib/alchemy/test_support/controller_requests.rb @@ -1,3 +1,11 @@ +# *There is generally no need* to use this module. Instead, in +# a functional/controller test against a Alchemy controller, just +# use standard Rails functionality by including: +# +# routes { Alchemy::Engine.routes } +# +# And then use standard Rails test `get`, `post` etc methods. +# # Use this module to easily test Alchemy actions within Alchemy components # or inside your application to test routes for the mounted Alchemy engine. # @@ -25,35 +33,47 @@ # # Note: Based on Spree::TestingSupport::ControllerRequests. Thanks <3 # +# @deprecated Use Rails build in test request methods instead +# module Alchemy module TestSupport module ControllerRequests extend ActiveSupport::Concern # Executes a request simulating GET HTTP method + # @deprecated Use Rails test `get` helper instead def alchemy_get(action, parameters = nil, session = nil, flash = nil) process_alchemy_action(action, parameters, session, flash, "GET") end + deprecate alchemy_get: :get, deprecator: Alchemy::Deprecation # Executes a request simulating POST HTTP method + # @deprecated Use Rails test `post` helper instead def alchemy_post(action, parameters = nil, session = nil, flash = nil) process_alchemy_action(action, parameters, session, flash, "POST") end + deprecate alchemy_post: :post, deprecator: Alchemy::Deprecation # Executes a request simulating PUT HTTP method + # @deprecated Use Rails test `put` helper instead def alchemy_put(action, parameters = nil, session = nil, flash = nil) process_alchemy_action(action, parameters, session, flash, "PUT") end + deprecate alchemy_put: :put, deprecator: Alchemy::Deprecation # Executes a request simulating DELETE HTTP method + # @deprecated Use Rails test `delete` helper instead def alchemy_delete(action, parameters = nil, session = nil, flash = nil) process_alchemy_action(action, parameters, session, flash, "DELETE") end + deprecate alchemy_delete: :delete, deprecator: Alchemy::Deprecation # Executes a simulated XHR request + # @deprecated Use Rails test `xhr` helper instead def alchemy_xhr(method, action, parameters = nil, session = nil, flash = nil) process_alchemy_xhr_action(method, action, parameters, session, flash) end + deprecate alchemy_xhr: :xhr, deprecator: Alchemy::Deprecation private diff --git a/lib/alchemy_cms.rb b/lib/alchemy_cms.rb index 92f32ef642..4edd894258 100644 --- a/lib/alchemy_cms.rb +++ b/lib/alchemy_cms.rb @@ -32,6 +32,7 @@ module Alchemy require_relative 'alchemy/config' require_relative 'alchemy/configuration_methods' require_relative 'alchemy/controller_actions' +require_relative 'alchemy/deprecation' require_relative 'alchemy/errors' require_relative 'alchemy/essence' require_relative 'alchemy/filetypes' diff --git a/spec/controllers/alchemy/admin/attachments_controller_spec.rb b/spec/controllers/alchemy/admin/attachments_controller_spec.rb index ff29067c61..008a56b3ed 100644 --- a/spec/controllers/alchemy/admin/attachments_controller_spec.rb +++ b/spec/controllers/alchemy/admin/attachments_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::AttachmentsController do + routes { Alchemy::Engine.routes } + let(:attachment) { build_stubbed(:alchemy_attachment) } let(:file) do @@ -18,13 +20,13 @@ module Alchemy describe "#index" do it "should always paginate the records" do expect_any_instance_of(ActiveRecord::Relation).to receive(:page).and_call_original - alchemy_get :index + get :index end context "when params[:tagged_with] is set" do it "should filter the records by tags" do expect(Attachment).to receive(:tagged_with).and_return(Attachment.all) - alchemy_get :index, tagged_with: "pdf" + get :index, params: {tagged_with: "pdf"} end end @@ -34,7 +36,7 @@ module Alchemy context "is set" do it "it renders the archive_overlay partial" do expect(Content).to receive(:find_by).and_return(content) - alchemy_get :index, {content_id: content.id} + get :index, params: {content_id: content.id} expect(response).to render_template(partial: '_archive_overlay') expect(assigns(:content)).to eq(content) end @@ -42,7 +44,7 @@ module Alchemy context "is not set" do it "should render the default index view" do - alchemy_get :index + get :index expect(response).to render_template(:index) end end @@ -58,7 +60,7 @@ module Alchemy context 'with params[:file_type]' do it 'loads only attachments with matching content type' do - alchemy_get :index, file_type: 'image/jpeg' + get :index, params: {file_type: 'image/jpeg'} expect(assigns(:attachments).to_a).to eq([jpg]) expect(assigns(:attachments).to_a).to_not eq([png]) end @@ -72,13 +74,13 @@ module Alchemy end it "renders the show template" do - alchemy_get :show, id: attachment.id + get :show, params: {id: attachment.id} expect(response).to render_template(:show) end end describe '#create' do - subject { alchemy_post :create, params } + subject { post :create, params: params } context 'with passing validations' do let(:params) { {attachment: {file: file}} } @@ -110,7 +112,7 @@ module Alchemy end subject do - alchemy_put :update, params + put :update, params: params end let!(:attachment) { create(:alchemy_attachment) } @@ -161,7 +163,7 @@ module Alchemy end subject do - alchemy_put :update, { + put :update, params: { id: attachment.id, attachment: {name: ''} }.merge(search_params) end @@ -188,7 +190,7 @@ module Alchemy it "destroys the attachment and sets a success message" do expect(attachment).to receive(:destroy) - alchemy_xhr :delete, :destroy, id: 1 + delete :destroy, params: {id: 1}, xhr: true expect(assigns(:attachment)).to eq(attachment) expect(assigns(:url)).not_to be_blank expect(flash[:notice]).not_to be_blank @@ -206,7 +208,7 @@ module Alchemy it "passes them along" do expect(attachment).to receive(:destroy) { true } - alchemy_xhr :delete, :destroy, {id: 1}.merge(search_params) + delete :destroy, params: {id: 1}.merge(search_params), xhr: true expect(assigns(:url)).to eq admin_attachments_url(search_params.merge(host: 'test.host')) end end @@ -218,7 +220,7 @@ module Alchemy end it "sends the file as download" do - alchemy_get :download, id: attachment.id + get :download, params: {id: attachment.id} expect(response.headers['Content-Disposition']).to match(/attachment/) end end diff --git a/spec/controllers/alchemy/admin/clipboard_controller_spec.rb b/spec/controllers/alchemy/admin/clipboard_controller_spec.rb index 2bfc83ab08..0273c5fad0 100644 --- a/spec/controllers/alchemy/admin/clipboard_controller_spec.rb +++ b/spec/controllers/alchemy/admin/clipboard_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::ClipboardController do + routes { Alchemy::Engine.routes } + let(:public_page) { build_stubbed(:alchemy_page, :public) } let(:element) { build_stubbed(:alchemy_element, page: public_page) } let(:another_element) { build_stubbed(:alchemy_element, page: public_page) } @@ -14,7 +16,7 @@ module Alchemy describe '#index' do context 'with `remarkable_type` being an allowed type' do it 'is successful' do - alchemy_get :index, {remarkable_type: 'elements'} + get :index, params: {remarkable_type: 'elements'} expect(response).to be_success end end @@ -22,7 +24,7 @@ module Alchemy context 'with `remarkable_type` not an allowed type' do it 'raises 400 Bad Request' do expect { - alchemy_get :index, {remarkable_type: 'evil'} + get :index, params: {remarkable_type: 'evil'} }.to raise_error(ActionController::BadRequest) end end @@ -35,13 +37,13 @@ module Alchemy describe "#insert" do it "should hold element ids" do - alchemy_xhr :post, :insert, {remarkable_type: 'elements', remarkable_id: element.id} + post :insert, params: {remarkable_type: 'elements', remarkable_id: element.id}, xhr: true expect(session[:alchemy_clipboard]['elements']).to eq([{'id' => element.id.to_s, 'action' => 'copy'}]) end it "should not have the same element twice" do session[:alchemy_clipboard]['elements'] = [{'id' => element.id.to_s, 'action' => 'copy'}] - alchemy_xhr :post, :insert, {remarkable_type: 'elements', remarkable_id: element.id} + post :insert, params: {remarkable_type: 'elements', remarkable_id: element.id}, xhr: true expect(session[:alchemy_clipboard]['elements'].collect { |e| e['id'] }).not_to eq([element.id, element.id]) end end @@ -50,7 +52,7 @@ module Alchemy it "should remove element ids from clipboard" do session[:alchemy_clipboard]['elements'] = [{'id' => element.id.to_s, 'action' => 'copy'}] session[:alchemy_clipboard]['elements'] << {'id' => another_element.id.to_s, 'action' => 'copy'} - alchemy_xhr :delete, :remove, {remarkable_type: 'elements', remarkable_id: another_element.id} + delete :remove, params: {remarkable_type: 'elements', remarkable_id: another_element.id}, xhr: true expect(session[:alchemy_clipboard]['elements']).to eq([{'id' => element.id.to_s, 'action' => 'copy'}]) end end @@ -60,7 +62,7 @@ module Alchemy context "with elements as remarkable_type" do it "should clear the elements clipboard" do session[:alchemy_clipboard]['elements'] = [{'id' => element.id.to_s}] - alchemy_xhr :delete, :clear, {remarkable_type: 'elements'} + delete :clear, params: {remarkable_type: 'elements'}, xhr: true expect(session[:alchemy_clipboard]['elements']).to be_empty end end @@ -68,7 +70,7 @@ module Alchemy context "with pages as remarkable_type" do it "should clear the pages clipboard" do session[:alchemy_clipboard]['pages'] = [{'id' => public_page.id.to_s}] - alchemy_xhr :delete, :clear, {remarkable_type: 'pages'} + delete :clear, params: {remarkable_type: 'pages'}, xhr: true expect(session[:alchemy_clipboard]['pages']).to be_empty end end diff --git a/spec/controllers/alchemy/admin/contents_controller_spec.rb b/spec/controllers/alchemy/admin/contents_controller_spec.rb index a61cc268db..6d74fc85d3 100644 --- a/spec/controllers/alchemy/admin/contents_controller_spec.rb +++ b/spec/controllers/alchemy/admin/contents_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::ContentsController do + routes { Alchemy::Engine.routes } + before do authorize_user(:as_admin) end @@ -12,17 +14,17 @@ module Alchemy it "creates a content from name" do expect { - alchemy_xhr :post, :create, {content: {element_id: element.id, name: 'headline'}} + post :create, params: {content: {element_id: element.id, name: 'headline'}}, xhr: true }.to change { Alchemy::Content.count }.by(1) end it "creates a content from essence_type" do expect { - alchemy_xhr :post, :create, { + post :create, params: { content: { element_id: element.id, essence_type: 'EssencePicture' } - } + }, xhr: true }.to change { Alchemy::Content.count }.by(1) end end @@ -43,13 +45,13 @@ module Alchemy end it "adds it into the gallery editor" do - alchemy_xhr :post, :create, attributes + post :create, params: attributes, xhr: true expect(assigns(:content_dom_id)).to eq("#add_picture_#{element.id}") end context 'with picture_id given' do it "assigns the picture to the essence" do - alchemy_xhr :post, :create, attributes.merge(picture_id: '1') + post :create, params: attributes.merge(picture_id: '1'), xhr: true expect(Alchemy::Content.last.essence.picture_id).to eq(1) end end @@ -65,7 +67,7 @@ module Alchemy it "should update a content via ajax" do expect { - alchemy_xhr :post, :update, {id: content.id, content: {ingredient: 'Peters Petshop'}} + post :update, params: {id: content.id, content: {ingredient: 'Peters Petshop'}}, xhr: true }.to change { content.ingredient }.to 'Peters Petshop' end end @@ -79,7 +81,7 @@ module Alchemy let(:content_ids) { element.contents.pluck(:id).shuffle } it "should reorder the contents" do - alchemy_xhr :post, :order, {content_ids: content_ids} + post :order, params: {content_ids: content_ids}, xhr: true expect(response.status).to eq(200) expect(element.contents(true).pluck(:id)).to eq(content_ids) diff --git a/spec/controllers/alchemy/admin/dashboard_controller_spec.rb b/spec/controllers/alchemy/admin/dashboard_controller_spec.rb index 213b0cb9e8..0e588768d3 100644 --- a/spec/controllers/alchemy/admin/dashboard_controller_spec.rb +++ b/spec/controllers/alchemy/admin/dashboard_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::DashboardController do + routes { Alchemy::Engine.routes } + let(:user) { build_stubbed(:alchemy_dummy_user, :as_admin) } before { authorize_user(user) } @@ -18,12 +20,12 @@ module Alchemy end it "assigns @last_edited_pages" do - alchemy_get :index + get :index expect(assigns(:last_edited_pages)).to eq([]) end it "assigns @all_locked_pages" do - alchemy_get :index + get :index expect(assigns(:all_locked_pages)).to eq([]) end @@ -36,14 +38,14 @@ module Alchemy end it "assigns @online_users" do - alchemy_get :index + get :index expect(assigns(:online_users)).to eq([another_user]) end end context 'without other users online' do it "does not assign @online_users" do - alchemy_get :index + get :index expect(assigns(:online_users)).to eq([]) end end @@ -56,20 +58,20 @@ module Alchemy end it "assigns @first_time" do - alchemy_get :index + get :index expect(assigns(:first_time)).to eq(false) end end it "assigns @sites" do - alchemy_get :index + get :index expect(assigns(:sites)).to eq(Site.all) end end describe '#info' do it "assigns @alchemy_version with the current Alchemy version" do - alchemy_get :info + get :info expect(assigns(:alchemy_version)).to eq(Alchemy.version) end end @@ -82,7 +84,7 @@ module Alchemy } it "should render 'false'" do - alchemy_get :update_check + get :update_check expect(response.body).to eq('false') end end @@ -94,7 +96,7 @@ module Alchemy } it "should render 'true'" do - alchemy_get :update_check + get :update_check expect(response.body).to eq('true') end end @@ -108,7 +110,7 @@ module Alchemy } it "should have response code of 200" do - alchemy_get :update_check + get :update_check expect(response.code).to eq('200') end end @@ -122,7 +124,7 @@ module Alchemy } it "should have response code of 200" do - alchemy_get :update_check + get :update_check expect(response.code).to eq('200') end end @@ -135,7 +137,7 @@ module Alchemy } it "should have status code 503" do - alchemy_get :update_check + get :update_check expect(response.code).to eq('503') end end diff --git a/spec/controllers/alchemy/admin/elements_controller_spec.rb b/spec/controllers/alchemy/admin/elements_controller_spec.rb index 3950bcb8fe..65be7e6d95 100644 --- a/spec/controllers/alchemy/admin/elements_controller_spec.rb +++ b/spec/controllers/alchemy/admin/elements_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::ElementsController do + routes { Alchemy::Engine.routes } + let(:alchemy_page) { create(:alchemy_page) } let(:element) { create(:alchemy_element, page: alchemy_page) } let(:element_in_clipboard) { create(:alchemy_element, page: alchemy_page) } @@ -25,7 +27,7 @@ module Alchemy it "groups elements by cell" do expect(alchemy_page).to receive(:elements_grouped_by_cells) - alchemy_get :index, {page_id: alchemy_page.id} + get :index, params: {page_id: alchemy_page.id} expect(assigns(:cells)).to eq([cell]) end end @@ -37,7 +39,7 @@ module Alchemy it "assigns page elements" do expect(alchemy_page).to receive(:elements).and_return(double(not_trashed: [])) - alchemy_get :index, {page_id: alchemy_page.id} + get :index, params: {page_id: alchemy_page.id} end end end @@ -46,7 +48,7 @@ module Alchemy context 'without page_id, but with page_urlname' do it "loads page from urlname" do expect { - alchemy_xhr :get, :list, {page_urlname: alchemy_page.urlname} + get :list, params: {page_urlname: alchemy_page.urlname}, xhr: true }.to_not raise_error end @@ -54,7 +56,7 @@ module Alchemy render_views it "should return a select tag with elements" do - alchemy_xhr :get, :list, {page_urlname: alchemy_page.urlname} + get :list, params: {page_urlname: alchemy_page.urlname}, xhr: true expect(response.body).to match(/select(.*)elements_from_page_selector(.*)option/) end end @@ -62,7 +64,7 @@ module Alchemy context 'with page_id' do it "loads page from urlname" do - alchemy_xhr :get, :list, {page_id: alchemy_page.id} + get :list, params: {page_id: alchemy_page.id}, xhr: true expect(assigns(:page_id)).to eq(alchemy_page.id.to_s) end end @@ -76,14 +78,14 @@ module Alchemy let(:page) { element_1.page } it "sets new position for given element ids" do - alchemy_xhr :post, :order, page_id: page.id, element_ids: element_ids + post :order, params: {page_id: page.id, element_ids: element_ids}, xhr: true expect(Element.all.pluck(:id)).to eq(element_ids) end context 'with missing [:element_ids] param' do it 'does not raise any error and silently rejects to order' do expect { - alchemy_xhr :post, :order, page_id: page.id + post :order, params: {page_id: page.id}, xhr: true }.to_not raise_error end end @@ -94,17 +96,19 @@ module Alchemy it 'touches the cache key of parent element' do expect(Element).to receive(:find_by) { parent } expect(parent).to receive(:touch) { true } - alchemy_xhr :post, :order, + post :order, params: { page_id: page.id, element_ids: element_ids, parent_element_id: parent.id + }, xhr: true end it 'assigns parent element id to each element' do - alchemy_xhr :post, :order, + post :order, params: { page_id: page.id, element_ids: element_ids, parent_element_id: parent.id + }, xhr: true [element_1, element_2, element_3].each do |element| expect(element.reload.parent_element_id).to eq parent.id end @@ -121,12 +125,12 @@ module Alchemy end it "sets a list of trashed element ids" do - alchemy_xhr :post, :order, page_id: page.id, element_ids: [trashed_element.id] + post :order, params: {page_id: page.id, element_ids: [trashed_element.id]}, xhr: true expect(assigns(:trashed_element_ids).to_a).to eq [trashed_element.id] end it "sets a new position to the element" do - alchemy_xhr :post, :order, page_id: page.id, element_ids: [trashed_element.id] + post :order, params: {page_id: page.id, element_ids: [trashed_element.id]}, xhr: true trashed_element.reload expect(trashed_element.position).to_not be_nil end @@ -135,7 +139,7 @@ module Alchemy let(:page) { create(:alchemy_page) } it "should assign the (new) page_id to the element" do - alchemy_xhr :post, :order, element_ids: [trashed_element.id], page_id: page.id + post :order, params: {element_ids: [trashed_element.id], page_id: page.id}, xhr: true trashed_element.reload expect(trashed_element.page_id).to be page.id end @@ -145,10 +149,11 @@ module Alchemy let(:cell) { create(:alchemy_cell) } it "should assign the (new) cell_id to the element" do - alchemy_xhr :post, :order, + post :order, params: { element_ids: [trashed_element.id], page_id: trashed_element.page_id, cell_id: cell.id + }, xhr: true trashed_element.reload expect(trashed_element.cell_id).to be cell.id @@ -166,7 +171,7 @@ module Alchemy it "assign variable for all available element definitions" do expect(alchemy_page).to receive(:available_element_definitions) - alchemy_get :new, {page_id: alchemy_page.id} + get :new, params: {page_id: alchemy_page.id} end context "with elements in clipboard" do @@ -177,7 +182,7 @@ module Alchemy it "should load all elements from clipboard" do expect(Element).to receive(:all_from_clipboard_for_page).and_return(clipboard_items) - alchemy_get :new, {page_id: alchemy_page.id} + get :new, params: {page_id: alchemy_page.id} expect(assigns(:clipboard_items)).to eq(clipboard_items) end end @@ -188,7 +193,7 @@ module Alchemy before { element } it "should insert the element at bottom of list" do - alchemy_xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}} + post :create, params: {element: {name: 'news', page_id: alchemy_page.id}}, xhr: true expect(alchemy_page.elements.count).to eq(2) expect(alchemy_page.elements.last.name).to eq('news') end @@ -203,7 +208,7 @@ module Alchemy end it "should insert the element at top of list" do - alchemy_xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}} + post :create, params: {element: {name: 'news', page_id: alchemy_page.id}}, xhr: true expect(alchemy_page.elements.count).to eq(2) expect(alchemy_page.elements.first.name).to eq('news') end @@ -229,14 +234,14 @@ module Alchemy end it "should put the element in the correct cell" do - alchemy_xhr :post, :create, {element: {name: "article#header", page_id: page.id}} + post :create, params: {element: {name: "article#header", page_id: page.id}}, xhr: true expect(cell.elements.first).to be_an_instance_of(Element) end end context "and no cell name in element name" do it "should put the element in the main cell" do - alchemy_xhr :post, :create, {element: {name: "article", page_id: page.id}} + post :create, params: {element: {name: "article", page_id: page.id}}, xhr: true expect(page.elements.not_in_cell.first).to be_an_instance_of(Element) end end @@ -262,7 +267,7 @@ module Alchemy end it "should create the element in the correct cell" do - alchemy_xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"} + post :create, params: {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}, xhr: true expect(cell.elements.first).to be_an_instance_of(Element) end @@ -272,7 +277,7 @@ module Alchemy end it "should set the correct position for the element" do - alchemy_xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"} + post :create, params: {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}, xhr: true expect(cell.elements.last.position).to eq(cell.elements.count) end end @@ -280,7 +285,7 @@ module Alchemy context "and no cell name in element name" do it "should create the element in the nil cell" do - alchemy_xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: element_in_clipboard.id.to_s} + post :create, params: {element: {page_id: page.id}, paste_from_clipboard: element_in_clipboard.id.to_s}, xhr: true expect(page.elements.first.cell).to eq(nil) end end @@ -308,7 +313,7 @@ module Alchemy end it "should insert the element at top of list" do - alchemy_xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"} + post :create, params: {element: {name: 'news', page_id: alchemy_page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}, xhr: true expect(cell.elements.count).to eq(2) expect(cell.elements.first.name).to eq('news') expect(cell.elements.first).not_to eq(element) @@ -325,21 +330,21 @@ module Alchemy end it "should create an element from clipboard" do - alchemy_xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}} + post :create, params: {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}, xhr: true expect(response.status).to eq(200) expect(response.body).to match(/Successfully added new element/) end context "and with cut as action parameter" do it "should also remove the element id from clipboard" do - alchemy_xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}} + post :create, params: {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}, xhr: true expect(session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }).to be_nil end end end context 'if element could not be saved' do - subject { alchemy_post :create, {element: {page_id: alchemy_page.id}} } + subject { post :create, params: {element: {page_id: alchemy_page.id}} } before do expect_any_instance_of(Element).to receive(:save).and_return false @@ -421,20 +426,20 @@ module Alchemy it "updates all contents in element" do expect(element).to receive(:update_contents).with(contents_parameters) - alchemy_xhr :put, :update, {id: element.id} + put :update, params: {id: element.id}, xhr: true end it "updates the element" do expect(controller).to receive(:element_params).and_return(element_parameters) expect(element).to receive(:update_contents).and_return(true) expect(element).to receive(:update_attributes!).with(element_parameters).and_return(true) - alchemy_xhr :put, :update, {id: element.id} + put :update, params: {id: element.id}, xhr: true end context "failed validations" do it "displays validation failed notice" do expect(element).to receive(:update_contents).and_return(false) - alchemy_xhr :put, :update, {id: element.id} + put :update, params: {id: element.id}, xhr: true expect(assigns(:element_validated)).to be_falsey end end @@ -490,7 +495,7 @@ module Alchemy end describe '#trash' do - subject { alchemy_xhr :delete, :trash, {id: element.id} } + subject { delete :trash, params: {id: element.id}, xhr: true } let(:element) { build_stubbed(:alchemy_element) } @@ -503,7 +508,7 @@ module Alchemy end describe '#fold' do - subject { alchemy_xhr :post, :fold, {id: element.id} } + subject { post :fold, params: {id: element.id}, xhr: true } let(:element) { build_stubbed(:alchemy_element) } diff --git a/spec/controllers/alchemy/admin/essence_files_controller_spec.rb b/spec/controllers/alchemy/admin/essence_files_controller_spec.rb index a86d6e2d9e..529b1856cd 100644 --- a/spec/controllers/alchemy/admin/essence_files_controller_spec.rb +++ b/spec/controllers/alchemy/admin/essence_files_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::EssenceFilesController do + routes { Alchemy::Engine.routes } + before do authorize_user(:as_admin) end @@ -18,12 +20,12 @@ module Alchemy end it "assigns @essence_file with the EssenceFile found by id" do - alchemy_get :edit, id: essence_file.id + get :edit, params: {id: essence_file.id} expect(assigns(:essence_file)).to eq(essence_file) end it "should assign @content with essence_file's content" do - alchemy_get :edit, id: essence_file.id + get :edit, params: {id: essence_file.id} expect(assigns(:content)).to eq(content) end end @@ -36,11 +38,14 @@ module Alchemy end it "should update the attributes of essence_file" do - alchemy_xhr :put, :update, id: essence_file.id, essence_file: { - title: 'new title', - css_class: 'left', - link_text: 'Download this file' - } + put :update, params: { + id: essence_file.id, + essence_file: { + title: 'new title', + css_class: 'left', + link_text: 'Download this file' + } + }, xhr: true expect(essence_file.title).to eq 'new title' expect(essence_file.css_class).to eq 'left' expect(essence_file.link_text).to eq 'Download this file' @@ -57,19 +62,19 @@ module Alchemy end it "should assign @attachment with the Attachment found by attachment_id" do - alchemy_xhr :put, :assign, content_id: content.id, attachment_id: attachment.id + put :assign, params: {content_id: content.id, attachment_id: attachment.id}, xhr: true expect(assigns(:attachment)).to eq(attachment) end it "should assign @content.essence.attachment with the attachment found by id" do expect(content.essence).to receive(:attachment=).with(attachment) - alchemy_xhr :put, :assign, content_id: content.id, attachment_id: attachment.id + put :assign, params: {content_id: content.id, attachment_id: attachment.id}, xhr: true end it "updates the @content.updated_at column" do content.update_column(:updated_at, 3.days.ago) expect { - alchemy_xhr :put, :assign, content_id: content.id, attachment_id: attachment.id + put :assign, params: {content_id: content.id, attachment_id: attachment.id}, xhr: true }.to change(content, :updated_at) end end diff --git a/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb b/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb index 380be5d30d..e691ac524a 100644 --- a/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb +++ b/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Admin::EssencePicturesController do + routes { Alchemy::Engine.routes } + before { authorize_user(:as_admin) } let(:essence) { EssencePicture.new } @@ -15,7 +17,7 @@ module Alchemy end it 'should assign @essence_picture and @content instance variables' do - alchemy_post :edit, id: 1, content_id: 1 + post :edit, params: {id: 1, content_id: 1} expect(assigns(:essence_picture)).to be_a(EssencePicture) expect(assigns(:content)).to be_a(Content) end @@ -32,7 +34,7 @@ module Alchemy end it "renders error message" do - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:no_image_notice)).to eq(Alchemy.t(:no_image_for_cropper_found)) end end @@ -60,14 +62,14 @@ module Alchemy context 'with sizes in params' do it "sets sizes to given values" do - alchemy_get :crop, id: 1, options: {size: '300x250'} + get :crop, params: {id: 1, options: {size: '300x250'}} expect(assigns(:min_size)).to eq({ width: 300, height: 250 }) end end context 'with no sizes in params' do it "sets sizes to zero" do - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 0, height: 0 }) end end @@ -77,7 +79,7 @@ module Alchemy it "sets sizes from these values" do expect(essence).to receive(:render_size).at_least(:once).and_return('30x25') - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 30, height: 25 }) end @@ -85,14 +87,14 @@ module Alchemy it 'infers the height from the image file preserving the aspect ratio' do expect(essence).to receive(:render_size).at_least(:once).and_return('30x') - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 30, height: 0}) end it 'does not infer the height from the image file preserving the aspect ratio' do expect(essence).to receive(:render_size).at_least(:once).and_return('x25') - alchemy_get :crop, id: 1, options: { fixed_ratio: "2"} + get :crop, params: {id: 1, options: { fixed_ratio: "2"}} expect(assigns(:min_size)).to eq({ width: 50, height: 25 }) end end @@ -101,14 +103,14 @@ module Alchemy it 'width is given, it infers the height from width and ratio' do expect(essence).to receive(:render_size).at_least(:once).and_return('30x') - alchemy_get :crop, id: 1, options: { fixed_ratio: "0.5" } + get :crop, params: {id: 1, options: { fixed_ratio: "0.5" }} expect(assigns(:min_size)).to eq({ width: 30, height: 60 }) end it 'infers the height from the image file preserving the aspect ratio' do expect(essence).to receive(:render_size).at_least(:once).and_return('x25') - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 0, height: 25}) end end @@ -121,7 +123,7 @@ module Alchemy end it "assigns default mask boxes" do - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:initial_box)).to eq(default_mask) expect(assigns(:default_box)).to eq(default_mask) end @@ -137,7 +139,7 @@ module Alchemy it "assigns cropping boxes" do expect(essence).to receive(:cropping_mask).and_return(mask) - alchemy_get :crop, id: 1 + get :crop, params: {id: 1} expect(assigns(:initial_box)).to eq(mask) expect(assigns(:default_box)).to eq(default_mask) end @@ -145,21 +147,21 @@ module Alchemy context 'with fixed_ratio set to false' do it "sets ratio to false" do - alchemy_get :crop, id: 1, options: {fixed_ratio: false} + get :crop, params: {id: 1, options: {fixed_ratio: false}} expect(assigns(:ratio)).to eq(false) end end context 'with fixed_ratio set to a non float string' do it "doesn't set a fixed ratio" do - alchemy_get :crop, id: 1, options: {fixed_ratio: '123,45'} + get :crop, params: {id: 1, options: {fixed_ratio: '123,45'}} expect(assigns(:ratio)).to eq(false) end end context 'with no fixed_ratio set in params' do it "sets a fixed ratio from sizes" do - alchemy_get :crop, id: 1, options: {size: '80x60'} + get :crop, params: {id: 1, options: {size: '80x60'}} expect(assigns(:ratio)).to eq(80.0 / 60.0) end end @@ -172,16 +174,31 @@ module Alchemy expect(Content).to receive(:find).and_return(content) end - let(:attributes) { {render_size: '1x1', alt_tag: 'Alt Tag', caption: 'Caption', css_class: 'CSS Class', title: 'Title'} } + let(:attributes) do + { + render_size: '1x1', + alt_tag: 'Alt Tag', + caption: 'Caption', + css_class: 'CSS Class', + title: 'Title' + } + end it "updates the essence attributes" do expect(essence).to receive(:update).and_return(true) - alchemy_xhr :put, :update, id: 1, essence_picture: attributes + put :update, params: {id: 1, essence_picture: attributes}, xhr: true end it "saves the cropping mask" do expect(essence).to receive(:update).and_return(true) - alchemy_xhr :put, :update, id: 1, essence_picture: {render_size: '1x1', crop_from: '0x0', crop_size: '100x100'} + put :update, params: { + id: 1, + essence_picture: { + render_size: '1x1', + crop_from: '0x0', + crop_size: '100x100' + } + }, xhr: true end end @@ -195,14 +212,14 @@ module Alchemy end it "should assign a Picture" do - alchemy_xhr :put, :assign, content_id: '1', picture_id: '1' + put :assign, params: {content_id: '1', picture_id: '1'}, xhr: true expect(assigns(:content).essence.picture).to eq(picture) end it "updates the content timestamp" do content.update_column(:updated_at, 3.days.ago) expect { - alchemy_xhr :put, :assign, content_id: '1', picture_id: '1' + put :assign, params: {content_id: '1', picture_id: '1'}, xhr: true }.to change(content, :updated_at) end end diff --git a/spec/controllers/alchemy/admin/languages_controller_spec.rb b/spec/controllers/alchemy/admin/languages_controller_spec.rb index f2c013d798..f73f17b77a 100644 --- a/spec/controllers/alchemy/admin/languages_controller_spec.rb +++ b/spec/controllers/alchemy/admin/languages_controller_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Alchemy::Admin::LanguagesController do + routes { Alchemy::Engine.routes } + before do authorize_user(:as_admin) end @@ -20,7 +22,7 @@ end it 'only shows languages from current site' do - alchemy_get :index + get :index expect(assigns(:languages)).to include(default_site_language) expect(assigns(:languages)).to_not include(site_2_language) end @@ -32,7 +34,7 @@ end it "should be able to index language" do - alchemy_get :index + get :index expect(response).to render_template(:index) end end @@ -40,7 +42,7 @@ describe "#new" do it "has default language's page_layout set" do - alchemy_get :new + get :new expect(assigns(:language).page_layout). to eq(Alchemy::Config.get(:default_language)['page_layout']) end diff --git a/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb b/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb index 8c76da3bf7..5a404b5c3c 100644 --- a/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb +++ b/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb @@ -2,18 +2,20 @@ module Alchemy describe Admin::LayoutpagesController do + routes { Alchemy::Engine.routes } + before(:each) do authorize_user(:as_admin) end describe "#index" do it "should assign @layout_root" do - alchemy_get :index + get :index expect(assigns(:layout_root)).to be_a(Page) end it "should assign @languages" do - alchemy_get :index + get :index expect(assigns(:languages).first).to be_a(Language) end @@ -31,7 +33,7 @@ module Alchemy end it 'only shows languages from current site' do - alchemy_get :index + get :index expect(assigns(:languages)).to include(language) expect(assigns(:languages)).to_not include(language_2) end diff --git a/spec/controllers/alchemy/admin/pictures_controller_spec.rb b/spec/controllers/alchemy/admin/pictures_controller_spec.rb index 51133646b2..3308fb86ae 100644 --- a/spec/controllers/alchemy/admin/pictures_controller_spec.rb +++ b/spec/controllers/alchemy/admin/pictures_controller_spec.rb @@ -18,6 +18,8 @@ module Alchemy describe Admin::PicturesController do + routes { Alchemy::Engine.routes } + before do authorize_user(:as_admin) end @@ -28,7 +30,7 @@ module Alchemy let!(:picture_2) { create(:alchemy_picture, name: 'nice beach') } it 'assigns @pictures with filtered pictures' do - alchemy_get :index, q: {name_or_image_file_name_cont: 'kitten'} + get :index, params: {q: {name_or_image_file_name_cont: 'kitten'}} expect(assigns(:pictures)).to include(picture_1) expect(assigns(:pictures)).to_not include(picture_2) end @@ -39,7 +41,7 @@ module Alchemy let!(:picture_2) { create(:alchemy_picture, tag_list: %w(kitten)) } it 'assigns @pictures with filtered pictures' do - alchemy_get :index, filter: 'without_tag' + get :index, params: {filter: 'without_tag'} expect(assigns(:pictures)).to include(picture_1) expect(assigns(:pictures)).to_not include(picture_2) end @@ -50,20 +52,20 @@ module Alchemy let!(:picture_2) { create(:alchemy_picture, tag_list: %w(kitten)) } it 'assigns @pictures with filtered pictures' do - alchemy_get :index, tagged_with: 'water' + get :index, params: {tagged_with: 'water'} expect(assigns(:pictures)).to include(picture_1) expect(assigns(:pictures)).to_not include(picture_2) end end it 'assigns @size to default value' do - alchemy_get :index + get :index expect(assigns(:size)).to eq('medium') end context "with params[:size] set to 'large'" do it 'assigns @size to large' do - alchemy_get :index, size: 'large' + get :index, params: {size: 'large'} expect(assigns(:size)).to eq('large') end end @@ -76,19 +78,19 @@ module Alchemy end it "for html requests it renders the archive_overlay partial" do - alchemy_get :index, {element_id: 1} + get :index, params: {element_id: 1} expect(response).to render_template(partial: '_archive_overlay') end it "for ajax requests it renders the archive_overlay template" do - alchemy_xhr :get, :index, {element_id: 1} + get :index, params: {element_id: 1}, xhr: true expect(response).to render_template(:archive_overlay) end end context "is not set" do it "should render the default index view" do - alchemy_get :index + get :index expect(response).to render_template(:index) end end @@ -96,7 +98,7 @@ module Alchemy end describe '#create' do - subject { alchemy_post :create, params } + subject { post :create, params: params } let(:params) { {picture: {name: ''}} } let(:picture) { mock_model('Picture', humanized_name: 'Cute kittens', to_jq_upload: {}) } @@ -128,7 +130,7 @@ module Alchemy let(:picture) { create(:alchemy_picture, name: 'kitten') } it 'assigns @picture' do - alchemy_get :show, id: picture.id + get :show, params: {id: picture.id} expect(assigns(:picture).id).to eq(picture.id) end @@ -139,7 +141,7 @@ module Alchemy let!(:essence) { create(:alchemy_essence_picture, content: content, picture: picture) } it 'assigns @pages to assignments grouped by page' do - alchemy_get :show, id: picture.id + get :show, params: {id: picture.id} expect(assigns(:pages)).to eq({page => [essence]}) end end @@ -148,7 +150,7 @@ module Alchemy let!(:previous) { create(:alchemy_picture, name: 'abraham') } it 'assigns @previous to previous picture' do - alchemy_get :show, id: picture.id + get :show, params: {id: picture.id} expect(assigns(:previous).id).to eq(previous.id) end end @@ -157,7 +159,7 @@ module Alchemy let!(:next_picture) { create(:alchemy_picture, name: 'zebra') } it 'assigns @next to next picture' do - alchemy_get :show, id: picture.id + get :show, params: {id: picture.id} expect(assigns(:next).id).to eq(next_picture.id) end end @@ -168,18 +170,20 @@ module Alchemy before { expect(Picture).to receive(:where).and_return(pictures) } it 'assigns pictures instance variable' do - alchemy_get :edit_multiple + get :edit_multiple expect(assigns(:pictures)).to eq(pictures) end it 'assigns tags instance variable' do - alchemy_get :edit_multiple + get :edit_multiple expect(assigns(:tags)).to include('kitten') end end describe '#update' do - subject { alchemy_xhr :put, :update, {id: 1, picture: {name: ''}} } + subject do + put :update, params: {id: 1, picture: {name: ''}}, xhr: true + end let(:picture) { build_stubbed(:alchemy_picture, name: 'Cute kitten') } @@ -223,21 +227,21 @@ module Alchemy end it "loads and assigns pictures" do - alchemy_post :update_multiple + post :update_multiple expect(assigns(:pictures)).to eq(pictures) end it_behaves_like :redirecting_to_picture_library do - let(:subject) { alchemy_post(:update_multiple, params) } + let(:subject) { post(:update_multiple, params: params) } end end describe "#delete_multiple" do - subject { alchemy_delete :delete_multiple, picture_ids: picture_ids } + subject { delete :delete_multiple, params: {picture_ids: picture_ids} } it_behaves_like :redirecting_to_picture_library do let(:subject) do - alchemy_delete :delete_multiple, { + delete :delete_multiple, params: { picture_ids: %w(1 2) }.merge(params) end @@ -317,7 +321,7 @@ module Alchemy it "destroys the picture and sets and success message" do expect(picture).to receive(:destroy) - alchemy_delete :destroy, id: picture.id + delete :destroy, params: {id: picture.id} expect(assigns(:picture)).to eq(picture) expect(flash[:notice]).not_to be_blank end @@ -328,18 +332,18 @@ module Alchemy end it "shows error notice" do - alchemy_delete :destroy, id: picture.id + delete :destroy, params: {id: picture.id} expect(flash[:error]).not_to be_blank end it "redirects to index" do - alchemy_delete :destroy, id: picture.id + delete :destroy, params: {id: picture.id} expect(response).to redirect_to admin_pictures_path end end it_behaves_like :redirecting_to_picture_library do - let(:subject) { alchemy_delete :destroy, {id: picture.id}.merge(params) } + let(:subject) { delete :destroy, params: {id: picture.id}.merge(params) } end end diff --git a/spec/controllers/alchemy/admin/resources_controller_spec.rb b/spec/controllers/alchemy/admin/resources_controller_spec.rb index e035e613a5..09eed7c3fc 100644 --- a/spec/controllers/alchemy/admin/resources_controller_spec.rb +++ b/spec/controllers/alchemy/admin/resources_controller_spec.rb @@ -18,7 +18,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController end it "returns all records" do - get :index, params + get :index, params: params expect(assigns(:events)).to include(peter) expect(assigns(:events)).to include(lustig) end @@ -27,7 +27,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController let(:params) { {q: {name_or_hidden_name_or_location_name_cont: "PeTer"}} } it "returns only matching records" do - get :index, params + get :index, params: params expect(assigns(:events)).to include(peter) expect(assigns(:events)).not_to include(lustig) end @@ -42,7 +42,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController end it "returns only matching records" do - get :index, params + get :index, params: params expect(assigns(:events)).to include(peter) expect(assigns(:events)).not_to include(lustig) end @@ -55,7 +55,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController let!(:peter) { Event.create(name: 'Peter') } it 'redirects to index, keeping the current location parameters' do - post :update, {id: peter.id, event: {name: "Hans"}}.merge(params) + post :update, params: {id: peter.id, event: {name: "Hans"}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q=some_query") end end @@ -64,7 +64,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController let(:params) { {q: 'some_query', page: 6} } it 'redirects to index, keeping the current location parameters' do - post :create, {event: {name: "Hans"}}.merge(params) + post :create, params: {event: {name: "Hans"}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q=some_query") end end @@ -74,7 +74,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController let!(:peter) { Event.create(name: 'Peter') } it 'redirects to index, keeping the current location parameters' do - delete :destroy, {id: peter.id}.merge(params) + delete :destroy, params: {id: peter.id}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q=some_query") end end diff --git a/spec/controllers/alchemy/admin/tags_controller_spec.rb b/spec/controllers/alchemy/admin/tags_controller_spec.rb index 03a05f1cd9..969d667f04 100644 --- a/spec/controllers/alchemy/admin/tags_controller_spec.rb +++ b/spec/controllers/alchemy/admin/tags_controller_spec.rb @@ -3,6 +3,8 @@ module Alchemy module Admin describe TagsController do + routes { Alchemy::Engine.routes } + before { authorize_user(:as_admin) } describe '#create' do @@ -10,7 +12,7 @@ module Admin render_views it "does not create tag" do - alchemy_post :create, tag: {name: ''} + post :create, params: {tag: {name: ''}} expect(response.body).to have_content("can't be blank") end end @@ -18,7 +20,7 @@ module Admin context 'with required params' do it "creates tag and redirects to tags view" do expect { - alchemy_post :create, tag: {name: 'Foo'} + post :create, params: {tag: {name: 'Foo'}} }.to change { ActsAsTaggableOn::Tag.count }.by(1) expect(response).to redirect_to admin_tags_path end @@ -32,7 +34,7 @@ module Admin before { another_tag; tag } it "loads alls tags but not the one editing" do - alchemy_get :edit, id: tag.id + get :edit, params: {id: tag.id} expect(assigns(:tags)).to include(another_tag) expect(assigns(:tags)).not_to include(tag) end @@ -42,7 +44,7 @@ module Admin let(:tag) { ActsAsTaggableOn::Tag.create(name: 'Sputz') } it "changes tags name" do - alchemy_put :update, id: tag.id, tag: {name: 'Foo'} + put :update, params: {id: tag.id, tag: {name: 'Foo'}} expect(response).to redirect_to(admin_tags_path) expect(tag.reload.name).to eq('Foo') end @@ -53,7 +55,7 @@ module Admin it "replaces tag with other tag" do expect(Alchemy::Tag).to receive(:replace) expect_any_instance_of(ActsAsTaggableOn::Tag).to receive(:destroy) - alchemy_put :update, id: tag.id, tag: {merge_to: another_tag.id} + put :update, params: {id: tag.id, tag: {merge_to: another_tag.id}} expect(response).to redirect_to(admin_tags_path) end end diff --git a/spec/controllers/alchemy/admin/trash_controller_spec.rb b/spec/controllers/alchemy/admin/trash_controller_spec.rb index 86c0da85aa..181995c2a1 100644 --- a/spec/controllers/alchemy/admin/trash_controller_spec.rb +++ b/spec/controllers/alchemy/admin/trash_controller_spec.rb @@ -3,6 +3,8 @@ module Alchemy module Admin describe TrashController do + routes { Alchemy::Engine.routes } + render_views let(:alchemy_page) { create(:alchemy_page, :public) } @@ -14,13 +16,13 @@ module Admin } it "should hold trashed elements" do - alchemy_get :index, page_id: alchemy_page.id + get :index, params: {page_id: alchemy_page.id} expect(response.body).to have_selector("#element_#{element.id}.element-editor") end it "should not hold elements that are not trashed" do element = create(:alchemy_element, page: alchemy_page, public: false) - alchemy_get :index, page_id: alchemy_page.id + get :index, params: {page_id: alchemy_page.id} expect(response.body).not_to have_selector("#element_#{element.id}.element-editor") end @@ -34,7 +36,7 @@ module Admin end it "unique elements should be draggable" do - alchemy_get :index, page_id: alchemy_page.id + get :index, params: {page_id: alchemy_page.id} expect(response.body).to have_selector("#element_#{trashed.id}.element-editor.draggable") end end @@ -49,7 +51,7 @@ module Admin end it "unique elements should not be draggable" do - alchemy_get :index, page_id: page.id + get :index, params: {page_id: page.id} expect(response.body).to have_selector("#element_#{trashed.id}.element-editor.not-draggable") end end @@ -58,7 +60,7 @@ module Admin describe "#clear" do it "should destroy all containing elements" do expect(Element.trashed).not_to be_empty - alchemy_xhr :post, :clear, page_id: alchemy_page.id + post :clear, params: {page_id: alchemy_page.id}, xhr: true expect(Element.trashed).to be_empty end end diff --git a/spec/controllers/alchemy/api/contents_controller_spec.rb b/spec/controllers/alchemy/api/contents_controller_spec.rb index feefea985e..7d05c8660d 100644 --- a/spec/controllers/alchemy/api/contents_controller_spec.rb +++ b/spec/controllers/alchemy/api/contents_controller_spec.rb @@ -2,13 +2,15 @@ module Alchemy describe Api::ContentsController do + routes { Alchemy::Engine.routes } + describe '#index' do let!(:page) { create(:alchemy_page) } let!(:element) { create(:alchemy_element, page: page) } let!(:content) { create(:alchemy_content, element: element) } it "returns all public contents as json objects" do - alchemy_get :index, format: :json + get :index, params: {format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -24,7 +26,7 @@ module Alchemy let!(:other_content) { create(:alchemy_content, element: other_element) } it "returns only contents from this element" do - alchemy_get :index, element_id: other_element.id, format: :json + get :index, params: {element_id: other_element.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -39,7 +41,7 @@ module Alchemy context 'with empty element_id' do it "returns all contents" do - alchemy_get :index, element_id: element.id, format: :json + get :index, params: {element_id: element.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -63,7 +65,7 @@ module Alchemy end it "returns content as json" do - alchemy_get :show, id: content.id, format: :json + get :show, params: {id: content.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -77,7 +79,7 @@ module Alchemy let(:page) { create(:alchemy_page, restricted: true) } it "responds with 403" do - alchemy_get :show, id: content.id, format: :json + get :show, params: {id: content.id, format: :json} expect(response.content_type).to eq('application/json') expect(response.status).to eq(403) @@ -96,7 +98,7 @@ module Alchemy let!(:content) { create(:alchemy_content, element: element) } it 'returns the named content from element with given id.' do - alchemy_get :show, element_id: element.id, name: content.name, format: :json + get :show, params: {element_id: element.id, name: content.name, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -109,7 +111,7 @@ module Alchemy context 'with empty element_id or name param' do it 'returns 404 error.' do - alchemy_get :show, element_id: '', name: '', format: :json + get :show, params: {element_id: '', name: '', format: :json} expect(response.status).to eq(404) expect(response.content_type).to eq('application/json') diff --git a/spec/controllers/alchemy/api/elements_controller_spec.rb b/spec/controllers/alchemy/api/elements_controller_spec.rb index a47a96d71f..c6fad671fe 100644 --- a/spec/controllers/alchemy/api/elements_controller_spec.rb +++ b/spec/controllers/alchemy/api/elements_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe Api::ElementsController do + routes { Alchemy::Engine.routes } + describe '#index' do let(:page) { create(:alchemy_page, :public) } @@ -10,7 +12,7 @@ module Alchemy end it "returns all public elements as json objects" do - alchemy_get :index, format: :json + get :index, params: {format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -26,7 +28,7 @@ module Alchemy let!(:other_element) { create(:alchemy_element, page: other_page) } it "returns only elements from this page" do - alchemy_get :index, page_id: other_page.id, format: :json + get :index, params: {page_id: other_page.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -41,7 +43,7 @@ module Alchemy context 'with empty page_id param' do it "returns all elements" do - alchemy_get :index, page_id: '', format: :json + get :index, params: {page_id: '', format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -57,7 +59,7 @@ module Alchemy let!(:other_element) { create(:alchemy_element, page: page, name: 'news') } it "returns only elements named like this." do - alchemy_get :index, named: 'news', format: :json + get :index, params: {named: 'news', format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -72,7 +74,7 @@ module Alchemy context 'with empty named param' do it "returns all elements" do - alchemy_get :index, named: '', format: :json + get :index, params: {named: '', format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -94,7 +96,7 @@ module Alchemy end it "returns element as json" do - alchemy_get :show, id: element.id, format: :json + get :show, params: {id: element.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -108,7 +110,7 @@ module Alchemy let(:page) { build_stubbed(:alchemy_page, restricted: true) } it "responds with 403" do - alchemy_get :show, id: element.id, format: :json + get :show, params: {id: element.id, format: :json} expect(response.status).to eq(403) expect(response.content_type).to eq('application/json') diff --git a/spec/controllers/alchemy/api/pages_controller_spec.rb b/spec/controllers/alchemy/api/pages_controller_spec.rb index b28948b0d7..22b1e7b2cc 100644 --- a/spec/controllers/alchemy/api/pages_controller_spec.rb +++ b/spec/controllers/alchemy/api/pages_controller_spec.rb @@ -2,11 +2,13 @@ module Alchemy describe Api::PagesController do + routes { Alchemy::Engine.routes } + describe '#index' do let!(:page) { create(:alchemy_page, :public) } it "returns all public pages as json objects" do - alchemy_get :index, format: :json + get :index, params: {format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -21,7 +23,7 @@ module Alchemy let!(:other_page) { create(:alchemy_page, :public, page_layout: 'news') } it "returns only page with this page layout" do - alchemy_get :index, {page_layout: 'news', format: :json} + get :index, params: {page_layout: 'news', format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -35,7 +37,7 @@ module Alchemy context 'with empty string as page_layout' do it "returns all pages" do - alchemy_get :index, {page_layout: '', format: :json} + get :index, params: {page_layout: '', format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -52,7 +54,7 @@ module Alchemy let!(:page) { create(:alchemy_page, :public, page_layout: 'contact') } it "returns all pages as nested json tree without admin related infos", :aggregate_failures do - alchemy_get :nested, format: :json + get :nested, params: {format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -80,7 +82,7 @@ module Alchemy end it "returns all pages as nested json tree with admin related infos", :aggregate_failures do - alchemy_get :nested, format: :json + get :nested, params: {format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -105,7 +107,7 @@ module Alchemy context "when a page_id is passed" do it 'returns all pages as nested json from this page only' do - alchemy_get :nested, page_id: page.id, format: :json + get :nested, params: {page_id: page.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -119,7 +121,7 @@ module Alchemy context "when `elements=true` is passed" do it 'returns all pages as nested json tree with elements included' do - alchemy_get :nested, elements: 'true', format: :json + get :nested, params: {elements: 'true', format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -136,7 +138,7 @@ module Alchemy end it 'returns all pages as nested json tree with only these elements included' do - alchemy_get :nested, elements: 'headline,text', format: :json + get :nested, params: {elements: 'headline,text', format: :json} result = JSON.parse(response.body) @@ -158,7 +160,7 @@ module Alchemy end it "returns page as json" do - alchemy_get :show, {urlname: page.urlname, format: :json} + get :show, params: {urlname: page.urlname, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -172,7 +174,7 @@ module Alchemy let(:page) { build_stubbed(:alchemy_page, restricted: true, urlname: 'a-page') } it "responds with 403" do - alchemy_get :show, {urlname: page.urlname, format: :json} + get :show, params: {urlname: page.urlname, format: :json} expect(response.status).to eq(403) expect(response.content_type).to eq('application/json') @@ -188,7 +190,7 @@ module Alchemy let(:page) { build_stubbed(:alchemy_page, urlname: 'a-page') } it "responds with 403" do - alchemy_get :show, {urlname: page.urlname, format: :json} + get :show, params: {urlname: page.urlname, format: :json} expect(response.status).to eq(403) expect(response.content_type).to eq('application/json') @@ -203,7 +205,7 @@ module Alchemy context 'requesting an unknown page' do it "responds with 404" do - alchemy_get :show, {urlname: 'not-existing', format: :json} + get :show, params: {urlname: 'not-existing', format: :json} expect(response.status).to eq(404) expect(response.content_type).to eq('application/json') @@ -218,7 +220,7 @@ module Alchemy let(:page) { create(:alchemy_page, :public) } it "responds with 404" do - alchemy_get :show, {urlname: page.urlname, locale: 'na', format: :json} + get :show, params: {urlname: page.urlname, locale: 'na', format: :json} expect(response.status).to eq(404) end end @@ -228,7 +230,7 @@ module Alchemy let(:page) { create(:alchemy_page, :public) } it "responds with json" do - alchemy_get :show, {id: page.id, format: :json} + get :show, params: {id: page.id, format: :json} expect(response.status).to eq(200) expect(response.content_type).to eq('application/json') @@ -248,7 +250,7 @@ module Alchemy context 'when a locale is given' do it 'renders the page related to its language' do - alchemy_get :show, {urlname: "same-name", locale: klingon_page.language_code, format: :json} + get :show, params: {urlname: "same-name", locale: klingon_page.language_code, format: :json} result = JSON.parse(response.body) expect(result['id']).to eq(klingon_page.id) end @@ -256,7 +258,7 @@ module Alchemy context 'when no locale is given' do it 'renders the page of the default language' do - alchemy_get :show, {urlname: "same-name", format: :json} + get :show, params: {urlname: "same-name", format: :json} result = JSON.parse(response.body) expect(result['id']).to eq(english_page.id) end diff --git a/spec/controllers/alchemy/attachments_controller_spec.rb b/spec/controllers/alchemy/attachments_controller_spec.rb index f23b839973..c8dbbe9007 100644 --- a/spec/controllers/alchemy/attachments_controller_spec.rb +++ b/spec/controllers/alchemy/attachments_controller_spec.rb @@ -2,10 +2,12 @@ module Alchemy describe AttachmentsController do + routes { Alchemy::Engine.routes } + let(:attachment) { build_stubbed(:alchemy_attachment) } it "should raise ActiveRecord::RecordNotFound for requesting not existing attachments" do - expect { alchemy_get :download, id: 0 }.to raise_error(ActiveRecord::RecordNotFound) + expect { get :download, params: {id: 0} }.to raise_error(ActiveRecord::RecordNotFound) end context 'with public attachment' do @@ -14,25 +16,25 @@ module Alchemy end it "sends download as attachment." do - alchemy_get :download, id: attachment.id + get :download, params: {id: attachment.id} expect(response.status).to eq(200) expect(response.headers['Content-Disposition']).to match(/attachment/) end it "sends download inline." do - alchemy_get :show, id: attachment.id + get :show, params: {id: attachment.id} expect(response.status).to eq(200) expect(response.headers['Content-Disposition']).to match(/inline/) end context "adds Content-Length to header" do it "when downloading attachment" do - alchemy_get :download, id: attachment.id + get :download, params: {id: attachment.id} expect(response.headers['Content-Length']).to eq(attachment.file_size.to_s) end it "when showing attachment" do - alchemy_get :show, id: attachment.id + get :show, params: {id: attachment.id} expect(response.headers['Content-Length']).to eq(attachment.file_size.to_s) end end @@ -46,13 +48,13 @@ module Alchemy context 'as anonymous user' do it "should not be possible to download attachments from restricted pages" do - alchemy_get :download, id: attachment.id + get :download, params: {id: attachment.id} expect(response.status).to eq(302) expect(response).to redirect_to(Alchemy.login_path) end it "should not be possible to see attachments from restricted pages" do - alchemy_get :show, id: attachment.id + get :show, params: {id: attachment.id} expect(response.status).to eq(302) expect(response).to redirect_to(Alchemy.login_path) end @@ -62,12 +64,12 @@ module Alchemy before { authorize_user(build(:alchemy_dummy_user)) } it "should be possible to download attachments from restricted pages" do - alchemy_get :download, id: attachment.id + get :download, params: {id: attachment.id} expect(response.status).to eq(200) end it "should be possible to see attachments from restricted pages" do - alchemy_get :show, id: attachment.id + get :show, params: {id: attachment.id} expect(response.status).to eq(200) end end diff --git a/spec/controllers/alchemy/elements_controller_spec.rb b/spec/controllers/alchemy/elements_controller_spec.rb index be75dd50b3..53274716f6 100644 --- a/spec/controllers/alchemy/elements_controller_spec.rb +++ b/spec/controllers/alchemy/elements_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe ElementsController do + routes { Alchemy::Engine.routes } + let(:public_page) { create(:alchemy_page, :public) } let(:element) { create(:alchemy_element, page: public_page, name: 'download') } let(:restricted_page) { create(:alchemy_page, :public, restricted: true) } @@ -9,28 +11,28 @@ module Alchemy describe '#show' do it "should render available elements" do - alchemy_get :show, id: element.id + get :show, params: {id: element.id} expect(response.status).to eq(200) end it "should raise ActiveRecord::RecordNotFound error for trashed elements" do element.trash! expect { - alchemy_get :show, id: element.id + get :show, params: {id: element.id} }.to raise_error(ActiveRecord::RecordNotFound) end it "should raise ActiveRecord::RecordNotFound error for unpublished elements" do element.update_attributes(public: false) expect { - alchemy_get :show, id: element.id + get :show, params: {id: element.id} }.to raise_error(ActiveRecord::RecordNotFound) end context "for guest user" do it "should raise ActiveRecord::RecordNotFound error for elements of restricted pages" do expect { - alchemy_get :show, id: restricted_element.id + get :show, params: {id: restricted_element.id} }.to raise_error(ActiveRecord::RecordNotFound) end end @@ -39,7 +41,7 @@ module Alchemy before { authorize_user(build(:alchemy_dummy_user)) } it "should render elements of restricted pages" do - alchemy_get :show, id: restricted_element.id + get :show, params: {id: restricted_element.id} expect(response.status).to eq(200) end end diff --git a/spec/controllers/alchemy/messages_controller_spec.rb b/spec/controllers/alchemy/messages_controller_spec.rb index cce0401108..021ea01e5a 100644 --- a/spec/controllers/alchemy/messages_controller_spec.rb +++ b/spec/controllers/alchemy/messages_controller_spec.rb @@ -2,6 +2,8 @@ module Alchemy describe MessagesController do + routes { Alchemy::Engine.routes } + let(:page) { mock_model('Page') } before do @@ -13,14 +15,14 @@ module Alchemy let(:page) { mock_model('Page', {urlname: 'contact', page_layout: 'contact'}) } it "should redirect to @page" do - expect(alchemy_get(:index)).to redirect_to(show_page_path(urlname: page.urlname)) + expect(get(:index)).to redirect_to(show_page_path(urlname: page.urlname)) end end describe "#new" do it "should render the alchemy/pages/show template" do - alchemy_get :new - expect(alchemy_get(:new)).to render_template('alchemy/pages/show') + get :new + expect(get(:new)).to render_template('alchemy/pages/show') end end @@ -34,7 +36,7 @@ module Alchemy let(:message) { Message.new } it "should raise ActiveRecord::RecordNotFound if element of contactform could not be found" do - expect { alchemy_post :create }.to raise_error(ActiveRecord::RecordNotFound) + expect { post :create }.to raise_error(ActiveRecord::RecordNotFound) end context "if validation of message" do @@ -50,7 +52,7 @@ module Alchemy end it "should render 'alchemy/pages/show' template" do - expect(alchemy_post(:create)).to render_template('alchemy/pages/show') + expect(post(:create)).to render_template('alchemy/pages/show') end end @@ -62,7 +64,7 @@ module Alchemy it "Messages should call Messages#contact_form_mail to send the email" do expect(MessagesMailer).to receive(:contact_form_mail) - alchemy_post :create + post :create end describe '#mail_to' do @@ -75,7 +77,7 @@ module Alchemy it "returns the ingredient" do expect(MessagesMailer).to receive(:contact_form_mail).with(message, 'peter@schroeder.de', '', '') - alchemy_post :create + post :create end end @@ -88,7 +90,7 @@ module Alchemy it "returns the config value" do expect(MessagesMailer).to receive(:contact_form_mail).with(message, 'your.mail@your-domain.com', '', '') - alchemy_post :create + post :create end end end @@ -103,7 +105,7 @@ module Alchemy it "returns the ingredient" do expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', 'peter@schroeder.de', '') - alchemy_post :create + post :create end end @@ -116,7 +118,7 @@ module Alchemy it "returns the config value" do expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', 'your.mail@your-domain.com', '') - alchemy_post :create + post :create end end end @@ -131,7 +133,7 @@ module Alchemy it "returns the ingredient" do expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', '', 'A new message') - alchemy_post :create + post :create end end @@ -144,7 +146,7 @@ module Alchemy it "returns the config value" do expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', '', 'A new contact form message') - alchemy_post :create + post :create end end end @@ -157,7 +159,7 @@ module Alchemy it "should redirect to the given urlname" do expect( - alchemy_post(:create) + post(:create) ).to redirect_to(show_page_path(urlname: 'success-page')) end end @@ -175,7 +177,7 @@ module Alchemy it "redirect to the given success page" do expect( - alchemy_post(:create) + post(:create) ).to redirect_to(show_page_path(urlname: 'mailer-config-success-page')) end end @@ -191,7 +193,7 @@ module Alchemy it "should redirect to the language root page" do allow(Language).to receive(:current).and_return(language) expect( - alchemy_post(:create) + post(:create) ).to redirect_to(show_page_path(urlname: 'lang-root')) end end diff --git a/spec/controllers/alchemy/on_page_layout_mixin_spec.rb b/spec/controllers/alchemy/on_page_layout_mixin_spec.rb index 155521d6d5..9cf7ae6723 100644 --- a/spec/controllers/alchemy/on_page_layout_mixin_spec.rb +++ b/spec/controllers/alchemy/on_page_layout_mixin_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' RSpec.describe Alchemy::PagesController, 'OnPageLayout mixin', type: :controller do + routes { Alchemy::Engine.routes } + before(:all) do ApplicationController.send(:extend, Alchemy::OnPageLayout) end @@ -21,7 +23,7 @@ %w(standard news).each do |page_layout| it "runs callback on #{page_layout} layout" do page = create(:alchemy_page, :public, page_layout: page_layout) - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:on_all_layouts)).to eq(page_layout) end end @@ -32,7 +34,7 @@ it "runs callback on #{page_layout} layout" do create(:alchemy_page, :language_root, page_layout: page_layout) - alchemy_get :index + get :index expect(assigns(:on_all_layouts)).to eq(page_layout) end end @@ -53,7 +55,7 @@ let(:page) { create(:alchemy_page, :public, page_layout: 'standard') } it 'runs the callback' do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_standard)).to eq(true) end end @@ -62,7 +64,7 @@ let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } it 'runs the callback' do - alchemy_get :index + get :index expect(assigns(:successful_for_standard)).to eq(true) end end @@ -73,7 +75,7 @@ context "for show action" do it "doesn't run the callback" do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_standard)).to eq(nil) end end @@ -82,7 +84,7 @@ let!(:page) { create(:alchemy_page, :language_root, page_layout: 'news') } it "doesn't run the callback" do - alchemy_get :index + get :index expect(assigns(:successful_for_standard)).to eq(nil) end end @@ -107,7 +109,7 @@ it "runs both callbacks for #{page_layout} layout" do page = create(:alchemy_page, :public, page_layout: page_layout) - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:urlname)).to eq(page.urlname) end end @@ -130,7 +132,7 @@ it "runs both callbacks on #{page_layout} layout" do create(:alchemy_page, :language_root, page_layout: page_layout) - alchemy_get :index + get :index expect(assigns(:page_layout)).to eq(page_layout) end end @@ -152,7 +154,7 @@ context "for show action" do it 'runs both callbacks' do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_standard_first)).to eq(true) expect(assigns(:successful_for_standard_second)).to eq(true) end @@ -162,7 +164,7 @@ let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } it 'runs both callbacks' do - alchemy_get :index + get :index expect(assigns(:successful_for_standard_first)).to eq(true) expect(assigns(:successful_for_standard_second)).to eq(true) end @@ -180,7 +182,7 @@ context 'for show action' do it 'evaluates the given block' do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_callback_method)).to eq(true) end end @@ -189,7 +191,7 @@ let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } it 'evaluates the given block' do - alchemy_get :index + get :index expect(assigns(:successful_for_callback_method)).to eq(true) end end @@ -208,7 +210,7 @@ def run_method context 'for show action' do it 'runs the given callback method' do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_callback_method)).to eq(true) end end @@ -217,7 +219,7 @@ def run_method let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } it 'runs the given callback method' do - alchemy_get :index + get :index expect(assigns(:successful_for_callback_method)).to eq(true) end end @@ -246,7 +248,7 @@ def run_method it 'evaluates the given callback on both page_layouts for show action' do page = create(:alchemy_page, :public, page_layout: page_layout) - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(assigns(:successful)).to eq(page_layout) end end @@ -255,7 +257,7 @@ def run_method it 'evaluates the given callback on both page_layouts for index action' do create(:alchemy_page, :language_root, page_layout: page_layout) - alchemy_get :index + get :index expect(assigns(:successful)).to eq(page_layout) end end @@ -293,6 +295,8 @@ def index end RSpec.describe Alchemy::Admin::PagesController, 'OnPageLayout mixin', type: :controller do + routes { Alchemy::Engine.routes } + before(:all) do ApplicationController.send(:extend, Alchemy::OnPageLayout) end @@ -311,14 +315,14 @@ def index let(:page) { create(:alchemy_page, page_layout: 'standard') } it 'callback also runs' do - alchemy_get :show, id: page.id + get :show, params: {id: page.id} expect(assigns(:successful_for_alchemy_admin_pages_controller)).to be(true) end end context "for index action" do it 'does not run callback' do - alchemy_get :index + get :index expect(assigns(:successful_for_alchemy_admin_pages_controller)).to be(nil) end end diff --git a/spec/controllers/alchemy/pages_controller_spec.rb b/spec/controllers/alchemy/pages_controller_spec.rb index 1d1ffe4b88..3a8e8561f1 100644 --- a/spec/controllers/alchemy/pages_controller_spec.rb +++ b/spec/controllers/alchemy/pages_controller_spec.rb @@ -3,6 +3,8 @@ module Alchemy describe PagesController do + routes { Alchemy::Engine.routes } + let(:default_language) { Language.default } let(:default_language_root) do @@ -30,17 +32,17 @@ module Alchemy end it 'renders :show template' do - expect(alchemy_get(:index)).to render_template(:show) + expect(get(:index)).to render_template(:show) end context 'requesting nothing' do it 'loads default language root page' do - alchemy_get :index + get :index expect(assigns(:page)).to eq(default_language_root) end it 'sets @root_page to default language root' do - alchemy_get(:index) + get :index expect(assigns(:root_page)).to eq(default_language_root) end @@ -56,7 +58,7 @@ module Alchemy it 'raises routing error (404)' do expect { - alchemy_get :index + get :index }.to raise_error(ActionController::RoutingError) end @@ -70,7 +72,7 @@ module Alchemy it 'raises routing error (404) and no "undefined method for nil" error' do expect { - alchemy_get :index + get :index }.to raise_error(ActionController::RoutingError) end end @@ -87,7 +89,7 @@ module Alchemy end it 'loads this page' do - alchemy_get :index + get :index expect(assigns(:page)).to eq(public_child) end end @@ -103,7 +105,7 @@ module Alchemy end it 'loads this page' do - alchemy_get :index + get :index expect(assigns(:page)).to eq(public_child) end end @@ -115,7 +117,7 @@ module Alchemy it 'raises routing error (404)' do expect { - alchemy_get :index + get :index }.to raise_error(ActionController::RoutingError) end end @@ -140,12 +142,12 @@ module Alchemy end it 'loads the root page of that language' do - alchemy_get :index, locale: 'de' + get :index, params: {locale: 'de'} expect(assigns(:page)).to eq(startseite) end it 'sets @root_page to root page of that language' do - alchemy_get :index, locale: 'de' + get :index, params: {locale: 'de'} expect(assigns(:root_page)).to eq(startseite) end end @@ -160,7 +162,7 @@ module Alchemy it "renders 404" do expect { - alchemy_get :show, urlname: not_yet_public.urlname + get :show, params: {urlname: not_yet_public.urlname} }.to raise_error(ActionController::RoutingError) end end @@ -175,7 +177,7 @@ module Alchemy it "renders 404" do expect { - alchemy_get :show, urlname: no_longer_public.urlname + get :show, params: {urlname: no_longer_public.urlname} }.to raise_error(ActionController::RoutingError) end end @@ -189,7 +191,7 @@ module Alchemy end it "renders page" do - alchemy_get :show, urlname: still_public_page.urlname + get :show, params: {urlname: still_public_page.urlname} expect(response).to be_success end end @@ -203,7 +205,7 @@ module Alchemy end it "renders page" do - alchemy_get :show, urlname: still_public_page.urlname + get :show, params: {urlname: still_public_page.urlname} expect(response).to be_success end end @@ -212,20 +214,20 @@ module Alchemy render_views it "should render a rss feed" do - alchemy_get :show, urlname: page.urlname, format: :rss + get :show, params: {urlname: page.urlname, format: :rss} expect(response.content_type).to eq('application/rss+xml') end it "should include content" do page.elements.first.content_by_name('news_headline').essence.update_attributes({body: 'Peters Petshop'}) - alchemy_get :show, urlname: 'news', format: :rss + get :show, params: {urlname: 'news', format: :rss} expect(response.body).to match /Peters Petshop/ end end context "requested for a page that does not contain a feed" do it "should render xml 404 error" do - alchemy_get :show, urlname: default_language_root.urlname, format: :rss + get :show, params: {urlname: default_language_root.urlname, format: :rss} expect(response.status).to eq(404) end end @@ -233,7 +235,7 @@ module Alchemy describe "Layout rendering" do context "with ajax request" do it "should not render a layout" do - alchemy_xhr :get, :show, urlname: page.urlname + get :show, params: {urlname: page.urlname}, xhr: true expect(response).to render_template(:show) expect(response).not_to render_template(layout: 'application') end @@ -255,7 +257,7 @@ module Alchemy context "with correct levelnames in params" do it "should show the requested page" do - alchemy_get :show, {urlname: 'catalog/products/screwdriver'} + get :show, params: {urlname: 'catalog/products/screwdriver'} expect(response.status).to eq(200) expect(response.body).to have_content("screwdriver") end @@ -264,7 +266,7 @@ module Alchemy context "with incorrect levelnames in params" do it "should render a 404 page" do expect { - alchemy_get :show, {urlname: 'catalog/faqs/screwdriver'} + get :show, params: {urlname: 'catalog/faqs/screwdriver'} }.to raise_error(ActionController::RoutingError) end end @@ -273,7 +275,7 @@ module Alchemy context "when a non-existent page is requested" do it "should rescue a RoutingError with rendering a 404 page." do expect { - alchemy_get :show, {urlname: 'doesntexist'} + get :show, params: {urlname: 'doesntexist'} }.to raise_error(ActionController::RoutingError) end end @@ -286,12 +288,12 @@ module Alchemy context "with no lang parameter present" do it "should store defaults language id in the session." do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(controller.session[:alchemy_language_id]).to eq(Language.default.id) end it "should store default language as class var." do - alchemy_get :show, urlname: page.urlname + get :show, params: {urlname: page.urlname} expect(Language.current).to eq(Language.default) end end @@ -313,7 +315,7 @@ module Alchemy end it 'renders the page related to its language' do - alchemy_get :show, {urlname: "same-name", locale: klingon_page.language_code} + get :show, params: {urlname: "same-name", locale: klingon_page.language_code} expect(response.body).to have_content("klingon page") end end diff --git a/spec/requests/alchemy/admin/pages_controller_spec.rb b/spec/requests/alchemy/admin/pages_controller_spec.rb index d034e76501..65062d3e55 100644 --- a/spec/requests/alchemy/admin/pages_controller_spec.rb +++ b/spec/requests/alchemy/admin/pages_controller_spec.rb @@ -219,7 +219,7 @@ module Alchemy content_pages travel_to(Time.current) do - xhr :post, flush_admin_pages_path + post flush_admin_pages_path, xhr: true # Reloading because published_at was directly updated in the database. content_pages.map(&:reload) content_pages.each do |page| @@ -232,7 +232,7 @@ module Alchemy layout_pages travel_to(Time.current) do - xhr :post, flush_admin_pages_path + post flush_admin_pages_path, xhr: true # Reloading because published_at was directly updated in the database. layout_pages.map(&:reload) layout_pages.each do |page| @@ -253,7 +253,7 @@ module Alchemy end it "should load all pages from clipboard" do - xhr :get, new_admin_page_path(page_id: page.id) + get new_admin_page_path(page_id: page.id), xhr: true expect(assigns(:clipboard_items)).to be_kind_of(Array) end end @@ -299,7 +299,7 @@ module Alchemy let(:set_of_pages) { [page_item_1] } it "stores the new order" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true page_1.reload expect(page_1.descendants).to eq([page_2, page_3]) end @@ -310,7 +310,7 @@ module Alchemy end it "updates the pages urlnames" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true [page_1, page_2, page_3].map(&:reload) expect(page_1.urlname).to eq(page_1.slug.to_s) expect(page_2.urlname).to eq("#{page_1.slug}/#{page_2.slug}") @@ -328,7 +328,7 @@ module Alchemy end it "does not use this pages slug in urlnames of descendants" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true [page_1, page_2, page_3].map(&:reload) expect(page_1.urlname).to eq(page_1.slug.to_s) expect(page_2.urlname).to eq("#{page_1.slug}/#{page_2.slug}") @@ -347,7 +347,7 @@ module Alchemy end it "does not use this pages slug in urlnames of descendants" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true [page_1, page_2, page_3].map(&:reload) expect(page_3.urlname).to eq("#{page_1.slug}/#{page_3.slug}") end @@ -365,7 +365,7 @@ module Alchemy end it "updates restricted status of descendants" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true page_3.reload expect(page_3.restricted).to be_truthy end @@ -382,19 +382,19 @@ module Alchemy it "does not raise error" do expect { - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true }.not_to raise_error end it "still generates the correct urlname on page_3" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true [page_1, page_2, page_3].map(&:reload) expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}") end end it "creates legacy urls" do - xhr :post, order_admin_pages_path(set: set_of_pages.to_json) + post order_admin_pages_path(set: set_of_pages.to_json), xhr: true [page_2, page_3].map(&:reload) expect(page_2.legacy_urls.size).to eq(1) expect(page_3.legacy_urls.size).to eq(1) @@ -407,7 +407,7 @@ module Alchemy let(:page) { create(:alchemy_page, name: 'Foobar', urlname: 'foobar') } it "should always show the slug" do - xhr :get, configure_admin_page_path(page) + get configure_admin_page_path(page), xhr: true expect(response.body).to match /value="foobar"/ end end @@ -506,10 +506,10 @@ module Alchemy it "should call Page#copy_and_paste" do expect(Page).to receive(:copy_and_paste). with(page_in_clipboard, parent, page_params[:name]) - xhr :post, admin_pages_path( + post admin_pages_path( page: page_params, paste_from_clipboard: page_in_clipboard.id - ) + ), xhr: true end end end @@ -657,7 +657,7 @@ module Alchemy end it "should also remove the page from clipboard" do - xhr :delete, admin_page_path(page) + delete admin_page_path(page), xhr: true expect(clipboard).to be_empty end end @@ -709,7 +709,7 @@ module Alchemy it "should fold the page" do expect(page).to receive(:fold!).with(user.id, true).and_return(true) - xhr :post, fold_admin_page_path(page) + post fold_admin_page_path(page), xhr: true end end @@ -718,13 +718,13 @@ module Alchemy it "should unfold the page" do expect(page).to receive(:fold!).with(user.id, false).and_return(true) - xhr :post, fold_admin_page_path(page) + post fold_admin_page_path(page), xhr: true end end end describe '#unlock' do - subject { xhr :post, unlock_admin_page_path(page) } + subject { post unlock_admin_page_path(page), xhr: true } let(:page) { mock_model(Alchemy::Page, name: 'Best practices') } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index df5bcf1bdf..1b1e160ec8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -70,7 +70,6 @@ config.filter_run :focus config.include ActiveSupport::Testing::TimeHelpers config.include Alchemy::Engine.routes.url_helpers - config.include Alchemy::TestSupport::ControllerRequests, type: :controller config.include Alchemy::TestSupport::ConfigStubbing [:controller, :feature, :request].each do |type| config.include Alchemy::TestSupport::IntegrationHelpers, type: type