diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/controllers/revisions_controller_test.rb | 29 | ||||
| -rw-r--r-- | test/models/page_test.rb | 34 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/controllers/revisions_controller_test.rb b/test/controllers/revisions_controller_test.rb index b4dcd8f..e2fc976 100644 --- a/test/controllers/revisions_controller_test.rb +++ b/test/controllers/revisions_controller_test.rb | |||
| @@ -59,4 +59,33 @@ class RevisionsControllerTest < ActionController::TestCase | |||
| 59 | assert_equal @node.head, @node.pages.first | 59 | assert_equal @node.head, @node.pages.first |
| 60 | assert_equal "first", @node.head.reload.body | 60 | assert_equal "first", @node.head.reload.body |
| 61 | end | 61 | end |
| 62 | |||
| 63 | test "diffing two revisions renders real markup with only the changed words marked" do | ||
| 64 | login_as :quentin | ||
| 65 | post( | ||
| 66 | :diff, params: { | ||
| 67 | :node_id => @node.id, | ||
| 68 | :start_revision => @node.pages.first.revision, | ||
| 69 | :end_revision => @node.pages.last.revision | ||
| 70 | } | ||
| 71 | ) | ||
| 72 | assert_response :success | ||
| 73 | assert_select "del", "first" | ||
| 74 | assert_select "ins", "second" | ||
| 75 | assert_no_match /</, response.body | ||
| 76 | end | ||
| 77 | |||
| 78 | test "diffing two revisions in side by side view renders two columns" do | ||
| 79 | login_as :quentin | ||
| 80 | post( | ||
| 81 | :diff, params: { | ||
| 82 | :node_id => @node.id, | ||
| 83 | :start_revision => @node.pages.first.revision, | ||
| 84 | :end_revision => @node.pages.last.revision, | ||
| 85 | :view => "side_by_side" | ||
| 86 | } | ||
| 87 | ) | ||
| 88 | assert_response :success | ||
| 89 | assert_select ".diff_column", 2 | ||
| 90 | end | ||
| 62 | end | 91 | end |
diff --git a/test/models/page_test.rb b/test/models/page_test.rb index ad2742f..ac5691a 100644 --- a/test/models/page_test.rb +++ b/test/models/page_test.rb | |||
| @@ -176,4 +176,38 @@ class PageTest < ActiveSupport::TestCase | |||
| 176 | assert_not_equal first_page.id, first_page.node.head_id | 176 | assert_not_equal first_page.id, first_page.node.head_id |
| 177 | assert first_page.published_at.present? | 177 | assert first_page.published_at.present? |
| 178 | end | 178 | end |
| 179 | |||
| 180 | def test_diff_against_inline_keeps_tags_and_marks_only_the_changed_word | ||
| 181 | n = Node.root.children.create! :slug => "diff_against_test" | ||
| 182 | d = n.find_or_create_draft @user1 | ||
| 183 | d.title = "Old heading" | ||
| 184 | d.save! | ||
| 185 | n.publish_draft! | ||
| 186 | |||
| 187 | d2 = n.find_or_create_draft @user1 | ||
| 188 | d2.title = "New heading" | ||
| 189 | d2.save! | ||
| 190 | |||
| 191 | diff = d2.diff_against(n.head) | ||
| 192 | |||
| 193 | assert_match "<del>Old</del>", diff[:title] | ||
| 194 | assert_match "<ins>New</ins>", diff[:title] | ||
| 195 | end | ||
| 196 | |||
| 197 | def test_diff_against_side_by_side_returns_two_annotated_strings | ||
| 198 | n = Node.root.children.create! :slug => "diff_against_sbs_test" | ||
| 199 | d = n.find_or_create_draft @user1 | ||
| 200 | d.title = "Old heading" | ||
| 201 | d.save! | ||
| 202 | n.publish_draft! | ||
| 203 | |||
| 204 | d2 = n.find_or_create_draft @user1 | ||
| 205 | d2.title = "New heading" | ||
| 206 | d2.save! | ||
| 207 | |||
| 208 | old_html, new_html = d2.diff_against(n.head, view: :side_by_side)[:title] | ||
| 209 | |||
| 210 | assert_match "<del>Old</del>", old_html | ||
| 211 | assert_match "<ins>New</ins>", new_html | ||
| 212 | end | ||
| 179 | end | 213 | end |
