diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a8ef1c8b6..c428c0735 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -14,7 +14,7 @@ class CommentsController < ApplicationController text = params[:text] if target - @comment = current_user.build_comment(text, :on => target) + @comment = current_user.build_comment(:text => text, :on => target) if @comment.save Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success comment=#{@comment.id} chars=#{params[:text].length}") diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index fd8e77063..357c3b90e 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -12,7 +12,7 @@ class LikesController < ApplicationController target = current_user.find_visible_post_by_id params[:post_id] positive = (params[:positive] == 'true') ? true : false if target - @like = current_user.build_like(positive, :on => target) + @like = current_user.build_like(:positive => positive, :on => target) if @like.save Rails.logger.info("event=create type=like user=#{current_user.diaspora_handle} status=success like=#{@like.id} positive=#{positive}") diff --git a/app/models/message.rb b/app/models/message.rb index abebfc04d..1f79ad6a4 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -63,7 +63,7 @@ class Message < ActiveRecord::Base vis.save self else - raise NotVisibileException("Attempting to access a ConversationVisibility that does not exist!") + raise NotVisibleException("Attempting to access a ConversationVisibility that does not exist!") end end diff --git a/app/models/user.rb b/app/models/user.rb index e7b352c75..82534c1e4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -153,38 +153,30 @@ class User < ActiveRecord::Base Salmon::SalmonSlap.create(self, post.to_diaspora_xml) end - ######## Commenting ######## - def build_comment(text, options = {}) - comment = Comment.new(:author_id => self.person.id, - :text => text, - :post => options[:on]) - comment.set_guid - #sign comment as commenter - comment.author_signature = comment.sign_with_key(self.encryption_key) + def build_relayable(model, options = {}) + options[:post] = options.delete(:on) + m = model.new(options.merge(:author_id => self.person.id)) + m.set_guid - if !comment.post_id.blank? && person.owns?(comment.parent) - #sign comment as post owner - comment.parent_author_signature = comment.sign_with_key(self.encryption_key) + #sign relayable as model creator + m.author_signature = m.sign_with_key(self.encryption_key) + + if !m.post_id.blank? && person.owns?(m.parent) + #sign relayable as parent object owner + m.parent_author_signature = m.sign_with_key(self.encryption_key) end - comment + m + end + + ######## Commenting ######## + def build_comment(options = {}) + build_relayable(Comment, options) end ######## Liking ######## - def build_like(positive, options = {}) - like = Like.new(:author_id => self.person.id, - :positive => positive, - :post => options[:on]) - like.set_guid - #sign like as liker - like.author_signature = like.sign_with_key(self.encryption_key) - - if !like.post_id.blank? && person.owns?(like.parent) - #sign like as post owner - like.parent_author_signature = like.sign_with_key(self.encryption_key) - end - - like + def build_like(options = {}) + build_relayable(Like, options) end def liked?(post) @@ -194,7 +186,7 @@ class User < ActiveRecord::Base return false end end - + def like_for(post) [post.likes, post.dislikes].each do |likes| likes.each do |like| diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index a3f0fa9d6..dd958f810 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -104,7 +104,7 @@ describe AspectsController do post.save! @posts << post end - alice.build_comment('lalala', :on => @posts.first ).save + alice.build_comment(:text => 'lalala', :on => @posts.first ).save end describe "post visibilities" do diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index ee99e5339..1ded8837d 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -11,7 +11,7 @@ describe LikesController do @aspect1 = @user1.aspects.first @aspect2 = @user2.aspects.first - + @controller.stub(:current_user).and_return(alice) sign_in :user, @user1 end @@ -76,7 +76,7 @@ describe LikesController do context 'your like' do before do @message = bob.post(:status_message, :text => "hey", :to => @aspect1.id) - @like = alice.build_like(true, :on => @message) + @like = alice.build_like(:positive => true, :on => @message) @like.save end @@ -87,11 +87,11 @@ describe LikesController do end it 'does not let a user destroy other likes' do - like2 = eve.build_like(true, :on => @message) + like2 = eve.build_like(:positive => true, :on => @message) like2.save - expect { - delete :destroy, :format => "js", :post_id => like2.post_id, :id => like2.id + expect { + delete :destroy, :format => "js", :post_id => like2.post_id, :id => like2.id }.should_not change(Like, :count) end end diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index d1e4fae54..f46a0ca60 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -84,7 +84,7 @@ describe Postzord::Dispatch do end context "local leia" do before do - @comment = @local_leia.build_comment "yo", :on => @post + @comment = @local_leia.build_comment :text => "yo", :on => @post @comment.save end context "local leia's mailman" do @@ -156,7 +156,7 @@ describe Postzord::Dispatch do end context "local luke" do before do - @comment = @local_luke.build_comment "yo", :on => @post + @comment = @local_luke.build_comment :text => "yo", :on => @post @comment.save @mailman = Postzord::Dispatch.new(@local_luke, @comment) end @@ -182,7 +182,7 @@ describe Postzord::Dispatch do context "remote raphael's post is commented on by local luke" do before do @post = Factory(:status_message, :author => @remote_raphael) - @comment = @local_luke.build_comment "yo", :on => @post + @comment = @local_luke.build_comment :text => "yo", :on => @post @comment.save @mailman = Postzord::Dispatch.new(@local_luke, @comment) end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index f844c2ab7..8f0a10c12 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -104,7 +104,7 @@ describe Comment do mock_http.should_receive(:get).with(/\/feeds\/api\/videos/, nil).twice.and_return( [nil, 'Foobar