From f9e5a469e061ebd9f548d7373336d5b088fd3ad1 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 17 Oct 2010 10:44:45 +0200 Subject: [PATCH 01/32] bugfixes.. --- pkg/fedora/make-dist.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 6777ae773..564ce02fb 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -126,8 +126,7 @@ function checkout() git clone --quiet $GIT_REPO; ( cd diaspora; - git remote add upstream \ - git://github.com/diaspora/diaspora.git + git remote add upstream $GIT_REPO for p in ../../*.patch; do git apply --whitespace=fix $p > /dev/null done &> /dev/null || : From 3a3ad1f053e336b70087ce1dbc62f69f214c4230 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 17 Oct 2010 10:56:25 +0200 Subject: [PATCH 02/32] bugfix --- pkg/fedora/make-dist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 564ce02fb..4dbee30b2 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -193,7 +193,7 @@ set -x if [ "$BUNDLE_FIX" = 'yes' ]; then rm -f Gemfile.lock rm -rf .bundle - bundle update + bundle update --path="../$bundle_name/bundle" fi bundle install --deployment \ --path="../$bundle_name/bundle" \ From a6300ecbdb6f5e3f4a08daa5c8ca85feb1135417 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 17 Oct 2010 23:14:07 +0200 Subject: [PATCH 03/32] Mewrging --- pkg/fedora/make-dist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 4dbee30b2..564ce02fb 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -193,7 +193,7 @@ set -x if [ "$BUNDLE_FIX" = 'yes' ]; then rm -f Gemfile.lock rm -rf .bundle - bundle update --path="../$bundle_name/bundle" + bundle update fi bundle install --deployment \ --path="../$bundle_name/bundle" \ From a99c15d388665ff903cc82ba660dbdf1a7d9dd04 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 17 Oct 2010 23:00:05 +0200 Subject: [PATCH 04/32] Removing set -x --- pkg/fedora/make-dist.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 564ce02fb..dcfafb6e1 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -180,7 +180,6 @@ function make_bundle() # Usage: make_bundle [ commit, defaults to HEAD] # { -set -x checkout ${1:-'HEAD'} >/dev/null bundle_id=$( git_id dist/diaspora/Gemfile) bundle_name="diaspora-bundle-$VERSION-$bundle_id" From 815e846684aff1498d8840cfa1d8982f18260260 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Mon, 18 Oct 2010 10:21:41 +0200 Subject: [PATCH 05/32] Test provisions. --- pkg/ubuntu/diaspora-setup | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/ubuntu/diaspora-setup b/pkg/ubuntu/diaspora-setup index 4b9207fd3..96284dd9b 100755 --- a/pkg/ubuntu/diaspora-setup +++ b/pkg/ubuntu/diaspora-setup @@ -9,6 +9,7 @@ test "$( perl -e 'print $<')" = "0" || { echo "You need to be root to do this, giving up" exit 2 } +external_hostname="$1" arg_hostname="$1" @@ -46,12 +47,13 @@ fi chmod 777 /var/lib/diaspora/uploads chown -R diaspora /var/log/diaspora -if [ -n "$arg_hostname" ]; then - sed -i "/pod_url:/s/$hostname/$arg_hostname/g" config/app_config.yml && - echo "config/app_config.yml updated." - exit 0 +if [ -n "$external_hostname" ]; then + sed -i "/pod_url:/s/$hostname/$external_hostname/g" \ + config/app_config.yml && echo "config/app_config.yml updated." + exit $? fi + hostname=$( awk '/pod_url:/ { print $2; exit }' Date: Tue, 19 Oct 2010 19:58:17 +0200 Subject: [PATCH 06/32] Firts try, nothing tested --- config/app_config.yml.example | 1 + pkg/fedora/diaspora-setup | 2 + pkg/fedora/diaspora-wsd | 2 +- pkg/fedora/diaspora.spec | 6 + pkg/fedora/dist/.gitkeep | 0 pkg/ubuntu/diaspora-install | 3 +- pkg/ubuntu/diaspora-setup | 2 + pkg/ubuntu/diaspora-wsd | 208 +++++++++++++++++++++------------- pkg/ubuntu/dist/.gitkeep | 0 script/websocket_server.rb | 23 ++++ 10 files changed, 165 insertions(+), 82 deletions(-) create mode 100644 pkg/fedora/dist/.gitkeep create mode 100644 pkg/ubuntu/dist/.gitkeep diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 0bd3771f7..90d9ac9f4 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -7,6 +7,7 @@ default: debug: false socket_debug : false socket_host: 0.0.0.0 + socket_pidfile: log/diaspora-wsd.pid socket_port: 8080 socket_collection_name: 'websocket' pubsub_server: 'https://pubsubhubbub.appspot.com/' diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup index a1df72fbc..3e8ff3bb4 100755 --- a/pkg/fedora/diaspora-setup +++ b/pkg/fedora/diaspora-setup @@ -24,6 +24,8 @@ cd /usr/share/diaspora/master test -e config/app_config.yml || cp config/app_config.yml.example config/app_config.yml +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml if rake db:seed:dev; then echo "Database config OK, new user tom/evankorth in place" diff --git a/pkg/fedora/diaspora-wsd b/pkg/fedora/diaspora-wsd index 6f0c7593f..f99492e80 100755 --- a/pkg/fedora/diaspora-wsd +++ b/pkg/fedora/diaspora-wsd @@ -33,7 +33,7 @@ cd /usr/share/diaspora RETVAL=0 prog="Diaspora websocket server" exec="script/websocket_server.rb" -pidfile="/var/run/diaspora-wsd" +pidfile="/var/run/diaspora/diaspora-wsd" lockfile="/var/lock/subsys/diaspora-wsd" logfile=/var/log/diaspora-wsd.log diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index 4c0cca719..1d61026e5 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -77,6 +77,7 @@ mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp cp %SOURCE2 $RPM_BUILD_ROOT/%{_datadir}/diaspora mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/log/diaspora +mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/run/diaspora mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/uploads mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp @@ -94,6 +95,8 @@ find -L $RPM_BUILD_ROOT/%{_datadir}/diaspora -type f \ cat files >> dirs && mv -f dirs files sed -i -e '\|.*/master/config.ru"$|d' \ -e '\|.*/master/config/environment.rb"$|d' \ + -e '\|.*/run/diaspora"$|d' \ + -e '\|.*/pkg/fedora/dist"$|d' \ -e 's|%{buildroot}||' -e 's|//|/|' -e '/""/d' \ files @@ -101,6 +104,7 @@ sed -i -e '\|.*/master/config.ru"$|d' \ %post wsd /sbin/chkconfig --add diaspora-wsd || : + %preun wsd if [ $1 -eq 0 ] ; then service diaspora-wsd stop &>/dev/null || : @@ -117,9 +121,11 @@ rm -fr $RPM_BUILD_ROOT %doc AUTHORS README.md GNU-AGPL-3.0 COPYRIGHT README-Fedora.md %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config.ru %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config/environment.rb +%attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/pkg/fedora/dist %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/uploads %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/tmp +%attr(-, diaspora, diaspora) %{_localstatedir}/run/diaspora %{_datadir}/diaspora/master/tmp %{_datadir}/diaspora/master/public/uploads diff --git a/pkg/fedora/dist/.gitkeep b/pkg/fedora/dist/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/ubuntu/diaspora-install b/pkg/ubuntu/diaspora-install index e7cef8f31..daaf33b54 100755 --- a/pkg/ubuntu/diaspora-install +++ b/pkg/ubuntu/diaspora-install @@ -41,8 +41,8 @@ cp master/pkg/ubuntu/diaspora-setup . mkdir -p /var/log/diaspora mkdir -p /var/lib/diaspora/uploads mkdir -p /var/lib/diaspora/tmp +mkdir -p /var/run/diaspora mkdir -p /etc/diaspora -mkdir -p /usr/share/diaspora/master/pkg/ubuntu/dist ln -sf /var/log/diaspora ./master/log cp master/config/app_config.yml.example /etc/diaspora/app_config.yml @@ -65,5 +65,6 @@ chown diaspora:diaspora /var/log/diaspora chown diaspora:diaspora /var/lib/diaspora/uploads chown diaspora:diaspora /var/lib/diaspora/tmp chown diaspora:diaspora /var/lib/diaspora +chown diaspora:diaspora /var/run/diaspora chown diaspora:diaspora /usr/share/diaspora/master/pkg/ubuntu/dist diff --git a/pkg/ubuntu/diaspora-setup b/pkg/ubuntu/diaspora-setup index 96284dd9b..20d0207f0 100755 --- a/pkg/ubuntu/diaspora-setup +++ b/pkg/ubuntu/diaspora-setup @@ -27,6 +27,8 @@ cd /usr/share/diaspora/master test -e config/app_config.yml || cp config/app_config.yml.example config/app_config.yml +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml if rake db:seed:dev; then echo "Database config OK, new user tom/evankorth in place" diff --git a/pkg/ubuntu/diaspora-wsd b/pkg/ubuntu/diaspora-wsd index e80f24f6e..db4edf254 100755 --- a/pkg/ubuntu/diaspora-wsd +++ b/pkg/ubuntu/diaspora-wsd @@ -1,102 +1,150 @@ -#!/bin/bash -# -# /etc/rc.d/init.d/diaspora-wsd -# -# SHOULD start the diaspora websocket daemon, but it doesn't. No way. -# -# chkconfig: - 80 80 -# description: Diaspora websocket daemon - +#! /bin/sh ### BEGIN INIT INFO -# Provides: diaspora-wsd -# Required-Start: $local_fs $network -# Required-Stop: $local_fs $network -# Should-Start: $remote_fs -# Should-Stop: $remote_fs -# Default-Start: -# Default-Stop: 0 1 2 3 4 5 6 -# Short-Description: start and stop Diaspora websocket server -# Description: The websocket server provides websocket services for -# diaspora. +# Provides: diaspora-wsd +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: diaspora websocket daemon +# Description: The diaspora websocket service provider, normally + listening on port 8080 ### END INIT INFO -# Source function library. -. /etc/init.d/functions +# Author: Alec leamas -if [ -f /etc/sysconfig/diaspora-wsd -a $UID -eq 0 ]; then - . /etc/sysconfig/diaspora-wsd -fi +PATH=/usr/sbin:/usr/bin +DESC="Websocket server for diaspora clients" +NAME='diaspora-wsd' +DAEMON='/usr/share/diaspora/master/script/websocket_server.rb' +DAEMON_ARGS="" +PIDFILE=/var/run/diaspora/diaspora-wsd.pid +SCRIPTNAME=/etc/init.d/diaspora-wsd -# Note: this line is patched by installation scripts. -cd /usr/share/diaspora +[ -x "$DAEMON" ] || exit 0 +vncvi +[ -r /etc/default/$NAME ] && . /etc/default/$NAME -RETVAL=0 -prog="Diaspora websocket server" -exec="script/websocket_server.rb" -pidfile="/var/run/diaspora-wsd" -lockfile="/var/lock/subsys/diaspora-wsd" -logfile=/var/log/diaspora-wsd.log +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh -[ -n "$OPTIONS" ] && OPTIONS=" $OPTIONS" -ruby_cmd="ruby -C $PWD $exec$OPTIONS" +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions -start() { - [ $UID -eq 0 ] || exit 4 - [ -f $exec ] || exit 5 - - echo -n $"Starting $prog: " - daemon --pidfile $pidfile "$ruby_cmd >>$logfile 2>&1 &" - RETVAL=$? - echo - if test $RETVAL = 0; then - touch $lockfile - pgrep -f "$ruby_cmd" > $pidfile || { - echo "Warning: cannot find running diaspora-webserver" - exit 7 - } - fi -} - -stop() { - [ $UID -eq 0 ] || exit 4 - echo -n $"Stopping $prog: " - killproc -p $pidfile $exec - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f $lockfile - echo +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ + $DAEMON_ARGS \ + || return 2 + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. } # -# See how we were called. +# Function that stops the daemon/service # +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + case "$1" in start) - start + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac ;; stop) - stop - ;; - force-reload|restart) - stop - sleep 1 - start - RETVAL=$? - ;; - condrestart|try-restart) - if [ -f $lockfile ]; then - stop - sleep 3 - start - fi + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac ;; status) - status -p $pidfile $exec - RETVAL=$? + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac ;; *) - echo $"Usage: $0 {condrestart|try-restart|start|stop|restart|force-reload|status}" - RETVAL=2 - [ "$1" = 'usage' ] && RETVAL=0 + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; esac -exit $RETVAL +: diff --git a/pkg/ubuntu/dist/.gitkeep b/pkg/ubuntu/dist/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 65199175e..64f6ddf8a 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -5,6 +5,27 @@ require File.dirname(__FILE__) + '/../config/environment' require File.dirname(__FILE__) + '/../lib/diaspora/websocket' +at_exit do + begin + File.delete(PID_FILE) + rescue + puts 'Cannot remove pidfile: ' + (PID_FILE ? PID_FILE : "NIL") + end +end + +def write_pidfile + begin + f = File.open(PID_FILE, "w") + f.write(Process.pid) + f.close + rescue => e + puts "Can't write to pidfile!" + puts e.inspect + puts e.backtrace + end +end + + CHANNEL = Magent::GenericChannel.new('websocket') def process_message if CHANNEL.queue_count > 0 @@ -37,6 +58,8 @@ begin } end + PID_FILE = APP_CONFIG[:socket_pidfile] + write_pidfile puts "Websocket server started." process_message } From a0c6c175f6a3e5b94a7d44039b13e7caba62689d Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 19 Oct 2010 19:58:17 +0200 Subject: [PATCH 07/32] websocket service cleanup Complete implementation of the websocket service as a separate SystemV service. Patch to websocket_server.rb to make it support a pidfile. Complete rewrite of the /etc/init.d script for ubuntu. Support in installation scripts. --- pkg/ubuntu/diaspora-wsd | 50 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/pkg/ubuntu/diaspora-wsd b/pkg/ubuntu/diaspora-wsd index db4edf254..0e8d08f20 100755 --- a/pkg/ubuntu/diaspora-wsd +++ b/pkg/ubuntu/diaspora-wsd @@ -1,4 +1,4 @@ -#! /bin/sh +#!/bin/sh ### BEGIN INIT INFO # Provides: diaspora-wsd # Required-Start: $remote_fs $syslog @@ -7,21 +7,22 @@ # Default-Stop: 0 1 6 # Short-Description: diaspora websocket daemon # Description: The diaspora websocket service provider, normally - listening on port 8080 +# listening on port 8080 ### END INIT INFO # Author: Alec leamas -PATH=/usr/sbin:/usr/bin +PATH=/bin:/sbin:/usr/sbin:/usr/bin DESC="Websocket server for diaspora clients" NAME='diaspora-wsd' -DAEMON='/usr/share/diaspora/master/script/websocket_server.rb' -DAEMON_ARGS="" +DAEMON='/usr/local/bin/bundle' +DAEMON_ARGS=' exec ruby ./script/websocket_server.rb' PIDFILE=/var/run/diaspora/diaspora-wsd.pid SCRIPTNAME=/etc/init.d/diaspora-wsd +cd /usr/share/diaspora/master + [ -x "$DAEMON" ] || exit 0 -vncvi [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables @@ -40,14 +41,15 @@ do_start() # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ - || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ - $DAEMON_ARGS \ + [ -f $PIDFILE ] && { + pid=$( cat $PIDFILE) + name=$( ps -p "$pid" -o comm= 2> /dev/null) || : + [ "$name" = "ruby" ] && return 1 + } + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ + --chdir $PWD -- $DAEMON_ARGS \ || return 2 - # Add code here, if necessary, that waits for the process to be ready - # to handle requests from services started subsequently which depend - # on this one. As a last resort, sleep for some time. + return 0 } # @@ -60,7 +62,8 @@ do_stop() # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE \ + --name $NAME --chdir $PWD RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks @@ -69,7 +72,8 @@ do_stop() # that waits for the process to drop all resources that could be # needed by services started subsequently. A last resort is to # sleep for some time. - start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --chdir $PWD \ + --exec $DAEMON [ "$?" = 2 ] && return 2 # Many daemons don't delete their pidfiles when they exit. rm -f $PIDFILE @@ -85,7 +89,8 @@ do_reload() { # restarting (for example, when it is sent a SIGHUP), # then implement that here. # - start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --chdir $PWD \ + --name $NAME return 0 } @@ -98,6 +103,7 @@ case "$1" in 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; + stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop @@ -106,9 +112,11 @@ case "$1" in 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; + status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; + #reload|force-reload) # # If do_reload() is not implemented then leave this commented out @@ -118,11 +126,8 @@ case "$1" in #do_reload #log_end_msg $? #;; + restart|force-reload) - # - # If the "reload" option is implemented then remove the - # 'force-reload' alias - # log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in @@ -140,9 +145,8 @@ case "$1" in ;; esac ;; - *) - #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 - echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + + *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac From 10f6a6994c6fea3fb85a5b2bf92b2e6a6f374a90 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 19 Oct 2010 22:29:25 +0200 Subject: [PATCH 08/32] Docs... --- pkg/fedora/README.md | 3 ++- pkg/ubuntu/README.md | 13 ++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index e294302ce..4ce99520f 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -120,7 +120,8 @@ directory, copy-paste previous version nr. It will be updated. This has been confirmed to start up and provide basic functionality both using the thin webserver and apache passenger, on 32/64 bit systems and in the -mock build environment. +mock build environment. Irregular nightly builds are available form time to time +at ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds #### Implementation diff --git a/pkg/ubuntu/README.md b/pkg/ubuntu/README.md index 15a4947dc..394ba8eb4 100644 --- a/pkg/ubuntu/README.md +++ b/pkg/ubuntu/README.md @@ -79,19 +79,10 @@ dependencies lives in the application - nothing is installed by user or on system level. This has been tested on a Ubuntu 32-bit 10.10 , clean server and on 10.04 -Lucid desktop, also clean installation. +Lucid desktop, also clean installation. Irregular nightly builds are +available from time to time at ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds mongodb is having problems occasionally. Sometimes the dependencies are not installed, and mongod refuses to start. invoke */usr/bin/mongod -f /etc/mongodb.conf* to test. The lockfile /var/lib/mongodb/mongod.conf is also a potential problem. Remove to make it start again. - -The diaspora-wsd is just placeholder FTM, it does **not** work. - - - - - - - - From 0096fd11e524cb9e964b95e2945e5b164901bba2 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 19 Oct 2010 22:33:53 +0200 Subject: [PATCH 09/32] LInking?! --- pkg/fedora/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index 4ce99520f..47d4e432f 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -121,7 +121,7 @@ directory, copy-paste previous version nr. It will be updated. This has been confirmed to start up and provide basic functionality both using the thin webserver and apache passenger, on 32/64 bit systems and in the mock build environment. Irregular nightly builds are available form time to time -at ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds +at [[ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds]] #### Implementation From 2cf2b5f8b773aab5de5c5be2d2018b50496d9d1f Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 19 Oct 2010 22:44:07 +0200 Subject: [PATCH 10/32] Linking --- pkg/fedora/README.md | 10 +++++----- pkg/ubuntu/README.md | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index 47d4e432f..cb2820d71 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -12,11 +12,11 @@ aimed for packaging purposes. Prerequisites: - ruby-1.8, rubygem, git and rake as described in - http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora - or http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora + [RPM installation Fedora](http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora) + or [Installing-on-CentOS-Fedora](http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora) - A personal environment to build RPM:s, also described in - http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora + [RPM installation Fedora](http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora) Install g++ (possibly unnnecessary?): % yum install gcc-c++ @@ -46,7 +46,7 @@ Start development server: cd /usr/share/diaspora/master ./script/server -See http://github.com/diaspora/diaspora/wiki/Using-apache for +See [Using Apache](http://github.com/diaspora/diaspora/wiki/Using-apache) for apache/passenger setup. After configuration, start with: /sbin/service diaspora-wsd start /sbin/service httpd restart @@ -121,7 +121,7 @@ directory, copy-paste previous version nr. It will be updated. This has been confirmed to start up and provide basic functionality both using the thin webserver and apache passenger, on 32/64 bit systems and in the mock build environment. Irregular nightly builds are available form time to time -at [[ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds]] +at [my underpowered home server](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) #### Implementation diff --git a/pkg/ubuntu/README.md b/pkg/ubuntu/README.md index 394ba8eb4..4faf09593 100644 --- a/pkg/ubuntu/README.md +++ b/pkg/ubuntu/README.md @@ -5,6 +5,7 @@ work as a first step towards packaging, but should be usable as is. ### Synopsis + Bootstrap the distribution from git: % sudo apt-get install git-core % git clone git://github.com/diaspora/diaspora.git @@ -80,7 +81,8 @@ on system level. This has been tested on a Ubuntu 32-bit 10.10 , clean server and on 10.04 Lucid desktop, also clean installation. Irregular nightly builds are -available from time to time at ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds +available from time to time at +[my underpowered home server](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) mongodb is having problems occasionally. Sometimes the dependencies are not installed, and mongod refuses to start. invoke */usr/bin/mongod -f From 53fef63a9a555a083ac9237f872a70e2b2a7115b Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 19 Oct 2010 22:53:38 +0200 Subject: [PATCH 11/32] linking --- pkg/fedora/README.md | 2 +- pkg/ubuntu/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index cb2820d71..7c5c9e3a2 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -121,7 +121,7 @@ directory, copy-paste previous version nr. It will be updated. This has been confirmed to start up and provide basic functionality both using the thin webserver and apache passenger, on 32/64 bit systems and in the mock build environment. Irregular nightly builds are available form time to time -at [my underpowered home server](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) +at [ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) #### Implementation diff --git a/pkg/ubuntu/README.md b/pkg/ubuntu/README.md index 4faf09593..cd633fdfb 100644 --- a/pkg/ubuntu/README.md +++ b/pkg/ubuntu/README.md @@ -82,7 +82,7 @@ on system level. This has been tested on a Ubuntu 32-bit 10.10 , clean server and on 10.04 Lucid desktop, also clean installation. Irregular nightly builds are available from time to time at -[my underpowered home server](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) +[ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) mongodb is having problems occasionally. Sometimes the dependencies are not installed, and mongod refuses to start. invoke */usr/bin/mongod -f From d200aaab5298c107c79d81353f417539c2a4b5e7 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 19 Oct 2010 18:19:14 -0700 Subject: [PATCH 12/32] mail has some style. couldn't figure out devise mailer templating at the time... --- .../confirmation_instructions.html.haml | 55 ++++++++++++- app/views/devise/mailer/invitation.html.haml | 77 +++++++++++++++---- .../reset_password_instructions.html.haml | 59 ++++++++++++-- .../mailer/unlock_instructions.html.haml | 57 ++++++++++++-- 4 files changed, 217 insertions(+), 31 deletions(-) diff --git a/app/views/devise/mailer/confirmation_instructions.html.haml b/app/views/devise/mailer/confirmation_instructions.html.haml index 7840b9c11..0dd9d28c0 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.haml +++ b/app/views/devise/mailer/confirmation_instructions.html.haml @@ -1,4 +1,51 @@ -%p - Welcome #{@resource.email}! -%p You can confirm your account through the link below: -%p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag '/images/diaspora_white.png' + #container + %p + Welcome #{@resource.email}! + %p You can confirm your account through the link below: + %p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token), :class => "large_text" diff --git a/app/views/devise/mailer/invitation.html.haml b/app/views/devise/mailer/invitation.html.haml index c16b6fe83..f7c1c7be5 100644 --- a/app/views/devise/mailer/invitation.html.haml +++ b/app/views/devise/mailer/invitation.html.haml @@ -1,16 +1,61 @@ -%p - Hello #{@resource.email}! -%p - #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below. -- @resource.inviters.each do |inv| - - if @resource.invite_messages[inv.id.to_s] - = "#{inv.real_name}:" - = @resource.invite_messages[inv.id.to_s] - %p - - -%p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) -%p - If you don't want to accept the invitation, please ignore this email. - %br/ - Your account won't be created until you access the link above and sign up. +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag '/images/diaspora_white.png' + #container + %p + Hello #{@resource.email}! + %p + #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below. + - @resource.inviters.each do |inv| + - if @resource.invite_messages[inv.id.to_s] + = "#{inv.real_name}:" + = @resource.invite_messages[inv.id.to_s] + %p + %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" + %p.small + If you don't want to accept the invitation, please ignore this email. + %br/ + Your account won't be created until you access the link above and sign up. diff --git a/app/views/devise/mailer/reset_password_instructions.html.haml b/app/views/devise/mailer/reset_password_instructions.html.haml index 4fc4743f8..4b344d44e 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.haml +++ b/app/views/devise/mailer/reset_password_instructions.html.haml @@ -1,6 +1,53 @@ -%p - Hello #{@resource.email}! -%p Someone has requested a link to change your password, and you can do this through the link below. -%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) -%p If you didn't request this, please ignore this email. -%p Your password won't change until you access the link above and create a new one. +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag '/images/diaspora_white.png' + #container + %p + Hello #{@resource.email}! + %p Someone has requested a link to change your password, and you can do this through the link below. + %p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token), :class => "large_text" + %p Your password won't change until you access the link above and create a new one. + %p.small If you didn't request this, please ignore this email. diff --git a/app/views/devise/mailer/unlock_instructions.html.haml b/app/views/devise/mailer/unlock_instructions.html.haml index 34b0e9e4e..6fff6bfce 100644 --- a/app/views/devise/mailer/unlock_instructions.html.haml +++ b/app/views/devise/mailer/unlock_instructions.html.haml @@ -1,5 +1,52 @@ -%p - Hello #{@resource.email}! -%p Your account has been locked due to an excessive amount of unsuccessful sign in attempts. -%p Click the link below to unlock your account: -%p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) +!!! +%html + %head + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ + :css + body{ + width:600px; + font-family:'Arial','Helvetica',sans-serif; + font-size:14px; + color:#333; + } + #container{ + margin-bottom:25px + min-height:400px; + padding-left:15px; + } + header{ + background-color:#333; + padding: 15px; + margin-bottom: 25px; + } + p{ + padding:5px; + } + p.small{ + font-size:smaller; + color:#999; + font-style:italic; + } + a{ + color:#107FC9; + font-weight:bold; + } + a:hover{ + color: #22AAE0; + } + a:active{ + color: #005D9C; + } + .large_text{ + font-size:21px; + font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; + } + %body + %header + = image_tag '/images/diaspora_white.png' + #container + %p + Hello #{@resource.email}! + %p Your account has been locked due to an excessive amount of unsuccessful sign in attempts. + %p Click the link below to unlock your account: + %p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token), :class => "large_text" From da95930c9ad0976398a904a8c748c35b18b07349 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 19 Oct 2010 20:23:20 -0700 Subject: [PATCH 13/32] added a bit to test email --- app/views/devise/mailer/invitation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/devise/mailer/invitation.html.haml b/app/views/devise/mailer/invitation.html.haml index f7c1c7be5..7bfe190a6 100644 --- a/app/views/devise/mailer/invitation.html.haml +++ b/app/views/devise/mailer/invitation.html.haml @@ -48,7 +48,7 @@ %p Hello #{@resource.email}! %p - #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below. + #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below. - @resource.inviters.each do |inv| - if @resource.invite_messages[inv.id.to_s] = "#{inv.real_name}:" From bfe57b13cc6add544adc65f5c69df90dc9431115 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 19 Oct 2010 20:34:10 -0700 Subject: [PATCH 14/32] added diaspora handle to user profile page --- app/views/people/show.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 83e7cf50d..8a76a63a6 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -12,6 +12,8 @@ = person_image_link(@person) %ul -unless @posts.first.nil? + %li + %b.small= @person.diaspora_handle %li %i= t(".last_seen",:how_long_ago => how_long_ago(@posts.first)) - if @person != current_user.person && current_user.friends.include?(@person) From f26dc039c9557e72c93b210b7ae87ea6626873b7 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 19 Oct 2010 20:43:45 -0700 Subject: [PATCH 15/32] removed empty hash from invite email --- app/views/invitations/_new.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index 8619562a3..c53b84513 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -12,7 +12,7 @@ - else = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) Message: - = invite.text_area :invite_messages + = invite.text_area :invite_messages, :value => "" %p= invite.submit "Send an invitation" From e7f84f5434a227fba326792753b4653b456227cf Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 19 Oct 2010 20:46:26 -0700 Subject: [PATCH 16/32] fix hcard when parsing friend photo --- lib/hcard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hcard.rb b/lib/hcard.rb index e858bdfc6..1bdd8a704 100644 --- a/lib/hcard.rb +++ b/lib/hcard.rb @@ -11,7 +11,7 @@ module HCard {:given_name => doc.css(".given_name").text, :family_name => doc.css(".family_name").text, :url => doc.css("#pod_location").text, - :photo => doc.css(".photo[src]").text} + :photo => doc.css(".photo[src]").attribute('src').text } end def self.find url From d0055cee37afcfb1e996045f17f733668d658a72 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 19 Oct 2010 21:07:10 -0700 Subject: [PATCH 17/32] changed a bit of text in the invite, also made it show on all aspects now that we have it fixed --- app/views/invitations/_new.haml | 4 +++- app/views/shared/_invitations.haml | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index c53b84513..77b07faa2 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -1,7 +1,8 @@ .span-12.last .modal_title_bar - %h4 Send invitation + %h4 Invite someone to join Diaspora! + %i if they accept, they will be added to the aspect you invited them = form_for User.new, :url => invitation_path(User) do |invite| %p = invite.label :email @@ -11,6 +12,7 @@ = invite.select(:aspects, @aspects_dropdown_array) - else = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) + Message: = invite.text_area :invite_messages, :value => "" diff --git a/app/views/shared/_invitations.haml b/app/views/shared/_invitations.haml index b82cca104..40476eae7 100644 --- a/app/views/shared/_invitations.haml +++ b/app/views/shared/_invitations.haml @@ -1,8 +1,7 @@ -- unless @aspect == :all - %h4 Invites - = link_to "Invite a friend", "#invite_user_pane", :class => "invite_user_button", :title => "Invite a friend" - = "(#{invites} left)" - %br - .yo{ :style => "display:none;"} - #invite_user_pane - = render "invitations/new" +%h4 Invites += link_to "Invite a friend", "#invite_user_pane", :class => "invite_user_button", :title => "Invite a friend" += "(#{invites} left)" +%br +.yo{ :style => "display:none;"} + #invite_user_pane + = render "invitations/new" From 8cf1b836626490aaa0c51e35b93b10e127375442 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 19 Oct 2010 22:29:07 -0700 Subject: [PATCH 18/32] cucumber feature closer to passing. --- features/user_creates_an_aspect.feature | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/features/user_creates_an_aspect.feature b/features/user_creates_an_aspect.feature index 7d7789f78..d611d412f 100644 --- a/features/user_creates_an_aspect.feature +++ b/features/user_creates_an_aspect.feature @@ -12,12 +12,10 @@ Feature: User creates an aspect Scenario: success Given I fill in "Name" with "Dorm Mates" in the modal window When I press "Create" in the modal window - Then I should see "Manage aspects" - And I should see "Dorm Mates" in the header - And I should see "Dorm Mates" in the aspect list + Then I should see "Dorm Mates" in the header + And I should see "Your aspect 'Dorm Mates' is empty." Scenario: I omit the name Given I fill in "Name" with "" in the modal window When I press "Create" in the modal window - Then I should see "Manage aspects" - And I should see "Aspect creation failed." + Then I should see "Aspect creation failed." From 81ef7386b35f02afd8832ae53fdf0f3cd5d767f3 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 19 Oct 2010 22:33:12 -0700 Subject: [PATCH 19/32] validation errors in profile and person bubble up to user. --- Gemfile.lock | 57 ++++++++---------- app/controllers/registrations_controller.rb | 10 ++-- app/models/person.rb | 8 +++ app/models/profile.rb | 8 ++- app/models/user.rb | 8 ++- .../registrations_controller_spec.rb | 14 ++++- spec/models/person_spec.rb | 16 +++++ spec/models/profile_spec.rb | 58 +++++++++++-------- spec/models/user_spec.rb | 54 +++++++++++++++-- 9 files changed, 160 insertions(+), 73 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 91fca3349..5757dfcde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,9 +15,9 @@ GIT GIT remote: git://github.com/dcu/magent.git - revision: 59b8563961b830f491cd6f6592cced67791ce0ef + revision: 90ee5db241abd2e2b7d7de5c80f0d7c5b4b8db2d specs: - magent (0.5.0) + magent (0.5.1) em-websocket mongo uuidtools @@ -97,10 +97,9 @@ GEM activesupport (= 3.0.1) activesupport (3.0.1) addressable (2.2.2) - archive-tar-minitar (0.5.2) arel (1.0.1) activesupport (~> 3.0.0) - aws (2.3.21) + aws (2.3.22) http_connection uuidtools xml-simple @@ -121,7 +120,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) selenium-webdriver (>= 0.0.3) - childprocess (0.0.7) + childprocess (0.1.3) ffi (~> 0.6.3) columnize (0.3.1) crack (0.1.8) @@ -154,18 +153,17 @@ GEM rails (>= 3.0.0.beta4) ffi (0.6.3) rake (>= 0.8.7) - gherkin (2.2.8) + gherkin (2.2.9) json (~> 1.4.6) term-ansicolor (~> 1.0.5) - haml (3.0.21) + haml (3.0.22) hashie (0.4.0) highline (1.6.1) - http_connection (1.3.1) + http_connection (1.4.0) i18n (0.4.1) json (1.4.6) json_pure (1.4.6) - linecache19 (0.5.11) - ruby_core_source (>= 0.1.4) + linecache (0.43) mail (2.2.7) activesupport (>= 2.3.6) mime-types @@ -215,28 +213,23 @@ GEM rake (0.8.7) rest-client (1.6.1) mime-types (>= 1.16) - rspec (2.0.0) - rspec-core (= 2.0.0) - rspec-expectations (= 2.0.0) - rspec-mocks (= 2.0.0) - rspec-core (2.0.0) - rspec-expectations (2.0.0) + rspec (2.0.1) + rspec-core (~> 2.0.1) + rspec-expectations (~> 2.0.1) + rspec-mocks (~> 2.0.1) + rspec-core (2.0.1) + rspec-expectations (2.0.1) diff-lcs (>= 1.1.2) - rspec-mocks (2.0.0) - rspec-core (= 2.0.0) - rspec-expectations (= 2.0.0) - rspec-rails (2.0.0) - rspec (= 2.0.0) - ruby-debug-base19 (0.11.24) - columnize (>= 0.3.1) - linecache19 (>= 0.5.11) - ruby_core_source (>= 0.1.4) - ruby-debug19 (0.11.6) - columnize (>= 0.3.1) - linecache19 (>= 0.5.11) - ruby-debug-base19 (>= 0.11.19) - ruby_core_source (0.1.4) - archive-tar-minitar (>= 0.5.2) + rspec-mocks (2.0.1) + rspec-core (~> 2.0.1) + rspec-expectations (~> 2.0.1) + rspec-rails (2.0.1) + rspec (~> 2.0.0) + ruby-debug (0.10.3) + columnize (>= 0.1) + ruby-debug-base (~> 0.10.3.0) + ruby-debug-base (0.10.3) + linecache (>= 0.3) rubyzip (0.9.4) selenium-webdriver (0.0.29) childprocess (>= 0.0.7) @@ -294,7 +287,7 @@ DEPENDENCIES roxml! rspec (>= 2.0.0) rspec-rails (>= 2.0.0) - ruby-debug19 + ruby-debug sprinkle! thin webmock diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 75745a0ab..541563d48 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -5,22 +5,22 @@ class RegistrationsController < Devise::RegistrationsController def create begin - user = User.instantiate!(params[:user]) + @user = User.instantiate!(params[:user]) rescue MongoMapper::DocumentNotValid => e flash[:error] = e.message redirect_to new_user_registration_path return end - if user.save + if @user.save flash[:notice] = I18n.t 'registrations.create.success' - sign_in_and_redirect(:user, user) + sign_in_and_redirect(:user, @user) else - flash[:error] = user.errors.full_messages.join(', ') + flash[:error] = @user.errors.full_messages.join(', ') redirect_to new_user_registration_path end end - def update + def update super end end diff --git a/app/models/person.rb b/app/models/person.rb index 8a9011fa4..ccf034d59 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -22,6 +22,13 @@ class Person key :owner_id, ObjectId one :profile, :class_name => 'Profile' + validate :profile_is_valid + def profile_is_valid + if profile.present? && !profile.valid? + profile.errors.full_messages.each { |m| errors.add(:base, m) } + end + end + many :albums, :class_name => 'Album', :foreign_key => :person_id belongs_to :owner, :class_name => 'User' @@ -162,4 +169,5 @@ class Person def remove_all_traces Post.all(:person_id => id).each { |p| p.delete } end + end diff --git a/app/models/profile.rb b/app/models/profile.rb index 328fa45c0..baab495d7 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -18,6 +18,7 @@ class Profile key :image_url, String validates_presence_of :first_name, :last_name + after_validation :strip_names before_save :strip_names @@ -29,9 +30,10 @@ class Profile self._parent_document end - private + protected + def strip_names - first_name.strip! - last_name.strip! + self.first_name.strip! if self.first_name + self.last_name.strip! if self.last_name end end diff --git a/app/models/user.rb b/app/models/user.rb index 5152acbdf..aee21b543 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,6 +48,12 @@ class User validates_with InvitedUserValidator one :person, :class_name => 'Person', :foreign_key => :owner_id + validate :person_is_valid + def person_is_valid + if person.present? && !person.valid? + person.errors.full_messages.each {|m| errors.add(:base, m)} + end + end many :inviters, :in => :inviter_ids, :class_name => 'User' many :friends, :in => :friend_ids, :class_name => 'Person' @@ -379,7 +385,7 @@ class User opts[:serialized_private_key] = generate_key opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key - + u = User.new(opts) u.seed_aspects u.save! diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index da7643fc9..e89795532 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -26,6 +26,10 @@ describe RegistrationsController do it "creates a user" do lambda { get :create, @valid_params }.should change(User, :count).by(1) end + it "assigns @user" do + get :create, @valid_params + assigns(:user).should_not be_nil + end it "sets the flash" do get :create, @valid_params flash[:notice].should_not be_empty @@ -37,19 +41,25 @@ describe RegistrationsController do end context "with invalid parameters" do before do - @valid_params["user"].delete("username") + @valid_params["user"]["person"]["profile"].delete("first_name") @invalid_params = @valid_params end it "does not create a user" do lambda { get :create, @invalid_params }.should_not change(User, :count) end + it "assigns @user" do + pending "GAAAH stupid mongo mapper. Figure out why it thinks it's persisted when validations fail" + get :create, @valid_params + assigns(:user).should_not be_nil + end it "sets the flash error" do get :create, @invalid_params flash[:error].should_not be_blank end it "goes back to the form" do + pending "GAAAH stupid mongo mapper. Figure out why it thinks it's persisted when validations fail" get :create, @invalid_params - response.should redirect_to new_user_registration_path + response.should be_success end end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index fd5ea0162..c67e55f8a 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -13,6 +13,22 @@ describe Person do @aspect2 = @user2.aspect(:name => "Abscence of Babes") end + describe "validation" do + describe "of associated profile" do + it "fails if the profile isn't valid" do + person = Factory.build(:person) + person.should be_valid + + person.profile.update_attribute(:first_name, nil) + person.profile.should_not be_valid + person.should_not be_valid + + person.errors.count.should == 1 + person.errors.full_messages.first.should =~ /first name/i + end + end + end + describe '#diaspora_handle' do context 'local people' do it 'uses the pod config url to set the diaspora_handle' do diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 4830652f8..de2eb6955 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -5,32 +5,40 @@ require 'spec_helper' describe Profile do - before do - @person = Factory.build(:person) - end - - describe 'sanitization' do - it 'strips the names' do - @person.profile = Factory.build(:profile, :first_name => " Bob", :last_name => "Bobson ") - @person.profile.save - @person.profile.first_name.should == "Bob" - @person.profile.last_name.should == "Bobson" + describe 'validation' do + describe "of first_name" do + it "requires first name" do + profile = Factory.build(:profile, :first_name => nil) + profile.should_not be_valid + profile.first_name = "Hortense" + profile.should be_valid + end + it "requires non-empty first name" do + profile = Factory.build(:profile, :first_name => " ") + profile.should_not be_valid + end + it "strips leading and trailing whitespace" do + profile = Factory.build(:profile, :first_name => " Shelly ") + profile.should be_valid + profile.first_name.should == "Shelly" + end end - end - - describe 'requirements' do - it "should include a first name" do - @person.profile = Factory.build(:profile,:first_name => nil) - @person.profile.valid?.should be false - @person.profile.first_name = "Bob" - @person.profile.valid?.should be true - end - - it "should include a last name" do - @person.profile = Factory.build(:profile, :last_name => nil) - @person.profile.valid?.should be false - @person.profile.last_name = "Smith" - @person.profile.valid?.should be true + describe "of last_name" do + it "requires a last name" do + profile = Factory.build(:profile, :last_name => nil) + profile.should_not be_valid + profile.last_name = "Shankar" + profile.should be_valid + end + it "requires non-empty last name" do + profile = Factory.build(:profile, :last_name => " ") + profile.should_not be_valid + end + it "strips leading and trailing whitespace" do + profile = Factory.build(:profile, :last_name => " Ohba ") + profile.should be_valid + profile.last_name.should == "Ohba" + end end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 61e37b3aa..536e7b68c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -13,6 +13,20 @@ describe User do let(:aspect3) { user3.aspect(:name => 'stuff') } describe "validation" do + describe "of associated person" do + it "fails if person is not valid" do + user = Factory.build(:user) + user.should be_valid + + user.person.update_attribute(:serialized_public_key, nil) + user.person.should_not be_valid + user.should_not be_valid + + user.errors.full_messages.count.should == 1 + user.errors.full_messages.first.should =~ /serialized public key/i + end + end + describe "of passwords" do it "fails if password doesn't match confirmation" do user = Factory.build(:user, :password => "password", :password_confirmation => "nope") @@ -72,6 +86,41 @@ describe User do end end + describe ".instantiate!" do + it "creates the user if params are valid" do + User.find_by_username("ohai").should be_nil + user = User.instantiate!({ + :username => "ohai", + :email => "ohai@example.com", + :password => "password", + :password_confirmation => "password", + :person => {:profile => {:first_name => "O", :last_name => "Hai"}}}) + user.should be_valid + User.find_by_username("ohai").should == user + end + describe "with invalid params" do + before do + @invalid_params = { + :username => "ohai", + :email => "ohai@example.com", + :password => "password", + :password_confirmation => "password", + :person => {:profile => {:first_name => "", :last_name => ""}}} + end + it "raises an error" do + lambda { User.instantiate!(@invalid_params) }.should raise_error + end + it "does not create the user" do + User.find_by_username("ohai").should be_nil + begin + User.instantiate!(@invalid_params) + rescue + end + User.find_by_username("ohai").should be_nil + end + end + end + describe ".find_for_authentication" do it "preserves case" do User.find_for_authentication(:username => user.username).should == user @@ -98,7 +147,6 @@ describe User do end context 'aspects' do - it 'should delete an empty aspect' do user.drop_aspect(aspect) user.aspects.include?(aspect).should == false @@ -128,7 +176,6 @@ describe User do user.destroy end - it 'should remove all aspects' do aspects = user.aspects aspects.count.should > 0 @@ -137,7 +184,6 @@ describe User do aspects.count.should == 0 end - describe '#remove_person' do it 'should remove the person object' do person = user.person @@ -155,7 +201,6 @@ describe User do end describe '#unfriend_everyone' do - before do user3.delete end @@ -173,5 +218,4 @@ describe User do end end end - end From b007ba148734eb523a251345beeb253b43725eec Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 19 Oct 2010 22:57:55 -0700 Subject: [PATCH 20/32] Fixed cucumber features. Backfilled tests for AspectsController#create. --- app/controllers/aspects_controller.rb | 3 +- spec/controllers/aspects_controller_spec.rb | 38 +++++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 35ddbaec9..53a696a47 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -20,10 +20,11 @@ class AspectsController < ApplicationController @aspect = current_user.aspect(params[:aspect]) if @aspect.valid? flash[:notice] = I18n.t('aspects.create.success') + respond_with @aspect else flash[:error] = I18n.t('aspects.create.failure') + redirect_to aspects_manage_path end - respond_with @aspect end def new diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 19bb7bf5d..81571fb54 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' describe AspectsController do - render_views + render_views + before do @user = Factory.create(:user) @user.aspect(:name => "lame-os") @@ -13,11 +14,36 @@ describe AspectsController do sign_in :user, @user end - it "on index sets a variable containing all a user's friends when a user is signed in" do - sign_in :user, @user - Factory.create :person - get :index - assigns[:friends].should == @user.friends + describe "#index" do + it "assigns @friends to all the user's friends" do + Factory.create :person + get :index + assigns[:friends].should == @user.friends + end end + describe "#create" do + describe "with valid params" do + it "creates an aspect" do + @user.aspects.count.should == 1 + post :create, "aspect" => {"name" => "new aspect"} + @user.reload.aspects.count.should == 2 + end + it "redirects to the aspect page" do + post :create, "aspect" => {"name" => "new aspect"} + response.should redirect_to(aspect_path(Aspect.find_by_name("new aspect"))) + end + end + describe "with invalid params" do + it "does not create an aspect" do + @user.aspects.count.should == 1 + post :create, "aspect" => {"name" => ""} + @user.reload.aspects.count.should == 1 + end + it "goes back to manage aspects" do + post :create, "aspect" => {"name" => ""} + response.should redirect_to(aspects_manage_path) + end + end + end end From 43dd95147eccaa741d930c1377cf7dfd47286efc Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 18:38:39 -0700 Subject: [PATCH 21/32] Starting to remove database-cleaner --- spec/lib/diaspora_parser_spec.rb | 4 ++-- spec/misc_spec.rb | 23 +---------------------- spec/models/comments_spec.rb | 6 +++--- spec/spec_helper.rb | 7 +------ 4 files changed, 7 insertions(+), 33 deletions(-) diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 3b9e090f9..3504cfc73 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe Diaspora::Parser do before do - @user = Factory.create(:user, :email => "bob@aol.com") + @user = Factory.create(:user) @aspect = @user.aspect(:name => 'spies') @user3 = Factory.create :user @@ -20,7 +20,7 @@ describe Diaspora::Parser do end it 'should be able to correctly handle comments with person in db' do - person = Factory.create(:person, :diaspora_handle => "test@testing.com") + person = Factory.create(:person) post = Factory.create(:status_message, :person => @user.person) comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") xml = comment.to_diaspora_xml diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 1db3f3f82..12f7837c1 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -5,34 +5,13 @@ require 'spec_helper' describe 'making sure the spec runner works' do - - it 'should not delete the database mid-spec' do - User.count.should == 0 - Factory.create(:user) - User.count.should == 1 - end - - it 'should make sure the last user no longer exsists' do - User.count.should == 0 - end - it 'should factory create a user with a person saved' do user = Factory.create(:user) loaded_user = User.first(:id => user.id) loaded_user.person.owner_id.should == user.id end - describe 'testing a before do block' do - before do - Factory.create(:user) - end - - it 'should have cleaned before the before do block runs' do - User.count.should == 1 - end - - end - describe '#friend_users' do + describe '#friend_users' do before do @user1 = Factory.create(:user) @aspect1 = @user1.aspect(:name => "losers") diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index b2f2d3c61..08252ada2 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -18,7 +18,7 @@ describe Comment do status.comments.should == [] @user.comment "Yeah, it was great", :on => status - StatusMessage.first.comments.first.text.should == "Yeah, it was great" + status.reload.comments.first.text.should == "Yeah, it was great" end it "should be able to comment on a person's status" do @@ -26,8 +26,8 @@ describe Comment do status = Factory.create(:status_message, :person => person) @user.comment "sup dog", :on => status - StatusMessage.first.comments.first.text.should == "sup dog" - StatusMessage.first.comments.first.person.should == @user.person + status.reload.comments.first.text.should == "sup dog" + status.reload.comments.first.person.should == @user.person end it 'should not send out comments when we have no people' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 552fd884d..9bc58c2e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,19 +27,14 @@ RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) + DatabaseCleaner.clean stub_signature_verification - end config.before(:each) do - DatabaseCleaner.start stub_sockets User.stub!(:allowed_email?).and_return(:true) end - - config.after(:each) do - DatabaseCleaner.clean - end end ImageUploader.enable_processing = false From 52f7350f78bff309b9e6a2d49629d11dbc88c8e3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 18:54:18 -0700 Subject: [PATCH 22/32] Fix a couple more specs --- spec/lib/diaspora_parser_spec.rb | 4 +--- spec/models/photo_spec.rb | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 3504cfc73..33efe2f0a 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -54,9 +54,7 @@ describe Diaspora::Parser do retraction = Retraction.for(message) xml = retraction.to_diaspora_xml - StatusMessage.count.should == 1 - @user.receive xml, person - StatusMessage.count.should == 0 + proc {@user.receive xml, person}.should change(StatusMessage, :count).by(-1) end it "should create a new person upon getting a person request" do diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index de70ce030..701bf079d 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -51,8 +51,7 @@ describe Photo do it 'should have a caption' do @photo.image.store! File.open(@fixture_name) @photo.caption = "cool story, bro" - @photo.save - Photo.first.caption.should == "cool story, bro" + @photo.save.should be_true end it 'should remove its reference in user profile if it is referred' do @@ -63,9 +62,9 @@ describe Photo do @user.save @user.person.save - User.first.profile.image_url.should == @photo.image.url(:thumb_medium) + @user.profile.image_url.should == @photo.image.url(:thumb_medium) @photo.destroy - User.first.profile.image_url.should be nil + @user.profile.image_url.should be nil end it 'should not use the imported filename as the url' do From 74ec629b018c9ffa8b625f8dc478e3f9bee9df16 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 19:28:49 -0700 Subject: [PATCH 23/32] user_friending_spec passes again --- spec/models/photo_spec.rb | 2 +- spec/models/user/user_friending_spec.rb | 101 +++++++++++------------- 2 files changed, 46 insertions(+), 57 deletions(-) diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 701bf079d..51b1c058d 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -64,7 +64,7 @@ describe Photo do @user.profile.image_url.should == @photo.image.url(:thumb_medium) @photo.destroy - @user.profile.image_url.should be nil + @user.reload.profile.image_url.should be nil end it 'should not use the imported filename as the url' do diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 8bcc093f1..2756c0841 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -28,10 +28,9 @@ describe User do it "should be able to accept a pending friend request" do r = Request.instantiate(:to => user.receive_url, :from => friend) r.save - Person.all.count.should == 2 - Request.for_user(user).all.count.should == 1 - user.accept_friend_request(r.id, aspect.id) - Request.for_user(user).all.count.should == 0 + + proc {user.accept_friend_request(r.id, aspect.id)}.should change{ + Request.for_user(user).all.count}.by(-1) end it 'should be able to ignore a pending friend request' do @@ -39,12 +38,8 @@ describe User do r = Request.instantiate(:to => user.receive_url, :from => friend) r.save - Person.count.should == 2 - - user.ignore_friend_request(r.id) - - Person.count.should == 2 - Request.count.should == 0 + proc{user.ignore_friend_request(r.id)}.should change{ + Request.for_user(user).count}.by(-1) end it 'should not be able to friend request an existing friend' do @@ -80,59 +75,53 @@ describe User do @request_three.destroy end - it 'should befriend the user other user on the same pod' do - user2.receive @req_three_xml, user.person - user2.pending_requests.size.should be 1 - user2.accept_friend_request @request_three.id, aspect2.id - user2.friends.include?(user.person).should be true - Person.all.count.should be 3 + context 'request from one remote person to one local user' do + before do + user2.receive @req_three_xml, user.person + end + it 'should befriend the user other user on the same pod' do + proc{ + user2.accept_friend_request @request_three.id, aspect2.id + }.should_not change(Person, :count) + user2.friends.include?(user.person).should be true + end + + it 'should not delete the ignored user on the same pod' do + proc{ + user2.ignore_friend_request @request_three.id + }.should_not change(Person, :count) + user2.friends.include?(user.person).should be false + end end + context 'Two users receiving requests from one person' do + before do + user.receive @req_xml, person_one - it 'should not delete the ignored user on the same pod' do - user2.receive @req_three_xml, user.person - user2.pending_requests.size.should be 1 - user2.ignore_friend_request @request_three.id - user2.friends.include?(user.person).should be false - Person.all.count.should be 3 - end + user2.receive @req_two_xml, person_one + end + it 'should both users should befriend the same person' do + user.accept_friend_request @request.id, aspect.id + user.friends.include?(person_one).should be true - it 'should both users should befriend the same person' do - user.receive @req_xml, person_one - user.pending_requests.size.should be 1 - user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + user2.accept_friend_request @request_two.id, aspect2.id + user2.friends.include?(person_one).should be true + end - user2.receive @req_two_xml, person_one - user2.pending_requests.size.should be 1 - user2.accept_friend_request @request_two.id, aspect2.id - user2.friends.include?(person_one).should be true - Person.all.count.should be 3 - end + it 'should keep the person around if one of the users rejects him' do + user.accept_friend_request @request.id, aspect.id + user.friends.include?(person_one).should be true - it 'should keep the person around if one of the users rejects him' do - user.receive @req_xml, person_one - user.pending_requests.size.should be 1 - user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + user2.ignore_friend_request @request_two.id + user2.friends.include?(person_one).should be false + end - user2.receive @req_two_xml, person_one - user2.pending_requests.size.should be 1 - user2.ignore_friend_request @request_two.id - user2.friends.include?(person_one).should be false - Person.all.count.should be 3 - end + it 'should keep the person around if the users ignores them' do + user.ignore_friend_request user.pending_requests.first.id + user.friends.include?(person_one).should be false - it 'should keep the person around if the users ignores them' do - user.receive @req_xml, person_one - user.pending_requests.size.should be 1 - user.ignore_friend_request user.pending_requests.first.id - user.friends.include?(person_one).should be false - - user2.receive @req_two_xml, person_one - user2.pending_requests.size.should be 1 - user2.ignore_friend_request user2.pending_requests.first.id #@request_two.id - user2.friends.include?(person_one).should be false - Person.all.count.should be 3 + user2.ignore_friend_request user2.pending_requests.first.id #@request_two.id + user2.friends.include?(person_one).should be false + end end end From 197bd8eb49140352ce0ca6459db263beda18311c Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 22:55:11 -0700 Subject: [PATCH 24/32] make user/receive spec less repetitive --- spec/models/user/receive_spec.rb | 82 ++++++++------------------------ 1 file changed, 19 insertions(+), 63 deletions(-) diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 1d97cdad1..779919587 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -47,96 +47,52 @@ describe User do end describe 'post refs' do - it "should add a received post to the aspect and visible_posts array" do - status_message = user.post :status_message, :message => "hi", :to =>aspect.id + before do + @status_message = user2.post :status_message, :message => "hi", :to =>aspect2.id + user.receive @status_message.to_diaspora_xml, user2.person user.reload - salmon = user.salmon(status_message).xml_for user2.person - user2.receive_salmon salmon - user2.reload - user2.raw_visible_posts.include?(status_message).should be true - aspect2.reload - aspect2.posts.include?(status_message).should be_true + end + + it "should add a received post to the aspect and visible_posts array" do + user.raw_visible_posts.include?(@status_message).should be true + aspect.reload + aspect.posts.include?(@status_message).should be_true end it 'should be removed on unfriending' do - status_message = user2.post :status_message, :message => "hi", :to => aspect2.id - user.receive status_message.to_diaspora_xml, user2.person - user.reload - - user.raw_visible_posts.count.should == 1 - user.unfriend(user2.person) - user.reload user.raw_visible_posts.count.should == 0 - - Post.count.should be 1 end it 'should be remove a post if the noone links to it' do - status_message = user2.post :status_message, :message => "hi", :to => aspect2.id - user.receive status_message.to_diaspora_xml, user2.person - user.reload - - user.raw_visible_posts.count.should == 1 - person = user2.person user2.delete - user.unfriend(person) + lambda {user.unfriend(person)}.should change(Post, :count).by(-1) user.reload user.raw_visible_posts.count.should == 0 - - Post.count.should be 0 end it 'should keep track of user references for one person ' do - status_message = user2.post :status_message, :message => "hi", :to => aspect2.id - user.receive status_message.to_diaspora_xml, user2.person - user.reload - - user.raw_visible_posts.count.should == 1 - - status_message.reload - status_message.user_refs.should == 1 + @status_message.reload + @status_message.user_refs.should == 1 user.unfriend(user2.person) - status_message.reload - - user.reload - user.raw_visible_posts.count.should == 0 - - status_message.reload - status_message.user_refs.should == 0 - - Post.count.should be 1 + @status_message.reload + @status_message.user_refs.should == 0 end it 'should not override userrefs on receive by another person' do user3.activate_friend(user2.person, aspect3) + user3.receive @status_message.to_diaspora_xml, user2.person - status_message = user2.post :status_message, :message => "hi", :to => aspect2.id - user.receive status_message.to_diaspora_xml, user2.person - - user3.receive status_message.to_diaspora_xml, user2.person - user.reload - user3.reload - - user.raw_visible_posts.count.should == 1 - - status_message.reload - status_message.user_refs.should == 2 + @status_message.reload + @status_message.user_refs.should == 2 user.unfriend(user2.person) - status_message.reload - - user.reload - user.raw_visible_posts.count.should == 0 - - status_message.reload - status_message.user_refs.should == 1 - - Post.count.should be 1 + @status_message.reload + @status_message.user_refs.should == 1 end end From d98ac7015580a16eb2fd46431fdeddf2a8f1b591 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 23:29:22 -0700 Subject: [PATCH 25/32] Clean up some repetition in specs --- spec/models/person_spec.rb | 52 ++++++++---------------------- spec/models/post_spec.rb | 3 +- spec/models/status_message_spec.rb | 2 +- spec/models/user/receive_spec.rb | 7 ++-- 4 files changed, 17 insertions(+), 47 deletions(-) diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index c67e55f8a..edc5b20ee 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -77,64 +77,38 @@ describe Person do person_two.owns?(person_message).should be false end - it 'should delete all of user posts except comments upon user deletion' do + it "deletes all of a person's posts upon person deletion" do person = Factory.create(:person) - Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => person) + status = Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => @person) + + lambda {person.destroy}.should change(Post, :count).by(-1) + end + + it "does not delete a person's comments on person deletion" do + person = Factory.create(:person) status_message = Factory.create(:status_message, :person => @person) - Factory.create(:comment, :person_id => person.id, :text => "yes i do", :post => status_message) Factory.create(:comment, :person_id => person.id, :text => "i love you", :post => status_message) - Factory.create(:comment, :person_id => person.id, :text => "hello", :post => status_message) Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => status_message) - - person.destroy - - Post.count.should == 1 - Comment.all.count.should == 4 - status_message.comments.count.should == 4 + + lambda {person.destroy}.should_not change(Comment, :count) end describe "unfriending" do it 'should not delete an orphaned friend' do - request = @user.send_friend_request_to @person, @aspect - @user.activate_friend(@person, @aspect) - @user.reload - Person.all.count.should == 3 - @user.friends.count.should == 1 - @user.unfriend(@person) - @user.reload - @user.friends.count.should == 0 - Person.all.count.should == 3 + lambda {@user.unfriend(@person)}.should_not change(Person, :count) end it 'should not delete an un-orphaned friend' do - request = @user.send_friend_request_to @person, @aspect - request2 = @user2.send_friend_request_to @person, @aspect2 - @user.activate_friend(@person, @aspect) @user2.activate_friend(@person, @aspect2) - @user.reload - @user2.reload - - Person.all.count.should == 3 - @user.friends.count.should == 1 - @user2.friends.count.should == 1 - - @user.unfriend(@person) - @user.reload - @user2.reload - @user.friends.count.should == 0 - @user2.friends.count.should == 1 - - Person.all.count.should == 3 + lambda {@user.unfriend(@person)}.should_not change(Person, :count) end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index bc445af99..4c3daf4b6 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -6,8 +6,7 @@ require 'spec_helper' describe Post do before do - @user = Factory.create(:user, :email => "bob@aol.com") - @user.person.save + @user = Factory.create(:user) end describe 'xml' do diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 2d8d0c5bf..8449b964c 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe StatusMessage do before do - @user = Factory.create(:user, :email => "bob@aol.com") + @user = Factory.create(:user) @aspect = @user.aspect(:name => "losers") end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 779919587..c8e4891de 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -22,16 +22,13 @@ describe User do it 'should be able to parse and store a status message from xml' do status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id - person = user2.person xml = status_message.to_diaspora_xml user2.destroy status_message.destroy - StatusMessage.all.size.should == 0 - user.receive xml , user2.person - Post.all(:person_id => person.id).first.message.should == 'store this!' - StatusMessage.all.size.should == 1 + user + lambda {user.receive xml , user2.person}.should change (Post,:count).by(1) end it 'should not create new aspects on message receive' do From d3d01821644fcc0a1306998b2f3deda857d623b3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 23:29:36 -0700 Subject: [PATCH 26/32] Put database cleaner back in --- spec/spec_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9bc58c2e6..218def68b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,14 +26,12 @@ RSpec.configure do |config| DatabaseCleaner.orm = "mongo_mapper" config.before(:suite) do - DatabaseCleaner.clean_with(:truncation) - DatabaseCleaner.clean stub_signature_verification end config.before(:each) do stub_sockets - User.stub!(:allowed_email?).and_return(:true) + DatabaseCleaner.clean end end From a01c1c74617f32a5315abeb3aaf2090c2a80ac98 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 19 Oct 2010 23:54:12 -0700 Subject: [PATCH 27/32] Remove remove_all_aspects without ill effect --- app/models/user.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index aee21b543..cc9531c8c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,7 +64,7 @@ class User #after_create :seed_aspects - before_destroy :unfriend_everyone, :remove_person, :remove_all_aspects + before_destroy :unfriend_everyone, :remove_person def strip_username if username.present? @@ -436,8 +436,4 @@ class User end } end - - def remove_all_aspects - aspects.destroy_all - end end From d2945c83dc3cfd859a15fe443ec1d2f1a73e9894 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 20 Oct 2010 00:02:15 -0700 Subject: [PATCH 28/32] status message show is now a real show page. photo partial in stream shouldn't display a slideshow of album. --- app/views/layouts/application.html.haml | 2 +- app/views/photos/_photo.haml | 3 +-- app/views/status_messages/show.html.haml | 24 ++++++++++++++++-------- public/stylesheets/sass/application.sass | 21 +++++++++++++++++++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 0defb3463..84fb4d812 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -62,5 +62,5 @@ .span-24.last = yield - .span-19.prepend-5.last + .span-24.last = render "posts/debug" diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index 01baaf74e..5b7d8462e 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -27,8 +27,7 @@ %br %br - = render "albums/album", :post => post.album, :current_user => current_user - = link_to (image_tag post.url(:thumb_medium)), object_path(post) + = link_to (image_tag post.url(:thumb_large)), object_path(post) .info %span.time= link_to(how_long_ago(post), photo_path(post)) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 4521bae5a..7046c69a2 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -2,14 +2,22 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -%h1 - = link_to @status_message.person.real_name, @status_message.person - = @status_message.message +.span-14.append-1.last + #stream + %h1.show_text + = person_image_link(@status_message.person) + = link_to @status_message.person.real_name, @status_message.person + = make_links(@status_message.message) -%h4= "#{t('.comments')} (#{@status_message.comments.count})" + = "Posted #{how_long_ago(@status_message)} to" + - for aspect in current_user.aspects_with_post( @status_message.id ) + = link_to aspect.name, aspect -= render "comments/comments", :post => @status_message - -%p - if current_user.owns? @status_message - = link_to t('.destroy'), @status_message, :confirm => t('are_you_sure?'), :method => :delete + %p + = link_to t('.destroy'), @status_message, :confirm => t('.are_you_sure'), :method => :delete + +.span-9.last + #stream.show + %li.message{:id => @status_message.id} + = render "comments/comments", :post => @status_message diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 5f1106f03..064017959 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -179,14 +179,13 @@ header :margin :left 425px -ul#stream +#stream :margin 0 :padding 0 > li :min-height 50px :list-style none :padding 12px 0 - :right 12px :border :bottom 1px solid #eee @@ -404,6 +403,20 @@ form :margin :right 1em +#stream.show + div.comments + :display block + ul.comment_set + :margin + :top 0 + > li + :border none + :padding 0 + &:hover + > li + :background none + :border none + #stream div.comments :display none @@ -1066,3 +1079,7 @@ header :font :size small +.show_text + img + :height 27px + :width 27px From e7f764ffeb60b59b12b51b6e86756fc20f7950b7 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 20 Oct 2010 00:42:33 -0700 Subject: [PATCH 29/32] attack vector where you take posts from valid (unknown) diaspora people is now fixed --- lib/diaspora/user/receiving.rb | 22 ++++++++----- spec/controllers/publics_controller_spec.rb | 6 ++-- spec/lib/diaspora_parser_spec.rb | 34 ++++++++++++--------- spec/models/photo_spec.rb | 10 +++++- spec/models/user/attack_vectors_spec.rb | 1 - 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index 3a8fc5fa6..f459862ba 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -17,17 +17,23 @@ module Diaspora sender_in_xml = sender(object, xml) if (salmon_author == sender_in_xml) - if object.is_a? Retraction - receive_retraction object, xml - elsif object.is_a? Request + + if object.is_a? Request receive_request object, sender_in_xml - elsif object.is_a? Profile - receive_profile object, xml - elsif object.is_a?(Comment) - receive_comment object, xml + elsif self.friend_ids.include? salmon_author.id + if object.is_a? Retraction + receive_retraction object, xml + elsif object.is_a? Profile + receive_profile object, xml + elsif object.is_a?(Comment) + receive_comment object, xml + else + receive_post object, xml + end else - receive_post object, xml + raise "Not friends with that person" end + else raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} " end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 113ca4a9b..cf1a71d88 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -8,7 +8,8 @@ describe PublicsController do render_views let(:user) {Factory.create :user} let(:user2){Factory.create :user} - + let(:aspect1){user.aspect(:name => "foo")} + let(:aspect2){user2.aspect(:name => "far")} before do sign_in :user, user end @@ -21,7 +22,8 @@ describe PublicsController do it 'should accept a post from another node and save the information' do message = user2.build_post(:status_message, :message => "hi") - + friend_users(user, aspect1, user2, aspect2) + user.reload user.visible_post_ids.include?(message.id).should be false diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 33efe2f0a..6c3c697df 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -12,6 +12,8 @@ describe Diaspora::Parser do @user3 = Factory.create :user @person = @user3.person @user2 = Factory.create(:user) + @aspect2 = @user2.aspect(:name => "pandas") + friend_users(@user, @aspect, @user2, @aspect2) end describe "parsing compliant XML object" do @@ -49,7 +51,7 @@ describe Diaspora::Parser do end it 'should marshal retractions' do - person = Factory.create(:person) + person = @user2.person message = Factory.create(:status_message, :person => person) retraction = Retraction.for(message) xml = retraction.to_diaspora_xml @@ -95,17 +97,17 @@ describe Diaspora::Parser do end it "should activate the Person if I initiated a request to that url" do - request = @user.send_friend_request_to( @user2.person, @aspect) + request = @user.send_friend_request_to( @user3.person, @aspect) @user.reload - request.reverse_for @user2 + request.reverse_for @user3 xml = request.to_diaspora_xml - @user2.person.destroy - @user2.destroy + @user3.person.destroy + @user3.destroy - @user.receive xml, @user2.person - new_person = Person.first(:url => @user2.person.url) + @user.receive xml, @user3.person + new_person = Person.first(:url => @user3.person.url) new_person.nil?.should be false @user.reload @@ -115,18 +117,20 @@ describe Diaspora::Parser do end it 'should process retraction for a person' do + user4 = Factory(:user) + person_count = Person.all.count - request = @user.send_friend_request_to( @user2.person, @aspect) + request = @user.send_friend_request_to( user4.person, @aspect) @user.reload - request.reverse_for @user2 + request.reverse_for user4 xml = request.to_diaspora_xml - retraction = Retraction.for(@user2) + retraction = Retraction.for(user4) retraction_xml = retraction.to_diaspora_xml - @user2.person.destroy - @user2.destroy - @user.receive xml, @user2.person + user4.person.destroy + user4.destroy + @user.receive xml, user4.person @aspect.reload @@ -134,7 +138,7 @@ describe Diaspora::Parser do #They are now friends Person.count.should == person_count - @user.receive retraction_xml, @user2.person + @user.receive retraction_xml, user4.person @aspect.reload @@ -143,7 +147,7 @@ describe Diaspora::Parser do it 'should marshal a profile for a person' do #Create person - person = Factory.create(:person) + person = @user2.person id = person.id person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") person.save diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 51b1c058d..d97f14d75 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -102,10 +102,18 @@ describe Photo do end it 'should set the remote_photo on marshalling' do + pending "did the socket get unstubbed?" @photo.image.store! File.open(@fixture_name) + + #security hax + user2 = Factory.create(:user) + aspect2 = user2.aspect(:name => "foobars") + friend_users(@user, @aspect, user2, aspect2) + @photo.person = user2.person + @photo.save - @photo.reload + #@photo.reload url = @photo.url thumb_url = @photo.url :thumb_medium diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index ebab7cf37..67235f447 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -25,7 +25,6 @@ describe User do context 'non-friend valid user' do it 'raises if receives post by non-friend' do - pending "need to that posts come from friends.... requests need special treatment(because the person may not be in the db)" post_from_non_friend = bad_user.build_post( :status_message, :message => 'hi') xml = bad_user.salmon(post_from_non_friend).xml_for(user.person) From c08121e6ebc3b0ce65f931acb2d1633b75cc8702 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Wed, 20 Oct 2010 08:49:36 +0200 Subject: [PATCH 30/32] socket server update: pidfile, ubuntu upstart, bugfixes patching websocket_server.rb to provide a pidfile, important for SystemV init files. Ubuntu upstart configuration. Bugfixes --- pkg/fedora/diaspora-setup | 7 +- pkg/fedora/diaspora-wsd | 2 +- pkg/ubuntu/diaspora-install | 2 +- pkg/ubuntu/diaspora-setup | 6 +- pkg/ubuntu/diaspora-wsd | 154 ----------------------------------- pkg/ubuntu/diaspora-wsd.conf | 19 +++++ script/websocket_server.rb | 1 - 7 files changed, 27 insertions(+), 164 deletions(-) delete mode 100755 pkg/ubuntu/diaspora-wsd create mode 100644 pkg/ubuntu/diaspora-wsd.conf diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup index 01f0d3cdc..0214e419a 100755 --- a/pkg/fedora/diaspora-setup +++ b/pkg/fedora/diaspora-setup @@ -24,8 +24,6 @@ cd /usr/share/diaspora/master test -e config/app_config.yml || cp config/app_config.yml.example config/app_config.yml -sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ - config/app_config.yml if rake db:seed:dev; then echo "Database config OK, new user tom/evankorth in place" @@ -41,10 +39,11 @@ else exit 1 fi -# %attr(0777, diaspora, diaspora) doesn't work in specfile due to umask 022. -chmod 777 /var/lib/diaspora/uploads chown -R diaspora /var/log/diaspora +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml + hostname=$( awk '/pod_url:/ { print $2; exit }' - -PATH=/bin:/sbin:/usr/sbin:/usr/bin -DESC="Websocket server for diaspora clients" -NAME='diaspora-wsd' -DAEMON='/usr/local/bin/bundle' -DAEMON_ARGS=' exec ruby ./script/websocket_server.rb' -PIDFILE=/var/run/diaspora/diaspora-wsd.pid -SCRIPTNAME=/etc/init.d/diaspora-wsd - -cd /usr/share/diaspora/master - -[ -x "$DAEMON" ] || exit 0 -[ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# Load the VERBOSE setting and other rcS variables -. /lib/init/vars.sh - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -# -# Function that starts the daemon/service -# -do_start() -{ - # Return - # 0 if daemon has been started - # 1 if daemon was already running - # 2 if daemon could not be started - [ -f $PIDFILE ] && { - pid=$( cat $PIDFILE) - name=$( ps -p "$pid" -o comm= 2> /dev/null) || : - [ "$name" = "ruby" ] && return 1 - } - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ - --chdir $PWD -- $DAEMON_ARGS \ - || return 2 - return 0 -} - -# -# Function that stops the daemon/service -# -do_stop() -{ - # Return - # 0 if daemon has been stopped - # 1 if daemon was already stopped - # 2 if daemon could not be stopped - # other if a failure occurred - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE \ - --name $NAME --chdir $PWD - RETVAL="$?" - [ "$RETVAL" = 2 ] && return 2 - # Wait for children to finish too if this is a daemon that forks - # and if the daemon is only ever run from this initscript. - # If the above conditions are not satisfied then add some other code - # that waits for the process to drop all resources that could be - # needed by services started subsequently. A last resort is to - # sleep for some time. - start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --chdir $PWD \ - --exec $DAEMON - [ "$?" = 2 ] && return 2 - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE - return "$RETVAL" -} - -# -# Function that sends a SIGHUP to the daemon/service -# -do_reload() { - # - # If the daemon can reload its configuration without - # restarting (for example, when it is sent a SIGHUP), - # then implement that here. - # - start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --chdir $PWD \ - --name $NAME - return 0 -} - -case "$1" in - start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - do_start - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - - stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - do_stop - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - - status) - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - - #reload|force-reload) - # - # If do_reload() is not implemented then leave this commented out - # and leave 'force-reload' as an alias for 'restart'. - # - #log_daemon_msg "Reloading $DESC" "$NAME" - #do_reload - #log_end_msg $? - #;; - - restart|force-reload) - log_daemon_msg "Restarting $DESC" "$NAME" - do_stop - case "$?" in - 0|1) - do_start - case "$?" in - 0) log_end_msg 0 ;; - 1) log_end_msg 1 ;; # Old process is still running - *) log_end_msg 1 ;; # Failed to start - esac - ;; - *) - # Failed to stop - log_end_msg 1 - ;; - esac - ;; - - *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 - exit 3 - ;; -esac - -: diff --git a/pkg/ubuntu/diaspora-wsd.conf b/pkg/ubuntu/diaspora-wsd.conf new file mode 100644 index 000000000..95d78118e --- /dev/null +++ b/pkg/ubuntu/diaspora-wsd.conf @@ -0,0 +1,19 @@ +# Ubuntu upstart file at /etc/init/diaspora-wsd.conf + +start on runlevel [5] +stop on runlevel [06] + +export fork + +script + if [ -f /etc/default/diaspora ]; then + . /etc/default/diaspora; + fi; + cd /usr/share/diaspora/master; + start-stop-daemon --start \ + --chuid diaspora:diaspora \ + --chdir $PWD \ + --exec "/usr/local/bin/bundle" \ + -- exec ruby -C $PWD script/websocket_server.rb; + +end script diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 64f6ddf8a..4dddca11e 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -25,7 +25,6 @@ def write_pidfile end end - CHANNEL = Magent::GenericChannel.new('websocket') def process_message if CHANNEL.queue_count > 0 From 3faca8380b5bac4ab9159d1777affda681ff9216 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Wed, 20 Oct 2010 14:52:18 +0200 Subject: [PATCH 31/32] Revert "Merge remote branch 'upstream/master'" This reverts commit 4bb5aeb34baa4dbe5a2b438f58bf05afc78953f0, reversing changes made to fb70dc8c99a1bc7a8a3595b9cdd9d53d1ff81bab. --- app/models/user.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index cc9531c8c..aee21b543 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,7 +64,7 @@ class User #after_create :seed_aspects - before_destroy :unfriend_everyone, :remove_person + before_destroy :unfriend_everyone, :remove_person, :remove_all_aspects def strip_username if username.present? @@ -436,4 +436,8 @@ class User end } end + + def remove_all_aspects + aspects.destroy_all + end end From 1481056af23ed7dd70eed73a847d40fbe2d3ba2d Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Wed, 20 Oct 2010 14:59:55 +0200 Subject: [PATCH 32/32] Revert "Merge remote branch 'upstream/master'" This reverts commit fb70dc8c99a1bc7a8a3595b9cdd9d53d1ff81bab, reversing changes made to 53fef63a9a555a083ac9237f872a70e2b2a7115b. Conflicts: pkg/fedora/diaspora-setup pkg/ubuntu/diaspora-setup public/stylesheets/sass/application.sass spec/models/user/attack_vectors_spec.rb --- .gitignore | 2 +- Gemfile | 2 - Gemfile.lock | 36 +-- app/controllers/aspects_controller.rb | 3 +- app/controllers/registrations_controller.rb | 9 +- app/controllers/users_controller.rb | 28 +-- app/models/person.rb | 8 - app/models/post.rb | 1 - app/models/profile.rb | 9 - app/models/user.rb | 14 +- app/views/albums/_new_album.haml | 18 +- app/views/aspects/_new_aspect.haml | 18 +- .../confirmation_instructions.html.haml | 55 +--- app/views/devise/mailer/invitation.html.haml | 77 ++---- .../reset_password_instructions.html.haml | 59 +---- .../mailer/unlock_instructions.html.haml | 57 +---- app/views/invitations/_new.haml | 31 +-- app/views/people/show.html.haml | 2 - app/views/registrations/new.html.haml | 24 -- app/views/requests/_new_request.haml | 28 +-- app/views/shared/_invitations.haml | 15 +- app/views/shared/_public_explain.haml | 30 +-- app/views/shared/_reshare.haml | 10 + config/routes.rb | 1 - features/user_creates_an_aspect.feature | 8 +- lib/diaspora/exporter.rb | 51 ++-- lib/diaspora/importer.rb | 179 -------------- lib/hcard.rb | 2 +- pkg/fedora/diaspora-setup | 5 +- pkg/ubuntu/diaspora-setup | 2 +- public/javascripts/stream.js | 9 +- public/javascripts/view.js | 15 -- public/stylesheets/sass/application.sass | 49 ++-- spec/controllers/aspects_controller_spec.rb | 38 +-- .../registrations_controller_spec.rb | 14 +- spec/lib/diaspora_parser_spec.rb | 8 +- spec/lib/exporter_spec.rb | 42 +--- spec/lib/importer_spec.rb | 234 ------------------ spec/lib/verify_spec.rb | 109 -------- spec/misc_spec.rb | 23 +- spec/models/aspect_spec.rb | 2 +- spec/models/comments_spec.rb | 6 +- spec/models/person_spec.rb | 70 +++--- spec/models/photo_spec.rb | 7 +- spec/models/post_spec.rb | 3 +- spec/models/profile_spec.rb | 55 ++-- spec/models/status_message_spec.rb | 2 +- spec/models/user/attack_vectors_spec.rb | 20 +- spec/models/user/receive_spec.rb | 89 +++++-- spec/models/user/user_friending_spec.rb | 101 ++++---- spec/models/user_spec.rb | 54 +--- spec/spec_helper.rb | 7 + 52 files changed, 434 insertions(+), 1307 deletions(-) delete mode 100644 lib/diaspora/importer.rb delete mode 100644 spec/lib/importer_spec.rb delete mode 100644 spec/lib/verify_spec.rb diff --git a/.gitignore b/.gitignore index a17dc3a1b..379d97a20 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ public/stylesheets/ui.css # Uploded files and local files public/uploads/* -public/source.tar* +public/source.tar tmp/**/* db/*.sqlite3 diff --git a/Gemfile b/Gemfile index 83cb3ea08..aefce4437 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,6 @@ source 'http://rubygems.org' gem 'rails', '>= 3.0.0' - gem 'bundler', '>= 1.0.0' #Security @@ -42,7 +41,6 @@ gem 'aws' group :test, :development do gem 'factory_girl_rails' - gem 'ruby-debug19' if RUBY_VERSION.include? "1.9" gem 'ruby-debug' if RUBY_VERSION.include? "1.8" end diff --git a/Gemfile.lock b/Gemfile.lock index 5757dfcde..14e3f10ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,9 +15,9 @@ GIT GIT remote: git://github.com/dcu/magent.git - revision: 90ee5db241abd2e2b7d7de5c80f0d7c5b4b8db2d + revision: 59b8563961b830f491cd6f6592cced67791ce0ef specs: - magent (0.5.1) + magent (0.5.0) em-websocket mongo uuidtools @@ -99,7 +99,7 @@ GEM addressable (2.2.2) arel (1.0.1) activesupport (~> 3.0.0) - aws (2.3.22) + aws (2.3.21) http_connection uuidtools xml-simple @@ -120,7 +120,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) selenium-webdriver (>= 0.0.3) - childprocess (0.1.3) + childprocess (0.0.7) ffi (~> 0.6.3) columnize (0.3.1) crack (0.1.8) @@ -153,13 +153,13 @@ GEM rails (>= 3.0.0.beta4) ffi (0.6.3) rake (>= 0.8.7) - gherkin (2.2.9) + gherkin (2.2.8) json (~> 1.4.6) term-ansicolor (~> 1.0.5) - haml (3.0.22) + haml (3.0.21) hashie (0.4.0) highline (1.6.1) - http_connection (1.4.0) + http_connection (1.3.1) i18n (0.4.1) json (1.4.6) json_pure (1.4.6) @@ -213,18 +213,18 @@ GEM rake (0.8.7) rest-client (1.6.1) mime-types (>= 1.16) - rspec (2.0.1) - rspec-core (~> 2.0.1) - rspec-expectations (~> 2.0.1) - rspec-mocks (~> 2.0.1) - rspec-core (2.0.1) - rspec-expectations (2.0.1) + rspec (2.0.0) + rspec-core (= 2.0.0) + rspec-expectations (= 2.0.0) + rspec-mocks (= 2.0.0) + rspec-core (2.0.0) + rspec-expectations (2.0.0) diff-lcs (>= 1.1.2) - rspec-mocks (2.0.1) - rspec-core (~> 2.0.1) - rspec-expectations (~> 2.0.1) - rspec-rails (2.0.1) - rspec (~> 2.0.0) + rspec-mocks (2.0.0) + rspec-core (= 2.0.0) + rspec-expectations (= 2.0.0) + rspec-rails (2.0.0) + rspec (= 2.0.0) ruby-debug (0.10.3) columnize (>= 0.1) ruby-debug-base (~> 0.10.3.0) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 53a696a47..35ddbaec9 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -20,11 +20,10 @@ class AspectsController < ApplicationController @aspect = current_user.aspect(params[:aspect]) if @aspect.valid? flash[:notice] = I18n.t('aspects.create.success') - respond_with @aspect else flash[:error] = I18n.t('aspects.create.failure') - redirect_to aspects_manage_path end + respond_with @aspect end def new diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 541563d48..ec9bd7f1b 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -5,17 +5,16 @@ class RegistrationsController < Devise::RegistrationsController def create begin - @user = User.instantiate!(params[:user]) + user = User.instantiate!(params[:user]) rescue MongoMapper::DocumentNotValid => e flash[:error] = e.message redirect_to new_user_registration_path - return end - if @user.save + if user.save flash[:notice] = I18n.t 'registrations.create.success' - sign_in_and_redirect(:user, @user) + sign_in_and_redirect(:user, user) else - flash[:error] = @user.errors.full_messages.join(', ') + flash[:error] = user.errors.full_messages.join(', ') redirect_to new_user_registration_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b9bd53ab5..0a2c2b0ad 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,11 +5,10 @@ class UsersController < ApplicationController require File.join(Rails.root, 'lib/diaspora/ostatus_builder') require File.join(Rails.root, 'lib/diaspora/exporter') - require File.join(Rails.root, 'lib/diaspora/importer') require File.join(Rails.root, 'lib/collect_user_photos') - before_filter :authenticate_user!, :except => [:new, :create, :public, :import] + before_filter :authenticate_user!, :except => [:new, :create, :public] respond_to :html @@ -79,31 +78,6 @@ class UsersController < ApplicationController send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" ) end - def invite - User.invite!(:email => params[:email]) - end - - - def import - xml = params[:upload][:file].read - - params[:user][:diaspora_handle] = 'asodij@asodij.asd' - - - begin - importer = Diaspora::Importer.new(Diaspora::Parsers::XML) - importer.execute(xml, params[:user]) - flash[:notice] = "hang on a sec, try logging in!" - - rescue Exception => e - flash[:error] = "Derp, something went wrong: #{e.message}" - end - - redirect_to new_user_registration_path - #redirect_to user_session_path - end - - private def prep_image_url(params) url = APP_CONFIG[:pod_url].dup diff --git a/app/models/person.rb b/app/models/person.rb index ccf034d59..8a9011fa4 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -22,13 +22,6 @@ class Person key :owner_id, ObjectId one :profile, :class_name => 'Profile' - validate :profile_is_valid - def profile_is_valid - if profile.present? && !profile.valid? - profile.errors.full_messages.each { |m| errors.add(:base, m) } - end - end - many :albums, :class_name => 'Album', :foreign_key => :person_id belongs_to :owner, :class_name => 'User' @@ -169,5 +162,4 @@ class Person def remove_all_traces Post.all(:person_id => id).each { |p| p.delete } end - end diff --git a/app/models/post.rb b/app/models/post.rb index 0e1fc1959..aa68dc897 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -14,7 +14,6 @@ class Post xml_accessor :_id xml_accessor :person, :as => Person xml_reader :public - xml_reader :created_at key :public , Boolean, :default => false diff --git a/app/models/profile.rb b/app/models/profile.rb index baab495d7..ecc0fb5ef 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -18,9 +18,6 @@ class Profile key :image_url, String validates_presence_of :first_name, :last_name - after_validation :strip_names - - before_save :strip_names def person_id self._parent_document.id @@ -30,10 +27,4 @@ class Profile self._parent_document end - protected - - def strip_names - self.first_name.strip! if self.first_name - self.last_name.strip! if self.last_name - end end diff --git a/app/models/user.rb b/app/models/user.rb index aee21b543..1593ee29c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,12 +48,6 @@ class User validates_with InvitedUserValidator one :person, :class_name => 'Person', :foreign_key => :owner_id - validate :person_is_valid - def person_is_valid - if person.present? && !person.valid? - person.errors.full_messages.each {|m| errors.add(:base, m)} - end - end many :inviters, :in => :inviter_ids, :class_name => 'User' many :friends, :in => :friend_ids, :class_name => 'Person' @@ -62,7 +56,7 @@ class User many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :aspects, :class_name => 'Aspect', :dependent => :destroy - #after_create :seed_aspects + after_create :seed_aspects before_destroy :unfriend_everyone, :remove_person, :remove_all_aspects @@ -385,11 +379,7 @@ class User opts[:serialized_private_key] = generate_key opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key - - u = User.new(opts) - u.seed_aspects - u.save! - u + User.create(opts) end def seed_aspects diff --git a/app/views/albums/_new_album.haml b/app/views/albums/_new_album.haml index d7bd2d997..07431d20c 100644 --- a/app/views/albums/_new_album.haml +++ b/app/views/albums/_new_album.haml @@ -2,14 +2,12 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4= t('.add_a_new_album') +%h1=t('.add_a_new_album') - = form_for Album.new do |f| - = f.error_messages - %p - = f.label :name - = f.text_field :name - = f.hidden_field :to, :value => aspect - = f.submit t('.create'), :class => 'button' += form_for Album.new do |f| + = f.error_messages + %p + = f.label :name + = f.text_field :name + = f.hidden_field :to, :value => aspect + = f.submit t('.create'), :class => 'button' diff --git a/app/views/aspects/_new_aspect.haml b/app/views/aspects/_new_aspect.haml index a3dec9d31..151ab07d4 100644 --- a/app/views/aspects/_new_aspect.haml +++ b/app/views/aspects/_new_aspect.haml @@ -2,14 +2,10 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4= t('.add_a_new_aspect') - - = form_for Aspect.new do |aspect| - = aspect.error_messages - %p - = aspect.label :name - = aspect.text_field :name - = aspect.submit t('.create'), :class => 'button' - +%h1=t('.add_a_new_aspect') += form_for Aspect.new do |aspect| + = aspect.error_messages + %p + = aspect.label :name + = aspect.text_field :name + = aspect.submit t('.create'), :class => 'button' diff --git a/app/views/devise/mailer/confirmation_instructions.html.haml b/app/views/devise/mailer/confirmation_instructions.html.haml index 0dd9d28c0..7840b9c11 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.haml +++ b/app/views/devise/mailer/confirmation_instructions.html.haml @@ -1,51 +1,4 @@ -!!! -%html - %head - %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - :css - body{ - width:600px; - font-family:'Arial','Helvetica',sans-serif; - font-size:14px; - color:#333; - } - #container{ - margin-bottom:25px - min-height:400px; - padding-left:15px; - } - header{ - background-color:#333; - padding: 15px; - margin-bottom: 25px; - } - p{ - padding:5px; - } - p.small{ - font-size:smaller; - color:#999; - font-style:italic; - } - a{ - color:#107FC9; - font-weight:bold; - } - a:hover{ - color: #22AAE0; - } - a:active{ - color: #005D9C; - } - .large_text{ - font-size:21px; - font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; - } - %body - %header - = image_tag '/images/diaspora_white.png' - #container - %p - Welcome #{@resource.email}! - %p You can confirm your account through the link below: - %p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token), :class => "large_text" +%p + Welcome #{@resource.email}! +%p You can confirm your account through the link below: +%p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) diff --git a/app/views/devise/mailer/invitation.html.haml b/app/views/devise/mailer/invitation.html.haml index 7bfe190a6..c16b6fe83 100644 --- a/app/views/devise/mailer/invitation.html.haml +++ b/app/views/devise/mailer/invitation.html.haml @@ -1,61 +1,16 @@ -!!! -%html - %head - %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - :css - body{ - width:600px; - font-family:'Arial','Helvetica',sans-serif; - font-size:14px; - color:#333; - } - #container{ - margin-bottom:25px - min-height:400px; - padding-left:15px; - } - header{ - background-color:#333; - padding: 15px; - margin-bottom: 25px; - } - p{ - padding:5px; - } - p.small{ - font-size:smaller; - color:#999; - font-style:italic; - } - a{ - color:#107FC9; - font-weight:bold; - } - a:hover{ - color: #22AAE0; - } - a:active{ - color: #005D9C; - } - .large_text{ - font-size:21px; - font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; - } - %body - %header - = image_tag '/images/diaspora_white.png' - #container - %p - Hello #{@resource.email}! - %p - #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below. - - @resource.inviters.each do |inv| - - if @resource.invite_messages[inv.id.to_s] - = "#{inv.real_name}:" - = @resource.invite_messages[inv.id.to_s] - %p - %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" - %p.small - If you don't want to accept the invitation, please ignore this email. - %br/ - Your account won't be created until you access the link above and sign up. +%p + Hello #{@resource.email}! +%p + #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below. +- @resource.inviters.each do |inv| + - if @resource.invite_messages[inv.id.to_s] + = "#{inv.real_name}:" + = @resource.invite_messages[inv.id.to_s] + %p + + +%p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) +%p + If you don't want to accept the invitation, please ignore this email. + %br/ + Your account won't be created until you access the link above and sign up. diff --git a/app/views/devise/mailer/reset_password_instructions.html.haml b/app/views/devise/mailer/reset_password_instructions.html.haml index 4b344d44e..4fc4743f8 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.haml +++ b/app/views/devise/mailer/reset_password_instructions.html.haml @@ -1,53 +1,6 @@ -!!! -%html - %head - %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - :css - body{ - width:600px; - font-family:'Arial','Helvetica',sans-serif; - font-size:14px; - color:#333; - } - #container{ - margin-bottom:25px - min-height:400px; - padding-left:15px; - } - header{ - background-color:#333; - padding: 15px; - margin-bottom: 25px; - } - p{ - padding:5px; - } - p.small{ - font-size:smaller; - color:#999; - font-style:italic; - } - a{ - color:#107FC9; - font-weight:bold; - } - a:hover{ - color: #22AAE0; - } - a:active{ - color: #005D9C; - } - .large_text{ - font-size:21px; - font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; - } - %body - %header - = image_tag '/images/diaspora_white.png' - #container - %p - Hello #{@resource.email}! - %p Someone has requested a link to change your password, and you can do this through the link below. - %p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token), :class => "large_text" - %p Your password won't change until you access the link above and create a new one. - %p.small If you didn't request this, please ignore this email. +%p + Hello #{@resource.email}! +%p Someone has requested a link to change your password, and you can do this through the link below. +%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) +%p If you didn't request this, please ignore this email. +%p Your password won't change until you access the link above and create a new one. diff --git a/app/views/devise/mailer/unlock_instructions.html.haml b/app/views/devise/mailer/unlock_instructions.html.haml index 6fff6bfce..34b0e9e4e 100644 --- a/app/views/devise/mailer/unlock_instructions.html.haml +++ b/app/views/devise/mailer/unlock_instructions.html.haml @@ -1,52 +1,5 @@ -!!! -%html - %head - %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - :css - body{ - width:600px; - font-family:'Arial','Helvetica',sans-serif; - font-size:14px; - color:#333; - } - #container{ - margin-bottom:25px - min-height:400px; - padding-left:15px; - } - header{ - background-color:#333; - padding: 15px; - margin-bottom: 25px; - } - p{ - padding:5px; - } - p.small{ - font-size:smaller; - color:#999; - font-style:italic; - } - a{ - color:#107FC9; - font-weight:bold; - } - a:hover{ - color: #22AAE0; - } - a:active{ - color: #005D9C; - } - .large_text{ - font-size:21px; - font-family:"Helvetica Neue",Arial,Helvetica,sans-serif; - } - %body - %header - = image_tag '/images/diaspora_white.png' - #container - %p - Hello #{@resource.email}! - %p Your account has been locked due to an excessive amount of unsuccessful sign in attempts. - %p Click the link below to unlock your account: - %p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token), :class => "large_text" +%p + Hello #{@resource.email}! +%p Your account has been locked due to an excessive amount of unsuccessful sign in attempts. +%p Click the link below to unlock your account: +%p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index 77b07faa2..8c540092b 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -1,20 +1,15 @@ -.span-12.last - .modal_title_bar - %h4 Invite someone to join Diaspora! +%h2 Send invitation += form_for User.new, :url => invitation_path(User) do |invite| + %p + = invite.label :email + = invite.text_field :email + To + - unless @aspect.is_a? Aspect + = invite.select(:aspects, @aspects_dropdown_array) + - else + = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) + Message: + = invite.text_area :invite_messages - %i if they accept, they will be added to the aspect you invited them - = form_for User.new, :url => invitation_path(User) do |invite| - %p - = invite.label :email - = invite.text_field :email - To - - unless @aspect.is_a? Aspect - = invite.select(:aspects, @aspects_dropdown_array) - - else - = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) - - Message: - = invite.text_area :invite_messages, :value => "" - - %p= invite.submit "Send an invitation" + %p= invite.submit "Send an invitation" diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 8a76a63a6..83e7cf50d 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -12,8 +12,6 @@ = person_image_link(@person) %ul -unless @posts.first.nil? - %li - %b.small= @person.diaspora_handle %li %i= t(".last_seen",:how_long_ago => how_long_ago(@posts.first)) - if @person != current_user.person && current_user.friends.include?(@person) diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index cea31ff78..7e74a2157 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -24,27 +24,3 @@ = pr.text_field :last_name = f.submit t('.sign_up') = render :partial => "devise/shared/links" - - -%br -%br - -%h2 or, upload yourself - - -= form_tag '/users/import', :multipart => true do - - %p - = label_tag 'user[email]' - = text_field_tag 'user[email]' - %p - = label_tag 'user[password]' - = password_field_tag 'user[password]' - %p - = label_tag 'user[password_confirmation]' - = password_field_tag 'user[password_confirmation]' - - %label Select File - = file_field 'upload', 'file' - = submit_tag "Upload" - diff --git a/app/views/requests/_new_request.haml b/app/views/requests/_new_request.haml index 4c12486b8..68ee5922e 100644 --- a/app/views/requests/_new_request.haml +++ b/app/views/requests/_new_request.haml @@ -2,22 +2,20 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4 - =t('.add_a_new_friend_to') - %i= aspect.name +%h1 + =t('.add_a_new_friend_to') + %i= aspect.name - = form_for Request.new do |fr_request| - = fr_request.error_messages += form_for Request.new do |fr_request| + = fr_request.error_messages - =t('.enter_a_diaspora_username') - %br - %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle + =t('.enter_a_diaspora_username') + %br + %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle - %p - = fr_request.label :destination_url, t(".friends_username") - = fr_request.text_field :destination_url - = fr_request.hidden_field :aspect_id, :value => aspect.id - = fr_request.submit + %p + = fr_request.label :destination_url, t(".friends_username") + = fr_request.text_field :destination_url + = fr_request.hidden_field :aspect_id, :value => aspect.id + = fr_request.submit diff --git a/app/views/shared/_invitations.haml b/app/views/shared/_invitations.haml index 40476eae7..b82cca104 100644 --- a/app/views/shared/_invitations.haml +++ b/app/views/shared/_invitations.haml @@ -1,7 +1,8 @@ -%h4 Invites -= link_to "Invite a friend", "#invite_user_pane", :class => "invite_user_button", :title => "Invite a friend" -= "(#{invites} left)" -%br -.yo{ :style => "display:none;"} - #invite_user_pane - = render "invitations/new" +- unless @aspect == :all + %h4 Invites + = link_to "Invite a friend", "#invite_user_pane", :class => "invite_user_button", :title => "Invite a friend" + = "(#{invites} left)" + %br + .yo{ :style => "display:none;"} + #invite_user_pane + = render "invitations/new" diff --git a/app/views/shared/_public_explain.haml b/app/views/shared/_public_explain.haml index ca1a2b1d7..b1d2048b2 100644 --- a/app/views/shared/_public_explain.haml +++ b/app/views/shared/_public_explain.haml @@ -1,18 +1,12 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -.span-12.last - .modal_title_bar - %h4 You are about to post a public message! - %p - Public messages will be available for others outside of Diaspora to see. - %br - %br - - if @logged_in - = connected_fb_as(@access_token) - - else - = link_to "Connect to Facebook", @fb_access_url - %br - %br - = link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();' +%h3 You are about to post a public message! +%p + Public messages will be available for others outside of Diaspora to see. + %br + %br + - if @logged_in + = connected_fb_as(@access_token) + - else + = link_to "Connect to Facebook", @fb_access_url + %br + %br + = link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();' diff --git a/app/views/shared/_reshare.haml b/app/views/shared/_reshare.haml index 44c8f00dd..2ac09a78f 100644 --- a/app/views/shared/_reshare.haml +++ b/app/views/shared/_reshare.haml @@ -2,6 +2,16 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +:javascript + $(".reshare_button").toggle(function(e){ + e.preventDefault(); + $(this).parent(".reshare_pane").children(".reshare_box").fadeIn(200); + }, function(e) { + e.preventDefault(); + $(this).parent(".reshare_pane").children(".reshare_box").fadeOut(200); + }); + + - unless current_user.aspects.size == current_user.aspects_with_post(post.id).size .reshare_pane %span.reshare_button diff --git a/config/routes.rb b/config/routes.rb index 47e73807b..8fbd132a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,6 @@ Diaspora::Application.routes.draw do # added public route to user match 'public/:username', :to => 'users#public' match 'users/export', :to => 'users#export' - match 'users/import', :to => 'users#import' match 'users/export_photos', :to => 'users#export_photos' resources :users, :except => [:create, :new, :show] diff --git a/features/user_creates_an_aspect.feature b/features/user_creates_an_aspect.feature index d611d412f..7d7789f78 100644 --- a/features/user_creates_an_aspect.feature +++ b/features/user_creates_an_aspect.feature @@ -12,10 +12,12 @@ Feature: User creates an aspect Scenario: success Given I fill in "Name" with "Dorm Mates" in the modal window When I press "Create" in the modal window - Then I should see "Dorm Mates" in the header - And I should see "Your aspect 'Dorm Mates' is empty." + Then I should see "Manage aspects" + And I should see "Dorm Mates" in the header + And I should see "Dorm Mates" in the aspect list Scenario: I omit the name Given I fill in "Name" with "" in the modal window When I press "Create" in the modal window - Then I should see "Aspect creation failed." + Then I should see "Manage aspects" + And I should see "Aspect creation failed." diff --git a/lib/diaspora/exporter.rb b/lib/diaspora/exporter.rb index 5f40322fb..b560f729c 100644 --- a/lib/diaspora/exporter.rb +++ b/lib/diaspora/exporter.rb @@ -14,51 +14,36 @@ module Diaspora module XML def execute(user) builder = Nokogiri::XML::Builder.new do |xml| - user_person_id = user.person.id - xml.export { - xml.user { - xml.username user.username - xml.serialized_private_key user.serialized_private_key - - xml.parent << user.person.to_xml - } + xml.user { + xml.username user.username + xml.parent << user.person.to_xml + xml.serialized_private_key user.serialized_private_key + xml.aspects { user.aspects.each do |aspect| xml.aspect { + xml.id_ aspect.id xml.name aspect.name - - xml.person_ids { - aspect.person_ids.each do |id| - xml.person_id id + + xml.people { + aspect.people.each do |person| + xml.person person.to_xml end } + xml.posts { + aspect.posts.find_all_by_person_id(user.person.id).each do |post| + post_doc = post.to_xml + + post.comments.each do |comment| + post_doc << comment.to_xml + end - xml.post_ids { - aspect.posts.find_all_by_person_id(user_person_id).each do |post| - xml.post_id post.id + xml.post post_doc end } } end } - - xml.people { - user.friends.each do |friend| - xml.parent << friend.to_xml - end - } - - xml.posts { - user.raw_visible_posts.find_all_by_person_id(user_person_id).each do |post| - #post_doc = post.to_xml - - #post.comments.each do |comment| - # post_doc << comment.to_xml - #end - - xml.parent << post.to_xml - end - } } end diff --git a/lib/diaspora/importer.rb b/lib/diaspora/importer.rb deleted file mode 100644 index e1e8ad97f..000000000 --- a/lib/diaspora/importer.rb +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module Diaspora - - class Importer - def initialize(strategy) - self.class.send(:include, strategy) - end - - def commit(user, person, aspects, people, posts, opts = {}) - filter = verify_and_clean(user, person, people, aspects, posts) - #assume data is good - - # to go - user.email = opts[:email] - user.password= opts[:password] - user.password_confirmation = opts[:pasword_confirmation] - - - - user.person = person - - - user.person.diaspora_handle = opts[:diaspora_handle] - - user.visible_post_ids = filter[:whitelist].keys - - user.friend_ids = people.collect{ |x| x.id } - user.visible_person_ids = user.friend_ids - - user.save! - user.person.save! - - posts.each do |post| - post.save! if filter[:unknown].include? post.id - end - - - - aspects.each do |aspect| - user.aspects << aspect - end - - - - people.each do |p| - p.save! if filter[:people].include? p.id.to_s - end - end - - ### verification (to be module) ################ - - def verify_and_clean(user, person, people, aspects, posts) - verify_user(user) - verify_person_for_user(user, person) - filters = filter_posts(posts, person) - - - clean_aspects(aspects, filters[:whitelist]) - - - filters[:people] = filter_people(people) - filters - end - - def verify_user(user) - User.find_by_id(user.id).nil? ? true : raise("User already exists!") - end - - def verify_person_for_user(user, person) - local_person = Person.find_by_id(person.id) - if local_person - unless user.encryption_key.public_key.to_s == local_person.public_key.to_s - raise "local person found with different owner" - end - end - true - end - - - def filter_people(people) - person_ids = people.collect{|x| x.id} - people_from_db = Person.find_all_by_id(person_ids) #this query should be limited to only return person_id - person_ids = person_ids - people_from_db.collect{ |x| x.id } - - person_hash = {} - person_ids.each{|x| person_hash[x.to_s] = true } - person_hash - end - - def filter_posts(posts, person) - post_ids = posts.collect{|x| x.id} - posts_from_db = Post.find_all_by_id(post_ids) #this query should be limited to only return post id and owner id - - unknown_posts = post_ids - posts_from_db.collect{|x| x.id} - - posts_from_db.delete_if{|x| x.person_id == person.id} - unauthorized_post_ids = posts_from_db.collect{|x| x.id} - post_whitelist = post_ids - unauthorized_post_ids - - unknown = {} - unknown_posts.each{|x| unknown[x.to_s] = true } - - whitelist = {} - post_whitelist.each{|x| whitelist[x.to_s] = true } - - return { - :unknown => unknown, - :whitelist => whitelist } - end - - - def clean_aspects(aspects, whitelist) - aspects.each do |aspect| - aspect.post_ids.delete_if{ |x| !whitelist.include? x.to_s } - end - end - end - - module Parsers - module XML - def execute(xml, opts = {}) - doc = Nokogiri::XML.parse(xml) - - user, person = parse_user_and_person(doc) - aspects = parse_aspects(doc) - people = parse_people(doc) - posts = parse_posts(doc) - - user - commit(user, person, aspects, people, posts, opts) - end - - def parse_user_and_person(doc) - user = User.new - user_doc = doc.xpath('/export/user') - user.username = user_doc.xpath('//user/username').text - user.serialized_private_key= user_doc.xpath('//user/serialized_private_key').text - person = Person.from_xml(user_doc.xpath('//user/person').to_s) - [user, person] - end - - def parse_aspects(doc) - aspects = [] - aspect_doc = doc.xpath('/export/aspects/aspect') - - aspect_doc.each do |x| - a = Nokogiri::XML.parse(x.to_s) - - aspect = Aspect.new - aspect.name = a.xpath('/aspect/name').text - aspect.post_ids = a.xpath('/aspect/post_ids/post_id').collect{ |x| x.text.to_id } - aspect.person_ids = a.xpath('/aspect/person_ids/person_id').collect{ |x| x.text.to_id } - aspects << aspect - end - aspects - end - - def parse_people(doc) - people_doc = doc.xpath('/export/people/person') - people_doc.inject([]) do |people,curr| - people << Person.from_xml(curr.to_s) - end - end - - - def parse_posts(doc) - post_doc = doc.xpath('/export/posts/status_message') - post_doc.inject([]) do |posts,curr| - posts << StatusMessage.from_xml(curr.to_s) - end - end - - end - - end -end diff --git a/lib/hcard.rb b/lib/hcard.rb index 1bdd8a704..e858bdfc6 100644 --- a/lib/hcard.rb +++ b/lib/hcard.rb @@ -11,7 +11,7 @@ module HCard {:given_name => doc.css(".given_name").text, :family_name => doc.css(".family_name").text, :url => doc.css("#pod_location").text, - :photo => doc.css(".photo[src]").attribute('src').text } + :photo => doc.css(".photo[src]").text} end def self.find url diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup index 0214e419a..8ce4bae60 100755 --- a/pkg/fedora/diaspora-setup +++ b/pkg/fedora/diaspora-setup @@ -47,11 +47,12 @@ sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ hostname=$( awk '/pod_url:/ { print $2; exit }' li :background none :border none - + #stream div.comments :display none @@ -807,8 +798,8 @@ h1.big_text :margin 0 a - :-webkit-border-radius 5px 5px 0 0 - :-moz-border-radius 5px 5px 0 0 + :-webkit-border-radius 5px 5px 0 0 + :-moz-border-radius 5px 5px 0 0 :text-shadow 0 1px 0 #444 :line @@ -936,7 +927,7 @@ h1.big_text :color #333 :border-radius 5px - + a :color #ccc diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 81571fb54..19bb7bf5d 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -5,8 +5,7 @@ require 'spec_helper' describe AspectsController do - render_views - + render_views before do @user = Factory.create(:user) @user.aspect(:name => "lame-os") @@ -14,36 +13,11 @@ describe AspectsController do sign_in :user, @user end - describe "#index" do - it "assigns @friends to all the user's friends" do - Factory.create :person - get :index - assigns[:friends].should == @user.friends - end + it "on index sets a variable containing all a user's friends when a user is signed in" do + sign_in :user, @user + Factory.create :person + get :index + assigns[:friends].should == @user.friends end - describe "#create" do - describe "with valid params" do - it "creates an aspect" do - @user.aspects.count.should == 1 - post :create, "aspect" => {"name" => "new aspect"} - @user.reload.aspects.count.should == 2 - end - it "redirects to the aspect page" do - post :create, "aspect" => {"name" => "new aspect"} - response.should redirect_to(aspect_path(Aspect.find_by_name("new aspect"))) - end - end - describe "with invalid params" do - it "does not create an aspect" do - @user.aspects.count.should == 1 - post :create, "aspect" => {"name" => ""} - @user.reload.aspects.count.should == 1 - end - it "goes back to manage aspects" do - post :create, "aspect" => {"name" => ""} - response.should redirect_to(aspects_manage_path) - end - end - end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index e89795532..da7643fc9 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -26,10 +26,6 @@ describe RegistrationsController do it "creates a user" do lambda { get :create, @valid_params }.should change(User, :count).by(1) end - it "assigns @user" do - get :create, @valid_params - assigns(:user).should_not be_nil - end it "sets the flash" do get :create, @valid_params flash[:notice].should_not be_empty @@ -41,25 +37,19 @@ describe RegistrationsController do end context "with invalid parameters" do before do - @valid_params["user"]["person"]["profile"].delete("first_name") + @valid_params["user"].delete("username") @invalid_params = @valid_params end it "does not create a user" do lambda { get :create, @invalid_params }.should_not change(User, :count) end - it "assigns @user" do - pending "GAAAH stupid mongo mapper. Figure out why it thinks it's persisted when validations fail" - get :create, @valid_params - assigns(:user).should_not be_nil - end it "sets the flash error" do get :create, @invalid_params flash[:error].should_not be_blank end it "goes back to the form" do - pending "GAAAH stupid mongo mapper. Figure out why it thinks it's persisted when validations fail" get :create, @invalid_params - response.should be_success + response.should redirect_to new_user_registration_path end end end diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 6c3c697df..3f51cea96 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe Diaspora::Parser do before do - @user = Factory.create(:user) + @user = Factory.create(:user, :email => "bob@aol.com") @aspect = @user.aspect(:name => 'spies') @user3 = Factory.create :user @@ -22,7 +22,7 @@ describe Diaspora::Parser do end it 'should be able to correctly handle comments with person in db' do - person = Factory.create(:person) + person = Factory.create(:person, :diaspora_handle => "test@testing.com") post = Factory.create(:status_message, :person => @user.person) comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") xml = comment.to_diaspora_xml @@ -56,7 +56,9 @@ describe Diaspora::Parser do retraction = Retraction.for(message) xml = retraction.to_diaspora_xml - proc {@user.receive xml, person}.should change(StatusMessage, :count).by(-1) + StatusMessage.count.should == 1 + @user.receive xml, person + StatusMessage.count.should == 0 end it "should create a new person upon getting a person request" do diff --git a/spec/lib/exporter_spec.rb b/spec/lib/exporter_spec.rb index 88369dacf..fb3e6d29f 100644 --- a/spec/lib/exporter_spec.rb +++ b/spec/lib/exporter_spec.rb @@ -9,57 +9,25 @@ describe Diaspora::Exporter do let!(:user1) { Factory(:user) } let!(:user2) { Factory(:user) } - let!(:user3) { Factory(:user) } let(:aspect1) { user1.aspect(:name => "Work") } let(:aspect2) { user2.aspect(:name => "Family") } - let(:aspect3) { user3.aspect(:name => "Pivots") } let!(:status_message1) { user1.post(:status_message, :message => "One", :public => true, :to => aspect1.id) } let!(:status_message2) { user1.post(:status_message, :message => "Two", :public => true, :to => aspect1.id) } let!(:status_message3) { user2.post(:status_message, :message => "Three", :public => false, :to => aspect2.id) } - let(:exported) { Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1) } + let!(:exported) { Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1) } it 'should include a users posts' do - exported.should include status_message1.message - exported.should include status_message2.message - exported.should_not include status_message3.message + exported.should include status_message1.to_xml.to_s + exported.should include status_message2.to_xml.to_s + exported.should_not include status_message3.to_xml.to_s end it 'should include a users private key' do exported.should include user1.serialized_private_key end - it 'should include post_ids' do - doc = Nokogiri::XML::parse(exported) - doc.xpath('//aspects').to_s.should include status_message1.id.to_s - - doc.xpath('//aspects').to_s.should include status_message2.id.to_s - doc.xpath('//posts').to_s.should include status_message1.id.to_s - end - - it 'should include post created at time' do - doc = Nokogiri::XML::parse(exported) - Time.parse(doc.xpath('//posts/status_message/created_at').first.text).should == status_message1.created_at - end - - it 'should include a list of users posts' do - doc = Nokogiri::XML::parse(exported) - posts = doc.xpath('//posts').to_s - posts.should include(status_message1.message) - end - - it 'should serialize a users friends' do - friend_users(user1, aspect1, user3, aspect3) - doc = Nokogiri::XML::parse(exported) - doc.xpath('/export/people').to_s.should include user3.person.id.to_s - end - - it 'should serialize only a users posts within his aspects' do - message = Factory(:status_message, :message => "Shouldn't be here", :person => user3.person) - aspect1.posts << message - doc = Nokogiri::XML::parse(exported) - doc.xpath('/export/aspects').to_s.should_not include message.message - end end + diff --git a/spec/lib/importer_spec.rb b/spec/lib/importer_spec.rb deleted file mode 100644 index 268b0f5e1..000000000 --- a/spec/lib/importer_spec.rb +++ /dev/null @@ -1,234 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' -require File.join(Rails.root, 'lib/diaspora/exporter') -require File.join(Rails.root, 'lib/diaspora/importer') - -describe Diaspora::Importer do - - before(:each) do - # Five users on pod - @user1 = Factory(:user) - @user2 = Factory(:user) - @user3 = Factory(:user) - @user4 = Factory(:user) - @user5 = Factory(:user) - - # Two external people referenced on pod - @person1 = Factory(:person) - @person2 = Factory(:person) - - # User1 has four aspects(1-4), each following user has one aspect - @aspect1 = @user1.aspect(:name => "Dudes") - @aspect2 = @user1.aspect(:name => "Girls") - @aspect3 = @user1.aspect(:name => "Bros") - @aspect4 = @user1.aspect(:name => "People") - @aspect5 = @user2.aspect(:name => "Abe Lincolns") - @aspect6 = @user3.aspect(:name => "Cats") - @aspect7 = @user4.aspect(:name => "Dogs") - @aspect8 = @user5.aspect(:name => "Hamsters") - @aspect9 = @user5.aspect(:name => "Gophers") - - @aspect10 = @user1.aspect(:name => "Work") - @aspect11 = @user1.aspect(:name => "Family") - - # User1 posts one status messages to aspects (1-4), two other users post message to one aspect - @status_message1 = @user1.post(:status_message, :message => "One", :public => false, :to => @aspect1.id) - @status_message2 = @user1.post(:status_message, :message => "Two", :public => false, :to => @aspect2.id) - @status_message3 = @user1.post(:status_message, :message => "Three", :public => false, :to => @aspect3.id) - @status_message4 = @user1.post(:status_message, :message => "Four", :public => false, :to => @aspect4.id) - @status_message5 = @user2.post(:status_message, :message => "Five", :public => false, :to => @aspect5.id) - @status_message6 = @user3.post(:status_message, :message => "Six", :public => false, :to => @aspect6.id) - @status_message7 = @user5.post(:status_message, :message => "Seven", :public => false, :to => @aspect9.id) - - @aspect1.posts << @status_message1 - @aspect2.posts << @status_message2 - @aspect3.posts << @status_message3 - @aspect4.posts << @status_message4 - - # Friend users with user1 - friend_users( @user1, @aspect1, @user2, @aspect5 ) - friend_users( @user1, @aspect2, @user3, @aspect6 ) - friend_users( @user1, @aspect3, @user4, @aspect7 ) - friend_users( @user1, @aspect4, @user5, @aspect8 ) - - # Friend users 4 and 5 - friend_users( @user5, @aspect9, @user4, @aspect7 ) - - # Generate status messages and receive for user1 - @user2.receive @status_message1.to_diaspora_xml, @user1.person - @user3.receive @status_message2.to_diaspora_xml, @user1.person - @user4.receive @status_message3.to_diaspora_xml, @user1.person - @user5.receive @status_message4.to_diaspora_xml, @user1.person - @user1.receive @status_message5.to_diaspora_xml, @user2.person - @user1.receive @status_message6.to_diaspora_xml, @user3.person - - # Generate status message and recieve between user4 and user5 - @user4.receive @status_message7.to_diaspora_xml, @user5.person - end - - it 'should gut check this test' do - - @user1.friends.count.should be 4 - - @user1.friends.should include @user2.person - @user1.friends.should include @user3.person - @user1.friends.should include @user4.person - @user1.friends.should include @user5.person - - # User is generated with two pre-populated aspects - @user1.aspects.count.should be 6 - @user1.aspects.find_by_name("Dudes").people.should include @user2.person - @user1.aspects.find_by_name("Dudes").posts.should include @status_message5 - - @user1.raw_visible_posts.count.should be 6 - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).count.should be 4 - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).should_not include @status_message7 - end - - context 'parsing a user' do - - before(:each) do - # Generate exported XML for user1 - exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) - @user1.aspects.reload - @xml = exporter.execute(@user1) - - @old_user = @user1 - - # Remove user1 from the server - @user1.aspects.each( &:delete ) - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).each( &:delete ) - @user1.delete - - @importer = Diaspora::Importer.new(Diaspora::Parsers::XML) - @doc = Nokogiri::XML::parse(@xml) - end - - describe '#parse_user_and_person' do - before(:each) do - @user, @person = @importer.parse_user_and_person(@doc) - end - - it 'should set username' do - @user.username.should == @old_user.username - end - - it 'should set private key' do - @user.serialized_private_key.should_not be nil - @user.serialized_private_key.should == @old_user.serialized_private_key - end - - end - - describe '#parse_aspects' do - let(:aspects) { @importer.parse_aspects(@doc) } - - it 'should return valid aspects' do - aspects.all?(&:valid?).should be true - end - - it 'should return an array' do - aspects.count.should == 6 - end - - it 'should should have post ids' do - aspects.any?{|x| x.post_ids.count > 0}.should be true - end - - it 'should have person ids' do - aspects.any?{|x| x.person_ids.count > 0}.should be true - end - end - - describe '#parse_people' do - let(:people) { @importer.parse_people(@doc) } - - it 'should return an array' do - people.count.should == 4 - end - end - - describe '#parse_posts' do - let(:posts) { @importer.parse_posts(@doc) } - - it 'should return an array' do - posts.count.should == 4 - end - - it 'should return vaild posts' do - posts.all?(&:valid?).should be true - end - end - - end - - describe 'importing a user' do - - context '#execute' do - before(:each) do - # Generate exported XML for user1 - exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) - @xml = exporter.execute(@user1) - - # Remove user1 from the server - @user1.aspects.each( &:delete ) - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).each( &:delete ) - @user1.delete - - @importer = Diaspora::Importer.new(Diaspora::Parsers::XML) - end - - it 'should import' do - pending "there is some weirdness with diaspora handle we need to look into... and this test is terrible" - User.delete_all - Person.delete_all - Post.delete_all - StatusMessage.delete_all - Aspect.delete_all - - User.count.should == 0 - Person.count.should == 0 - - @importer.execute(@xml, - :email => "bob@bob.com", - :password => "bobbybob", - :password => "bobbybob", - :diaspora_handle => "bob@diaspora.com") - - User.count.should == 1 - n = User.first - Post.count.should == 4 - n.aspects.count.should == 6 - Person.count.should be == 5 - - User.first.person.diaspora_handle.should == User.first.diaspora_handle - - - Person.find_by_id( @user1.person.id ).nil?.should == false - Person.find_by_id( @user2.person.id ).nil?.should == false - - n.aspects.count.should == 6 - - people_count = 0 - n.aspects.each{|x| people_count += x.people.count } - people_count.should == 4 - - post_count = 0 - n.aspects.reload - n.aspects.each{ |x| post_count += x.post_ids.count } - post_count.should == 4 - - n.friends.count.should be 4 - end - - - - end - - end - -end - diff --git a/spec/lib/verify_spec.rb b/spec/lib/verify_spec.rb deleted file mode 100644 index b0b8a0de6..000000000 --- a/spec/lib/verify_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' -require File.join(Rails.root, 'lib/diaspora/importer') - -describe Diaspora::Importer do - - let!(:user1) { Factory(:user) } - let!(:user2) { Factory(:user) } - let!(:user3) { Factory(:user) } - - let(:aspect1) { user1.aspect(:name => "Work") } - let(:aspect2) { user2.aspect(:name => "Family") } - let(:aspect3) { user3.aspect(:name => "Pivots") } - - let!(:status_message1) { user1.post(:status_message, :message => "One", :public => true, :to => aspect1.id) } - let!(:status_message2) { user1.post(:status_message, :message => "Two", :public => true, :to => aspect1.id) } - let!(:status_message3) { user2.post(:status_message, :message => "Three", :public => false, :to => aspect2.id) } - - let(:importer) { Diaspora::Importer.new(Diaspora::Parsers::XML) } - - context 'serialized user' do - describe '#verify_user' do - it 'should return true for a new valid user' do - new_user = Factory(:user) - new_user.delete - importer.verify_user(new_user).should be true - end - - it 'should return false if vaild user already exists' do - u = User.first - lambda{ importer.verify_user(user1) }.should raise_error - end - end - - describe '#verify_person_for_user' do - it 'should pass if keys match' do - importer.verify_person_for_user(user1, user1.person).should be true - end - - it 'should fail if private and public keys do not match' do - person = Factory(:person) - lambda{ importer.verify_person_for_user(user1, person) }.should raise_error - end - - it 'should pass if the person does not exist' do - user = Factory.build(:user) - importer.verify_person_for_user(user, user.person) - end - end - - - describe '#filter_posts' do - it 'should make sure all found posts are owned by the user' do - posts = [status_message1, status_message2] - whitelist = importer.filter_posts(posts, user1.person)[:whitelist] - - whitelist.should have(2).posts - whitelist.should include status_message1.id.to_s - whitelist.should include status_message2.id.to_s - end - - it 'should remove posts not owned by the user' do - posts = [status_message1, status_message2, status_message3] - whitelist = importer.filter_posts(posts, user1.person)[:whitelist] - - whitelist.should have(2).posts - whitelist.should_not include status_message3.id - end - - it 'should return a list of unknown posts' do - posts = [status_message1, status_message2, Factory.build(:status_message)] - unknown = importer.filter_posts(posts, user1.person)[:unknown] - - unknown.should have(1).post - end - - it 'should generate a whitelist, unknown posts inclusive' do - posts = [status_message1, status_message2, Factory.build(:status_message)] - filters = importer.filter_posts(posts, user1.person) - - filters[:whitelist].should include filters[:unknown].keys.first - end - end - - describe '#clean_aspects' do - it 'should purge posts not in whitelist that are present in aspects' do - whitelist = {status_message1.id.to_s => true, status_message2.id.to_s => true} - - aspect1.reload - aspect1.post_ids << status_message3.id.to_s - - proc{ importer.clean_aspects([aspect1], whitelist) }.should change(aspect1.post_ids, :count).by(-1) - aspect1.post_ids.should_not include status_message3.id - end - end - - describe '#filter_people' do - it 'should filter people who already exist in the database' do - new_peep = Factory.build(:person) - people = [user1.person, user2.person, new_peep] - - importer.filter_people(people).keys.should == [new_peep.id.to_s] - end - end - end -end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 12f7837c1..1db3f3f82 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -5,13 +5,34 @@ require 'spec_helper' describe 'making sure the spec runner works' do + + it 'should not delete the database mid-spec' do + User.count.should == 0 + Factory.create(:user) + User.count.should == 1 + end + + it 'should make sure the last user no longer exsists' do + User.count.should == 0 + end + it 'should factory create a user with a person saved' do user = Factory.create(:user) loaded_user = User.first(:id => user.id) loaded_user.person.owner_id.should == user.id end + describe 'testing a before do block' do + before do + Factory.create(:user) - describe '#friend_users' do + end + + it 'should have cleaned before the before do block runs' do + User.count.should == 1 + end + + end + describe '#friend_users' do before do @user1 = Factory.create(:user) @aspect1 = @user1.aspect(:name => "losers") diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index d5c281a3b..e91d4a258 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -65,7 +65,7 @@ describe Aspect do it 'belong to a user' do @aspect.user.id.should == @user.id - @user.aspects.size.should == 1 + @user.aspects.size.should == 3 end it 'should have people' do diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index 08252ada2..b2f2d3c61 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -18,7 +18,7 @@ describe Comment do status.comments.should == [] @user.comment "Yeah, it was great", :on => status - status.reload.comments.first.text.should == "Yeah, it was great" + StatusMessage.first.comments.first.text.should == "Yeah, it was great" end it "should be able to comment on a person's status" do @@ -26,8 +26,8 @@ describe Comment do status = Factory.create(:status_message, :person => person) @user.comment "sup dog", :on => status - status.reload.comments.first.text.should == "sup dog" - status.reload.comments.first.person.should == @user.person + StatusMessage.first.comments.first.text.should == "sup dog" + StatusMessage.first.comments.first.person.should == @user.person end it 'should not send out comments when we have no people' do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index edc5b20ee..fd5ea0162 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -13,22 +13,6 @@ describe Person do @aspect2 = @user2.aspect(:name => "Abscence of Babes") end - describe "validation" do - describe "of associated profile" do - it "fails if the profile isn't valid" do - person = Factory.build(:person) - person.should be_valid - - person.profile.update_attribute(:first_name, nil) - person.profile.should_not be_valid - person.should_not be_valid - - person.errors.count.should == 1 - person.errors.full_messages.first.should =~ /first name/i - end - end - end - describe '#diaspora_handle' do context 'local people' do it 'uses the pod config url to set the diaspora_handle' do @@ -77,38 +61,64 @@ describe Person do person_two.owns?(person_message).should be false end - it "deletes all of a person's posts upon person deletion" do + it 'should delete all of user posts except comments upon user deletion' do person = Factory.create(:person) - status = Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => @person) - - lambda {person.destroy}.should change(Post, :count).by(-1) - end - - it "does not delete a person's comments on person deletion" do - person = Factory.create(:person) + Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => person) status_message = Factory.create(:status_message, :person => @person) + Factory.create(:comment, :person_id => person.id, :text => "yes i do", :post => status_message) Factory.create(:comment, :person_id => person.id, :text => "i love you", :post => status_message) + Factory.create(:comment, :person_id => person.id, :text => "hello", :post => status_message) Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => status_message) - - lambda {person.destroy}.should_not change(Comment, :count) + + person.destroy + + Post.count.should == 1 + Comment.all.count.should == 4 + status_message.comments.count.should == 4 end describe "unfriending" do it 'should not delete an orphaned friend' do - @user.activate_friend(@person, @aspect) + request = @user.send_friend_request_to @person, @aspect - lambda {@user.unfriend(@person)}.should_not change(Person, :count) + @user.activate_friend(@person, @aspect) + @user.reload + + Person.all.count.should == 3 + @user.friends.count.should == 1 + @user.unfriend(@person) + @user.reload + @user.friends.count.should == 0 + Person.all.count.should == 3 end it 'should not delete an un-orphaned friend' do + request = @user.send_friend_request_to @person, @aspect + request2 = @user2.send_friend_request_to @person, @aspect2 + @user.activate_friend(@person, @aspect) @user2.activate_friend(@person, @aspect2) - lambda {@user.unfriend(@person)}.should_not change(Person, :count) + @user.reload + @user2.reload + + Person.all.count.should == 3 + @user.friends.count.should == 1 + @user2.friends.count.should == 1 + + @user.unfriend(@person) + @user.reload + @user2.reload + @user.friends.count.should == 0 + @user2.friends.count.should == 1 + + Person.all.count.should == 3 end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index d97f14d75..7fcf5967e 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -51,7 +51,8 @@ describe Photo do it 'should have a caption' do @photo.image.store! File.open(@fixture_name) @photo.caption = "cool story, bro" - @photo.save.should be_true + @photo.save + Photo.first.caption.should == "cool story, bro" end it 'should remove its reference in user profile if it is referred' do @@ -62,9 +63,9 @@ describe Photo do @user.save @user.person.save - @user.profile.image_url.should == @photo.image.url(:thumb_medium) + User.first.profile.image_url.should == @photo.image.url(:thumb_medium) @photo.destroy - @user.reload.profile.image_url.should be nil + User.first.profile.image_url.should be nil end it 'should not use the imported filename as the url' do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 4c3daf4b6..bc445af99 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -6,7 +6,8 @@ require 'spec_helper' describe Post do before do - @user = Factory.create(:user) + @user = Factory.create(:user, :email => "bob@aol.com") + @user.person.save end describe 'xml' do diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index de2eb6955..7bba8311c 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -5,40 +5,25 @@ require 'spec_helper' describe Profile do - describe 'validation' do - describe "of first_name" do - it "requires first name" do - profile = Factory.build(:profile, :first_name => nil) - profile.should_not be_valid - profile.first_name = "Hortense" - profile.should be_valid - end - it "requires non-empty first name" do - profile = Factory.build(:profile, :first_name => " ") - profile.should_not be_valid - end - it "strips leading and trailing whitespace" do - profile = Factory.build(:profile, :first_name => " Shelly ") - profile.should be_valid - profile.first_name.should == "Shelly" - end - end - describe "of last_name" do - it "requires a last name" do - profile = Factory.build(:profile, :last_name => nil) - profile.should_not be_valid - profile.last_name = "Shankar" - profile.should be_valid - end - it "requires non-empty last name" do - profile = Factory.build(:profile, :last_name => " ") - profile.should_not be_valid - end - it "strips leading and trailing whitespace" do - profile = Factory.build(:profile, :last_name => " Ohba ") - profile.should be_valid - profile.last_name.should == "Ohba" - end - end + before do + @person = Factory.build(:person) end + + describe 'requirements' do + it "should include a first name" do + @person.profile = Factory.build(:profile,:first_name => nil) + @person.profile.valid?.should be false + @person.profile.first_name = "Bob" + @person.profile.valid?.should be true + end + + it "should include a last name" do + @person.profile = Factory.build(:profile, :last_name => nil) + @person.profile.valid?.should be false + @person.profile.last_name = "Smith" + @person.profile.valid?.should be true + end + + end + end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 8449b964c..2d8d0c5bf 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe StatusMessage do before do - @user = Factory.create(:user) + @user = Factory.create(:user, :email => "bob@aol.com") @aspect = @user.aspect(:name => "losers") end diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index 67235f447..4ae9184dd 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -8,8 +8,6 @@ describe User do let(:user) { Factory(:user) } let(:aspect) { user.aspect(:name => 'heroes') } - - let(:bad_user) { Factory(:user)} let(:user2) { Factory(:user) } let(:aspect2) { user2.aspect(:name => 'losers') } @@ -23,7 +21,7 @@ describe User do end context 'non-friend valid user' do - + it 'raises if receives post by non-friend' do post_from_non_friend = bad_user.build_post( :status_message, :message => 'hi') xml = bad_user.salmon(post_from_non_friend).xml_for(user.person) @@ -42,7 +40,7 @@ describe User do end context 'malicious friend attack vector' do - it 'overwrites messages with a different user' do + it 'overwrites messages with a different user' do original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id user.receive_salmon(user2.salmon(original_message).xml_for(user.person)) @@ -54,8 +52,8 @@ describe User do user.raw_visible_posts.count.should be 1 user.raw_visible_posts.first.message.should == "store this!" end - - it 'overwrites messages which apear to be from the same user' do + + it 'overwrites messages which apear to be from the same user' do original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id user.receive_salmon(user2.salmon(original_message).xml_for(user.person)) user.raw_visible_posts.count.should be 1 @@ -78,12 +76,12 @@ describe User do user2.reload user2.profile.first_name.should == "Robert" end - + it 'should not overwrite another persons profile through comment' do pending user_status = user.post(:status_message, :message => "hi", :to => 'all') comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => user_status) - + comment.creator_signature = comment.sign_with_key(user3.encryption_key) comment.post_creator_signature = comment.sign_with_key(user.encryption_key) @@ -91,14 +89,14 @@ describe User do original_url = person.url original_id = person.id puts original_url - + comment.person.url = "http://bad.com/" user3.delete person.delete - + comment.to_diaspora_xml.include?("bad.com").should be true user2.receive_salmon(user.salmon(comment).xml_for(user2.person)) - + comment.person.url.should == original_url Person.first(:id => original_id).url.should == original_url end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index c8e4891de..1d97cdad1 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -22,13 +22,16 @@ describe User do it 'should be able to parse and store a status message from xml' do status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id + person = user2.person xml = status_message.to_diaspora_xml user2.destroy status_message.destroy + StatusMessage.all.size.should == 0 + user.receive xml , user2.person - user - lambda {user.receive xml , user2.person}.should change (Post,:count).by(1) + Post.all(:person_id => person.id).first.message.should == 'store this!' + StatusMessage.all.size.should == 1 end it 'should not create new aspects on message receive' do @@ -44,52 +47,96 @@ describe User do end describe 'post refs' do - before do - @status_message = user2.post :status_message, :message => "hi", :to =>aspect2.id - user.receive @status_message.to_diaspora_xml, user2.person - user.reload - end - it "should add a received post to the aspect and visible_posts array" do - user.raw_visible_posts.include?(@status_message).should be true - aspect.reload - aspect.posts.include?(@status_message).should be_true + status_message = user.post :status_message, :message => "hi", :to =>aspect.id + user.reload + salmon = user.salmon(status_message).xml_for user2.person + user2.receive_salmon salmon + user2.reload + user2.raw_visible_posts.include?(status_message).should be true + aspect2.reload + aspect2.posts.include?(status_message).should be_true end it 'should be removed on unfriending' do + status_message = user2.post :status_message, :message => "hi", :to => aspect2.id + user.receive status_message.to_diaspora_xml, user2.person + user.reload + + user.raw_visible_posts.count.should == 1 + user.unfriend(user2.person) + user.reload user.raw_visible_posts.count.should == 0 + + Post.count.should be 1 end it 'should be remove a post if the noone links to it' do + status_message = user2.post :status_message, :message => "hi", :to => aspect2.id + user.receive status_message.to_diaspora_xml, user2.person + user.reload + + user.raw_visible_posts.count.should == 1 + person = user2.person user2.delete + user.unfriend(person) - lambda {user.unfriend(person)}.should change(Post, :count).by(-1) user.reload user.raw_visible_posts.count.should == 0 + + Post.count.should be 0 end it 'should keep track of user references for one person ' do - @status_message.reload - @status_message.user_refs.should == 1 + status_message = user2.post :status_message, :message => "hi", :to => aspect2.id + user.receive status_message.to_diaspora_xml, user2.person + user.reload + + user.raw_visible_posts.count.should == 1 + + status_message.reload + status_message.user_refs.should == 1 user.unfriend(user2.person) - @status_message.reload - @status_message.user_refs.should == 0 + status_message.reload + + user.reload + user.raw_visible_posts.count.should == 0 + + status_message.reload + status_message.user_refs.should == 0 + + Post.count.should be 1 end it 'should not override userrefs on receive by another person' do user3.activate_friend(user2.person, aspect3) - user3.receive @status_message.to_diaspora_xml, user2.person - @status_message.reload - @status_message.user_refs.should == 2 + status_message = user2.post :status_message, :message => "hi", :to => aspect2.id + user.receive status_message.to_diaspora_xml, user2.person + + user3.receive status_message.to_diaspora_xml, user2.person + user.reload + user3.reload + + user.raw_visible_posts.count.should == 1 + + status_message.reload + status_message.user_refs.should == 2 user.unfriend(user2.person) - @status_message.reload - @status_message.user_refs.should == 1 + status_message.reload + + user.reload + user.raw_visible_posts.count.should == 0 + + status_message.reload + status_message.user_refs.should == 1 + + Post.count.should be 1 end end diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 2756c0841..8bcc093f1 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -28,9 +28,10 @@ describe User do it "should be able to accept a pending friend request" do r = Request.instantiate(:to => user.receive_url, :from => friend) r.save - - proc {user.accept_friend_request(r.id, aspect.id)}.should change{ - Request.for_user(user).all.count}.by(-1) + Person.all.count.should == 2 + Request.for_user(user).all.count.should == 1 + user.accept_friend_request(r.id, aspect.id) + Request.for_user(user).all.count.should == 0 end it 'should be able to ignore a pending friend request' do @@ -38,8 +39,12 @@ describe User do r = Request.instantiate(:to => user.receive_url, :from => friend) r.save - proc{user.ignore_friend_request(r.id)}.should change{ - Request.for_user(user).count}.by(-1) + Person.count.should == 2 + + user.ignore_friend_request(r.id) + + Person.count.should == 2 + Request.count.should == 0 end it 'should not be able to friend request an existing friend' do @@ -75,53 +80,59 @@ describe User do @request_three.destroy end - context 'request from one remote person to one local user' do - before do - user2.receive @req_three_xml, user.person - end - it 'should befriend the user other user on the same pod' do - proc{ - user2.accept_friend_request @request_three.id, aspect2.id - }.should_not change(Person, :count) - user2.friends.include?(user.person).should be true - end - - it 'should not delete the ignored user on the same pod' do - proc{ - user2.ignore_friend_request @request_three.id - }.should_not change(Person, :count) - user2.friends.include?(user.person).should be false - end + it 'should befriend the user other user on the same pod' do + user2.receive @req_three_xml, user.person + user2.pending_requests.size.should be 1 + user2.accept_friend_request @request_three.id, aspect2.id + user2.friends.include?(user.person).should be true + Person.all.count.should be 3 end - context 'Two users receiving requests from one person' do - before do - user.receive @req_xml, person_one - user2.receive @req_two_xml, person_one - end - it 'should both users should befriend the same person' do - user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + it 'should not delete the ignored user on the same pod' do + user2.receive @req_three_xml, user.person + user2.pending_requests.size.should be 1 + user2.ignore_friend_request @request_three.id + user2.friends.include?(user.person).should be false + Person.all.count.should be 3 + end - user2.accept_friend_request @request_two.id, aspect2.id - user2.friends.include?(person_one).should be true - end + it 'should both users should befriend the same person' do + user.receive @req_xml, person_one + user.pending_requests.size.should be 1 + user.accept_friend_request @request.id, aspect.id + user.friends.include?(person_one).should be true - it 'should keep the person around if one of the users rejects him' do - user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + user2.receive @req_two_xml, person_one + user2.pending_requests.size.should be 1 + user2.accept_friend_request @request_two.id, aspect2.id + user2.friends.include?(person_one).should be true + Person.all.count.should be 3 + end - user2.ignore_friend_request @request_two.id - user2.friends.include?(person_one).should be false - end + it 'should keep the person around if one of the users rejects him' do + user.receive @req_xml, person_one + user.pending_requests.size.should be 1 + user.accept_friend_request @request.id, aspect.id + user.friends.include?(person_one).should be true - it 'should keep the person around if the users ignores them' do - user.ignore_friend_request user.pending_requests.first.id - user.friends.include?(person_one).should be false + user2.receive @req_two_xml, person_one + user2.pending_requests.size.should be 1 + user2.ignore_friend_request @request_two.id + user2.friends.include?(person_one).should be false + Person.all.count.should be 3 + end - user2.ignore_friend_request user2.pending_requests.first.id #@request_two.id - user2.friends.include?(person_one).should be false - end + it 'should keep the person around if the users ignores them' do + user.receive @req_xml, person_one + user.pending_requests.size.should be 1 + user.ignore_friend_request user.pending_requests.first.id + user.friends.include?(person_one).should be false + + user2.receive @req_two_xml, person_one + user2.pending_requests.size.should be 1 + user2.ignore_friend_request user2.pending_requests.first.id #@request_two.id + user2.friends.include?(person_one).should be false + Person.all.count.should be 3 end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 536e7b68c..61e37b3aa 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -13,20 +13,6 @@ describe User do let(:aspect3) { user3.aspect(:name => 'stuff') } describe "validation" do - describe "of associated person" do - it "fails if person is not valid" do - user = Factory.build(:user) - user.should be_valid - - user.person.update_attribute(:serialized_public_key, nil) - user.person.should_not be_valid - user.should_not be_valid - - user.errors.full_messages.count.should == 1 - user.errors.full_messages.first.should =~ /serialized public key/i - end - end - describe "of passwords" do it "fails if password doesn't match confirmation" do user = Factory.build(:user, :password => "password", :password_confirmation => "nope") @@ -86,41 +72,6 @@ describe User do end end - describe ".instantiate!" do - it "creates the user if params are valid" do - User.find_by_username("ohai").should be_nil - user = User.instantiate!({ - :username => "ohai", - :email => "ohai@example.com", - :password => "password", - :password_confirmation => "password", - :person => {:profile => {:first_name => "O", :last_name => "Hai"}}}) - user.should be_valid - User.find_by_username("ohai").should == user - end - describe "with invalid params" do - before do - @invalid_params = { - :username => "ohai", - :email => "ohai@example.com", - :password => "password", - :password_confirmation => "password", - :person => {:profile => {:first_name => "", :last_name => ""}}} - end - it "raises an error" do - lambda { User.instantiate!(@invalid_params) }.should raise_error - end - it "does not create the user" do - User.find_by_username("ohai").should be_nil - begin - User.instantiate!(@invalid_params) - rescue - end - User.find_by_username("ohai").should be_nil - end - end - end - describe ".find_for_authentication" do it "preserves case" do User.find_for_authentication(:username => user.username).should == user @@ -147,6 +98,7 @@ describe User do end context 'aspects' do + it 'should delete an empty aspect' do user.drop_aspect(aspect) user.aspects.include?(aspect).should == false @@ -176,6 +128,7 @@ describe User do user.destroy end + it 'should remove all aspects' do aspects = user.aspects aspects.count.should > 0 @@ -184,6 +137,7 @@ describe User do aspects.count.should == 0 end + describe '#remove_person' do it 'should remove the person object' do person = user.person @@ -201,6 +155,7 @@ describe User do end describe '#unfriend_everyone' do + before do user3.delete end @@ -218,4 +173,5 @@ describe User do end end end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 218def68b..552fd884d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,11 +26,18 @@ RSpec.configure do |config| DatabaseCleaner.orm = "mongo_mapper" config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) stub_signature_verification + end config.before(:each) do + DatabaseCleaner.start stub_sockets + User.stub!(:allowed_email?).and_return(:true) + end + + config.after(:each) do DatabaseCleaner.clean end end