Commit 4ab1ad9c850b57becd62e460ddfc69c3f653a6fe
Committed by
Daniela Feitosa
1 parent
fd59bb99
Exists in
master
and in
29 other branches
Add links to articles versions.
(ActionItem2822) Signed-off-by: Daniela Feitosa Signed-off-by: Ana Losnak <analosnak@gmail.com> Signed-off-by: Daniel Bucher <daniel.bucher88@gmail.com>
Showing
5 changed files
with
78 additions
and
0 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -7,6 +7,7 @@ class ContentViewerController < ApplicationController | @@ -7,6 +7,7 @@ class ContentViewerController < ApplicationController | ||
7 | 7 | ||
8 | def view_page | 8 | def view_page |
9 | path = params[:page].join('/') | 9 | path = params[:page].join('/') |
10 | + version = params[:rev] | ||
10 | 11 | ||
11 | if path.blank? | 12 | if path.blank? |
12 | @page = profile.home_page | 13 | @page = profile.home_page |
@@ -22,6 +23,10 @@ class ContentViewerController < ApplicationController | @@ -22,6 +23,10 @@ class ContentViewerController < ApplicationController | ||
22 | redirect_to profile.url.merge(:page => page_from_old_path.explode_path) | 23 | redirect_to profile.url.merge(:page => page_from_old_path.explode_path) |
23 | return | 24 | return |
24 | end | 25 | end |
26 | + else | ||
27 | + if version | ||
28 | + @page = @page.versions.find_by_version version | ||
29 | + end | ||
25 | end | 30 | end |
26 | end | 31 | end |
27 | 32 |
app/views/content_viewer/view_page.rhtml
@@ -85,6 +85,10 @@ | @@ -85,6 +85,10 @@ | ||
85 | </div> | 85 | </div> |
86 | <% end %> | 86 | <% end %> |
87 | 87 | ||
88 | +<div id="article-versions"> | ||
89 | + <%= @page.versions.map {|v| link_to("r#{v.version}", @page.url.merge(:rev => v.version))} %> | ||
90 | +</div> | ||
91 | + | ||
88 | <%= display_source_info(@page) %> | 92 | <%= display_source_info(@page) %> |
89 | 93 | ||
90 | <div class="comments" id="comments_list"> | 94 | <div class="comments" id="comments_list"> |
@@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
1 | +Feature: article versioning | ||
2 | + As a user | ||
3 | + I want to see article versions | ||
4 | + In order to be able to change between versions of an article | ||
5 | + | ||
6 | + Background: | ||
7 | + Given the following users | ||
8 | + | login | name | | ||
9 | + | joaosilva | Joao Silva | | ||
10 | + And "joaosilva" has no articles | ||
11 | + And the following articles | ||
12 | + | owner | name | body | | ||
13 | + | joaosilva | Sample Article | This is the first version of the article | | ||
14 | + And the article "Sample Article" is updated with | ||
15 | + | name | body | | ||
16 | + | Edited Article | This is the second version of the article | | ||
17 | + And I am logged in as "joaosilva" | ||
18 | + | ||
19 | + Scenario: display only link for original version | ||
20 | + Given the following articles | ||
21 | + | owner | name | body | | ||
22 | + | joaosilva | One version article | This is the first published article | | ||
23 | + And I am on joaosilva's control panel | ||
24 | + And I follow "Manage Content" | ||
25 | + When I follow "One version article" | ||
26 | + Then I should see "r1" within "#article-versions" | ||
27 | + And I should not see "r2" within "#article-versions" | ||
28 | + | ||
29 | + Scenario: display links for versions | ||
30 | + Given I am on joaosilva's control panel | ||
31 | + And I follow "Manage Content" | ||
32 | + When I follow "Edited Article" | ||
33 | + Then I should see "r1" within "#article-versions" | ||
34 | + And I should see "r2" within "#article-versions" | ||
35 | + | ||
36 | + Scenario: display links for versions | ||
37 | + Given I am on joaosilva's control panel | ||
38 | + And I follow "Manage Content" | ||
39 | + And I follow "Edited Article" | ||
40 | + When I follow "r2" within "#article-versions" | ||
41 | + Then I should see "This is the first version of the article" within ".article-body" |
features/step_definitions/noosfero_steps.rb
@@ -687,6 +687,14 @@ Given /^the article "([^\"]*)" is updated by "([^\"]*)"$/ do |article, person| | @@ -687,6 +687,14 @@ Given /^the article "([^\"]*)" is updated by "([^\"]*)"$/ do |article, person| | ||
687 | a.save! | 687 | a.save! |
688 | end | 688 | end |
689 | 689 | ||
690 | +Given /^the article "([^\"]*)" is updated with$/ do |article, table| | ||
691 | + a = Article.find_by_name article | ||
692 | + | ||
693 | + row = table.hashes.first | ||
694 | + | ||
695 | + a.update_attributes(row) | ||
696 | +end | ||
697 | + | ||
690 | Given /^the cache is turned (on|off)$/ do |state| | 698 | Given /^the cache is turned (on|off)$/ do |state| |
691 | ActionController::Base.perform_caching = (state == 'on') | 699 | ActionController::Base.perform_caching = (state == 'on') |
692 | end | 700 | end |
test/functional/content_viewer_controller_test.rb
@@ -369,6 +369,26 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -369,6 +369,26 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
369 | assert_redirected_to :host => p.default_hostname, :controller => 'content_viewer', :action => 'view_page', :profile => p.identifier, :page => a2.explode_path | 369 | assert_redirected_to :host => p.default_hostname, :controller => 'content_viewer', :action => 'view_page', :profile => p.identifier, :page => a2.explode_path |
370 | end | 370 | end |
371 | 371 | ||
372 | + should "display current article's versions" do | ||
373 | + page = profile.articles.create!(:name => 'myarticle', :body => 'test article') | ||
374 | + page.body = 'test article edited'; page.save | ||
375 | + | ||
376 | + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ] | ||
377 | + assert_tag :tag => 'div', :attributes => { :id => 'article-versions' }, :descendant => { | ||
378 | + :tag => 'a', | ||
379 | + :attributes => { :href => "http://#{profile.environment.default_hostname}/#{profile.identifier}/#{page.path}?rev=1" } | ||
380 | + } | ||
381 | + end | ||
382 | + | ||
383 | + should "fetch correct article version" do | ||
384 | + page = profile.articles.create!(:name => 'myarticle', :body => 'test article') | ||
385 | + page.body = 'test article edited'; page.save | ||
386 | + | ||
387 | + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :rev => 1 | ||
388 | + | ||
389 | + assert_equal 1, assigns(:page).version | ||
390 | + end | ||
391 | + | ||
372 | should 'not return an article of a different user' do | 392 | should 'not return an article of a different user' do |
373 | p1 = create_user('test_user').person | 393 | p1 = create_user('test_user').person |
374 | a = p1.articles.create!(:name => 'old-name') | 394 | a = p1.articles.create!(:name => 'old-name') |