diff --git a/app/controllers/dev_utilities_controller.rb b/app/controllers/dev_utilities_controller.rb index 549b25b00f4efe1110fa7d5592eb9bd5a50a9b91..6318dfb78acb0ced80aa3f61b322e30fcf9ae9fc 100644 --- a/app/controllers/dev_utilities_controller.rb +++ b/app/controllers/dev_utilities_controller.rb @@ -48,7 +48,8 @@ class DevUtilitiesController < ApplicationController @fixture_name = File.join(File.dirname(__FILE__), "..", "..", "public", "images", "user", "#{username}.jpg") - photo = Photo.new(:person => current_user.person, :album => album) + photo = Photo.new(:album => album) + photo.person = current_user.person photo.image.store! File.open(@fixture_name) photo.save photo.reload diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 1d4faa310864d71aedaf059ba3916de9f4d86664..c0c5851486a992352db29c09fdec1ea25048c7a8 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -97,7 +97,9 @@ class PhotosController < ApplicationController respond_with @photo else flash[:error] = I18n.t 'photos.update.error' - render :action => :edit + @album = @photo.album + set_friends_and_status + render :edit end end end diff --git a/app/models/aspect.rb b/app/models/aspect.rb index 56210f0db877ffe9f7b30a35f1319aabd863f4a4..5758f49c469c57f00b55c27e3c832d247a143d3d 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -18,7 +18,11 @@ class Aspect validates_presence_of :name validates_uniqueness_of :name, :scope => :user_id attr_accessible :name - + + before_validation do + name.strip! + end + timestamps! def to_s diff --git a/app/models/photo.rb b/app/models/photo.rb index 94985e2bf75ed328c2af14abe82f4e05f6de920e..afc3fa58387e0ca6d0229646e76dfa0ef42b0cfa 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -32,12 +32,16 @@ class Photo < Post before_destroy :ensure_user_picture + attr_protected :person + def self.instantiate(params = {}) - image_file = params[:user_file] - params.delete :user_file + image_file = params.delete(:user_file) + person = params.delete(:person) photo = Photo.new(params) + photo.image.store! image_file + photo.person = person photo.save photo end diff --git a/config/locales/devise/devise.sv.yml b/config/locales/devise/devise.sv.yml index 39d09b158b1c0fc36bb379c5c2ebca709f220c7e..0366d0c496e598a3bbe2986f894ab9d471e5f372 100644 --- a/config/locales/devise/devise.sv.yml +++ b/config/locales/devise/devise.sv.yml @@ -1,6 +1,8 @@ # Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +# +# See config/locales/devise/devise.sv.yml for Swedish Diaspora terms. sv: errors: diff --git a/config/locales/diaspora/sv.yml b/config/locales/diaspora/sv.yml index f09e938e403d5ef8a326850295392b373978ad9f..58165864577332312b2dae38dc1bcdc539a3c9f9 100644 --- a/config/locales/diaspora/sv.yml +++ b/config/locales/diaspora/sv.yml @@ -4,9 +4,23 @@ # Localization file for Swedish # -# This file has parts from rails-i18n project at +# This file has parts from rails-i18n project at # http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale - +# +# --- And now, Swedish! --- +# +# Svensk terminologi i denna översättning: +# +# album: fotoalbum +# aspect: sida +# diaspora-handle: diaspora-adress +# diaspora-id: (diaspora-) användarnamn +# email: mail, ebrev (diskussion pågår); +# pod: plats +# request: (vän-) förfrågan +# profile: profil +# seed: frö +# sv: activemodel: errors: @@ -182,7 +196,7 @@ sv: sent: 'Din inbjudan är nu skickad.' no_more: 'Du har inga fler inbjudningar.' already_sent: 'Du har redan bjudit in denna person.' - already_friends: 'Du är redan vän med den här personen' + already_friends: 'Du är redan vän med den här personen' invitation_token_invalid: 'Din inbjudningskod är inte giltig!' updated: 'Ditt lösenord är nu uppdaterat, och du har loggats in.' @@ -348,13 +362,13 @@ sv: errors: # model.errors.full_messages format. format: "%{attribute} %{message}" - + template: header: one: "Ett fel förhindrade denna %{model} från att sparas" other: "%{count} fel förhindrade denna %{model} från att sparas" body: "Det var problem med följande fält:" - + # The values :model, :attribute and :value are always available for interpolation # The value :count is available when applicable. Can be used for pluralization. messages: diff --git a/pkg/ubuntu-setup.bash b/pkg/ubuntu-setup.bash index cbf42c60a99bd4c787d8770f1af04d53c68b7982..55ec1d2b722766cfde39dc41bbbb3e09f3c0aad0 100755 --- a/pkg/ubuntu-setup.bash +++ b/pkg/ubuntu-setup.bash @@ -8,22 +8,25 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -# USAGE: ./script/ubuntu-setup.bash + +# USAGE: ./pkg/ubuntu-setup.bash [external hostname] # Do NOT run this script as root. +arg_hostname="$1" + # Set extented globbing shopt -s extglob # fail on error set -e -[ "$(whoami)" == "root" ] && echo "Please do not run this script as root/sudo +[[ "$(whoami)" == "root" ]] && echo "Please do not run this script as root/sudo We need to do some actions as an ordinary user. We use sudo where necessary." && exit 1 # Check if the user has sudo privileges. sudo -v >/dev/null 2>&1 || { echo $(whoami) has no sudo privileges ; exit 1; } -# Check if universal repository is enabled +# Check if universal repository is enabled grep -ie '^deb .*universe' /etc/apt/sources.list > /dev/null || \ { echo "Please enable universe repository" ; exit 1 ; } @@ -63,8 +66,8 @@ then then echo "Lanchpad bug https://bugs.launchpad.net/ubuntu/+source/mongodb/+bug/557024 has not been fixed using workaround:" - echo "sudo ln -s /usr/lib/xulrunner-1.9.2.10/libmozjs.so /usr/lib/libmozjs.so" - sudo ln -s /usr/lib/xulrunner-1.9.2.10/libmozjs.so /usr/lib/libmozjs.so + echo "sudo ln -sf /usr/lib/xulrunner-1.9.2.10/libmozjs.so /usr/lib/libmozjs.so" + sudo ln -sf /usr/lib/xulrunner-1.9.2.10/libmozjs.so /usr/lib/libmozjs.so fi sudo apt-get -y --no-install-recommends install mongodb @@ -101,13 +104,13 @@ echo "Fetching and installing ruby gems.." if [ $RELEASE == "maverick" ] then sudo apt-get install --no-install-recommends -y rubygems - sudo ln -s /var/lib/gems/1.8/bin/bundle /usr/local/bin/bundle #for PATH + sudo ln -sf /var/lib/gems/1.8/bin/bundle /usr/local/bin/bundle #for PATH elif [ $RELEASE == "lucid" ] then sudo add-apt-repository ppa:maco.m/ruby sudo apt-get update sudo apt-get install --no-install-recommends -y rubygems - sudo ln -s /var/lib/gems/1.8/bin/bundle /usr/local/bin/bundle #for PATH + sudo ln -sf /var/lib/gems/1.8/bin/bundle /usr/local/bin/bundle #for PATH else # Old version echo "." @@ -147,26 +150,49 @@ echo "Installed bundler.." #Configure diaspora cp config/app_config.yml.example config/app_config.yml - echo "You need to configure diaspora to tell it which URL it has. -Opening editor in 5 seconds and then continuing with install." - sleep 5 - #ensure EDITOR is set - if [ -z "${EDITOR}"] - then - EDITOR=vi + hostname=$( awk '/pod_url:/ { print $2; exit }' <config/app_config.yml) + + 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 + else + while : ; do + echo "Current hostname is \"$hostname\"" + echo -n "Enter new hostname [$hostname] :" + read new_hostname garbage + echo -n "Use \"$new_hostname\" as pod_url (Yes/No) [Yes]? :" + read yesno garbage + [ "${yesno:0:1}" = 'y' -o "${yesno:0:1}" = 'Y' -o -z "$yesno" ] && { + sed -i "/pod_url:/s|$hostname|$new_hostname|g" \ + config/app_config.yml && + echo "config/app_config.yml updated." + break + } + done fi - $EDITOR config/app_config.yml + # Create the shared directory which is used by rake db:seed:tom - mkdir shared + ### mkdir shared # Install DB setup - echo "Seting up DB.." - rake db:seed:tom - echo "DB ready. Login -> tom and password -> evankorth. -More details ./diaspora/db/seeds/tom.rb." + echo "Setting up DB..." + if rake db:seed:dev ; then + cat <<- EOF + DB ready. Login -> tom and password -> evankorth. + More details ./diaspora/db/seeds/tom.rb. and ./diaspora/db/seeds/dev.rb. + EOF + else + cat <<- EOF + Database config failed. You might want to remove all db files with + 'rm -rf /var/lib/mongodb/*' and/or reset the config file by + 'cp config/app_config.yml.example config/app_config.yml' before + making a new try. Also, make sure the mongodb server is running + EOF + fi # Run appserver echo "Starting server" - bundle exec thin start + script/server ) diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 0afd2ad9e1147f6958cfa46fa484f052db11e504..86d8d448c5fe0b5c892c4d99a7f8bfa5e8a9bffc 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -15,7 +15,7 @@ describe PhotosController do image = File.open(@fixture_name) #@photo = Photo.instantiate( # :person => @user.person, :album => @album, :user_file => image) - @photo = @user.post(:photo, :album_id => @album.id, :user_file => image, :to => @aspect.id) + @photo = @user.post(:photo, :album_id => @album.id, :user_file => image, :to => @aspect.id) sign_in :user, @user end diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index 7d6cde6c993a4492be44837bd7e07b6cbeb4cdcb..5a179cce1ba9ebe616cdc654cef7fb6896e28001 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -18,11 +18,17 @@ describe Aspect do let(:aspect3) {user3.aspect(:name => "lala")} describe 'creation' do - let(:aspect){user.aspect(:name => 'losers')} + let!(:aspect){user.aspect(:name => 'losers')} it 'should have a name' do aspect.name.should == "losers" end + it 'should not allow duplicate names' do + lambda { + invalid_aspect = user.aspect(:name => "losers ") + }.should_not change(Aspect, :count) + end + it 'should not be creatable with people' do aspect = user.aspect(:name => 'losers', :people => [friend, friend_2]) aspect.people.size.should == 0 diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 1cf1340d40714f18d544c7d660f9dac3f2d1f419..edc3aecf6839e1d070e8d54ee7edc6db03860828 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -14,7 +14,21 @@ describe Photo do @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) @fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml') - @photo = Photo.new(:person => @user.person, :album => @album) + @photo = Photo.new(:album => @album) + @photo.person = @user.person + end + + describe "protected attributes" do + it "doesn't allow mass assignment of person" do + @photo.save! + @photo.update_attributes(:person => Factory(:person)) + @photo.reload.person.should == @user.person + end + it "doesn't allow mass assignment of person_id" do + @photo.save! + @photo.update_attributes(:person_id => Factory(:person).id) + @photo.reload.person.should == @user.person + end end it 'has a constructor' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a9530093f5e3da8bf546df0f7559552d7979ebcd..17a52afff77cd4029292f5021559868d7caf4fc7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -16,11 +16,13 @@ describe User do describe 'overwriting people' do it 'does not overwrite old users with factory' do + pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" new_user = Factory.create(:user, :id => user.id) new_user.persisted?.should be_true new_user.id.should_not == user.id end it 'does not overwrite old users with create' do + pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" params = {:username => "ohai", :email => "ohai@example.com", :password => "password",