Some specs for file Attachment
This commit is contained in:
		
							parent
							
								
									2581895c7c
								
							
						
					
					
						commit
						7265d31f62
					
				@ -1,44 +1,56 @@
 | 
				
			|||||||
require 'spec_helper'
 | 
					require 'spec_helper'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe Refinery::WordPress::Attachment, :type => :model do
 | 
					describe Refinery::WordPress::Attachment, :type => :model do
 | 
				
			||||||
  let(:attachment) { test_dump.attachments.first }
 | 
					  context "an image attchment" do
 | 
				
			||||||
 | 
					    let(:attachment) { test_dump.attachments.first }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  specify { attachment.title.should == '200px-Tux.svg' }
 | 
					    specify { attachment.title.should == '200px-Tux.svg' }
 | 
				
			||||||
  # doesn't get exported atm. for some reason
 | 
					    # doesn't get exported atm. for some reason
 | 
				
			||||||
  specify { attachment.description.should == '' }
 | 
					    specify { attachment.description.should == '' }
 | 
				
			||||||
  specify { attachment.url.should == 'http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png' }
 | 
					    specify { attachment.url.should == 'http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png' }
 | 
				
			||||||
  specify { attachment.file_name.should == '200px-Tux.svg_.png' }
 | 
					    specify { attachment.file_name.should == '200px-Tux.svg_.png' }
 | 
				
			||||||
  specify { attachment.post_date.should == DateTime.new(2011, 6, 5, 15, 26, 51) }
 | 
					    specify { attachment.post_date.should == DateTime.new(2011, 6, 5, 15, 26, 51) }
 | 
				
			||||||
  specify { attachment.should be_an_image }
 | 
					    specify { attachment.should be_an_image }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "#to_refinery" do
 | 
					    describe "#to_refinery" do
 | 
				
			||||||
    before do
 | 
					      before do
 | 
				
			||||||
      @image = attachment.to_refinery
 | 
					        @image = attachment.to_refinery
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "should create an Image from the Attachment" do
 | 
				
			||||||
 | 
					        @image.should be_a(Image)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "should copy the attributes from Attachment" do
 | 
				
			||||||
 | 
					        @image.created_at.should == attachment.post_date
 | 
				
			||||||
 | 
					        @image.image.url.end_with?(attachment.file_name).should be_true
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "should create an Image from the Attachment" do
 | 
					    describe "#replace_image_url" do
 | 
				
			||||||
      @image.should be_a(Image)
 | 
					      before do
 | 
				
			||||||
    end
 | 
					        test_dump.authors.each(&:to_refinery)
 | 
				
			||||||
 | 
					        test_dump.posts.each(&:to_refinery)
 | 
				
			||||||
 | 
					        @image = attachment.to_refinery
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        attachment.replace_image_url_in_blog_posts
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "should replace attachment urls in the generated BlogPosts" do
 | 
				
			||||||
 | 
					        BlogPost.first.body.should_not include(attachment.url)
 | 
				
			||||||
 | 
					        BlogPost.first.body.should include(@image.image.url)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "should copy the attributes from Attachment" do
 | 
					 | 
				
			||||||
      @image.created_at.should == attachment.post_date
 | 
					 | 
				
			||||||
      @image.image.url.end_with?(attachment.file_name).should be_true
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "#replace_image_url" do
 | 
					  context "a file attachment" do
 | 
				
			||||||
    before do
 | 
					    let(:attachment) { test_dump.attachments.last }
 | 
				
			||||||
      test_dump.authors.each(&:to_refinery)
 | 
					 | 
				
			||||||
      test_dump.posts.each(&:to_refinery)
 | 
					 | 
				
			||||||
      @image = attachment.to_refinery
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      attachment.replace_image_url_in_blog_posts
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    it "should replace attachment urls in the generated BlogPosts" do
 | 
					 | 
				
			||||||
      BlogPost.first.body.should_not include(attachment.url)
 | 
					 | 
				
			||||||
      BlogPost.first.body.should include(@image.image.url)
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    specify { attachment.title.should == 'cv' }
 | 
				
			||||||
 | 
					    specify { attachment.url.should == 'http://localhost/wordpress/wp-content/uploads/2011/05/cv.txt' }
 | 
				
			||||||
 | 
					    specify { attachment.file_name.should == 'cv.txt' }
 | 
				
			||||||
 | 
					    specify { attachment.post_date.should == DateTime.new(2011, 6, 6, 17, 27, 50) }
 | 
				
			||||||
 | 
					    specify { attachment.should_not be_an_image }
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user