Commit 1dfcb26deb5c1592aa2de1a253ff11d7b526e087
1 parent
5d182131
Exists in
master
and in
22 other branches
Added a option to create a link when approve an article
Showing
6 changed files
with
66 additions
and
1 deletions
Show diff stats
app/models/approve_article.rb
| ... | ... | @@ -22,6 +22,7 @@ class ApproveArticle < Task |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | settings_items :closing_statment, :article_parent_id, :highlighted |
| 25 | + settings_items :create_link, :type => :boolean, :default => false | |
| 25 | 26 | |
| 26 | 27 | def article_parent |
| 27 | 28 | Article.find_by_id article_parent_id.to_i |
| ... | ... | @@ -48,7 +49,11 @@ class ApproveArticle < Task |
| 48 | 49 | end |
| 49 | 50 | |
| 50 | 51 | def perform |
| 51 | - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.last_changed_by_id, :created_by_id => article.created_by_id) | |
| 52 | + if create_link | |
| 53 | + LinkArticle.create!(:reference_article => article, :profile => target) | |
| 54 | + else | |
| 55 | + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.last_changed_by_id, :created_by_id => article.created_by_id) | |
| 56 | + end | |
| 52 | 57 | end |
| 53 | 58 | |
| 54 | 59 | def title | ... | ... |
app/models/article.rb
| ... | ... | @@ -96,6 +96,11 @@ class Article < ActiveRecord::Base |
| 96 | 96 | self.activity.destroy if self.activity |
| 97 | 97 | end |
| 98 | 98 | |
| 99 | + after_destroy :destroy_link_article | |
| 100 | + def destroy_link_article | |
| 101 | + Article.where(:reference_article_id => self.id, :type => LinkArticle).destroy_all | |
| 102 | + end | |
| 103 | + | |
| 99 | 104 | xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' |
| 100 | 105 | |
| 101 | 106 | scope :in_category, lambda { |category| | ... | ... |
app/views/tasks/_approve_article_accept_details.html.erb
| 1 | 1 | <%= render :file => 'shared/tiny_mce' %> |
| 2 | 2 | |
| 3 | +<%= labelled_form_field(_('Create a link'), f.check_box(:create_link)) %> | |
| 4 | + | |
| 3 | 5 | <%= labelled_form_field(_('Name for publishing'), f.text_field(:name)) %> |
| 4 | 6 | <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %> |
| 5 | 7 | <%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %> | ... | ... |
test/unit/approve_article_test.rb
| ... | ... | @@ -431,4 +431,13 @@ class ApproveArticleTest < ActiveSupport::TestCase |
| 431 | 431 | end |
| 432 | 432 | end |
| 433 | 433 | |
| 434 | + should 'create link to referenced article' do | |
| 435 | + article = fast_create(Article) | |
| 436 | + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile) | |
| 437 | + a.create_link = true | |
| 438 | + a.finish | |
| 439 | + | |
| 440 | + assert_equal article, LinkArticle.last.reference_article | |
| 441 | + end | |
| 442 | + | |
| 434 | 443 | end | ... | ... |
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class LinkArticleTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @profile = create_user('testing').person | |
| 7 | + end | |
| 8 | + attr_reader :profile | |
| 9 | + | |
| 10 | + should 'url of article link redirects to referenced article' do | |
| 11 | + article = fast_create(Article, :profile_id => profile.id) | |
| 12 | + link = LinkArticle.new(:reference_article => article) | |
| 13 | + assert_equal article.url, link.url | |
| 14 | + end | |
| 15 | + | |
| 16 | + should 'name of article link is the same as the name of referenced article' do | |
| 17 | + article = fast_create(Article, :profile_id => profile.id) | |
| 18 | + link = LinkArticle.new(:reference_article => article) | |
| 19 | + assert_equal article.name, link.name | |
| 20 | + end | |
| 21 | + | |
| 22 | + should 'destroy link article when reference article is removed' do | |
| 23 | + target_profile = fast_create(Community) | |
| 24 | + article = fast_create(Article, :profile_id => profile.id) | |
| 25 | + link = LinkArticle.create!(:reference_article => article, :profile => target_profile) | |
| 26 | + article.destroy | |
| 27 | + assert_raise ActiveRecord::RecordNotFound do | |
| 28 | + link.reload | |
| 29 | + end | |
| 30 | + end | |
| 31 | + | |
| 32 | +end | ... | ... |