diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 5ce5990355d12095d4e8a14af94dbfbcf9d95c41..2fb5ac47f41b3c52574a882f260c9fc2e9b4fbfb 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -6,10 +6,9 @@ class AlbumsController < ApplicationController end def create - @album = Album.new(params[:album]) - @album.person = current_user + @album = current_user.post(:album, params[:album]) - if @album.save + if @album.created_at flash[:notice] = "Successfully created album." redirect_to @album else @@ -47,4 +46,5 @@ class AlbumsController < ApplicationController render :action => 'edit' end end + end diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index e7461cedc89803557057b624ad6f6fff7b44d6c2..21e25d8c51d3b32fa39294e411b9ea85daf6680d 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -21,9 +21,9 @@ class BlogsController < ApplicationController end def create - @blog = Blog.new(params[:blog]) - @blog.person = current_user - if @blog.save + @blog = current_user.post(:blog, params[:blog]) + + if @blog.created_at flash[:notice] = "Successfully created blog." redirect_to @blog else diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index d22e934c21a8d7343648fa30f3473ccf537b21c5..523cda3267d989a8bed5d6e407e903dd16f8b4e9 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -31,9 +31,9 @@ class BookmarksController < ApplicationController end def create - @bookmark = Bookmark.new(params[:bookmark]) - @bookmark.person = current_user - if @bookmark.save + @bookmark = current_user.post(:bookmark, params[:bookmark]) + + if @bookmark.created_at flash[:notice] = "Successfully created bookmark." redirect_to @bookmark else diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 4bf54cbf48876b8bbae2b588c4fe7f4de3fd511c..7008124690fb2ac2220524ee16a835b6c2c84895 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -3,11 +3,9 @@ class PhotosController < ApplicationController def create begin - #puts params.inspect - @photo = Photo.instantiate(params) - @photo.person = current_user + @photo = current_user.post(:photo, params) - if @photo.save + if @photo.created_at flash[:notice] = "Successfully uploaded photo." redirect_to @photo.album else diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 356612181b8d25316ca2b4974146f61ee38df3f0..cf5ee7f63f144f162d786df086c480c3374fe6c5 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -13,10 +13,9 @@ class StatusMessagesController < ApplicationController end def create - @status_message = StatusMessage.new(params[:status_message]) - @status_message.person = current_user + @status_message = current_user.post(:status_message, params[:status_message]) - if @status_message.save + if @status_message.created_at flash[:notice] = "Successfully created status message." redirect_to status_messages_url else diff --git a/app/models/album.rb b/app/models/album.rb index 14aa957789bf1ecf63fba994a9348a5a5072adcf..5a2e2a3f327739198c3037ab107870ecd80d3ac6 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -20,6 +20,10 @@ class Album after_save :notify_people before_destroy :propagate_retraction + def instantiate params + self.create params + end + def self.mine_or_friends(friend_param, current_user) if friend_param Album.where(:person_id.ne => current_user.id) diff --git a/app/models/post.rb b/app/models/post.rb index f270666fad179d28daa8a9ef339cb5affa39ecb2..b1002ce9178bb430142fd36c16aceff28e01cafb 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -26,6 +26,11 @@ class Post before_destroy :propagate_retraction after_destroy :destroy_comments, :remove_from_view + def self.instantiate params + self.create params + end + +#Querying def self.stream Post.sort(:created_at.desc).all end diff --git a/app/models/user.rb b/app/models/user.rb index a7326c18a902c595ac6daba29d26ec2796ddc60d..0f97022d71a8ce348cc9541db9f2d634319648f4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,6 +13,13 @@ class User < Person + ######## Posting ######## + + def post(class_name, options = {}) + options[:person] = self + model_class = class_name.to_s.camelize.constantize + post = model_class.instantiate(options) + end ######## Commenting ######## def comment(text, options = {}) diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 1ba47cbca3055656a34b2c82dfc923914ed9329b..7cdcd5beb06a57ecb47d5853edbb515c21d52eb6 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -173,9 +173,10 @@ form { color: black; } #user_name span { size: small; - font-style: italic; font-weight: normal; color: #999999; } + #user_name #latest_message_time { + font-style: italic; } #user_name ul { display: inline; margin: 0; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index bf344194077ef9db69fa6faf0d5aa0e9e0627b7d..a170bb967bf2a301ad8493181a61ffba71b16cb1 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -206,11 +206,11 @@ form span :size small - :font-style italic :font :weight normal :color #999 - + #latest_message_time + :font-style italic ul :display inline :margin 0 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 96b2718612569bedf3da75814a2ecac2ea69ad88..aac4898aa01c5f54d74c37c5daeacfe13e87e1bd 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -14,7 +14,6 @@ describe Post do it "should associate the owner if none is present" do @post.person.should == User.owner end - end describe "newest" do diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 4068972400ef1655840559b4757c5cf1685e7dd9..4bab96af292a0bfcdf881ac9bd314f4988c00626 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -11,7 +11,11 @@ describe StatusMessage do n.message = "wales" n.valid?.should be true end - + + it 'should be postable through the user' do + status = @user.post(:status_message, :message => "Users do things") + end + describe "XML" do it 'should serialize to XML' do message = Factory.create(:status_message, :message => "I hate WALRUSES!") diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1c4f1cb740cf45e30154d94272738f746ba19c17..01b0365be071eaae461ba5db8d01ca44b5e39c6c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -7,75 +7,68 @@ describe User do Person.count.should == n+1 end - it "should be able to accept a pending friend request" do - @user = Factory.create(:user) - @friend = Factory.create(:person, :active => false) - r = Request.instantiate(:to => @user.url, :from => @friend) - r.save - Person.all.count.should == 2 - Request.for_user(@user).all.count.should == 1 - @user.accept_friend_request(r.id) - Request.for_user(@user).all.count.should == 0 - Person.where(:id => @friend.id).first.active.should == true - end + describe 'friend requesting' do + before do + @user = Factory.create(:user) + end - it 'should be able to ignore a pending friend request' do - @user = Factory.create(:user) - @friend = Factory.create(:person, :active => false) - r = Request.instantiate(:to => @user.url, :from => @friend) - r.save + it "should be able to accept a pending friend request" do + friend = Factory.create(:person, :active => false) + r = Request.instantiate(:to => @user.url, :from => friend) + r.save + Person.all.count.should == 2 + Request.for_user(@user).all.count.should == 1 + @user.accept_friend_request(r.id) + Request.for_user(@user).all.count.should == 0 + Person.where(:id => friend.id).first.active.should == true + end - Person.count.should == 2 - @friend.active.should == false + it 'should be able to ignore a pending friend request' do + friend = Factory.create(:person, :active => false) + r = Request.instantiate(:to => @user.url, :from => friend) + r.save - @user.ignore_friend_request(r.id) + Person.count.should == 2 + friend.active.should == false - Person.count.should == 1 - Request.count.should == 0 - end + @user.ignore_friend_request(r.id) - it 'should not be able to friend request an existing friend' do - @user = Factory.create(:user) - @friend = Factory.create(:person) + Person.count.should == 1 + Request.count.should == 0 + end - @user.send_friend_request_to( @friend.url ).should be nil - end + it 'should not be able to friend request an existing friend' do + friend = Factory.create(:person) - it 'should be able to give me the terse url for webfinger' do - user = Factory.create(:user) - user.terse_url.should == 'example.com' - end + @user.send_friend_request_to( friend.url ).should be nil + end - it 'should be able to unsubscribe from a status.net user' do - @user = Factory.create(:user) - author = Factory.create(:author) - Author.all.count.should == 1 - q = Request.send :class_variable_get, :@@queue - q.stub!(:add_hub_unsubscribe_request) - q.should_receive(:add_hub_unsubscribe_request) + it 'should be able to give me the terse url for webfinger' do + @user.terse_url.should == 'example.com' + end - @user.unsubscribe_from_pubsub(author.id) - Author.all.count.should == 0 - end - - it 'should be able to update their profile and send it to their friends' do - Factory.create(:person) - p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clowntown.com"}} - - @user = Factory.create(:user) - p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} - - n = Profile.send :class_variable_get, :@@queue - n.should_receive(:process) - - - @user.update_profile(p).should == true - - @user.profile.image_url.should == "http://clown.com" - - + it 'should be able to unsubscribe from a status.net user' do + author = Factory.create(:author) + Author.all.count.should == 1 + q = Request.send :class_variable_get, :@@queue + q.stub!(:add_hub_unsubscribe_request) + q.should_receive(:add_hub_unsubscribe_request) + @user.unsubscribe_from_pubsub(author.id) + Author.all.count.should == 0 + end + + it 'should be able to update their profile and send it to their friends' do + Factory.create(:person) + + updated_profile = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} + + queue = Profile.send :class_variable_get, :@@queue + queue.should_receive(:process) + + @user.update_profile(updated_profile).should == true + @user.profile.image_url.should == "http://clown.com" + end end - end