Skip to content

Commit

Permalink
Merge d779dba into 0f3ab13
Browse files Browse the repository at this point in the history
  • Loading branch information
anitagraham committed May 22, 2018
2 parents 0f3ab13 + d779dba commit b3395bb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
5 changes: 2 additions & 3 deletions core/spec/features/refinery/application_layout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ module Refinery
end

describe 'body' do
it "id is the page's canonical id" do
it "has an id that includes the page's canonical name" do
visit home_page.url

expect(page).to have_css 'body#home-page'
expect(page.find("body")[:id]).to eq "home-page"
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion pages/app/controllers/refinery/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class PagesController < ::ApplicationController

# This action is usually accessed with the root path, normally '/'
def home
if page.link_url.present? && page.link_url != "/"
redirect_to page.link_url, status: 301 and return
end
render_with_templates?
end

Expand Down Expand Up @@ -101,7 +104,7 @@ def action_page_finder
module Finders
class Home
def self.call(_params)
Refinery::Page.find_by link_url: "/"
Refinery::Page.find_by link_url: Refinery::Pages.home_page_path
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ Refinery::Pages.configure do |config|
# config.show_title_in_body = <%= Refinery::Pages.show_title_in_body.inspect %>

# You can add new HTML elements not already supported by Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS
# For more information on whitelist see ALLOWED_ELEMENTS
# For more information on whitelist see ALLOWED_ELEMENTS
# (https://github.com/flavorjones/loofah/blob/v2.0.3/lib/loofah/html5/whitelist.rb#L151)
# config.add_whitelist_elements = <%= Refinery::Pages.add_whitelist_elements.inspect %>

# You can add new HTML attributes not already supported by Loofah::HTML5::WhiteList::ALLOWED_ATTRIBUTES
# For more information on whitelist see ALLOWED_ATTRIBUTES
# For more information on whitelist see ALLOWED_ATTRIBUTES
# (https://github.com/flavorjones/loofah/blob/v2.0.3/lib/loofah/html5/whitelist.rb#L152)
# config.add_whitelist_attributes = <%= Refinery::Pages.add_whitelist_attributes.inspect %>

# You can configure the site so that the home page is a model-index page
# config.home_page_path = <%= Refinery::Pages.home_page_path.inspect %>

end
4 changes: 3 additions & 1 deletion pages/lib/refinery/pages/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Pages
:use_layout_templates, :page_title, :absolute_page_links, :types,
:auto_expand_admin_tree, :show_title_in_body,
:friendly_id_reserved_words, :layout_templates_pattern, :view_templates_pattern,
:add_whitelist_elements, :add_whitelist_attributes, :whitelist_elements, :whitelist_attributes
:add_whitelist_elements, :add_whitelist_attributes, :whitelist_elements, :whitelist_attributes,
:home_page_path

self.pages_per_dialog = 14
self.pages_per_admin_index = 20
Expand All @@ -25,6 +26,7 @@ module Pages
self.add_whitelist_elements = %w[ source track ]
# Note: "data-" attributes are whitelisted by default. See https://github.com/refinery/refinerycms/pull/3187
self.add_whitelist_attributes = %w[ kind srclang placeholder controls required ]
self.home_page_path = "/"


class << self
Expand Down
25 changes: 19 additions & 6 deletions pages/spec/controllers/refinery/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
module Refinery
describe PagesController, :type => :controller do
before do
FactoryBot.create(:page, :link_url => "/")
FactoryBot.create(:page, :title => "test")
FactoryBot.create(:page, link_url: "/")
FactoryBot.create(:page, title: "testing")
FactoryBot.create(:page, link_url: "/items")
end

describe "#home" do
it "renders home template" do
get :home
expect(response).to render_template("home")
context "when page path set to default ('/') " do
render_views
it "renders home template" do
get :home
expect(response).to render_template("home")
end
end

context "when home_page_path set to another path" do
it "redirects to the specified path" do
allow(Refinery::Pages).to receive(:home_page_path).and_return('/items')
get :home
expect(response).to redirect_to('/items')
end
end
end

describe "#show" do
render_views
it "renders show template" do
get :show, params: {path: "test"}
get :show, params: {path: "testing"}
expect(response).to render_template("show")
end
end
Expand Down
12 changes: 6 additions & 6 deletions pages/spec/features/refinery/admin/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def switch_page_form_locale(locale)
expect(page).to have_selector("#switch_locale_picker li.selected a##{locale.downcase}")
end


module Refinery
module Admin
describe "Pages", :type => :feature do
Expand All @@ -45,6 +46,7 @@ module Admin
end

context "when no pages" do

it "doesn't show reorder pages link" do
visit refinery.admin_pages_path

Expand Down Expand Up @@ -811,20 +813,18 @@ module Admin
describe "a page with a single locale" do
before do
allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :lv])
Page.create :title => 'First Page'
end
let(:first_page){Page.create title: 'First Page'}

it "can have a second locale added to it" do
visit refinery.admin_pages_path
visit refinery.edit_admin_page_path(first_page.id)

click_link "Add new page"
switch_page_form_locale "LV"

fill_in "Title", :with => "Brīva vieta reklāmai"
click_button "Save"

expect(page).to have_content("'Brīva vieta reklāmai' was successfully added.")
expect(Refinery::Page.count).to eq(2)
expect(page).to have_content("'Brīva vieta reklāmai' was successfully updated.")
expect(first_page.translations.count).to eq(2)
end
end

Expand Down

0 comments on commit b3395bb

Please sign in to comment.