Skip to content

Commit

Permalink
Merge pull request #2025 from tf/rails-7
Browse files Browse the repository at this point in the history
Rails 7.1 support
  • Loading branch information
tf authored Nov 14, 2023
2 parents 6878b9b + eb979bd commit 29aa97b
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 48 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@ jobs:
rspec-command: bin/rspec --tag ~js
install-audiowaveform: true

- engine-name: pageflow
ruby-version: 3.2
rails-version: "~> 7.1"
engine-directory: .
rspec-command: bin/rspec --tag ~js
install-audiowaveform: true

- engine-name: pageflow
ruby-version: 3.2
engine-directory: .
rspec-command: bin/rspec-with-retry --tag js

- engine-name: pageflow
ruby-version: 3.2
rails-version: "~> 7.1"
engine-directory: .
rspec-command: bin/rspec-with-retry --tag js

- engine-name: pageflow_paged
ruby-version: 3.2
engine-directory: entry_types/paged
plugin-name: pageflow_paged
rspec-command: bin/rspec

- engine-name: pageflow_paged
ruby-version: 3.2
rails-version: "~> 7.1"
engine-directory: entry_types/paged
plugin-name: pageflow_paged
rspec-command: bin/rspec
Expand All @@ -36,12 +56,29 @@ jobs:
plugin-name: pageflow_scrolled
rspec-command: bin/rspec --tag ~js

- engine-name: pageflow_scrolled
ruby-version: 3.2
rails-version: "~> 7.1"
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec --tag ~js

- engine-name: pageflow_scrolled
ruby-version: 3.2
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec-with-retry-on-timeout --tag js

- engine-name: pageflow_scrolled
ruby-version: 3.2
rails-version: "~> 7.1"
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec-with-retry-on-timeout --tag js

env:
PAGEFLOW_RAILS_VERSION: ${{ matrix.rails-version }}

services:
mysql:
image: mysql:5.7
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ gemspec
require File.expand_path('lib/pageflow/rails_version', File.dirname(__FILE__))
gem 'rails', Pageflow::RailsVersion.detect

gem 'ammeter', '~> 1.1', require: false

gem 'pageflow-support', path: 'spec/support'

gem 'spring-commands-rspec', group: :development
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pageflow/entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EntriesController < Pageflow::ApplicationController
def index
site = Site.for_request(request).with_home_url.first!

redirect_to(site.home_url)
redirect_to(site.home_url, allow_other_host: true)
end

def show
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/pageflow/revision_file_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module RevisionFileHelper
#
# @since 15.0
# @returns UsedFile
def find_file_in_entry(file_type, file_perma_id)
raise 'No entry of type PublishedEntry or DraftEntry set.' unless @entry.present?
@entry.find_file_by_perma_id(file_type, file_perma_id)
def find_file_in_entry(file_type, file_perma_id, entry = @entry)
raise 'No entry of type PublishedEntry or DraftEntry set.' unless entry.present?
entry.find_file_by_perma_id(file_type, file_perma_id)
end
end
end
4 changes: 2 additions & 2 deletions app/helpers/pageflow/social_share_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def social_share_meta_tags_for(target)
if target.is_a?(Page)
render('pageflow/social_share/page_meta_tags', entry: @entry, page: @entry.share_target)
else
render('pageflow/social_share/entry_meta_tags', entry: @entry)
render('pageflow/social_share/entry_meta_tags', entry: target)
end
end

Expand Down Expand Up @@ -55,7 +55,7 @@ def social_share_entry_description(entry)

def social_share_entry_image_tags(entry)
share_images = []
image_file = find_file_in_entry(ImageFile, entry.share_image_id)
image_file = find_file_in_entry(ImageFile, entry.share_image_id, entry)

if image_file
image_url = image_file.thumbnail_url(:medium)
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/pageflow/uploadable_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ module UploadableFile
end
end

# see https://github.com/rails/rails/issues/50048
def file_name
attachment_on_s3_file_name
end

def attachment
attachment_on_s3
end
Expand Down
2 changes: 1 addition & 1 deletion entry_types/paged/spec/support/config/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'database_cleaner'
require 'database_cleaner-active_record'

RSpec.configure do |config|
config.before(:suite) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ class EntriesController < ActionController::Base
helper FaviconHelper

def show
@entry = get_published_entry_from_env
@widget_scope = get_entry_mode_from_env
entry = get_published_entry_from_env

I18n.locale = @entry.locale
I18n.locale = entry.locale

