-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/controllers/comfy/admin/blog/revisions/post_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Comfy::Admin::Blog::Revisions::PostController < Comfy::Admin::Cms::Revisions::BaseController | ||
|
||
def show | ||
@current_content = @record.fragments.inject({}){|c, b| c[b.identifier] = b.content; c } | ||
@versioned_content = @record.fragments.inject({}){|c, b| c[b.identifier] = @revision.data['fragments_attributes'].detect{|r| r[:identifier] == b.identifier}.try(:[], :content); c } | ||
|
||
render "comfy/admin/cms/revisions/show" | ||
end | ||
|
||
private | ||
|
||
def load_record | ||
@record = @site.blog_posts.find(params[:blog_post_id]) | ||
rescue ActiveRecord::RecordNotFound | ||
flash[:danger] = I18n.t('comfy.admin.cms.revisions.record_not_found') | ||
redirect_to comfy_admin_blog_posts_path(@site) | ||
end | ||
|
||
def record_path | ||
edit_comfy_admin_blog_post_path(@site, @record) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/controllers/comfy/admin/blog/revisions/post_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require_relative '../../../../../test_helper' | ||
|
||
class Comfy::Admin::Cms::Revisions::PageControllerTest < ActionDispatch::IntegrationTest | ||
|
||
setup do | ||
@site = comfy_cms_sites(:default) | ||
@post = comfy_blog_posts(:default) | ||
@revision = comfy_cms_revisions(:post) | ||
end | ||
|
||
def test_get_index | ||
r :get, comfy_admin_blog_post_revisions_path(@site, @post) | ||
assert_response :redirect | ||
assert_redirected_to action: :show, id: @revision | ||
end | ||
|
||
def test_get_index_with_no_revisions | ||
Comfy::Cms::Revision.delete_all | ||
r :get, comfy_admin_blog_post_revisions_path(@site, @post) | ||
assert_response :redirect | ||
assert_redirected_to edit_comfy_admin_blog_post_path(@site, @post) | ||
end | ||
|
||
def test_get_show | ||
r :get, comfy_admin_blog_post_revision_path(@site, @post, @revision) | ||
assert_response :success | ||
assert assigns(:record) | ||
assert assigns(:revision) | ||
assert assigns(:record).is_a?(Comfy::Blog::Post) | ||
assert_template :show | ||
end | ||
|
||
def test_get_show_for_invalid_record | ||
r :get, comfy_admin_blog_post_revision_path(@site, "invalid", @revision) | ||
assert_response :redirect | ||
assert_redirected_to comfy_admin_blog_posts_path(@site) | ||
assert_equal 'Record Not Found', flash[:danger] | ||
end | ||
|
||
|
||
def test_get_show_failure | ||
r :get, comfy_admin_blog_post_revision_path(@site, @post, "invalid") | ||
assert_response :redirect | ||
assert assigns(:record) | ||
assert_redirected_to edit_comfy_admin_blog_post_path(@site, assigns(:record)) | ||
assert_equal 'Revision Not Found', flash[:danger] | ||
end | ||
|
||
def test_revert | ||
assert_difference -> {@post.revisions.count} do | ||
r :patch, revert_comfy_admin_blog_post_revision_path(@site, @post, @revision) | ||
assert_response :redirect | ||
assert_redirected_to edit_comfy_admin_blog_post_path(@site, @post) | ||
assert_equal 'Content Reverted', flash[:success] | ||
|
||
@post.reload | ||
|
||
assert_equal [{ | ||
identifier: "content", | ||
tag: "text", | ||
content: "old content", | ||
datetime: nil, | ||
boolean: false | ||
}], @post.fragments_attributes | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
post: | ||
record: default (Comfy::Blog::Post) | ||
data: <%= { | ||
"fragments_attributes" => [ | ||
{ "identifier" => "content", | ||
"content" => "old content" } | ||
]}.to_yaml.inspect %> |