Skip to content

Commit

Permalink
Reverting multiple blocks still doesn't work.
Browse files Browse the repository at this point in the history
* Added tests to confirm its not working.
  • Loading branch information
peakpg committed May 10, 2012
1 parent e0b55a4 commit 6c65853
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
9 changes: 9 additions & 0 deletions test/factories/attachables.rb
Expand Up @@ -50,6 +50,15 @@ class HasManyAttachments < ActiveRecord::Base
m.publish_on_save true m.publish_on_save true
end end


factory :has_many_documents, :class => Cms::Attachment do |m|
m.attachment_name "documents"
m.attachable_type "HasManyAttachments"
m.data { mock_file }
m.parent { find_or_create_root_section }
m.attachable_version 1
m.publish_on_save true
end

factory :attachment_document, :class => Cms::Attachment do |m| factory :attachment_document, :class => Cms::Attachment do |m|
m.attachment_name "document" m.attachment_name "document"
m.attachable_type "VersionedAttachable" m.attachable_type "VersionedAttachable"
Expand Down
27 changes: 22 additions & 5 deletions test/unit/behaviors/attaching_test.rb
Expand Up @@ -419,7 +419,7 @@ def setup


test "delete an attachment should not be found when fetching the draft version of blocks" do test "delete an attachment should not be found when fetching the draft version of blocks" do
@attachable.attachments.first.destroy @attachable.attachments.first.destroy
update_to_version2(@attachable) update_to_version(@attachable)


current = @attachable.as_of_draft_version() current = @attachable.as_of_draft_version()
assert_equal 0, current.attachments.size assert_equal 0, current.attachments.size
Expand All @@ -428,19 +428,36 @@ def setup


test "deleted attachments should be found when looking up historical versions" do test "deleted attachments should be found when looking up historical versions" do
@attachable.attachments.first.destroy @attachable.attachments.first.destroy
update_to_version2(@attachable) update_to_version(@attachable)


assert_equal 0, @attachable.as_of_version(2).attachments.size assert_equal 0, @attachable.as_of_version(2).attachments.size
assert_equal 1, @attachable.as_of_version(1).attachments.size assert_equal 1, @attachable.as_of_version(1).attachments.size
end end


test "reverting with multiple attachments doesn't work correctly'" do
@attachable = create(:has_many_attachments)

@attachable.attachments.first.destroy
update_to_version(@attachable, 2)
@attachable.attachments << create(:has_many_documents, :data_file_name => "new.txt", :attachable_version => 2)
update_to_version(@attachable, 3)

assert_equal "new.txt", @attachable.attachments.first.data_file_name

@attachable.revert_to(1)
@attachable.reload

assert_equal 1, @attachable.attachments.size
assert_equal "new.txt", @attachable.attachments.first.data_file_name, "If this worked properly, it roll back to version 1 of the attachment."

end
private private


def update_to_version2(attachable) def update_to_version(attachable, v=2)
attachable.update_attributes(:name => "v2") attachable.update_attributes(:name => "v#{v}")
attachable.publish! attachable.publish!
attachable.reload attachable.reload
assert_equal 2, attachable.version, "Verifying that we have actually force this block to version 2" assert_equal v, attachable.version, "Verifying that we have actually force this block to version #{v}"
end end


def update_attachable_to_version2(new_path) def update_attachable_to_version2(new_path)
Expand Down
4 changes: 2 additions & 2 deletions todo_list.markdown
Expand Up @@ -3,8 +3,6 @@ Tasks:
* Paperclip Based Assets - Replace the existing 'custom' file upload behavior with one that uses Paperclip. Allow blocks to have more than one attachment. * Paperclip Based Assets - Replace the existing 'custom' file upload behavior with one that uses Paperclip. Allow blocks to have more than one attachment.


- [Documentation] Write a quick how to guide about Attachments API. - [Documentation] Write a quick how to guide about Attachments API.
- [BUG] If you revert a block with multiple attachments, it will still be associated with the latest attachments.
- [BUG] Minor - In development mode, need to restart if core CMS code is changed (loses definations for custom blocks with attachments)
- [IMPROVE] The error message for a duplicate path for Fileblocks is not clear. - [IMPROVE] The error message for a duplicate path for Fileblocks is not clear.




Expand All @@ -30,6 +28,8 @@ When almost certainly should be.


- [TEST] Upgrade script from 3.4.x and 3.3.x - [TEST] Upgrade script from 3.4.x and 3.3.x
- [BUG] Updating a page throws 'path already used' error? Created a public section. - [BUG] Updating a page throws 'path already used' error? Created a public section.
- [BUG] Reverting blocks with multiple attachments doesn't really work. It stays associated with the latest attachment, even if you had previous deleted attachments.
- [BUG] Minor - In development mode, need to restart if core CMS code is changed (loses definations for custom blocks with attachments)


# 3.4.x # 3.4.x


Expand Down

0 comments on commit 6c65853

Please sign in to comment.