diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index fd34d92..4f110e5 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -123,7 +123,6 @@ class CmsController < MyProfileController end @article.profile = profile - @article.author = user @article.last_changed_by = user translations if @article.translatable? @@ -161,7 +160,7 @@ class CmsController < MyProfileController end if request.post? && params[:uploaded_files] params[:uploaded_files].each do |file| - @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent, :author => user) unless file == '' + @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user) unless file == '' end @errors = @uploaded_files.select { |f| f.errors.any? } if @errors.any? diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb index 0adc1c4..2698465 100644 --- a/app/models/approve_article.rb +++ b/app/models/approve_article.rb @@ -48,7 +48,7 @@ class ApproveArticle < Task end def perform - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :author => article.author) + 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.author) end def title diff --git a/app/models/article.rb b/app/models/article.rb index 1b427d7..033af35 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -502,7 +502,6 @@ class Article < ActiveRecord::Base :slug, :updated_at, :created_at, - :last_changed_by_id, :version, :lock_version, :type, @@ -545,7 +544,12 @@ class Article < ActiveRecord::Base end def author - versions.empty? ? last_changed_by : versions.first.last_changed_by + if versions.empty? + last_changed_by + else + author_id = versions.first.last_changed_by_id + Person.exists?(author_id) ? Person.find(author_id) : nil + end end def author_name diff --git a/app/models/person.rb b/app/models/person.rb index 503c30c..7684717 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -54,8 +54,6 @@ class Person < Profile has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy - has_many :creations, :class_name => 'Article', :foreign_key => :author_id - named_scope :more_popular, :select => "#{Profile.qualified_column_names}, count(friend_id) as total", :group => Profile.qualified_column_names, diff --git a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb index 5c6a51d..788576c 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb @@ -3,9 +3,9 @@ class WorkAssignmentPlugin::WorkAssignment < Folder after_save do |work_assignment| work_assignment.children.select {|child| child.kind_of?(UploadedFile)}.each do |submission| author_folder = work_assignment.find_or_create_author_folder(submission.author) - submission.name = versioned_name(submission, author_folder) if !(submission.name =~ /\(V[0-9]*\)/) + submission.name = versioned_name(submission, author_folder) submission.parent = author_folder - submission.save! + submission.save(false) end end @@ -24,7 +24,9 @@ class WorkAssignmentPlugin::WorkAssignment < Folder end def self.versioned_name(submission, folder) - "(V#{folder.children.count + 1}) #{submission.name}" + return submission.name if submission.name =~ /\(V[0-9]*\)/ + count = folder.children.include?(submission) ? folder.children.count : folder.children.count + 1 + "(V#{count}) #{submission.name}" end def accept_comments? diff --git a/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb b/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb index f9f0969..a529a89 100644 --- a/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb +++ b/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb @@ -13,8 +13,8 @@ class WorkAssignmentTest < ActiveSupport::TestCase end should 'return versioned name' do - folder = fast_create(Folder) profile = fast_create(Profile) + folder = fast_create(Folder, :profile_id => profile) a1 = Article.create!(:name => "Article 1", :profile => profile) a2 = Article.create!(:name => "Article 2", :profile => profile) a3 = Article.create!(:name => "Article 3", :profile => profile) @@ -35,7 +35,7 @@ class WorkAssignmentTest < ActiveSupport::TestCase organization = fast_create(Organization) author = fast_create(Person) work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Sample Work Assignment', :profile => organization) - submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :author => author) + submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :last_changed_by => author) author_folder = work_assignment.find_or_create_author_folder(author) assert author_folder, submission.parent diff --git a/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb b/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb index c7c4898..5318a85 100644 --- a/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb +++ b/plugins/work_assignment/test/unit/work_assingment_plugin_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class WorkAssignmentPluginTest < ActiveSupport::TestCase should 'verify if a content is a work_assignment submission' do organization = fast_create(Organization) - content = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization) + content = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :last_changed_by => fast_create(Person)) assert !WorkAssignmentPlugin.is_submission?(content) work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) @@ -32,8 +32,7 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase submission = create_submission assert !WorkAssignmentPlugin.can_download_submission?(person, submission) - submission.author = person - submission.save! + submission = create_submission(person) assert WorkAssignmentPlugin.can_download_submission?(person, submission) end @@ -48,10 +47,10 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase private - def create_submission + def create_submission(author=nil) organization = fast_create(Organization) work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) author_folder = work_assignment.find_or_create_author_folder(fast_create(Person)) - UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => author_folder) + UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => author_folder, :last_changed_by => author) end end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 900d031..5a6210c 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1125,7 +1125,7 @@ class CmsControllerTest < ActionController::TestCase should 'not allow user edit article if he is owner but has no publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'bogus_permission', c) - a = c.articles.create!(:name => 'test_article', :author => u) + a = c.articles.create!(:name => 'test_article', :last_changed_by => u) login_as :test_user get :edit, :profile => c.identifier, :id => a.id @@ -1136,7 +1136,7 @@ class CmsControllerTest < ActionController::TestCase should 'allow user edit article if he is owner and has publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'publish_content', c) - a = c.articles.create!(:name => 'test_article', :author => u) + a = c.articles.create!(:name => 'test_article', :last_changed_by => u) login_as :test_user @controller.stubs(:user).returns(u) diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 829d9eb..2f66529 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -850,7 +850,7 @@ end c = Community.create!(:name => 'test_com') u = create_user_with_permission('test_user', 'publish_content', c) login_as u.identifier - a = c.articles.create!(:name => 'test-article', :author => u, :published => false) + a = c.articles.create!(:name => 'test-article', :last_changed_by => u, :published => false) get :view_page, :profile => c.identifier, :page => a.explode_path diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb index 7ba9815..1f71acc 100644 --- a/test/unit/approve_article_test.rb +++ b/test/unit/approve_article_test.rb @@ -210,9 +210,7 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'use author from original article on published' do - article.author = profile - article.save! - + article.class.any_instance.stubs(:author).returns(profile) a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) a.finish @@ -220,8 +218,7 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'use original article author even if article is destroyed' do - article.author = profile - article.save! + article.class.any_instance.stubs(:author).returns(profile) a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) a.finish diff --git a/test/unit/forum_helper_test.rb b/test/unit/forum_helper_test.rb index 378e28b..bd12a37 100644 --- a/test/unit/forum_helper_test.rb +++ b/test/unit/forum_helper_test.rb @@ -29,16 +29,16 @@ class ForumHelperTest < ActiveSupport::TestCase end should 'list posts with different classes' do - forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false, :author => profile) + forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false, :last_changed_by => profile) one_month_later = Time.now + 1.month Time.stubs(:now).returns(one_month_later) - forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true, :author => profile) + forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true, :last_changed_by => profile) assert_match /forum-post position-1 first odd-post.*forum-post position-2 last not-published even-post/, list_forum_posts(forum.posts) end should 'return post update if it has no comments' do author = create_user('forum test author').person - some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) + some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true, :last_changed_by => author) assert some_post.comments.empty? out = last_topic_update(some_post) assert_match some_post.updated_at.to_s, out diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 9963732..af7442a 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1262,15 +1262,4 @@ class PersonTest < ActiveSupport::TestCase assert person.has_permission?('bli', Profile.new) end - - should 'have creations' do - person = create_user('some-user').person - a1 = fast_create(Article, :author_id => person.id) - a2 = fast_create(Article, :author_id => person.id) - a3 = fast_create(Article) - - assert_includes person.creations, a1 - assert_includes person.creations, a2 - assert_not_includes person.creations, a3 - end end -- libgit2 0.21.2