s3 support minus rake migration.
This commit is contained in:
parent
bd4efe8c2d
commit
2eb1901073
9 changed files with 75 additions and 68 deletions
2
Gemfile
2
Gemfile
|
|
@ -8,6 +8,8 @@ gem 'chef', '0.9.12', :require => false
|
||||||
|
|
||||||
gem 'nokogiri', '1.4.3.1'
|
gem 'nokogiri', '1.4.3.1'
|
||||||
|
|
||||||
|
gem "fog"
|
||||||
|
|
||||||
#Security
|
#Security
|
||||||
gem 'devise', '1.1.3'
|
gem 'devise', '1.1.3'
|
||||||
gem 'devise_invitable','0.3.5'
|
gem 'devise_invitable','0.3.5'
|
||||||
|
|
|
||||||
14
Gemfile.lock
14
Gemfile.lock
|
|
@ -146,6 +146,7 @@ GEM
|
||||||
erubis (2.6.6)
|
erubis (2.6.6)
|
||||||
abstract (>= 1.0.0)
|
abstract (>= 1.0.0)
|
||||||
eventmachine (0.12.10)
|
eventmachine (0.12.10)
|
||||||
|
excon (0.3.4)
|
||||||
extlib (0.9.15)
|
extlib (0.9.15)
|
||||||
factory_girl (1.3.3)
|
factory_girl (1.3.3)
|
||||||
factory_girl_rails (1.0.1)
|
factory_girl_rails (1.0.1)
|
||||||
|
|
@ -161,6 +162,16 @@ GEM
|
||||||
fastthread (1.0.7)
|
fastthread (1.0.7)
|
||||||
ffi (0.6.3)
|
ffi (0.6.3)
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
|
fog (0.3.25)
|
||||||
|
builder
|
||||||
|
excon (>= 0.2.4)
|
||||||
|
formatador (>= 0.0.16)
|
||||||
|
json
|
||||||
|
mime-types
|
||||||
|
net-ssh (~> 2.0.23)
|
||||||
|
nokogiri (~> 1.4.3.1)
|
||||||
|
ruby-hmac
|
||||||
|
formatador (0.0.16)
|
||||||
gem_plugin (0.2.3)
|
gem_plugin (0.2.3)
|
||||||
gherkin (2.3.3)
|
gherkin (2.3.3)
|
||||||
json (~> 1.4.6)
|
json (~> 1.4.6)
|
||||||
|
|
@ -204,6 +215,7 @@ GEM
|
||||||
multipart-post (1.1.0)
|
multipart-post (1.1.0)
|
||||||
mysql2 (0.2.6)
|
mysql2 (0.2.6)
|
||||||
net-ldap (0.1.1)
|
net-ldap (0.1.1)
|
||||||
|
net-ssh (2.0.23)
|
||||||
nokogiri (1.4.3.1)
|
nokogiri (1.4.3.1)
|
||||||
oa-basic (0.1.6)
|
oa-basic (0.1.6)
|
||||||
multi_json (~> 0.0.2)
|
multi_json (~> 0.0.2)
|
||||||
|
|
@ -298,6 +310,7 @@ GEM
|
||||||
ruby-debug-base (~> 0.10.4.0)
|
ruby-debug-base (~> 0.10.4.0)
|
||||||
ruby-debug-base (0.10.4)
|
ruby-debug-base (0.10.4)
|
||||||
linecache (>= 0.3)
|
linecache (>= 0.3)
|
||||||
|
ruby-hmac (0.4.0)
|
||||||
ruby-openid (2.1.8)
|
ruby-openid (2.1.8)
|
||||||
ruby-openid-apps-discovery (1.2.0)
|
ruby-openid-apps-discovery (1.2.0)
|
||||||
ruby-openid (>= 2.1.7)
|
ruby-openid (>= 2.1.7)
|
||||||
|
|
@ -359,6 +372,7 @@ DEPENDENCIES
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
fastercsv (= 1.5.4)
|
fastercsv (= 1.5.4)
|
||||||
haml (= 3.0.25)
|
haml (= 3.0.25)
|
||||||
|
fog
|
||||||
http_accept_language!
|
http_accept_language!
|
||||||
jammit (= 0.5.4)
|
jammit (= 0.5.4)
|
||||||
jasmine!
|
jasmine!
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,11 @@ class Photo < Post
|
||||||
require 'carrierwave/orm/activerecord'
|
require 'carrierwave/orm/activerecord'
|
||||||
mount_uploader :image, ImageUploader
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
xml_attr :remote_photo
|
xml_reader :remote_photo_path
|
||||||
xml_attr :caption
|
xml_reader :remote_photo_name
|
||||||
xml_attr :status_message_id
|
|
||||||
|
xml_reader :caption
|
||||||
|
xml_reader :status_message_id
|
||||||
|
|
||||||
belongs_to :status_message
|
belongs_to :status_message
|
||||||
|
|
||||||
|
|
@ -17,7 +19,6 @@ class Photo < Post
|
||||||
|
|
||||||
before_destroy :ensure_user_picture
|
before_destroy :ensure_user_picture
|
||||||
|
|
||||||
#before_destroy :delete_parent_if_no_photos_or_message
|
|
||||||
def ownership_of_status_message
|
def ownership_of_status_message
|
||||||
message = StatusMessage.find_by_id(self.status_message_id)
|
message = StatusMessage.find_by_id(self.status_message_id)
|
||||||
if status_message_id && message
|
if status_message_id && message
|
||||||
|
|
@ -33,25 +34,28 @@ class Photo < Post
|
||||||
photo.random_string = gen_random_string(10)
|
photo.random_string = gen_random_string(10)
|
||||||
|
|
||||||
photo.image.store! image_file
|
photo.image.store! image_file
|
||||||
photo
|
|
||||||
|
unless photo.image.url.match(/^https?:\/\//)
|
||||||
|
pod_url = APP_CONFIG[:pod_url].dup
|
||||||
|
pod_url.chop! if APP_CONFIG[:pod_url][-1,1] == '/'
|
||||||
|
remote_path = "#{pod_url}#{photo.image.url}"
|
||||||
|
else
|
||||||
|
remote_path = photo.image.url
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_photo
|
|
||||||
image.url.nil? ? (remote_photo_path + '/' + remote_photo_name) : image.url
|
|
||||||
end
|
|
||||||
|
|
||||||
def remote_photo= remote_path
|
|
||||||
name_start = remote_path.rindex '/'
|
name_start = remote_path.rindex '/'
|
||||||
self.remote_photo_path = remote_path.slice(0, name_start )
|
photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/"
|
||||||
self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
|
photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
|
||||||
|
|
||||||
|
photo
|
||||||
end
|
end
|
||||||
|
|
||||||
def url(name = nil)
|
def url(name = nil)
|
||||||
if remote_photo_path
|
if remote_photo_path
|
||||||
name = name.to_s + "_" if name
|
name = name.to_s + '_' if name
|
||||||
person.url.chop + remote_photo_path + "/" + name.to_s + remote_photo_name
|
remote_photo_path + name.to_s + remote_photo_name
|
||||||
else
|
else
|
||||||
image.url name
|
image.url(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -71,17 +75,6 @@ class Photo < Post
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_update updated_post
|
|
||||||
self.caption = updated_post.caption
|
|
||||||
self.save
|
|
||||||
end
|
|
||||||
|
|
||||||
def absolute_url *args
|
|
||||||
pod_url = AppConfig[:pod_url].dup
|
|
||||||
pod_url.chop! if AppConfig[:pod_url][-1,1] == '/'
|
|
||||||
"#{pod_url}#{url(*args)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.gen_random_string(len)
|
def self.gen_random_string(len)
|
||||||
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||||
string = ""
|
string = ""
|
||||||
|
|
@ -89,6 +82,7 @@ class Photo < Post
|
||||||
return string
|
return string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def as_json(opts={})
|
def as_json(opts={})
|
||||||
{
|
{
|
||||||
:photo => {
|
:photo => {
|
||||||
|
|
|
||||||
|
|
@ -56,29 +56,17 @@ class Profile < ActiveRecord::Base
|
||||||
|
|
||||||
def image_url= url
|
def image_url= url
|
||||||
return image_url if url == ''
|
return image_url if url == ''
|
||||||
if url.nil? || url.match(/^https?:\/\//)
|
|
||||||
super(url)
|
super(url)
|
||||||
else
|
|
||||||
super(absolutify_local_url(url))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_url_small= url
|
def image_url_small= url
|
||||||
return image_url if url == ''
|
return image_url if url == ''
|
||||||
if url.nil? || url.match(/^https?:\/\//)
|
|
||||||
super(url)
|
super(url)
|
||||||
else
|
|
||||||
super(absolutify_local_url(url))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_url_medium= url
|
def image_url_medium= url
|
||||||
return image_url if url == ''
|
return image_url if url == ''
|
||||||
if url.nil? || url.match(/^https?:\/\//)
|
|
||||||
super(url)
|
super(url)
|
||||||
else
|
|
||||||
super(absolutify_local_url(url))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def date= params
|
def date= params
|
||||||
|
|
@ -98,10 +86,4 @@ class Profile < ActiveRecord::Base
|
||||||
self.last_name.strip! if self.last_name
|
self.last_name.strip! if self.last_name
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def absolutify_local_url url
|
|
||||||
pod_url = AppConfig[:pod_url].dup
|
|
||||||
pod_url.chop! if AppConfig[:pod_url][-1,1] == '/'
|
|
||||||
"#{pod_url}#{url}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
10
config/database.yml
Normal file
10
config/database.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
test:
|
||||||
|
adapter: mysql2
|
||||||
|
database: diaspora_test
|
||||||
|
user: root
|
||||||
|
password: password
|
||||||
|
development:
|
||||||
|
adapter: mysql2
|
||||||
|
database: diaspora_development
|
||||||
|
user: root
|
||||||
|
password: password
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
CarrierWave.configure do |config|
|
CarrierWave.configure do |config|
|
||||||
if ENV['S3_KEY'] && ENV['S3_SECRET'] && ENV['S3_BUCKET']
|
if APP_CONFIG[:s3_key] && APP_CONFIG[:s3_secret] && APP_CONFIG[:s3_bucket]
|
||||||
config.storage = :s3
|
config.storage = :s3
|
||||||
config.s3_access_key_id = ENV['S3_KEY']
|
config.s3_access_key_id = APP_CONFIG[:s3_key]
|
||||||
config.s3_secret_access_key = ENV['S3_SECRET']
|
config.s3_secret_access_key = APP_CONFIG[:s3_secret]
|
||||||
config.s3_bucket = ENV['S3_BUCKET']
|
config.s3_bucket = APP_CONFIG[:s3_bucket]
|
||||||
config.cache_dir = "#{Rails.root}/tmp/uploads"
|
config.cache_dir = "#{Rails.root}/tmp/uploads"
|
||||||
else
|
else
|
||||||
config.storage = :file
|
config.storage = :file
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,13 @@ describe Photo do
|
||||||
photo.created_at.nil?.should be_true
|
photo.created_at.nil?.should be_true
|
||||||
photo.image.read.nil?.should be_false
|
photo.image.read.nil?.should be_false
|
||||||
end
|
end
|
||||||
|
it 'sets a remote url' do
|
||||||
|
image = File.open(@fixture_name)
|
||||||
|
photo = Photo.instantiate(
|
||||||
|
:person => @user.person, :user_file => image)
|
||||||
|
photo.remote_photo_path.should include("http")
|
||||||
|
photo.remote_photo_name.should include(".png")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save a photo' do
|
it 'should save a photo' do
|
||||||
|
|
@ -82,7 +88,7 @@ describe Photo do
|
||||||
it 'should remove its reference in user profile if it is referred' do
|
it 'should remove its reference in user profile if it is referred' do
|
||||||
@photo.save
|
@photo.save
|
||||||
|
|
||||||
@user.profile.image_url = @photo.image.url(:thumb_large)
|
@user.profile.image_url = @photo.url(:thumb_large)
|
||||||
@user.person.save
|
@user.person.save
|
||||||
@photo.destroy
|
@photo.destroy
|
||||||
Person.find(@user.person.id).profile.image_url.should be_nil
|
Person.find(@user.person.id).profile.image_url.should be_nil
|
||||||
|
|
@ -111,7 +117,8 @@ describe Photo do
|
||||||
@xml = @photo.to_xml.to_s
|
@xml = @photo.to_xml.to_s
|
||||||
end
|
end
|
||||||
it 'serializes the url' do
|
it 'serializes the url' do
|
||||||
@xml.include?(@photo.image.url).should be true
|
@xml.include?(@photo.remote_photo_path).should be true
|
||||||
|
@xml.include?(@photo.remote_photo_name).should be true
|
||||||
end
|
end
|
||||||
it 'serializes the diaspora_handle' do
|
it 'serializes the diaspora_handle' do
|
||||||
@xml.include?(@user.diaspora_handle).should be true
|
@xml.include?(@user.diaspora_handle).should be true
|
||||||
|
|
|
||||||
|
|
@ -52,18 +52,16 @@ describe Profile do
|
||||||
lambda {@profile.image_url = ""}.should_not change(@profile, :image_url)
|
lambda {@profile.image_url = ""}.should_not change(@profile, :image_url)
|
||||||
end
|
end
|
||||||
it 'makes relative urls absolute' do
|
it 'makes relative urls absolute' do
|
||||||
@profile.image_url = "/relative/url"
|
@profile.image_url = @photo.url(:thumb_large)
|
||||||
@profile.image_url.should == "#{@pod_url}/relative/url"
|
|
||||||
end
|
|
||||||
it "doesn't change absolute urls" do
|
|
||||||
@profile.image_url = "http://not/a/relative/url"
|
|
||||||
@profile.image_url.should == "http://not/a/relative/url"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
@profile.image_url.should == @photo.url(:thumb_large)
|
||||||
|
end
|
||||||
|
end
|
||||||
describe 'serialization' do
|
describe 'serialization' do
|
||||||
it "includes the person's diaspora handle if it doesn't have one" do
|
let(:person) {Factory.create(:person)}
|
||||||
person = Factory(:person, :diaspora_handle => "foobar")
|
|
||||||
|
it 'should include persons diaspora handle' do
|
||||||
|
xml = person.profile.to_diaspora_xml
|
||||||
xml = person.profile.to_diaspora_xml
|
xml = person.profile.to_diaspora_xml
|
||||||
xml.should include "foobar"
|
xml.should include "foobar"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -288,9 +288,9 @@ describe User do
|
||||||
end
|
end
|
||||||
it 'updates image_url' do
|
it 'updates image_url' do
|
||||||
user.update_profile(@params).should be_true
|
user.update_profile(@params).should be_true
|
||||||
user.reload.profile.image_url.should == @photo.absolute_url(:thumb_large)
|
user.reload.profile.image_url.should == @photo.url(:thumb_large)
|
||||||
user.profile.image_url_medium.should == @photo.absolute_url(:thumb_medium)
|
user.profile.image_url_medium.should == @photo.url(:thumb_medium)
|
||||||
user.profile.image_url_small.should == @photo.absolute_url(:thumb_small)
|
user.profile.image_url_small.should == @photo.url(:thumb_small)
|
||||||
end
|
end
|
||||||
it 'unpends the photo' do
|
it 'unpends the photo' do
|
||||||
@photo.pending = true
|
@photo.pending = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue