Skip to content

Commit

Permalink
Do not use deprecated xhr request spec helper
Browse files Browse the repository at this point in the history
The `xhr` request spec helper will be removed from Rails 5.1
  • Loading branch information
tvdeyen committed Aug 14, 2017
1 parent eec30eb commit cd92c1c
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions spec/requests/alchemy/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}")
Expand All @@ -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}")
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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') }

Expand Down

0 comments on commit cd92c1c

Please sign in to comment.