diff --git a/app/models/person.rb b/app/models/person.rb index ac4a5dfa7..1e2a7b18d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -89,6 +89,8 @@ class Person f = Redfinger.finger(identifier) rescue SocketError => e raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ + rescue Errno::ETIMEDOUT => e + raise "Connection timed out to Diaspora server for #{identifier}" end raise "No webfinger profile found at #{identifier}" if f.nil? || f.links.empty? Person.from_webfinger_profile(identifier, f ) diff --git a/app/models/user.rb b/app/models/user.rb index 718d23674..4ec528e70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -34,7 +34,6 @@ class User many :aspects, :class_name => 'Aspect' - after_create :seed_aspects before_validation_on_create :downcase_username @@ -239,8 +238,7 @@ class User Rails.logger.info( "the person id is #{object.post_id} the friend found is #{visible_person_by_id(object.post_id).inspect}") unfriended_by visible_person_by_id(object.post_id) - - else +else object.perform self.id aspects = self.aspects_with_person(object.person) aspects.each{ |aspect| aspect.post_ids.delete(object.post_id.to_id) diff --git a/config/deploy.rb b/config/deploy.rb index 805eadf4d..bceef51b5 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -27,24 +27,19 @@ set :deploy_via, :checkout # set :rails_env, ENV['rails_env'] || ENV['RAILS_ENV'] || all['default_env'] -role :tom, "tom.joindiaspora.com" -backers.each{ |backer| - role :backer, "#{backer['username']}.joindiaspora.com", :number => backer['number'] -} +role :pivots, config['servers']['pivots']['url'] -#role :ci, "ci.joindiaspora.com" # If you are using Passenger mod_rails uncomment this: # if you're still using the script/reapear helper you will need # these http://github.com/rails/irs_process_scripts # Start Nginx after "deploy:cold" do - run("nginx stop") - run("killall nginx") - #run("nginx") + run("nginx") end namespace :deploy do + task :symlink_images do run "mkdir -p #{shared_path}/uploads" run "ln -s -f #{shared_path}/uploads #{current_path}/public/uploads" @@ -66,20 +61,25 @@ namespace :deploy do end task :start_mongo do - run("mkdir -p -v #{current_path}/log/db/ ") - run("mkdir -p -v #{shared_path}/db/") - run("mongod --fork --logpath #{current_path}/log/db/mongolog.txt --dbpath #{shared_path}/db/ " ) + run("mkdir -p -v #{current_path}/log/db/ ") + run("mkdir -p -v #{shared_path}/db/") + run("mongod --fork --logpath #{current_path}/log/db/mongolog.txt --dbpath #{shared_path}/db/ " ) end task :start_thin do - run("mkdir -p -v #{current_path}/log/thin/ ") - run("cd #{current_path} && bundle exec thin start -C config/thin.yml") + run("mkdir -p -v #{current_path}/log/thin/ ") + run("cd #{current_path} && bundle exec thin start -C config/thin.yml") end task :stop do stop_thin run("killall -s 2 mongod || true") end + + task :go_cold do + stop + run("killall nginx") + end task :stop_thin do run("killall -s 2 ruby || true") @@ -121,32 +121,13 @@ namespace :cloud do end end namespace :db do - - task :purge, :roles => [:tom, :backer] do + + task :purge, :roles => [:pivots] do run "cd #{current_path} && bundle exec rake db:purge --trace RAILS_ENV=#{rails_env}" end - - task :tom_seed, :roles => :tom do - run "cd #{current_path} && bundle exec rake db:seed:tom --trace RAILS_ENV=#{rails_env}" - run "curl -silent -u tom@tom.joindiaspora.com:evankorth http://tom.joindiaspora.com/zombiefriends" - backers.each do |backer| - run "curl -silent -u #{backer['username']}@#{backer['username']}.joindiaspora.com:#{backer['username']}#{backer['pin']} http://#{backer['username']}.joindiaspora.com/zombiefriendaccept" - #run "curl -silent -u #{backer['username']}@#{backer['username']}.joindiaspora.com:#{backer['username']}#{backer['pin']} http://#{backer['username']}.joindiaspora.com/set_profile_photo" - end - - end - - task :backer_seed, :roles => :backer do - (0..10).each { |n| - run "curl -silent http://localhost/set_backer_number?number=#{n}", :only => {:number => n} - } - run "cd #{current_path} && bundle exec rake db:seed:backer --trace RAILS_ENV=#{rails_env}" - end - + task :reset do purge - backer_seed - tom_seed end diff --git a/config/deploy_config.yml b/config/deploy_config.yml index c653b6565..01bd94470 100644 --- a/config/deploy_config.yml +++ b/config/deploy_config.yml @@ -7,65 +7,9 @@ cross_server: deploy_to: '/usr/local/app/diaspora' user: 'root' + branch: 'production' repo: 'git@github.com:diaspora/diaspora.git' - branch: 'master' - default_env: 'development' + default_env: 'production' servers: - tom: - - url: 'tom.joindiaspora.com' - backer: - - username: 'washington' - given_name: 'George' - family_name: 'Washington' - number: 0 - pin: 5072 - - username: 'adams' - given_name: 'John' - family_name: 'Adams' - number: 1 - pin: 3742 - - username: 'jefferson' - given_name: 'Thomas' - family_name: 'Jefferson' - number: 2 - pin: 7782 - - username: 'madison' - given_name: 'James' - family_name: 'Madison' - number: 3 - pin: 2691 - - username: 'monroe' - given_name: 'James' - family_name: 'Monroe' - number: 4 - pin: 6133 - - username: 'quincyadams' - given_name: 'John Quincy' - family_name: 'Adams' - number: 5 - pin: 7558 - - username: 'jackson' - given_name: 'Andrew' - family_name: 'Jackson' - number: 6 - pin: 8670 - - username: 'buren' - given_name: 'Martin' - family_name: 'Van Buren' - number: 7 - pin: 1559 - - username: 'harrison' - given_name: 'William Henry' - family_name: 'Harrison' - number: 8 - pin: 5404 - - username: 'tyler' - given_name: 'John' - family_name: 'Tyler' - number: 9 - pin: 6431 - - username: 'polk' - given_name: 'James K.' - family_name: 'Polk' - number: 10 - pin: 1957 + pivots: + url: 'pivots.joindiaspora.com' diff --git a/config/environments/development.rb b/config/environments/development.rb index 66a0ef31a..e73a3e9d1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -21,8 +21,19 @@ Diaspora::Application.configure do config.action_controller.perform_caching = false # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = true config.active_support.deprecation = :log config.middleware.use MongoMapper::ClearDevMemory #config.threadsafe! + config.action_mailer.delivery_method = :smtp + config.action_mailer.default_url_options = {:host => 'localhost:3000'} + config.action_mailer.smtp_settings = { + :address => 'smtp.gmail.com', + :port => 587, + :domain => 'mail.joindiaspora.com', + :authentication => 'plain', + :user_name => 'diaspora-pivots@joindiaspora.com', + :password => "xy289|]G+R*-kA", + :enable_starttls_auto => true + } end diff --git a/config/environments/production.rb b/config/environments/production.rb index 1267a96a3..3207c627d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -15,12 +15,12 @@ Diaspora::Application.configure do config.action_controller.perform_caching = true # Specifies the header that your server uses for sending files - config.action_dispatch.x_sendfile_header = "X-Sendfile" + #config.action_dispatch.x_sendfile_header = "X-Sendfile" config.active_support.deprecation = :notify # For nginx: - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # If you have no front-end server that supports something like X-Sendfile, # just comment this out and Rails will serve the files @@ -36,7 +36,7 @@ Diaspora::Application.configure do # Disable Rails's static asset server # In production, Apache or nginx will already do this - config.serve_static_assets = true + #config.serve_static_assets = true # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" @@ -44,12 +44,20 @@ Diaspora::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true config.threadsafe! + config.action_mailer.delivery_method = :smtp + config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} + config.action_mailer.smtp_settings = { + :address => 'smtp.gmail.com', + :port => 587, + :domain => 'mail.joindiaspora.com', + :authentication => 'plain', + :user_name => 'diaspora-pivots@joindiaspora.com', + :password => "xy289|]G+R*-kA", + :enable_starttls_auto => true + } end diff --git a/config/sprinkle/conf/nginx.conf b/config/sprinkle/conf/nginx.conf index 2b3aa8a40..eba9fa45b 100644 --- a/config/sprinkle/conf/nginx.conf +++ b/config/sprinkle/conf/nginx.conf @@ -33,12 +33,14 @@ http { # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; upstream thin_cluster { server unix:/tmp/thin.0.sock; + server unix:/tmp/thin.1.sock; + server unix:/tmp/thin.2.sock; } server { listen 80; - server_name babycakes.sofaer.net www.babycakes.sofaer.net; + server_name pivots.joindiaspora.com www.pivots.joindiaspora.com; root /usr/local/app/diaspora/current; location / { diff --git a/config/sprinkle/provision.rb b/config/sprinkle/provision.rb index ce0fd7374..fc81b1ca3 100644 --- a/config/sprinkle/provision.rb +++ b/config/sprinkle/provision.rb @@ -13,7 +13,7 @@ require '#{File.dirname(__FILE__)}/packages/server' require '#{File.dirname(__FILE__)}/packages/scm' require '#{File.dirname(__FILE__)}/packages/ruby' -policy :diaspora, :roles => [:tom,:backer] do +policy :diaspora, :roles => [:pivots] do # requires :clean_dreamhost requires :tools requires :rubygems diff --git a/config/thin.yml b/config/thin.yml index cc071975d..6a00fdb6c 100644 --- a/config/thin.yml +++ b/config/thin.yml @@ -13,9 +13,9 @@ max_conns: 1024 require: [] max_persistent_conns: 512 -environment: development -servers: 1 +environment: production +servers: 3 daemonize: true #chdir: /usr/applications/localhash/current -#socket: /tmp/thin.sock -port: 80 +socket: /tmp/thin.sock +#port: 80 diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index af6f737a9..2e06913f2 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -7,6 +7,7 @@ require 'config/environment' remote_url = "http://tom.joindiaspora.com/" +remote_url = "http://localhost:3000/" # Create seed user user = User.instantiate!( :email => "tom@tom.joindiaspora.com", :username => "tom", diff --git a/spec/factories.rb b/spec/factories.rb index 4c59631d8..c1dfcd50a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -36,7 +36,7 @@ end Factory.define :user do |u| u.sequence(:username) {|n| "bob#{n}"} - u.sequence(:email) {|n| "bob#{n}@aol.com"} + u.sequence(:email) {|n| "bob#{n}@pivotallabs.com"} u.password "bluepin7" u.password_confirmation "bluepin7" u.person { |a| Factory.create(:person_with_user, :owner_id => a._id)} diff --git a/spec/lib/websocket_spec.rb b/spec/lib/websocket_spec.rb index 762a725b5..018f5020d 100644 --- a/spec/lib/websocket_spec.rb +++ b/spec/lib/websocket_spec.rb @@ -9,6 +9,7 @@ describe Diaspora::WebSocket do @user = Factory.create(:user) @aspect = @user.aspect(:name => "losers") @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) + unstub_sockets end it 'should queue a job' do @@ -16,10 +17,21 @@ describe Diaspora::WebSocket do @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) end - it 'The queued job should reach Magent' do - @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) - channel = Magent::GenericChannel.new('websocket') - channel.message_count.should == 1 + describe 'queuing and dequeuing ' do + before do + @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + @channel = Magent::GenericChannel.new('websocket') + end + + it 'should send the queued job to Magent' do + @channel.message_count.should == 1 + end + + it 'should dequeue the job successfully' do + messages = @channel.message_count + @channel.dequeue + @channel.message_count.should == messages -1 + end end end diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 72a3b8dc1..5899cb7fb 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -19,8 +19,7 @@ describe Request do person_request.valid?.should be true end - it 'should generate xml for the User as a Person' do - + it 'should generate xml for the User as a Person' do request = @user.send_friend_request_to Factory.create(:person), @aspect xml = request.to_xml.to_s diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6e8355021..223881671 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -11,6 +11,15 @@ describe User do @user = Factory.create(:user) @aspect = @user.aspect(:name => 'heroes') end + + it 'should create with pivotal or allowed emails' do + user1 = Factory.create(:user, :email => "kimfuh@yahoo.com") + user2 = Factory.create(:user, :email => "awesome@sofaer.net") + user3 = Factory.create(:user, :email => "steveellis@pivotallabs.com") + user1.created_at.nil?.should be false + user2.created_at.nil?.should be false + user3.created_at.nil?.should be false + end describe 'profiles' do it 'should be able to update their profile and send it to their friends' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d6317d30..3fdac9810 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,7 @@ RSpec.configure do |config| config.before(:each) do DatabaseCleaner.start stub_sockets + User.stub!(:allowed_email?).and_return(:true) end config.after(:each) do @@ -45,11 +46,17 @@ RSpec.configure do |config| end end def stub_sockets - Diaspora::WebSocket.stub!(:push_to_user).and_return(true) + Diaspora::WebSocket.stub!(:queue_to_user).and_return(true) Diaspora::WebSocket.stub!(:subscribe).and_return(true) Diaspora::WebSocket.stub!(:unsubscribe).and_return(true) end + def unstub_sockets + Diaspora::WebSocket.unstub!(:queue_to_user) + Diaspora::WebSocket.unstub!(:subscribe) + Diaspora::WebSocket.unstub!(:unsubscribe) + end + def stub_signature_verification (get_models.map{|model| model.camelize.constantize} - [User]).each do |model| model.any_instance.stubs(:verify_signature).returns(true)