Skip to content

Commit

Permalink
Added _identifier to retrieve identifier/filename
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed May 19, 2011
1 parent 2361c58 commit 0ac7af9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/carrierwave/mount.rb
Expand Up @@ -65,7 +65,7 @@ def uploader_option(column, option)
# @user.image.url # => '/some_url.png'
#
# It is also possible (but not recommended) to ommit the uploader, which
# will create an anonymous uploader class.
# will create an anonymous uploader class.
#
# Passing a block makes it possible to customize the uploader. This can be
# convenient for brevity, but if there is any significatnt logic in the
Expand Down Expand Up @@ -98,6 +98,7 @@ def uploader_option(column, option)
# [image_processing_error] Returns an error object if the last file to be assigned caused a processing error
#
# [write_image_identifier] Uses the write_uploader method to set the identifier.
# [image_identifier] Reads out the identifier of the file
#
# === Parameters
#
Expand Down Expand Up @@ -230,6 +231,10 @@ def write_#{column}_identifier
_mounter(:#{column}).write_identifier
end
def #{column}_identifier
_mounter(:#{column}).identifier
end
RUBY

end
Expand Down
7 changes: 7 additions & 0 deletions spec/mount_spec.rb
Expand Up @@ -448,6 +448,13 @@ def monkey
end
end

describe '#image_identifier' do
it "should return the identifier from the mounted column" do
@instance.should_receive(:read_uploader).with(:image).and_return("test.jpg")
@instance.image_identifier.should == 'test.jpg'
end
end

end

describe '#mount_uploader without an uploader' do
Expand Down
4 changes: 3 additions & 1 deletion spec/orm/activerecord_spec.rb
Expand Up @@ -199,6 +199,7 @@ def monkey
@event.save.should be_true
@event.reload
@event[:image].should == 'test.jpeg'
@event.image_identifier.should == 'test.jpeg'
end

it "should preserve the image when nothing is assigned" do
Expand All @@ -208,6 +209,7 @@ def monkey
@event.foo = "bar"
@event.save.should be_true
@event[:image].should == 'test.jpeg'
@event.image_identifier.should == 'test.jpeg'
end

it "should remove the image if remove_image? returns true" do
Expand All @@ -218,6 +220,7 @@ def monkey
@event.reload
@event.image.should be_blank
@event[:image].should == ''
@event.image_identifier.should == ''
end

it "should mark image as changed when saving a new image" do
Expand Down Expand Up @@ -319,7 +322,6 @@ def filename
end

end

end

describe '#mount_uploader with :mount_on => :monkey' do
Expand Down

0 comments on commit 0ac7af9

Please sign in to comment.