render(
locals: {
entry: entry,
widget_scope: get_entry_mode_from_env
}
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module SeedHtmlHelper
def scrolled_editor_iframe_seed_html_script_tag(entry)
html = render(template: 'pageflow_scrolled/entries/show',
locals: {
:@entry => entry,
:@widget_scope => :editor,
:@skip_ssr => true,
:@skip_structured_data => true,
:@skip_feed_link_tags => true,
:@seed_options => {
entry: entry,
widget_scope: :editor,
skip_ssr: true,
skip_structured_data: true,
skip_feed_link_tags: true,
seed_options: {
skip_collections: true,
include_unused_additional_seed_data: true,
translations: {include_inline_editing: true}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<%= cache_scrolled_entry(entry: @entry, widget_scope: @widget_scope) do %>
<%= cache_scrolled_entry(entry: entry, widget_scope: widget_scope) do %>
<!DOCTYPE html>
<%= content_tag(:html, lang: @entry.locale, dir: text_direction(@entry.locale)) do %>
<%= content_tag(:html, lang: entry.locale, dir: text_direction(entry.locale)) do %>
<head>
<title><%= pretty_entry_title(@entry) %></title>
<title><%= pretty_entry_title(entry) %></title>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">


<%= social_share_meta_tags_for(@entry) %>
<%= meta_tags_for_entry(@entry) %>
<%= feed_link_tags_for_entry(@entry) unless @skip_feed_link_tags%>
<%= social_share_meta_tags_for(entry) %>
<%= meta_tags_for_entry(entry) %>
<%= feed_link_tags_for_entry(entry) unless local_assigns[:skip_feed_link_tags] %>

<%= scrolled_favicons_for_entry(@entry, entry_mode: @widget_scope) %>
<%= scrolled_favicons_for_entry(entry, entry_mode: widget_scope) %>

<%= javascript_include_tag 'pageflow_scrolled/legacy' %>
<%= scrolled_frontend_stylesheet_packs_tag(@entry, widget_scope: @widget_scope) %>
<%= scrolled_frontend_stylesheet_packs_tag(entry, widget_scope: widget_scope) %>

<%= scrolled_theme_properties_style_tag(@entry.theme) %>
<%= scrolled_theme_stylesheet_pack_tags(@entry.theme) %>
<%= scrolled_theme_properties_style_tag(entry.theme) %>
<%= scrolled_theme_stylesheet_pack_tags(entry.theme) %>

<%= render_widget_head_fragments(@entry, scope: @widget_scope) %>
<%= render_widget_head_fragments(entry, scope: widget_scope) %>

<% if Rails.env.development? %>
<script>
Expand All @@ -34,28 +34,28 @@
</script>
<% end %>

<% ssr_html = @skip_ssr ? '' : render_scrolled_entry(@entry) %>
<% ssr_html = local_assigns[:skip_ssr] ? '' : render_scrolled_entry(entry) %>

<% if !@skip_ssr && (params[:frontend] == 'v2' || @entry.feature_state('frontend_v2')) %>
<% if !local_assigns[:skip_ssr] && (params[:frontend] == 'v2' || entry.feature_state('frontend_v2')) %>
<%= generated_media_queries_tags_for(ssr_html) %>
<% end %>
</head>
<body>
<%= structured_data_for_entry(@entry) unless @skip_structured_data %>
<%= structured_data_for_entry(entry) unless local_assigns[:skip_structured_data] %>

<%= render 'pageflow_scrolled/entries/global_notices' %>

<div id="fullscreenRoot"></div>
<div id="root"><%= ssr_html %></div>

<div id='template-widget-container'>
<%= render_widgets(@entry, scope: @widget_scope, insert_point: :bottom_of_entry) %>
<%= render_widgets(entry, scope: widget_scope, insert_point: :bottom_of_entry) %>
</div>

<%= scrolled_webpack_public_path_script_tag %>
<%= scrolled_frontend_javascript_packs_tag(@entry, widget_scope: @widget_scope) %>
<%= scrolled_frontend_javascript_packs_tag(entry, widget_scope: widget_scope) %>

<%= scrolled_entry_json_seed_script_tag(@entry, @seed_options || {}) %>
<%= scrolled_entry_json_seed_script_tag(entry, local_assigns[:seed_options] || {}) %>
</body>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module PageflowScrolled
WebAppManifest = lambda do |entry|
EntriesController.renderer.render(
partial: 'manifest',
formats: 'json',
format: 'json',
locals: {
theme: entry.theme
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'database_cleaner'
require 'database_cleaner-active_record'

RSpec.configure do |config|
config.before(:suite) do
Expand Down
8 changes: 4 additions & 4 deletions pageflow.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |s|

s.require_paths = ['lib', 'entry_types/paged/lib', 'entry_types/scrolled/lib']

s.add_dependency 'rails', '~> 6.1.0'
s.add_dependency 'rails', Pageflow::RailsVersion.detect

# Framework for admin interface
s.add_dependency 'activeadmin', '~> 3.0'
Expand All @@ -37,7 +37,7 @@ Gem::Specification.new do |s|
#
# Pageflow::UserMixin depends on Devise internals. We therefore use
# a conservative version constraint.
s.add_dependency 'devise', '~> 4.7.3'
s.add_dependency 'devise', '~> 4.9.3'

# Faster JSON backend
s.add_dependency 'yajl-ruby', '~> 1.2'
Expand Down Expand Up @@ -150,7 +150,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'resque', '~> 1.25'
s.add_development_dependency 'resque-scheduler', '~> 4.10'

s.add_development_dependency 'ar_after_transaction', '~> 0.8.0'
s.add_development_dependency 'ar_after_transaction', '~> 0.10.0'

s.add_development_dependency 'redis', '~> 3.0'
s.add_development_dependency 'redis-namespace', '~> 1.5'
Expand Down Expand Up @@ -189,7 +189,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pundit-matchers', '~> 1.0'

# Clean database in integration tests
s.add_development_dependency 'database_cleaner', '~> 1.2'
s.add_development_dependency 'database_cleaner-active_record', '~> 2.1'

# Freeze time in tests
s.add_development_dependency 'timecop', '~> 0.7.1'
Expand Down
11 changes: 11 additions & 0 deletions spec/helpers/pageflow/revision_file_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ module Pageflow
expect(result).to eq(image_file)
end
end

it 'allows passing entry explicitly' do
entry = create(:entry)
revision = create(:revision, :published, entry: entry)
image_file = create(:image_file)
usage = create(:file_usage, revision: revision, file: image_file)
entry = PublishedEntry.new(entry)

result = helper.find_file_in_entry(ImageFile, usage.perma_id, entry)
expect(result).to eq(image_file)
end
end
end
end
11 changes: 11 additions & 0 deletions spec/helpers/pageflow/social_share_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

module Pageflow
describe SocialShareHelper do
describe '#social_share_meta_tags_for' do
it 'renders canonical url' do
entry = create(:entry, :published)
published_entry = PublishedEntry.new(entry)

result = helper.social_share_meta_tags_for(published_entry)

expect(result).to have_selector('link[rel=canonical]', visible: false)
end
end

describe '#social_share_entry_url' do
it 'returns share_url if present' do
entry = create(:entry, :published, published_revision_attributes: {
Expand Down
2 changes: 1 addition & 1 deletion spec/support/config/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'database_cleaner'
require 'database_cleaner-active_record'

RSpec.configure do |config|
config.before(:suite) do
Expand Down
6 changes: 5 additions & 1 deletion spec/support/helpers/stub_template_in_helper_specs.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
RSpec.configure do |config|
module StubTemplateTestHelper
def stub_template(hash)
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
if view.view_paths.respond_to?(:unshift)
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
else
view.lookup_context.prepend_view_paths([ActionView::FixtureResolver.new(hash)])
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/pageflow-support.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'resque', '~> 1.25'
s.add_runtime_dependency 'resque-scheduler', '~> 4.10'

s.add_runtime_dependency 'ar_after_transaction', '~> 0.8.0'
s.add_runtime_dependency 'ar_after_transaction', '~> 0.10.0'

s.add_runtime_dependency 'redis', '~> 3.0'
s.add_runtime_dependency 'redis-namespace', '~> 1.5'
Expand Down
4 changes: 2 additions & 2 deletions spec/support/pageflow/dummy/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def generate
if File.exist?(directory)
puts("Dummy directory #{directory} exists.")
else
system("bundle exec rails new #{directory} --skip-spring " \
system('SKIP_EAGER_LOAD=true ' \
"bundle exec rails new #{directory} --skip-spring " \
"--template #{template_path} #{rails_new_options}") ||
raise('Error generating dummy app.')
end

require(File.join(ENV['RAILS_ROOT'], 'config', 'environment'))
require('pageflow/dummy/config/pageflow')
end

def directory
Expand Down
3 changes: 0 additions & 3 deletions spec/support/pageflow/dummy/config/pageflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@
}
end
end

# Reconstruct current config to ensure config block above is used
Pageflow.configure!
Loading

0 comments on commit 29aa97b

Please sign in to comment.