From 4ab1ad9c850b57becd62e460ddfc69c3f653a6fe Mon Sep 17 00:00:00 2001 From: Daniel Bucher Date: Wed, 2 Oct 2013 03:11:53 +0400 Subject: [PATCH] Add links to articles versions. --- app/controllers/public/content_viewer_controller.rb | 5 +++++ app/views/content_viewer/view_page.rhtml | 4 ++++ features/article_versioning.feature | 41 +++++++++++++++++++++++++++++++++++++++++ features/step_definitions/noosfero_steps.rb | 8 ++++++++ test/functional/content_viewer_controller_test.rb | 20 ++++++++++++++++++++ 5 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 features/article_versioning.feature diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index d845e77..dd2bbcc 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -7,6 +7,7 @@ class ContentViewerController < ApplicationController def view_page path = params[:page].join('/') + version = params[:rev] if path.blank? @page = profile.home_page @@ -22,6 +23,10 @@ class ContentViewerController < ApplicationController redirect_to profile.url.merge(:page => page_from_old_path.explode_path) return end + else + if version + @page = @page.versions.find_by_version version + end end end diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index be612fc..3c16b10 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -85,6 +85,10 @@ <% end %> +
+ <%= @page.versions.map {|v| link_to("r#{v.version}", @page.url.merge(:rev => v.version))} %> +
+ <%= display_source_info(@page) %>
diff --git a/features/article_versioning.feature b/features/article_versioning.feature new file mode 100644 index 0000000..2d7107a --- /dev/null +++ b/features/article_versioning.feature @@ -0,0 +1,41 @@ +Feature: article versioning + As a user + I want to see article versions + In order to be able to change between versions of an article + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + And "joaosilva" has no articles + And the following articles + | owner | name | body | + | joaosilva | Sample Article | This is the first version of the article | + And the article "Sample Article" is updated with + | name | body | + | Edited Article | This is the second version of the article | + And I am logged in as "joaosilva" + + Scenario: display only link for original version + Given the following articles + | owner | name | body | + | joaosilva | One version article | This is the first published article | + And I am on joaosilva's control panel + And I follow "Manage Content" + When I follow "One version article" + Then I should see "r1" within "#article-versions" + And I should not see "r2" within "#article-versions" + + Scenario: display links for versions + Given I am on joaosilva's control panel + And I follow "Manage Content" + When I follow "Edited Article" + Then I should see "r1" within "#article-versions" + And I should see "r2" within "#article-versions" + + Scenario: display links for versions + Given I am on joaosilva's control panel + And I follow "Manage Content" + And I follow "Edited Article" + When I follow "r2" within "#article-versions" + Then I should see "This is the first version of the article" within ".article-body" diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 8e62fe4..d7c1c03 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -687,6 +687,14 @@ Given /^the article "([^\"]*)" is updated by "([^\"]*)"$/ do |article, person| a.save! end +Given /^the article "([^\"]*)" is updated with$/ do |article, table| + a = Article.find_by_name article + + row = table.hashes.first + + a.update_attributes(row) +end + Given /^the cache is turned (on|off)$/ do |state| ActionController::Base.perform_caching = (state == 'on') end diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index d2eb03b..fc1dde2 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -369,6 +369,26 @@ class ContentViewerControllerTest < ActionController::TestCase assert_redirected_to :host => p.default_hostname, :controller => 'content_viewer', :action => 'view_page', :profile => p.identifier, :page => a2.explode_path end + should "display current article's versions" do + page = profile.articles.create!(:name => 'myarticle', :body => 'test article') + page.body = 'test article edited'; page.save + + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ] + assert_tag :tag => 'div', :attributes => { :id => 'article-versions' }, :descendant => { + :tag => 'a', + :attributes => { :href => "http://#{profile.environment.default_hostname}/#{profile.identifier}/#{page.path}?rev=1" } + } + end + + should "fetch correct article version" do + page = profile.articles.create!(:name => 'myarticle', :body => 'test article') + page.body = 'test article edited'; page.save + + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :rev => 1 + + assert_equal 1, assigns(:page).version + end + should 'not return an article of a different user' do p1 = create_user('test_user').person a = p1.articles.create!(:name => 'old-name') -- libgit2 0.21.2