Created
September 5, 2012 21:53
-
-
Save timstephenson/3645628 to your computer and use it in GitHub Desktop.
Attachment test with CarrierWave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../spec_helper' | |
require 'carrierwave/test/matchers' | |
describe Attachment do | |
include CarrierWave::Test::Matchers | |
it "should be valid" do | |
Attachment.new.should be_valid | |
end | |
%w[jpg jpeg tif tiff doc docx ppt key png txt rtf JPG TIF].each do |ext| | |
it "should have a icon path" do | |
attachment = Attachment.new | |
AttachmentUploader.any_instance.stubs(:url).returns("/path_to_file/file.#{ext}") | |
attachment.icon_path.should == "/images/file_icons/icon_#{ext.upcase}_big.png" | |
end | |
end | |
it "should get attachments scoped to a project" do | |
project = Factory(:project) | |
sql = Attachment.attachments_within(project).to_sql | |
sql.should == %[SELECT "attachments".* FROM "attachments" WHERE ((attachable_type = 'Project' and attachable_id = 1) or (attachable_type = 'ProgressReport' and attachable_id in (1)))] | |
end | |
it "should search attachments scoped to a project" do | |
project = Factory(:project) | |
sql = Attachment.search_within(project, "Bob").to_sql | |
sql.should == %[SELECT "attachments".* FROM "attachments" WHERE ((attachable_type = 'Project' and attachable_id = 1) or (attachable_type = 'ProgressReport' and attachable_id in (1))) AND (lower(attachment) like '%bob%') ORDER BY attachment] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment