diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index f5a43360c..fc12437f6 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -16,9 +16,7 @@ class AlbumsController < ApplicationController def create aspect = params[:album][:to] - data = clean_hash(params[:album]) - - @album = current_user.post(:album, data) + @album = current_user.post(:album, params[:album]) flash[:notice] = I18n.t 'albums.create.success', :name => @album.name redirect_to :action => :show, :id => @album.id, :aspect => aspect end @@ -53,9 +51,7 @@ class AlbumsController < ApplicationController def update @album = current_user.find_visible_post_by_id params[:id] - data = clean_hash(params[:album]) - - if current_user.update_post( @album, data ) + if current_user.update_post( @album, params[:album] ) flash[:notice] = I18n.t 'albums.update.success', :name => @album.name respond_with @album else @@ -63,12 +59,4 @@ class AlbumsController < ApplicationController render :action => :edit end end - - private - def clean_hash(params) - return { - :name => params[:name], - :to => params[:to] - } - end end diff --git a/app/controllers/dev_utilities_controller.rb b/app/controllers/dev_utilities_controller.rb index a556547b0..549b25b00 100644 --- a/app/controllers/dev_utilities_controller.rb +++ b/app/controllers/dev_utilities_controller.rb @@ -39,7 +39,7 @@ class DevUtilitiesController < ApplicationController def set_profile_photo render :nothing => true - album = Album.create(:person => current_user.person, :name => "Profile Photos") + album = current_user.post(:album, :name => "Profile Photos", :to => current_user.aspects.first.id) current_user.raw_visible_posts << album current_user.save diff --git a/app/models/album.rb b/app/models/album.rb index 4f7294ff9..fbc64b2cf 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -16,6 +16,8 @@ class Album < Post before_destroy :destroy_photos + attr_accessible :name + def self.mine_or_friends(friend_param, current_user) friend_param ? Album.find_all_by_person_id(current_user.friend_ids) : current_user.person.albums end diff --git a/app/models/photo.rb b/app/models/photo.rb index a6e20ba33..94985e2bf 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -5,7 +5,7 @@ class PhotoAlbumValidator < ActiveModel::Validator def validate(document) unless document.album.person_id == document.person_id - document.errors[:base] << "You post photos to that album" + document.errors[:base] << "You can't post photos to that album" end end end diff --git a/app/models/post.rb b/app/models/post.rb index 0e1fc1959..5f9e0ca5c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -33,7 +33,11 @@ class Post after_destroy :destroy_comments def self.instantiate params - self.create params.to_hash + new_post = self.new params.to_hash + new_post.person = params[:person] + new_post.public = params[:public] + new_post.save + new_post end def as_json(opts={}) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 74bec4045..8bfcf61e5 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -13,11 +13,6 @@ describe AlbumsController do sign_in :user, @user end - it "should update the name of an album" do - put :update, :id => @album.id, :album => { :name => "new_name"} - @album.reload.name.should eql("new_name") - end - describe '#create' do it 'all aspects' do params = {"album" => {"name" => "Sunsets","to" => "all"}} @@ -28,4 +23,19 @@ describe AlbumsController do post :create, params end end + + describe "#update" do + it "should update the name of an album" do + put :update, :id => @album.id, :album => { :name => "new_name"} + @album.reload.name.should eql("new_name") + end + + it "doesn't overwrite random attributes" do + new_user = Factory.create :user + params = {:name => "Bruisers", :person_id => new_user.person.id} + put('update', :id => @album.id, "album" => params) + @album.reload.person_id.should == @user.person.id + @album.name.should == 'Bruisers' + end + end end diff --git a/spec/controllers/dev_utilities_controller_spec.rb b/spec/controllers/dev_utilities_controller_spec.rb index deb7b1975..6278952d7 100644 --- a/spec/controllers/dev_utilities_controller_spec.rb +++ b/spec/controllers/dev_utilities_controller_spec.rb @@ -8,7 +8,7 @@ describe DevUtilitiesController do render_views before do - @tom = Factory.create(:user, :email => "tom@tom.joindiaspora.org") + @tom = Factory.create(:user_with_aspect, :email => "tom@tom.joindiaspora.org") sign_in :user, @tom end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index d97f14d75..1cf1340d4 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -39,13 +39,14 @@ describe Photo do end it 'must have an album' do - photo = Photo.new(:person => @user.person) + photo = Photo.new() + photo.person = @user.person photo.image = File.open(@fixture_name) photo.save photo.valid?.should be false - photo.album = Album.create(:name => "foo", :person => @user.person) + photo.album = @album photo.save - Photo.first.album.name.should == 'foo' + photo.reload.album.name.should == 'foo' end it 'should have a caption' do