pageflow-support 15.1.0.beta2 → 15.1.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06d9abcf1014cbcaea5c278133641205394068482222227b0647064cf60a99e2
4
- data.tar.gz: 7699ddf3ae947b35144c88709595064ae3478aa1645e012c6d9acc319f8a43c6
3
+ metadata.gz: 638a7e6f9dc580d1f7aba4aa8202ae9915c9511c76048418fd6759e5380b8365
4
+ data.tar.gz: ee215e8c1fe7f07045f493d6139d2cbf8f004abf3b3c947166e9c093e5a50929
5
5
  SHA512:
6
- metadata.gz: 322ddb75d16500e333627f947bb617fa187b61db5d48014811a2b10898ce6ba70afed4191a6fa703f2e8554049a42666708cbcb4517acdcc7cf2194dfc07fbe9
7
- data.tar.gz: 84f0915e94b18e8f53eab749232312baa3126b6760a2285c3fb4c9e5cc9ef583d751915640982fde056dacde6eab9e0f713bc9f8a845167ac74eca8cc2fd241e
6
+ metadata.gz: 319c08b425e75e48c7cf402d5c977b584b17e6e967c62e53c0819e76ad58b95c80b5939ca4e57b1a6a631511b7f6c1448c5bf4e5489bef37e58b76f48a553de2
7
+ data.tar.gz: 09ba6ebbfc6462c94c420f7471a5435982090edac0fac9ab01e6a2166bf41edc71ce0ecac7fe2cd74be2351b2fd7b9f647243b0daecdc37e8ddabcf36fe5eb90
@@ -0,0 +1,8 @@
1
+ module Pageflow
2
+ module EditLockTestHelpers
3
+ def acquire_edit_lock(user, entry)
4
+ edit_lock = FactoryBot.create(:edit_lock, user: user, entry: entry)
5
+ request.headers['X-Edit-Lock'] = edit_lock.id
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ require 'pageflow/edit_lock_test_helper'
2
+
3
+ module Pageflow
4
+ # Helpers to test controllers that include
5
+ # {Pageflow::EditorController}.
6
+ #
7
+ # @since 15.1
8
+ module EditorControllerTestHelper
9
+ extend ActiveSupport::Concern
10
+
11
+ include EditLockTestHelpers
12
+ include Devise::Test::ControllerHelpers
13
+
14
+ # Sign in with user that has permission to edit the entry and
15
+ # acquire an edit lock.
16
+ def authorize_for_editor_controller(entry)
17
+ user = FactoryBot.create(:user)
18
+ FactoryBot.create(:membership, user: user, entity: entry, role: :editor)
19
+
20
+ sign_in(user, scope: :user)
21
+ acquire_edit_lock(user, entry)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,50 @@
1
+ module Pageflow
2
+ # Helpers to test entry type controllers.
3
+ #
4
+ # @since 15.1
5
+ module EntriesControllerTestHelper
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ # Entry type controllers are delegated to by
10
+ # `Pagefow::EntriesController`. Therefore they do not have their
11
+ # own routes. Controller specs only allow calling actions that
12
+ # have a route. So we create a fake route to work aroung this.
13
+
14
+ controller_name = described_class.name.sub(/Controller$/, '').underscore
15
+
16
+ routes do
17
+ ActionDispatch::Routing::RouteSet.new.tap do |routes|
18
+ routes.draw do
19
+ get '/test/entry', to: "#{controller_name}#show"
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # Invoke an action of the entries controller with the request env
26
+ # set up just like when Pageflow delegates to the entry type's
27
+ # frontend app.
28
+ #
29
+ # @param action [Symbol] Name of the action to invoke
30
+ #
31
+ # @param entry [Entry] Entry to render.
32
+ #
33
+ # @param mode [:published|:preview] Whether to render the
34
+ # published revision or the draft.
35
+ def get_with_entry_env(action, entry:, mode: :published, params: {})
36
+ revision =
37
+ if mode == :published
38
+ entry.published_revision
39
+ else
40
+ entry.draft
41
+ end
42
+
43
+ published_entry = PublishedEntry.new(entry, revision)
44
+ EntriesControllerEnvHelper.add_entry_info_to_env(request.env,
45
+ entry: published_entry,
46
+ mode: mode)
47
+ get(action, params: {**params})
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,46 @@
1
+ module Pageflow
2
+ module JsonTestHelper
3
+ def json_response(options = {})
4
+ json_get(response.body, options)
5
+ end
6
+
7
+ def json_get(text, options = {})
8
+ object = JSON.parse(text)
9
+ path = options[:path] || []
10
+ pretty_path = nil
11
+
12
+ Array.wrap(path).inject(object) do |component, key|
13
+ case key
14
+ when Integer, '*'
15
+ expect(component).to be_a(Array),
16
+ "Expected json response to have array at '#{pretty_path || 'root'}'"
17
+ pretty_path = [pretty_path, "[#{key}]"].compact.join
18
+
19
+ if key == '*'
20
+ component
21
+ else
22
+ expect(component[key]).to be_present,
23
+ "Expected json response to have item at '#{pretty_path}'"
24
+ component[key]
25
+ end
26
+ when String, Symbol
27
+ key = key.to_s
28
+ pretty_path = [pretty_path, key].compact * '.'
29
+
30
+ case component
31
+ when Array
32
+ component.map do |c|
33
+ expect(c).to have_key(key),
34
+ "Expected json response to have key '#{pretty_path}'"
35
+ c[key]
36
+ end
37
+ else
38
+ expect(component).to have_key(key),
39
+ "Expected json response to have key '#{pretty_path}'"
40
+ component[key]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
data/pageflow/lint.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'pageflow/global_config_api_test_helper'
2
2
  require 'pageflow/test_page_type'
3
3
 
4
+ require 'pageflow/lint/entry_type'
4
5
  require 'pageflow/lint/file_type'
5
6
  require 'pageflow/lint/page_type'
6
7
  require 'pageflow/lint/file_import'
@@ -11,6 +12,23 @@ module Pageflow
11
12
  #
12
13
  # @since 13.0
13
14
  module Lint
15
+ # Contract specs for page types. Ensure editor fragments render
16
+ # without error.
17
+ #
18
+ # @param entry_type [EntryType] Page type to run specs for
19
+ #
20
+ # @since 15.1
21
+ #
22
+ # @example
23
+ #
24
+ # require 'spec_helper'
25
+ # require 'pageflow/lint'
26
+ #
27
+ # Pageflow::Lint.entry_type(SomePlugin.entry_type)
28
+ def self.entry_type(*args)
29
+ Lint::EntryType.lint(*args)
30
+ end
31
+
14
32
  # Ensure file type json partials render correctly.
15
33
  #
16
34
  # @param name [String] File type name to use in spec descriptions
@@ -0,0 +1,40 @@
1
+ require 'pageflow/global_config_api_test_helper'
2
+
3
+ module Pageflow
4
+ module Lint
5
+ # @api private
6
+ module EntryType
7
+ def self.lint(entry_type)
8
+ RSpec.describe "entry type #{entry_type.name}" do
9
+ let(:entry_type) { entry_type }
10
+
11
+ describe '#editor_fragment_renderer' do
12
+ it 'renders head fragment without error' do
13
+ entry = DraftEntry.new(FactoryBot.create(:entry))
14
+
15
+ expect {
16
+ entry_type.editor_fragment_renderer.head_fragment(entry)
17
+ }.not_to raise_error
18
+ end
19
+
20
+ it 'renders body fragment without error' do
21
+ entry = DraftEntry.new(FactoryBot.create(:entry))
22
+
23
+ expect {
24
+ entry_type.editor_fragment_renderer.body_fragment(entry)
25
+ }.not_to raise_error
26
+ end
27
+
28
+ it 'renders seed fragment without error' do
29
+ entry = DraftEntry.new(FactoryBot.create(:entry))
30
+
31
+ expect {
32
+ entry_type.editor_fragment_renderer.seed_fragment(entry)
33
+ }.not_to raise_error
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -11,7 +11,7 @@ module Pageflow
11
11
  RSpec.describe "file importer #{file_importer.name}" do
12
12
  before do
13
13
  pageflow_configure do |config|
14
- config.file_importers.register(file_importer.name, file_importer)
14
+ config.file_importers.register(file_importer)
15
15
  end
16
16
  end
17
17
 
@@ -36,13 +36,21 @@ module Pageflow
36
36
  }.not_to raise_error
37
37
  end
38
38
 
39
+ it 'has a logo_source method which returns string source' do
40
+ expect(file_importer.class.method_defined?(:logo_source)).to be(true)
41
+ expect {
42
+ source = file_importer.logo_source
43
+ expect(source).to be_instance_of(String)
44
+ }.not_to raise_error
45
+ end
46
+
39
47
  it 'has a authentication_provider method' do
40
48
  expect(file_importer.class.method_defined?(:authentication_provider)).to be(true)
41
49
  provider = file_importer.authentication_provider
42
50
  expect(provider).to be_nil.or be_a(Symbol)
43
51
  end
44
52
 
45
- it 'has a search method' do
53
+ it 'has a search method', :vcr do
46
54
  expect(file_importer.class.method_defined?(:search)).to be(true)
47
55
  expect {
48
56
  provider = file_importer.authentication_provider
@@ -46,6 +46,7 @@ module Pageflow
46
46
 
47
47
  it 'renders editor json without error' do
48
48
  helper.extend(FilesHelper)
49
+ helper.extend(Editor::FilesHelper)
49
50
  helper.render(partial: 'pageflow/editor/files/file',
50
51
  formats: [:json],
51
52
  locals: {
@@ -0,0 +1,17 @@
1
+ RSpec::Matchers.define :have_json_ld do |expected_attributes|
2
+ match do |html|
3
+ expect(json_ld_objects(html)).to include(a_hash_including(expected_attributes))
4
+ end
5
+
6
+ failure_message do |html|
7
+ "expected\n\n#{JSON.pretty_generate(json_ld_objects(html))}\n\n" \
8
+ "to contain a JSON-LD object with attributes\n\n#{JSON.pretty_generate(expected_attributes)}"
9
+ end
10
+
11
+ def json_ld_objects(html)
12
+ Capybara
13
+ .string(html)
14
+ .all('script[type="application/ld+json"]', visible: false)
15
+ .map { |element| JSON.parse(element.text(:all)) }
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ RSpec::Matchers.define :have_meta_tag do
2
+ match do |body|
3
+ Capybara.string(body).has_selector?(selectors.join(''), visible: false)
4
+ end
5
+
6
+ chain :with_name do |value|
7
+ selectors << "[name='#{value}']"
8
+ end
9
+
10
+ chain :for_property do |value|
11
+ selectors << "[property='#{value}']"
12
+ end
13
+
14
+ chain :with_content_including do |value|
15
+ selectors << "[content~='#{value}']"
16
+ end
17
+
18
+ def selectors
19
+ @selectors ||= ['head meta']
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ require 'capybara/rspec'
2
+ require 'selenium-webdriver'
3
+ require 'capybara/chromedriver/logger'
4
+ require 'webdrivers/chromedriver'
5
+
6
+ Capybara.register_driver :selenium_chrome_headless_no_sandbox do |app|
7
+ browser_options = ::Selenium::WebDriver::Chrome::Options.new
8
+ browser_options.args << '--headless'
9
+ browser_options.args << '--disable-gpu'
10
+ # Required for chrome to work in container based Travis environment
11
+ # (see https://docs.travis-ci.com/user/chrome)
12
+ browser_options.args << '--no-sandbox'
13
+
14
+ capabilities = {
15
+ # see https://github.com/SeleniumHQ/selenium/issues/3738
16
+ loggingPrefs: {browser: 'ALL'},
17
+ # see https://github.com/dbalatero/capybara-chromedriver-logger/issues/11
18
+ chromeOptions: {
19
+ w3c: false
20
+ }
21
+ }
22
+
23
+ Capybara::Selenium::Driver.new(app,
24
+ browser: :chrome,
25
+ options: browser_options,
26
+ desired_capabilities: capabilities)
27
+ end
28
+
29
+ Capybara.javascript_driver = :selenium_chrome_headless_no_sandbox
30
+
31
+ Capybara::Chromedriver::Logger.raise_js_errors = true
32
+ Capybara::Chromedriver::Logger.filters = [
33
+ # Bandwidth probe files are not available in tests
34
+ /bandwidth_probe.*Failed to load resource/i,
35
+
36
+ # Logged by Pageflow after legacy bandwidth detection
37
+ /Detected bandwidth/,
38
+
39
+ # Not helpful in specs
40
+ /Download the React DevTools/,
41
+
42
+ # Caused by sign in form
43
+ /Input elements should have autocomplete attributes/,
44
+
45
+ # React does not like the server rendered "back to top" link inside
46
+ # page sections.
47
+ /Target node has markup rendered by React/i,
48
+
49
+ # Ignore failure of debounced request to save order of storylines
50
+ %r{storylines/order - Failed to load resource: the server responded with a status of 401},
51
+
52
+ # Ignore failure of debounced request to refresh partials while db
53
+ # has already been cleaned
54
+ /partials - Failed to load resource: the server responded with a status of 401/
55
+ ]
56
+
57
+ RSpec.configure do |config|
58
+ config.after :each, js: true do
59
+ Capybara::Chromedriver::Logger::TestHooks.after_example!
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ RSpec.configure do |config|
2
+ config.before(:each) do
3
+ Dir.glob(Rails.root.join('public', 'system', 's3', '*')).each do |f|
4
+ FileUtils.rm_r(f)
5
+ end
6
+ end
7
+
8
+ config.before(:each, stub_paperclip: true) do
9
+ allow_any_instance_of(Paperclip::Attachment).to receive(:post_process)
10
+ allow(Paperclip).to receive(:run).and_return('100x100')
11
+ end
12
+ end
13
+
14
+ module Paperclip
15
+ class Attachment
16
+ def bucket_name
17
+ 'test'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'webmock/rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+ driver_urls = Webdrivers::Common.subclasses.map(&:base_url)
6
+ WebMock.disable_net_connect!(allow_localhost: true, allow: driver_urls)
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ module Pageflow
2
+ class TestWidgetType < WidgetType
3
+ attr_reader :name, :roles
4
+
5
+ def initialize(options = {})
6
+ @name = options.fetch(:name, 'test_widget')
7
+ @roles = options.fetch(:roles, [])
8
+ @insert_point = options[:insert_point]
9
+ @enabled_in_editor = options.fetch(:enabled_in_editor, true)
10
+ @enabled_in_preview = options.fetch(:enabled_in_preview, true)
11
+ @rendered = options.fetch(:rendered, '')
12
+ @rendered_head_fragment = options.fetch(:rendered_head_fragment, '')
13
+ end
14
+
15
+ def enabled_in_editor?
16
+ @enabled_in_editor
17
+ end
18
+
19
+ def enabled_in_preview?
20
+ @enabled_in_preview
21
+ end
22
+
23
+ def insert_point
24
+ @insert_point || super
25
+ end
26
+
27
+ def render(_template, _entry)
28
+ if @rendered.respond_to?(:call)
29
+ @rendered.call.html_safe
30
+ else
31
+ @rendered.html_safe
32
+ end
33
+ end
34
+
35
+ def render_head_fragment(_template, _entry)
36
+ @rendered_head_fragment.html_safe
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pageflow-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.1.0.beta2
4
+ version: 15.1.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codevise Solutions Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2020-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pageflow
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 15.1.0.beta2
19
+ version: 15.1.0.beta4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 15.1.0.beta2
26
+ version: 15.1.0.beta4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '1.0'
173
+ version: '2.1'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '1.0'
180
+ version: '2.1'
181
181
  description:
182
182
  email:
183
183
  - info@codevise.de
@@ -208,15 +208,26 @@ files:
208
208
  - pageflow/dummy/templates/database.yml
209
209
  - pageflow/dummy/templates/test_theme.scss
210
210
  - pageflow/dummy/templates/test_theme_preview.png
211
+ - pageflow/edit_lock_test_helper.rb
212
+ - pageflow/editor_controller_test_helper.rb
213
+ - pageflow/entries_controller_test_helper.rb
211
214
  - pageflow/global_config_api_test_helper.rb
215
+ - pageflow/json_test_helper.rb
212
216
  - pageflow/lint.rb
217
+ - pageflow/lint/entry_type.rb
213
218
  - pageflow/lint/file_import.rb
214
219
  - pageflow/lint/file_type.rb
215
220
  - pageflow/lint/page_type.rb
221
+ - pageflow/matchers/have_json_ld.rb
222
+ - pageflow/matchers/have_meta_tag.rb
216
223
  - pageflow/rails_version.rb
217
224
  - pageflow/render_page_test_helper.rb
218
225
  - pageflow/support.rb
226
+ - pageflow/support/config/capybara.rb
227
+ - pageflow/support/config/paperclip.rb
228
+ - pageflow/support/config/webmock.rb
219
229
  - pageflow/test_page_type.rb
230
+ - pageflow/test_widget_type.rb
220
231
  - pageflow/used_file_test_helper.rb
221
232
  homepage: https://pageflow.io
222
233
  licenses: []