Skip to content

Commit d4bd6f5

Browse files
committed
[Fixes browsermedia#689] Portlets with parameters
Portlets that have parameters (other than id) will now work when being viewed in the edit mode. There may be issues if portlets want an :id paremeter since there is assumed to be the page id. Hopefully this won't be a problem in practice since Addressable content could be used (or upgrading sites can scope the parameter to something thing_id) * Set up scenarios to cover portlets that have/need parameters * Add the existing params to the content iframe link.
1 parent 39d1279 commit d4bd6f5

File tree

10 files changed

+93
-2
lines changed

10 files changed

+93
-2
lines changed

app/controllers/cms/content_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def assign(key, value)
6767

6868
def render_editing_frame
6969
@page_title = @page.page_title
70+
71+
# Adds all provided parameters to the iframe
72+
@edit_page_path = ActionDispatch::Http::URL.url_for(path: edit_content_path(current_page), params: params.except(:controller, :action, :path), only_path: true)
7073
render 'editing_frame', :layout => 'cms/page_editor'
7174
end
7275

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= page_content_iframe(edit_content_path(current_page)) %>
1+
<%= page_content_iframe(@edit_page_path) %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Portlets with Parameters
2+
Portlets should be able to read request parameters and display content accordingly.
3+
4+
Background:
5+
Given there is a portlet that finds content by parameter
6+
7+
# Finding content by id should be less necessary now that the Addressable Content feature is available.
8+
# However, this feature is still available and backwards compatible.
9+
Scenario: Find Content by parameter
10+
Given I am not logged in
11+
When I view that Find Content Portlet
12+
Then I should see the content loaded by that Portlet
13+
14+
Scenario: Find Content by parameter
15+
Given I am logged in as a Content Editor
16+
And I view that Find Content Portlet in the page editor
17+
Then I should see the content loaded by that Portlet
18+
19+
20+
21+

features/step_definitions/portlets_steps.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,28 @@
101101
refute page.has_content?('Error'), "The word 'Error' should not appear on the page"
102102
assert page.has_content?('hello'), "Should see other content"
103103
should_see_a_page_named(most_recently_created_page.title)
104+
end
105+
106+
Given /^there is a portlet that finds content by parameter$/ do
107+
@expected_page = create(:public_page)
108+
@find_content_portlet = FindCategoryPortlet.create(name: 'Find Content')
109+
@expected_page.add_content(@find_content_portlet)
110+
@expected_page.publish!
111+
@content = create(:category, name: 'I worked')
112+
end
113+
114+
When /^I view that Find Content Portlet$/ do
115+
visit "#{@expected_page.path}?category_id=#{@content.id}"
116+
end
117+
118+
Then /^I should see the content loaded by that Portlet$/ do
119+
should_be_successful
120+
should_see_a_page_titled @expected_page.name
121+
assert page.has_content?(@content.name)
122+
assert page.has_content?("Pass.")
123+
end
124+
125+
When /^I view that Find Content Portlet in the page editor$/ do
126+
visit "#{@expected_page.path}?category_id=#{@content.id}"
127+
visit_content_iframe
104128
end

features/support/cms_api.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ def most_recently_created_page
4949
# </pre>
5050
def within_content_frame
5151
if page_has_editor_iframe?
52-
visit find(editor_iframe_selector)['src']
52+
visit_content_iframe
5353
end
5454
yield
5555
end
5656

57+
# View the content iframe as a top level page.
58+
def visit_content_iframe
59+
visit find(editor_iframe_selector)['src']
60+
end
61+
5762
def page_has_editor_iframe?
5863
page.has_selector?(editor_iframe_selector)
5964
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class FindCategoryPortlet < Cms::Portlet
2+
3+
description "[TEST] Verify that portlets can read parameters."
4+
5+
# Mark this as 'true' to allow the portlet's template to be editable via the CMS admin UI.
6+
enable_template_editor false
7+
8+
def render
9+
@expected_parameter = params[:category_id]
10+
if @expected_parameter
11+
@category = Cms::Category.where(id: @expected_parameter).first # Explicitly want to return nil rather than NotFound
12+
end
13+
end
14+
15+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##
2+
# All methods from this helper will be available in the render.html.erb for FindCategoryPortlet
3+
module FindCategoryPortletHelper
4+
5+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<%= f.input :name %>
2+
<%= f.input :template, as: :template_editor %>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<% if @category %>
2+
Pass. Found category <%= @category.name %>
3+
<% elsif @expected_parameter.blank? %>
4+
Fail. param[:category_id] is missing.
5+
<% else %>
6+
Fail. Could not find category with param[:category_id] = <%= @expected_parameter %>
7+
<% end %>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require File.join(File.dirname(__FILE__), '/../../test_helper')
2+
3+
class FindCategoryTest < ActiveSupport::TestCase
4+
5+
test "Should be able to create new instance of a portlet" do
6+
assert FindCategoryPortlet.create!(:name => "New Portlet")
7+
end
8+
9+
end

0 commit comments

Comments
 (0)