From c096bbc126d7a099edd372349edce9953ea8e6d2 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 30 Jul 2008 20:53:10 +0000 Subject: [PATCH] ActionItem609: creating new articles from the public view --- app/views/content_viewer/view_page.rhtml | 1 + test/functional/content_viewer_controller_test.rb | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 64cefc9..f9997be 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -35,6 +35,7 @@ <%= link_to content_tag( 'span', _('Edit') ), { :controller => 'cms', :action => 'edit', :id => @page }, :class => 'button with-text icon-edit' %> + <%= lightbox_button(:new, _('New article'), :controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : nil)) %> <% end %> diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index fb91df0..5d8b8dc 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -307,4 +307,42 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_equal profile, assigns(:profile) end + should 'give link to edit the article for owner ' do + login_as('testinguser') + get :view_page, :profile => 'testinguser', :page => [] + assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/edit/#{@profile.home_page.id}" } } + end + should 'not give link to edit the article for non-logged-in people' do + get :view_page, :profile => 'testinguser', :page => [] + assert_no_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/edit/#{@profile.home_page.id}" } } + end + should 'not give link to edit article for other people' do + login_as(create_user('anotheruser').login) + + get :view_page, :profile => 'testinguser', :page => [] + assert_no_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/edit/#{@profile.home_page.id}" } } + end + + should 'give link to create new article' do + login_as('testinguser') + get :view_page, :profile => 'testinguser', :page => [] + assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new" } } + end + should 'give no link to create new article for non-logged in people ' do + get :view_page, :profile => 'testinguser', :page => [] + assert_no_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new" } } + end + should 'give no link to create new article for other people' do + login_as(create_user('anotheruser').login) + get :view_page, :profile => 'testinguser', :page => [] + assert_no_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new" } } + end + + should 'give link to create new article inside folder' do + login_as('testinguser') + folder = Folder.create!(:name => 'myfolder', :profile => @profile) + get :view_page, :profile => 'testinguser', :page => [ 'myfolder' ] + assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new?parent_id=#{folder.id}" } } + end + end -- libgit2 0.21.2