the photo image url is now randomized
This commit is contained in:
parent
c1703edc22
commit
7f5b98a6cb
3 changed files with 27 additions and 4 deletions
|
|
@ -13,6 +13,7 @@ class Photo < Post
|
||||||
key :caption, String
|
key :caption, String
|
||||||
key :remote_photo_path
|
key :remote_photo_path
|
||||||
key :remote_photo_name
|
key :remote_photo_name
|
||||||
|
key :random_string
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
|
|
@ -23,6 +24,7 @@ class Photo < Post
|
||||||
def self.instantiate(params = {})
|
def self.instantiate(params = {})
|
||||||
photo = super(params)
|
photo = super(params)
|
||||||
image_file = params.delete(:user_file)
|
image_file = params.delete(:user_file)
|
||||||
|
photo.random_string = gen_random_string(10)
|
||||||
|
|
||||||
photo.image.store! image_file
|
photo.image.store! image_file
|
||||||
photo
|
photo
|
||||||
|
|
@ -61,5 +63,12 @@ class Photo < Post
|
||||||
def mutable?
|
def mutable?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.gen_random_string(len)
|
||||||
|
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||||
|
string = ""
|
||||||
|
1.upto(len) { |i| string << chars[rand(chars.size-1)] }
|
||||||
|
return string
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
class ImageUploader < CarrierWave::Uploader::Base
|
class ImageUploader < CarrierWave::Uploader::Base
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def store_dir
|
def store_dir
|
||||||
"uploads/images"
|
"uploads/images"
|
||||||
end
|
end
|
||||||
|
|
@ -14,9 +16,11 @@ class ImageUploader < CarrierWave::Uploader::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def filename
|
def filename
|
||||||
model.id.to_s + File.extname(@filename) if @filename
|
model.random_string + model.id.to_s + File.extname(@filename) if @filename
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
version :thumb_small do
|
version :thumb_small do
|
||||||
process :resize_to_fill => [50,50]
|
process :resize_to_fill => [50,50]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,10 @@ describe Photo do
|
||||||
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
|
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
|
||||||
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
|
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
|
||||||
|
|
||||||
@photo = Photo.new
|
# @photo = Photo.new
|
||||||
@photo.person = @user.person
|
#@photo.person = @user.person
|
||||||
@photo.diaspora_handle = @user.person.diaspora_handle
|
#@photo.diaspora_handle = @user.person.diaspora_handle
|
||||||
|
@photo = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
||||||
|
|
||||||
@photo2 = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
@photo2 = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
||||||
end
|
end
|
||||||
|
|
@ -31,12 +32,21 @@ describe Photo do
|
||||||
@photo.update_attributes(:person_id => Factory(:person).id)
|
@photo.update_attributes(:person_id => Factory(:person).id)
|
||||||
@photo.reload.person.should == @user.person
|
@photo.reload.person.should == @user.person
|
||||||
end
|
end
|
||||||
|
it 'allows assignmant of caption' do
|
||||||
|
@photo.save!
|
||||||
|
@photo.update_attributes(:caption => "this is awesome!!")
|
||||||
|
@photo.reload.caption.should == "this is awesome!!"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be mutable' do
|
it 'should be mutable' do
|
||||||
@photo.mutable?.should == true
|
@photo.mutable?.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has a random string key' do
|
||||||
|
@photo2.random_string.should_not be nil
|
||||||
|
end
|
||||||
|
|
||||||
describe '.instantiate' do
|
describe '.instantiate' do
|
||||||
it 'sets the persons diaspora handle' do
|
it 'sets the persons diaspora handle' do
|
||||||
@photo2.diaspora_handle.should == @user.person.diaspora_handle
|
@photo2.diaspora_handle.should == @user.person.diaspora_handle
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue