From 495dd89dd2a734a8fdf0992c990669eb75b97d57 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Mon, 16 May 2011 15:54:18 -0700 Subject: [PATCH 01/17] Fix password reset, add cucumber feature --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/controllers/application_controller.rb | 4 ++++ features/change_password.feature | 13 +++++++++++++ features/step_definitions/user_steps.rb | 8 ++++++++ features/support/env.rb | 1 + spec/controllers/registrations_controller_spec.rb | 6 +++--- spec/controllers/sessions_controller_spec.rb | 10 +++++----- 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index cb6d11592..0bb2aa8f9 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem 'ohai', '0.5.8', :require => false #Chef dependency gem 'nokogiri', '1.4.3.1' #Security -gem 'devise', '1.3.1' +gem 'devise', '~> 1.3.1' gem 'devise_invitable', '0.5.0' #Authentication diff --git a/Gemfile.lock b/Gemfile.lock index 4c14681c6..db08a1db0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,7 +158,7 @@ GEM culerity (0.2.15) daemons (1.1.2) database_cleaner (0.6.0) - devise (1.3.1) + devise (1.3.4) bcrypt-ruby (~> 2.1.2) orm_adapter (~> 0.0.3) warden (~> 1.0.3) @@ -415,7 +415,7 @@ DEPENDENCIES cloudfiles (= 1.4.10) cucumber-rails (= 0.3.2) database_cleaner (= 0.6.0) - devise (= 1.3.1) + devise (~> 1.3.1) devise_invitable (= 0.5.0) em-websocket! excon (= 0.2.4) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 595d963a8..95956d754 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -107,4 +107,8 @@ class ApplicationController < ActionController::Base def grammatical_gender @grammatical_gender || nil end + + def after_sign_in_path_for(resource) + stored_location_for(:user) || aspects_path(:a_ids => current_user.aspects.where(:open => true).select(:id).all.map{|a| a.id}) + end end diff --git a/features/change_password.feature b/features/change_password.feature index aeb80bad2..31da98c01 100644 --- a/features/change_password.feature +++ b/features/change_password.feature @@ -14,3 +14,16 @@ Feature: Change password Then I should be on the new user session page When I sign in with password "newsecret" Then I should be on the aspects page + + Scenario: Reset my password + Given a user with email "forgetful@users.net" + Given I am on the new user password page + And I fill in "Email" with "forgetful@users.net" + And I press "Send me reset password instructions" + Then I should see "You will receive an email with instructions" + And I follow the "Change my password" link from the Devise.mailer + Then I should see "Change your password" + And I fill in "Password" with "supersecret" + And I fill in "Password confirmation" with "supersecret" + And I press "Change my password" + Then I should see "Your password was changed successfully" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 2a8e4ac2f..92fbcff53 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -154,3 +154,11 @@ Given /^many posts from alice for bob$/ do time_interval += 1000 end end + +And /^I follow the "([^\"]*)" link from the Devise.mailer$/ do |link_text| + doc = Nokogiri(Devise.mailer.deliveries.first.body.to_s) + links = doc.css('a') + link = links.detect{ |link| link.text == link_text } + path = link.attributes["href"].value + visit URI::parse(path).request_uri +end diff --git a/features/support/env.rb b/features/support/env.rb index 09827a3f5..b0bb208b8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -48,6 +48,7 @@ include HelperMethods Before do DatabaseCleaner.clean + Devise.mailer.deliveries = [] end silence_warnings do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 99256d3b1..1ce500268 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -63,9 +63,9 @@ describe RegistrationsController do flash[:notice].should_not be_empty end - it "redirects to the root path" do + it "redirects to the home path" do get :create, @valid_params - response.should redirect_to root_path + response.should redirect_to aspects_path end end @@ -99,4 +99,4 @@ describe RegistrationsController do end end end -end \ No newline at end of file +end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 3337787e5..5197c3f84 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -24,15 +24,15 @@ describe SessionsController do end describe "#create" do - it "redirects to / for a non-mobile user" do + it "redirects to /aspects for a non-mobile user" do post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} - response.should redirect_to root_path + response.should redirect_to aspects_path end - it "redirects to / for a mobile user" do + it "redirects to /aspects for a mobile user" do @request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7' post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} - response.should redirect_to root_path + response.should redirect_to aspects_path end it 'queues up an update job' do @@ -59,4 +59,4 @@ describe SessionsController do response.should redirect_to root_path end end -end \ No newline at end of file +end From a357cf92177466f73aba1e3640efa2ef977e19b8 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Mon, 16 May 2011 16:33:05 -0700 Subject: [PATCH 02/17] Fix build... damn question marks. --- spec/controllers/registrations_controller_spec.rb | 3 ++- spec/controllers/sessions_controller_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 1ce500268..f6cc2deae 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -65,7 +65,8 @@ describe RegistrationsController do it "redirects to the home path" do get :create, @valid_params - response.should redirect_to aspects_path + response.should be_redirect + response.location.should match /^#{aspects_url}\??$/ end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 5197c3f84..f7b9a133b 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -26,13 +26,15 @@ describe SessionsController do describe "#create" do it "redirects to /aspects for a non-mobile user" do post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} - response.should redirect_to aspects_path + response.should be_redirect + response.location.should match /^#{aspects_url}\??$/ end it "redirects to /aspects for a mobile user" do @request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7' post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} - response.should redirect_to aspects_path + response.should be_redirect + response.location.should match /^#{aspects_url}\??$/ end it 'queues up an update job' do From 8821043ed7197903f628352f33e3adfa09c1ea79 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 17:47:27 -0700 Subject: [PATCH 03/17] work in process --- config/environments/development.rb | 3 +++ config/environments/production.rb | 4 ++++ config/initializers/resque.rb | 13 +++++++++++-- script/server | 1 - 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 0051d171d..8329de4eb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -23,6 +23,9 @@ Diaspora::Application.configure do config.active_support.deprecation = :log #config.threadsafe! + # Process jobs in process? + config.work_in_process = true + # Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars # This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why # Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls diff --git a/config/environments/production.rb b/config/environments/production.rb index f02ea6132..d38457c5b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,6 +47,10 @@ Diaspora::Application.configure do # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true config.threadsafe! + + # Process jobs in process? + #config.work_in_process = false + end # Sacrifice readability for a 10% performance boost diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 94fe55ac4..48336f818 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -1,5 +1,14 @@ require File.join(Rails.root, 'app', 'models', 'jobs', 'base') Dir[File.join(Rails.root, 'app', 'models', 'jobs', '*.rb')].each { |file| require file } -#config = YAML::load(File.open("#{Rails.root}/config/redis.yml")) -#Resque.redis = Redis.new(:host => config['host'], :port => config['port']) + require 'resque' + +begin + if Diaspora::Application.config.work_in_process + module Resque + def enqueue(klass, *args) + klass.send(:perform, *args) + end + end + end +end diff --git a/script/server b/script/server index f2a2d2843..d94da6d15 100755 --- a/script/server +++ b/script/server @@ -121,7 +121,6 @@ if [ -n "$services" ]; then exit 64 fi - redis_config From 55d39521c4e6042a1f81755ca92f63e839bc7520 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 18:29:31 -0700 Subject: [PATCH 04/17] rescue redis connection attempts in websocket --- config/initializers/resque.rb | 6 ++++++ lib/diaspora/web_socket.rb | 12 ++++++++++-- spec/lib/diaspora/web_socket_spec.rb | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 48336f818..22be0cec2 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -5,10 +5,16 @@ require 'resque' begin if Diaspora::Application.config.work_in_process + if Rails.env == 'production' + puts "WARNING: You are running Diaspora in production without Resque workers turned on. Please don't do this." + end + module Resque def enqueue(klass, *args) klass.send(:perform, *args) end end end +rescue + nil end diff --git a/lib/diaspora/web_socket.rb b/lib/diaspora/web_socket.rb index f27527ca8..9df317df2 100644 --- a/lib/diaspora/web_socket.rb +++ b/lib/diaspora/web_socket.rb @@ -60,11 +60,19 @@ module Diaspora module Socketable def socket_to_user(user_or_id, opts={}) - SocketsController.new.outgoing(user_or_id, self, opts) + begin + SocketsController.new.outgoing(user_or_id, self, opts) + rescue + nil + end end def unsocket_from_user(user_or_id, opts={}) - SocketsController.new.outgoing(user_or_id, Retraction.for(self), opts) + begin + SocketsController.new.outgoing(user_or_id, Retraction.for(self), opts) + rescue + nil + end end end end diff --git a/spec/lib/diaspora/web_socket_spec.rb b/spec/lib/diaspora/web_socket_spec.rb index 551b874d0..37fda4e68 100644 --- a/spec/lib/diaspora/web_socket_spec.rb +++ b/spec/lib/diaspora/web_socket_spec.rb @@ -63,4 +63,11 @@ describe Diaspora::Socketable do Diaspora::WebSocket.should_receive(:queue_to_user) @post.socket_to_user(@user, :aspect_ids => @aspect.id) end + + it 'no-ops if redis isnt present' do + Diaspora::WebSocket.stub(:redis).and_return(nil) + lambda { + @post.socket_to_user(@user, :aspect_ids => @aspect.id) + }.should_not raise_error + end end From 164226a3d77622383a93da2df07dd8dd5a3bc0df Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Mon, 16 May 2011 18:48:03 -0700 Subject: [PATCH 05/17] Replace ServiceUser with fakes in ServicesController --- app/models/service_user.rb | 23 ++++++++++++++++++- app/models/services/facebook.rb | 12 ++++++---- spec/models/service_user_spec.rb | 33 +++++++++++++++++++++++++++ spec/models/services/facebook_spec.rb | 11 ++++++++- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/app/models/service_user.rb b/app/models/service_user.rb index 2f1ce222a..fc9b8455c 100644 --- a/app/models/service_user.rb +++ b/app/models/service_user.rb @@ -12,7 +12,7 @@ class ServiceUser < ActiveRecord::Base def attach_local_models service_for_uid = Services::Facebook.where(:type => service.type.to_s, :uid => self.uid).first if !service_for_uid.blank? && (service_for_uid.user.person.profile.searchable) - self.person = service_for_uid.user.person + self.person = service_for_uid.user.person else self.person = nil end @@ -28,3 +28,24 @@ class ServiceUser < ActiveRecord::Base :invitation_identifier => self.uid}).first end end + +class FakeServiceUser < HashWithIndifferentAccess + def initialize(row) + columns = ServiceUser.column_names + self.replace Hash[columns.zip(row)] + end + + ServiceUser.column_names.each do |column| + symbol = column.to_sym + define_method symbol do + self[symbol] + end + end + + ServiceUser.reflect_on_all_associations.each do |assoc| + define_method assoc.name do + assoc.klass.find(self[assoc.primary_key_name]) + end + end +end + diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 49243e12b..f1c4ea691 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -27,14 +27,16 @@ class Services::Facebook < Service Resque.enqueue(Job::UpdateServiceUsers, self.id) end person = Person.arel_table - service_user = ServiceUser.arel_table + + query = self.service_users.scoped if opts[:local] - ServiceUser.joins(:person).where(:service_id => self.id).where(person[:owner_id].not_eq(nil)).all + query = query.joins(:person).where(person[:owner_id].not_eq(nil)) elsif opts[:remote] - ServiceUser.joins(:person).where(:service_id => self.id).where(person[:owner_id].eq(nil)).all - else - self.service_users + query = query.joins(:person).where(person[:owner_id].eq(nil)) end + + result = ServiceUser.connection.execute(query.to_sql).to_a + fakes = result.map{|r| FakeServiceUser.new(r) } end def save_friends diff --git a/spec/models/service_user_spec.rb b/spec/models/service_user_spec.rb index d58da22e7..2a03343a6 100644 --- a/spec/models/service_user_spec.rb +++ b/spec/models/service_user_spec.rb @@ -106,3 +106,36 @@ JSON end end end + +describe FakeServiceUser do + describe '.initialize' do + before do + @data = [182, "820651", "Maxwell Salzberg", "http://cdn.fn.com/pic1.jpg", 299, 1610, nil, nil, nil, DateTime.parse("Tue May 17 00:31:44 UTC 2011"), DateTime.parse("Tue May 17 00:31:44 UTC 2011")] + @fake = FakeServiceUser.new(@data) + end + it 'takes a mysql row and sets the attr names to their values' do + @fake[:id].should == @data[0] + @fake[:uid].should == @data[1] + @fake[:name].should == @data[2] + @fake[:photo_url].should == @data[3] + @fake[:service_id].should == @data[4] + @fake[:person_id].should == @data[5] + @fake[:contact_id].should == @data[6] + @fake[:request_id].should == @data[7] + @fake[:invitation_id].should == @data[8] + @fake[:created_at].should == @data[9] + @fake[:updated_at].should == @data[10] + end + + it 'has reader methods' do + @fake.photo_url.should == @data[3] + @fake.person_id.should == @data[5] + end + + it 'has association methods' do + person = mock + Person.should_receive(:find).with(@data[5]).and_return person + @fake.person.should == person + end + end +end diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index 423ed582f..51a2d77ea 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -28,7 +28,7 @@ describe Services::Facebook do end context 'finder' do - before do + before do @user2 = Factory.create(:user_with_aspect) @user2_fb_id = '820651' @user2_fb_name = 'Maxwell Salzberg' @@ -70,16 +70,25 @@ JSON end describe '#finder' do + it 'returns an array of non-activerecord objects' do + @service.save_friends + result = @service.finder + result.should be_an(Array) + result.first.should_not be_an ActiveRecord::Base + end + it 'does a syncronous call if it has not been called before' do @service.should_receive(:save_friends) @service.finder end + it 'dispatches a resque job' do Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, @service.id) su2 = ServiceUser.create(:service => @user2_service, :uid => @user2_fb_id, :name => @user2_fb_name, :photo_url => @user2_fb_photo_url) @service.service_users = [su2] @service.finder end + context 'opts' do it 'only local does not return people who are remote' do @service.save_friends From 7042b43799b32023043c764d9f2045989a5e00e9 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 18:54:50 -0700 Subject: [PATCH 06/17] use appconfig instead of config --- config/app_config.yml.example | 4 ++++ config/environments/development.rb | 3 --- config/environments/production.rb | 4 ---- config/initializers/resque.rb | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 8d3c1ec47..393b6e53d 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -96,6 +96,9 @@ default: # It is false by default in development and test. enable_splunk_logging: true + # Process jobs in process? + single_process_mode: true + development: enable_splunk_logging: false @@ -105,3 +108,4 @@ test: enable_splunk_logging: false production: + single_process_mode: false diff --git a/config/environments/development.rb b/config/environments/development.rb index 8329de4eb..0051d171d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -23,9 +23,6 @@ Diaspora::Application.configure do config.active_support.deprecation = :log #config.threadsafe! - # Process jobs in process? - config.work_in_process = true - # Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars # This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why # Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls diff --git a/config/environments/production.rb b/config/environments/production.rb index d38457c5b..f02ea6132 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,10 +47,6 @@ Diaspora::Application.configure do # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true config.threadsafe! - - # Process jobs in process? - #config.work_in_process = false - end # Sacrifice readability for a 10% performance boost diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 22be0cec2..cc977ba6a 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -4,7 +4,7 @@ Dir[File.join(Rails.root, 'app', 'models', 'jobs', '*.rb')].each { |file| requir require 'resque' begin - if Diaspora::Application.config.work_in_process + if AppConfig[:single_process_mode] if Rails.env == 'production' puts "WARNING: You are running Diaspora in production without Resque workers turned on. Please don't do this." end From 4875d6557dd1fbd49b653a027086479e7c7a5b1e Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 22:30:25 -0700 Subject: [PATCH 07/17] update nokogiri, require false on sod --- Gemfile | 6 +++--- Gemfile.lock | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 0bb2aa8f9..a1af70f74 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'bundler', '>= 1.0.0' gem 'chef', '0.9.12', :require => false gem 'ohai', '0.5.8', :require => false #Chef dependency -gem 'nokogiri', '1.4.3.1' +gem 'nokogiri' #Security gem 'devise', '~> 1.3.1' @@ -61,7 +61,7 @@ gem 'SystemTimer', '1.2.1' unless RUBY_VERSION.include? '1.9' || RUBY_PLATFORM = group :development do gem 'capistrano', '2.5.19', :require => false gem 'capistrano-ext', '1.2.1', :require => false - gem 'sod', :git => "git://github.com/MikeSofaer/sod.git" + gem 'sod', :git => "git://github.com/MikeSofaer/sod.git", :require => false end group :test, :development do @@ -80,7 +80,7 @@ group :test do gem 'cucumber-rails', '0.3.2' gem 'rspec', '>= 2.0.0' gem 'rspec-rails', '>= 2.0.0' - gem 'rcov' + gem 'rcov', :require => false gem 'database_cleaner', '0.6.0' gem 'webmock', :require => false gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index db08a1db0..d8ae98214 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -156,7 +156,7 @@ GEM cucumber-rails (0.3.2) cucumber (>= 0.8.0) culerity (0.2.15) - daemons (1.1.2) + daemons (1.1.3) database_cleaner (0.6.0) devise (1.3.4) bcrypt-ruby (~> 2.1.2) @@ -185,7 +185,7 @@ GEM fastthread (1.0.7) ffi (0.6.3) rake (>= 0.8.7) - fixture_builder (0.2.0) + fixture_builder (0.2.2) fog (0.3.25) builder excon (>= 0.2.4) @@ -202,12 +202,12 @@ GEM rspec (~> 2.0) rspec-instafail (~> 0.1.4) gem_plugin (0.2.3) - gherkin (2.3.6) + gherkin (2.3.8) json (>= 1.4.6) haml (3.0.25) hashie (0.4.0) - highline (1.6.1) - http_connection (1.4.0) + highline (1.6.2) + http_connection (1.4.1) i18n (0.5.0) i18n-inflector (2.5.1) i18n (>= 0.4.1) @@ -224,7 +224,7 @@ GEM configuration (>= 0.0.5) rake (>= 0.8.1) linecache (0.43) - mail (2.2.15) + mail (2.2.19) activesupport (>= 2.3.6) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -245,7 +245,7 @@ GEM gem_plugin (>= 0.2.3) multi_json (0.0.5) multi_xml (0.2.2) - multipart-post (1.1.0) + multipart-post (1.1.1) mysql2 (0.2.6) net-ldap (0.1.1) net-scp (1.0.4) @@ -253,7 +253,7 @@ GEM net-sftp (2.0.5) net-ssh (>= 2.0.9) net-ssh (2.0.24) - net-ssh-gateway (1.0.1) + net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) nokogiri (1.4.3.1) oa-basic (0.1.6) @@ -366,8 +366,8 @@ GEM ffi (~> 0.6.3) json_pure rubyzip - simple_oauth (0.1.4) - sinatra (1.2.3) + simple_oauth (0.1.5) + sinatra (1.2.6) rack (~> 1.1) tilt (< 2.0, >= 1.2.2) subexec (0.0.4) @@ -378,7 +378,7 @@ GEM eventmachine (>= 0.12.6) rack (>= 1.0.0) thor (0.14.6) - tilt (1.2.2) + tilt (1.3) treetop (1.4.9) polyglot (>= 0.3.1) typhoeus (0.2.4) @@ -435,7 +435,7 @@ DEPENDENCIES mini_magick (= 3.2) mongrel mysql2 (= 0.2.6) - nokogiri (= 1.4.3.1) + nokogiri ohai (= 0.5.8) omniauth (= 0.1.6) rails (= 3.0.3) From 00c6631f11dd107832dcc1e7daaec05e20ec5878 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Tue, 17 May 2011 15:56:56 +0200 Subject: [PATCH 08/17] replaced SOCKET_PORT in config/server.sh with the setting from config/app_config.yml; respect single_process_mode setting in app_config.yml in script/server --- config/server.sh | 3 +-- lib/app_config.rb | 6 +++++- script/get_config.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ script/server | 7 +++++-- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100755 script/get_config.rb diff --git a/config/server.sh b/config/server.sh index 7398b2fd8..64d989275 100644 --- a/config/server.sh +++ b/config/server.sh @@ -2,11 +2,10 @@ # Included by script/server # THIN_PORT=3000 -SOCKET_PORT=8080 # Choose one mode by uncommenting export RAILS_ENV='development' -#export RAILS_ENV='production' +export RAILS_ENV='production' # See thin -h for possible values. DEFAULT_THIN_ARGS="-p $THIN_PORT -e $RAILS_ENV" diff --git a/lib/app_config.rb b/lib/app_config.rb index 7fefcf93d..53ad6de8c 100644 --- a/lib/app_config.rb +++ b/lib/app_config.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2010, Diaspora Inc. This file is +# Copyright (c) 2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. @@ -14,6 +14,10 @@ class AppConfig config_vars[key] = value end + def self.has_key?(key) + config_vars.has_key?(key) + end + def self.configure_for_environment(env) load_config_for_environment(env) generate_pod_uri diff --git a/script/get_config.rb b/script/get_config.rb new file mode 100755 index 000000000..1f0067965 --- /dev/null +++ b/script/get_config.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +# Copyright (c) 2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'rubygems' +require 'yaml' + +require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/core_ext/hash/keys' + +class Rails + def self.root + File.join(File.dirname(__FILE__), "..") + end + + def self.env + env = 'development' + env = ENV['RAILS_ENV'] if ENV.has_key?('RAILS_ENV') + env = ARGV[1] if ARGV.length == 2 + env.downcase + end +end + +require File.join(Rails.root, 'lib', 'app_config') + + +if ARGV.length >= 1 + key = ARGV[0].to_sym + AppConfig.configure_for_environment(Rails.env) + if AppConfig.has_key?(key) + print AppConfig[key] + else + puts "Invalid option #{ARGV[0]}" + exit 2 + end +else + puts "Usage: ./script/get_config.rb option [environment]" + puts "" + puts "envrionment defaults to development" + exit 1 +end diff --git a/script/server b/script/server index d94da6d15..8b6270b75 100755 --- a/script/server +++ b/script/server @@ -10,6 +10,7 @@ OS=`uname -s` [ -e config/server.sh ] && source config/server.sh +export SOCKET_PORT=$(./script/get_config.rb socket_port $RAILS_ENV) function init_public # Create all dynamically generated files in public/ folder @@ -169,6 +170,8 @@ fi mkdir -p -v log/thin/ bundle exec ruby ./script/websocket_server.rb& -redis-server config/redis.conf &>log/redis-console.log & -QUEUE=* bundle exec rake resque:work& +if [ "$(./script/get_config.rb single_process_mode $RAILS_ENV)" = "false" ]; then + redis-server config/redis.conf &>log/redis-console.log & + QUEUE=* bundle exec rake resque:work& +fi bundle exec thin start $args From 401b198bbfeaeb4eaff7143a2146c79250925648 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Tue, 17 May 2011 16:02:37 +0200 Subject: [PATCH 09/17] --amend --- config/server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/server.sh b/config/server.sh index 64d989275..7060a9f5c 100644 --- a/config/server.sh +++ b/config/server.sh @@ -5,7 +5,7 @@ THIN_PORT=3000 # Choose one mode by uncommenting export RAILS_ENV='development' -export RAILS_ENV='production' +#export RAILS_ENV='production' # See thin -h for possible values. DEFAULT_THIN_ARGS="-p $THIN_PORT -e $RAILS_ENV" From 18859a2fba4980560264a923c6432f590b74165e Mon Sep 17 00:00:00 2001 From: MrZYX Date: Tue, 17 May 2011 17:52:59 +0200 Subject: [PATCH 10/17] fixed #1073, websocket should now work again for some people at least --- script/websocket_server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 040070d00..8dde9c58f 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -69,7 +69,7 @@ begin debug_pp cookie - user_id = cookie["warden.user.user.key"].last + user_id = cookie["warden.user.user.key"][1].first debug_pp "In WSS, suscribing user: #{User.find(user_id).name} with id: #{user_id}" sid = Diaspora::WebSocket.subscribe(user_id, ws) From 934a91e47edf5c0d8c43a4e57b2694ac115adb57 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 17 May 2011 10:10:20 -0700 Subject: [PATCH 11/17] no need to run the websocket server if redis isn't running (in single_process_mode) --- script/server | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/server b/script/server index 8b6270b75..b65e087c9 100755 --- a/script/server +++ b/script/server @@ -169,9 +169,10 @@ if [ ! -e 'public/assets/default.css' ]; then fi mkdir -p -v log/thin/ -bundle exec ruby ./script/websocket_server.rb& if [ "$(./script/get_config.rb single_process_mode $RAILS_ENV)" = "false" ]; then redis-server config/redis.conf &>log/redis-console.log & QUEUE=* bundle exec rake resque:work& + + bundle exec ruby ./script/websocket_server.rb& fi bundle exec thin start $args From f9ef9a4b477a1b1a73a0bd5ab3ce65b7546aec74 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 17 May 2011 10:14:24 -0700 Subject: [PATCH 12/17] Make FakeServiceUser assoc methods tolerant of nil --- app/models/service_user.rb | 6 +++++- spec/models/service_user_spec.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/service_user.rb b/app/models/service_user.rb index fc9b8455c..369a91382 100644 --- a/app/models/service_user.rb +++ b/app/models/service_user.rb @@ -44,7 +44,11 @@ class FakeServiceUser < HashWithIndifferentAccess ServiceUser.reflect_on_all_associations.each do |assoc| define_method assoc.name do - assoc.klass.find(self[assoc.primary_key_name]) + if associated_id = self[assoc.primary_key_name] + assoc.klass.find(associated_id) + else + nil + end end end end diff --git a/spec/models/service_user_spec.rb b/spec/models/service_user_spec.rb index 2a03343a6..b93e7f855 100644 --- a/spec/models/service_user_spec.rb +++ b/spec/models/service_user_spec.rb @@ -137,5 +137,10 @@ describe FakeServiceUser do Person.should_receive(:find).with(@data[5]).and_return person @fake.person.should == person end + + it 'does not error on an association with no id' do + @fake[:person_id] = nil + lambda{ @fake.person }.should_not raise_error + end end end From 0a8ce3b9f213d804811e36c87ffccc36feb4421f Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 17 May 2011 10:24:28 -0700 Subject: [PATCH 13/17] Unscope assoc calls from FakeServiceUser, we can delete this once the last default scope has been removed in the follow merge --- app/models/service_user.rb | 2 +- spec/models/service_user_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/service_user.rb b/app/models/service_user.rb index 369a91382..21e40c62a 100644 --- a/app/models/service_user.rb +++ b/app/models/service_user.rb @@ -45,7 +45,7 @@ class FakeServiceUser < HashWithIndifferentAccess ServiceUser.reflect_on_all_associations.each do |assoc| define_method assoc.name do if associated_id = self[assoc.primary_key_name] - assoc.klass.find(associated_id) + assoc.klass.unscoped.find(associated_id) else nil end diff --git a/spec/models/service_user_spec.rb b/spec/models/service_user_spec.rb index b93e7f855..309ef50d4 100644 --- a/spec/models/service_user_spec.rb +++ b/spec/models/service_user_spec.rb @@ -134,6 +134,7 @@ describe FakeServiceUser do it 'has association methods' do person = mock + Person.stub!(:unscoped).and_return(Person) Person.should_receive(:find).with(@data[5]).and_return person @fake.person.should == person end From 1746f610b6f22510f2f758a3cbf1cdcfc8cad6b4 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Tue, 17 May 2011 19:26:28 +0200 Subject: [PATCH 14/17] if we disable websocket in single process mode, there's no need for the JS --- app/views/js/_websocket_js.haml | 16 ++++++++++------ public/javascripts/web-socket-receiver.js | 16 +++++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 4187ff631..f021fb1c1 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -2,9 +2,13 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -:javascript - WebSocket.__swfLocation = "#{javascript_path 'vendor/WebSocketMain.swf'}"; - $(document).ready(function(){ - WSR.initialize("#{(AppConfig[:socket_secure])?'wss':'ws'}://#{request.host}:#{AppConfig[:socket_port]}/"); - }); - +-if AppConfig[:single_process_mode] + :javascript + var websocket_enabled = false +- else + :javascript + var websocket_enabled = true + WebSocket.__swfLocation = "#{javascript_path 'vendor/WebSocketMain.swf'}"; + $(document).ready(function(){ + WSR.initialize("#{(AppConfig[:socket_secure])?'wss':'ws'}://#{request.host}:#{AppConfig[:socket_port]}/"); + }); diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index e0ad2349c..70a448adf 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -6,14 +6,16 @@ var WebSocketReceiver = { //Attach onmessage to websocket ws.onmessage = WSR.onMessage; ws.onclose = function() { - Diaspora.widgets.notifications.showNotification({ - html: '
' + - Diaspora.widgets.i18n.t("web_sockets.disconnected") + - '
', - incrementCount: false - }); + if (websocket_enabled) { + Diaspora.widgets.notifications.showNotification({ + html: '
' + + Diaspora.widgets.i18n.t("web_sockets.disconnected") + + '
', + incrementCount: false + }); - WSR.debug("socket closed"); + WSR.debug("socket closed"); + } }; ws.onopen = function() { ws.send(location.pathname); From 5218bd89c61a5a3effe05481795511051b8accc6 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 17 May 2011 10:29:07 -0700 Subject: [PATCH 15/17] Revert FakeServiceUser work, needs more testing to make sure extra models aren't instantiated. This reverts commit 0a8ce3b9f213d804811e36c87ffccc36feb4421f. This reverts commit f9ef9a4b477a1b1a73a0bd5ab3ce65b7546aec74. This reverts commit 164226a3d77622383a93da2df07dd8dd5a3bc0df. --- app/models/service_user.rb | 27 +------------------ app/models/services/facebook.rb | 12 ++++----- spec/models/service_user_spec.rb | 39 --------------------------- spec/models/services/facebook_spec.rb | 11 +------- 4 files changed, 7 insertions(+), 82 deletions(-) diff --git a/app/models/service_user.rb b/app/models/service_user.rb index 21e40c62a..2f1ce222a 100644 --- a/app/models/service_user.rb +++ b/app/models/service_user.rb @@ -12,7 +12,7 @@ class ServiceUser < ActiveRecord::Base def attach_local_models service_for_uid = Services::Facebook.where(:type => service.type.to_s, :uid => self.uid).first if !service_for_uid.blank? && (service_for_uid.user.person.profile.searchable) - self.person = service_for_uid.user.person + self.person = service_for_uid.user.person else self.person = nil end @@ -28,28 +28,3 @@ class ServiceUser < ActiveRecord::Base :invitation_identifier => self.uid}).first end end - -class FakeServiceUser < HashWithIndifferentAccess - def initialize(row) - columns = ServiceUser.column_names - self.replace Hash[columns.zip(row)] - end - - ServiceUser.column_names.each do |column| - symbol = column.to_sym - define_method symbol do - self[symbol] - end - end - - ServiceUser.reflect_on_all_associations.each do |assoc| - define_method assoc.name do - if associated_id = self[assoc.primary_key_name] - assoc.klass.unscoped.find(associated_id) - else - nil - end - end - end -end - diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index f1c4ea691..49243e12b 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -27,16 +27,14 @@ class Services::Facebook < Service Resque.enqueue(Job::UpdateServiceUsers, self.id) end person = Person.arel_table - - query = self.service_users.scoped + service_user = ServiceUser.arel_table if opts[:local] - query = query.joins(:person).where(person[:owner_id].not_eq(nil)) + ServiceUser.joins(:person).where(:service_id => self.id).where(person[:owner_id].not_eq(nil)).all elsif opts[:remote] - query = query.joins(:person).where(person[:owner_id].eq(nil)) + ServiceUser.joins(:person).where(:service_id => self.id).where(person[:owner_id].eq(nil)).all + else + self.service_users end - - result = ServiceUser.connection.execute(query.to_sql).to_a - fakes = result.map{|r| FakeServiceUser.new(r) } end def save_friends diff --git a/spec/models/service_user_spec.rb b/spec/models/service_user_spec.rb index 309ef50d4..d58da22e7 100644 --- a/spec/models/service_user_spec.rb +++ b/spec/models/service_user_spec.rb @@ -106,42 +106,3 @@ JSON end end end - -describe FakeServiceUser do - describe '.initialize' do - before do - @data = [182, "820651", "Maxwell Salzberg", "http://cdn.fn.com/pic1.jpg", 299, 1610, nil, nil, nil, DateTime.parse("Tue May 17 00:31:44 UTC 2011"), DateTime.parse("Tue May 17 00:31:44 UTC 2011")] - @fake = FakeServiceUser.new(@data) - end - it 'takes a mysql row and sets the attr names to their values' do - @fake[:id].should == @data[0] - @fake[:uid].should == @data[1] - @fake[:name].should == @data[2] - @fake[:photo_url].should == @data[3] - @fake[:service_id].should == @data[4] - @fake[:person_id].should == @data[5] - @fake[:contact_id].should == @data[6] - @fake[:request_id].should == @data[7] - @fake[:invitation_id].should == @data[8] - @fake[:created_at].should == @data[9] - @fake[:updated_at].should == @data[10] - end - - it 'has reader methods' do - @fake.photo_url.should == @data[3] - @fake.person_id.should == @data[5] - end - - it 'has association methods' do - person = mock - Person.stub!(:unscoped).and_return(Person) - Person.should_receive(:find).with(@data[5]).and_return person - @fake.person.should == person - end - - it 'does not error on an association with no id' do - @fake[:person_id] = nil - lambda{ @fake.person }.should_not raise_error - end - end -end diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index 51a2d77ea..423ed582f 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -28,7 +28,7 @@ describe Services::Facebook do end context 'finder' do - before do + before do @user2 = Factory.create(:user_with_aspect) @user2_fb_id = '820651' @user2_fb_name = 'Maxwell Salzberg' @@ -70,25 +70,16 @@ JSON end describe '#finder' do - it 'returns an array of non-activerecord objects' do - @service.save_friends - result = @service.finder - result.should be_an(Array) - result.first.should_not be_an ActiveRecord::Base - end - it 'does a syncronous call if it has not been called before' do @service.should_receive(:save_friends) @service.finder end - it 'dispatches a resque job' do Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, @service.id) su2 = ServiceUser.create(:service => @user2_service, :uid => @user2_fb_id, :name => @user2_fb_name, :photo_url => @user2_fb_photo_url) @service.service_users = [su2] @service.finder end - context 'opts' do it 'only local does not return people who are remote' do @service.save_friends From 1bdfd770b7f3b964f5b5aa665410c16d4f738e04 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 17 May 2011 10:15:08 -0700 Subject: [PATCH 16/17] check for redis only if not in single process mode --- script/server | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/script/server b/script/server index b65e087c9..714cb8177 100755 --- a/script/server +++ b/script/server @@ -122,9 +122,6 @@ if [ -n "$services" ]; then exit 64 fi -redis_config - - # Force AGPL if [ -w public -a ! -e public/source.tar.gz ]; then branch=$( git branch | awk '/^[*]/ {print $2}') @@ -170,7 +167,9 @@ fi mkdir -p -v log/thin/ if [ "$(./script/get_config.rb single_process_mode $RAILS_ENV)" = "false" ]; then + redis_config redis-server config/redis.conf &>log/redis-console.log & + QUEUE=* bundle exec rake resque:work& bundle exec ruby ./script/websocket_server.rb& From 524e4ba1dd9a07b82ad9dfa78217454d0e6155c6 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 17 May 2011 11:08:57 -0700 Subject: [PATCH 17/17] Update contributor agreement link --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3770c2d47..c03feba7c 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ See [here](http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091. for when to rebase. We need you to fill out a -[contributor agreement form](https://spreadsheets.google.com/a/joindiaspora.com/viewform?formkey=dGI2cHA3ZnNHLTJvbm10LUhXRTJjR0E6MQ&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq) +[contributor agreement form](https://spreadsheets.google.com/a/joindiaspora.com/spreadsheet/viewform?formkey=dFdRTnY0TGtfaklKQXZNUndsMlJ2eGc6MQ) before we can accept your patches. The agreement gives Diaspora joint ownership of the patch so the copyright isn't scattered. You can find it -[here](https://spreadsheets.google.com/a/joindiaspora.com/viewform?formkey=dGI2cHA3ZnNHLTJvbm10LUhXRTJjR0E6MQ&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq). +[here](https://spreadsheets.google.com/a/joindiaspora.com/spreadsheet/viewform?formkey=dFdRTnY0TGtfaklKQXZNUndsMlJ2eGc6MQ). We're currently working on revising it more details on what we're going for can be found [here](http://blog.joindiaspora.com/licensing.html). ## Resources @@ -73,4 +73,4 @@ Also, be sure to join the official [mailing list](http://eepurl.com/Vebk). If you wish to contact us privately about any exploits in Diaspora you may find, you can email -[exploits@joindiaspora.com](mailto:exploits@joindiaspora.com), [corresponding public key (keyID: 77485064)](http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0xCC6CAED977485064). \ No newline at end of file +[exploits@joindiaspora.com](mailto:exploits@joindiaspora.com), [corresponding public key (keyID: 77485064)](http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0xCC6CAED977485064).