Skip to content

Commit

Permalink
Fixed pages preview functionality and specs with save & continue.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Sep 18, 2012
1 parent 7212470 commit 5ecdce9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
5 changes: 0 additions & 5 deletions core/app/views/refinery/_message.html.erb
@@ -1,8 +1,3 @@
<% if local_assigns.has_key? :new_url %>
<%# Need the new action URL if the title has been changed.
Will be used by the js to update the form action %>
<%= hidden_field_tag 'new_action', new_url %>
<% end -%>
<% flash.each do |key, value| %>
<div id='flash' class="flash flash_<%= key %>" style='visibility: hidden;' >
<%= value %>
Expand Down
7 changes: 4 additions & 3 deletions pages/app/controllers/refinery/admin/pages_controller.rb
Expand Up @@ -41,9 +41,10 @@ def update
unless request.xhr?
redirect_to :back
else
render :partial => '/refinery/message',
#pass the new update url in case the title was updated
:locals => {:new_url => refinery.admin_page_path(@page.uncached_nested_url) }
render :partial => 'save_and_continue_callback', :locals => {
:new_refinery_page_path => refinery.admin_page_path(@page.uncached_nested_url),
:new_page_path => refinery.preview_page_path(@page.uncached_nested_url)
}
end
end
else
Expand Down
3 changes: 2 additions & 1 deletion pages/app/views/refinery/admin/pages/_form.html.erb
Expand Up @@ -36,6 +36,7 @@
<% content_for :javascripts do %>
<script>
var refinery_page_preview_url = '<%= @page.persisted? ? refinery.preview_page_path(@page.uncached_nested_url) : refinery.preview_pages_path %>';
$(document).ready(function(){
page_options.init(
<%= Refinery::Pages.new_page_parts.to_s %>
Expand All @@ -48,7 +49,7 @@
var prev_url = form.attr('action');
var prev_target = form.attr('target');
form.attr({
'action': '<%= @page.persisted? ? refinery.preview_page_path(@page.uncached_nested_url) : refinery.preview_pages_path %>'
'action': refinery_page_preview_url
, 'target': '_blank'
});
form.submit();
Expand Down
@@ -0,0 +1,3 @@
<%= render '/refinery/message' %>
<%= hidden_field_tag 'new_action', local_assigns[:new_refinery_page_path] %>
<script>refinery_page_preview_url = '<%= local_assigns[:new_page_path] %>';</script>
19 changes: 14 additions & 5 deletions pages/spec/requests/refinery/admin/pages_spec.rb
Expand Up @@ -8,6 +8,13 @@ def new_window_should_have_content(content)
end
end

def new_window_should_not_have_content(content)
new_window = page.driver.browser.window_handles.last
page.within_window new_window do
page.should_not have_content(content)
end
end

module Refinery
module Admin
describe "Pages" do
Expand Down Expand Up @@ -145,7 +152,7 @@ module Admin
describe "edit/update" do
before do
Page.create :title => "Update me"

visit refinery.admin_pages_path
page.should have_content("Update me")
end
Expand Down Expand Up @@ -174,10 +181,10 @@ module Admin
it "updates page", :js do
page.should have_content("'Updated' was successfully updated.")
end

# Regression test for https://github.com/refinery/refinerycms/issues/1892
context 'when saving to exit (a second time)' do
it 'updates page', :js do
it 'updates page', :js do
click_button "Save"
page.should have_content("'Updated' was successfully updated.")
end
Expand Down Expand Up @@ -219,11 +226,13 @@ module Admin
fill_in "Title", :with => "Save this"
click_button "Save & continue editing"
page.should have_content("'Save this' was successfully updated")

click_button "Preview"

# this test SHOULD fail but it does not. It does when run manually
new_window_should_have_content("Save this")
new_window_should_not_have_content(
::I18n.t('switch_to_website', :scope => 'refinery.site_bar')
)
end
end

Expand Down

0 comments on commit 5ecdce9

Please sign in to comment.