Change :on to :post in the comment and post methods

This commit is contained in:
Raphael Sofaer 2011-06-01 15:57:14 -07:00
parent c8dd8c98ca
commit df04b59857
20 changed files with 61 additions and 62 deletions

View file

@ -14,7 +14,7 @@ class CommentsController < ApplicationController
text = params[:text]
if target
@comment = current_user.build_comment(:text => text, :on => target)
@comment = current_user.build_comment(:text => text, :post => 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}")

View file

@ -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 => positive, :on => target)
@like = current_user.build_like(:positive => positive, :post => target)
if @like.save
Rails.logger.info("event=create type=like user=#{current_user.diaspora_handle} status=success like=#{@like.id} positive=#{positive}")

View file

@ -16,7 +16,7 @@ class User < ActiveRecord::Base
:timeoutable, :token_authenticatable
before_validation :strip_and_downcase_username
before_validation :set_current_language, :on => :create
before_validation :set_current_language, :post => :create
validates_presence_of :username
validates_uniqueness_of :username
@ -154,7 +154,6 @@ class User < ActiveRecord::Base
end
def build_relayable(model, options = {})
options[:post] = options.delete(:on)
m = model.new(options.merge(:author_id => self.person.id))
m.set_guid

View file

@ -65,7 +65,7 @@ describe AspectsController do
it 'generates a jasmine fixture with posts', :fixture => 'jasmine' do
message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id)
4.times { bob.comment("what", :on => message) }
4.times { bob.comment("what", :post => message) }
get :index
save_fixture(html_for("body"), "aspects_index_with_posts")
@ -104,7 +104,7 @@ describe AspectsController do
post.save!
@posts << post
end
alice.build_comment(:text => 'lalala', :on => @posts.first ).save
alice.build_comment(:text => 'lalala', :post => @posts.first ).save
end
describe "post visibilities" do
@ -187,7 +187,7 @@ describe AspectsController do
connect_users(alice, @alices_aspect_1, user, aspect)
post = alice.post(:status_message, :text => "hello#{n}", :to => @alices_aspect_2.id)
8.times do |n|
user.comment "yo#{post.text}", :on => post
user.comment "yo#{post.text}", :post => post
end
end
end

View file

@ -49,7 +49,7 @@ describe CommentsController do
end
it "doesn't overwrite id" do
old_comment = alice.comment("hello", :on => @post)
old_comment = alice.comment("hello", :post => @post)
comment_hash[:id] = old_comment.id
post :create, comment_hash
old_comment.reload.text.should == 'hello'
@ -73,9 +73,9 @@ describe CommentsController do
context 'your post' do
before do
@message = alice.post(:status_message, :text => "hey", :to => @aspect1.id)
@comment = alice.comment("hey", :on => @message)
@comment2 = bob.comment("hey", :on => @message)
@comment3 = eve.comment("hey", :on => @message)
@comment = alice.comment("hey", :post => @message)
@comment2 = bob.comment("hey", :post => @message)
@comment3 = eve.comment("hey", :post => @message)
end
it 'lets the user delete his comment' do
@ -94,9 +94,9 @@ describe CommentsController do
context "another user's post" do
before do
@message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id)
@comment = alice.comment("hey", :on => @message)
@comment2 = bob.comment("hey", :on => @message)
@comment3 = eve.comment("hey", :on => @message)
@comment = alice.comment("hey", :post => @message)
@comment2 = bob.comment("hey", :post => @message)
@comment3 = eve.comment("hey", :post => @message)
end
it 'let the user delete his comment' do

View file

@ -53,7 +53,7 @@ describe LikesController do
end
it "doesn't post multiple times" do
@user1.like(1, :on => @post)
@user1.like(1, :post => @post)
post :create, dislike_hash
response.code.should == '422'
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(:positive => true, :on => @message)
@like = alice.build_like(:positive => true, :post => @message)
@like.save
end
@ -87,7 +87,7 @@ describe LikesController do
end
it 'does not let a user destroy other likes' do
like2 = eve.build_like(:positive => true, :on => @message)
like2 = eve.build_like(:positive => true, :post => @message)
like2.save
expect {

View file

@ -89,7 +89,7 @@ describe PeopleController do
end
@posts.each do |post|
@users.each do |user|
user.comment "yo#{post.text}", :on => post
user.comment "yo#{post.text}", :post => post
end
end
end
@ -150,7 +150,7 @@ describe PeopleController do
it "renders the comments on the user's posts" do
message = @user.post :status_message, :text => 'test more', :to => @aspect.id
@user.comment 'I mean it', :on => message
@user.comment 'I mean it', :post => message
get :show, :id => @user.person.id
response.should be_success
end

View file

@ -54,8 +54,8 @@ describe StatusMessagesController do
end
it 'marks a corresponding notification as read' do
alice.comment("comment after me", :on => @message)
bob.comment("here you go", :on => @message)
alice.comment("comment after me", :post => @message)
bob.comment("here you go", :post => @message)
note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first
lambda{
get :show, :id => @message.id

View file

@ -99,7 +99,7 @@ describe TagsController do
end
it 'succeeds with comments' do
alice.comment('what WHAT!', :on => @post)
alice.comment('what WHAT!', :post => @post)
get :show, :name => 'what'
response.should be_success
end

View file

@ -233,7 +233,7 @@ describe 'a user receives a post' do
receive_with_zord(bob, alice.person, xml)
receive_with_zord(eve, alice.person, xml)
@comment = eve.comment('tada',:on => @post)
@comment = eve.comment('tada',:post => @post)
@comment.parent_author_signature = @comment.sign_with_key(alice.encryption_key)
@xml = @comment.to_diaspora_xml
@comment.delete
@ -290,7 +290,7 @@ describe 'a user receives a post' do
end
it 'does not raise a `Mysql2::Error: Duplicate entry...` exception on save' do
@comment = bob.comment('tada',:on => @post)
@comment = bob.comment('tada',:post => @post)
@xml = @comment.to_diaspora_xml
lambda {

View file

@ -84,7 +84,7 @@ describe Postzord::Dispatch do
end
context "local leia" do
before do
@comment = @local_leia.build_comment :text => "yo", :on => @post
@comment = @local_leia.build_comment :text => "yo", :post => @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 :text => "yo", :on => @post
@comment = @local_luke.build_comment :text => "yo", :post => @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 :text => "yo", :on => @post
@comment = @local_luke.build_comment :text => "yo", :post => @post
@comment.save
@mailman = Postzord::Dispatch.new(@local_luke, @comment)
end

View file

@ -163,7 +163,7 @@ describe Notifier do
context "comments" do
let!(:connect) { connect_users(user, aspect, user2, aspect2)}
let!(:sm) {user.post(:status_message, :text => "Sunny outside", :to => :all)}
let!(:comment) { user2.comment("Totally is", :on => sm )}
let!(:comment) { user2.comment("Totally is", :post => sm )}
describe ".comment_on_post" do
let!(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment.id).deliver}

View file

@ -58,7 +58,7 @@ describe 'making sure the spec runner works' do
m.stub!(:post)
Postzord::Dispatch.should_receive(:new).and_return(m)
alice.comment "yo", :on => person_status
alice.comment "yo", :post => person_status
end
end

View file

@ -17,19 +17,19 @@ describe Comment do
describe 'comment#notification_type' do
it "returns 'comment_on_post' if the comment is on a post you own" do
comment = bob.comment("why so formal?", :on => @status)
comment = bob.comment("why so formal?", :post => @status)
comment.notification_type(alice, bob.person).should == Notifications::CommentOnPost
end
it 'returns false if the comment is not on a post you own and no one "also_commented"' do
comment = alice.comment("I simply felt like issuing a greeting. Do step off.", :on => @status)
comment = alice.comment("I simply felt like issuing a greeting. Do step off.", :post => @status)
comment.notification_type(@bob, alice.person).should == false
end
context "also commented" do
before do
@bob.comment("a-commenta commenta", :on => @status)
@comment = @eve.comment("I also commented on the first user's post", :on => @status)
@bob.comment("a-commenta commenta", :post => @status)
@comment = @eve.comment("I also commented on the first user's post", :post => @status)
end
it 'does not return also commented if the user commented' do
@ -45,17 +45,17 @@ describe Comment do
describe 'User#comment' do
it "should be able to comment on one's own status" do
alice.comment("Yeah, it was great", :on => @status)
alice.comment("Yeah, it was great", :post => @status)
@status.reload.comments.first.text.should == "Yeah, it was great"
end
it "should be able to comment on a contact's status" do
bob.comment("sup dog", :on => @status)
bob.comment("sup dog", :post => @status)
@status.reload.comments.first.text.should == "sup dog"
end
it 'does not multi-post a comment' do
lambda {
alice.comment 'hello', :on => @status
alice.comment 'hello', :post => @status
}.should change { Comment.count }.by(1)
end
end
@ -66,7 +66,7 @@ describe Comment do
@commenter_aspect = @commenter.aspects.create(:name => "bruisers")
connect_users(alice, @alices_aspect, @commenter, @commenter_aspect)
@post = alice.post :status_message, :text => "hello", :to => @alices_aspect.id
@comment = @commenter.comment "Fool!", :on => @post
@comment = @commenter.comment "Fool!", :post => @post
@xml = @comment.to_xml.to_s
end
it 'serializes the sender handle' do
@ -104,7 +104,7 @@ describe Comment do
mock_http.should_receive(:get).with(/\/feeds\/api\/videos/, nil).twice.and_return(
[nil, 'Foobar <title>'+expected_title+'</title> hallo welt <asd><dasdd><a>dsd</a>'])
comment = alice.build_comment :text => url, :on => @message
comment = alice.build_comment :text => url, :post => @message
comment.save!
Comment.find(comment.id).youtube_titles.should == { first_video_id => CGI::escape(expected_title), second_video_id => CGI::escape(expected_title) }
@ -117,11 +117,11 @@ describe Comment do
@remote_parent = Factory.create(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.comment("yo", :on => @local_parent)
@object_by_recipient = @local_leia.build_comment(:text => "yo", :on => @local_parent)
@object_by_parent_author = @local_luke.comment("yo", :post => @local_parent)
@object_by_recipient = @local_leia.build_comment(:text => "yo", :post => @local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.comment("Yeah, it was great", :on => @remote_parent)
@object_on_remote_parent = @local_luke.comment("Yeah, it was great", :post => @remote_parent)
end
it_should_behave_like 'it is relayable'
end

View file

@ -21,26 +21,26 @@ describe Like do
describe 'User#like' do
it "should be able to like on one's own status" do
alice.like(1, :on => @status)
alice.like(1, :post => @status)
@status.reload.likes.first.positive.should == true
end
it "should be able to like on a contact's status" do
bob.like(0, :on => @status)
bob.like(0, :post => @status)
@status.reload.dislikes.first.positive.should == false
end
it "does not allow multiple likes" do
lambda {
alice.like(1, :on => @status)
alice.like(0, :on => @status)
alice.like(1, :post => @status)
alice.like(0, :post => @status)
}.should raise_error
end
end
describe '#notification_type' do
before do
@like = @alice.like(1, :on => @status)
@like = @alice.like(1, :post => @status)
end
it 'should be notifications liked if you are the post owner' do
@ -62,7 +62,7 @@ describe Like do
@liker_aspect = @liker.aspects.create(:name => "dummies")
connect_users(alice, @alices_aspect, @liker, @liker_aspect)
@post = alice.post :status_message, :text => "huhu", :to => @alices_aspect.id
@like = @liker.like 0, :on => @post
@like = @liker.like 0, :post => @post
@xml = @like.to_xml.to_s
end
it 'serializes the sender handle' do
@ -90,11 +90,11 @@ describe Like do
@remote_parent = Factory.create(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "foobar", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.like(1, :on => @local_parent)
@object_by_recipient = @local_leia.build_like(:positive => 1, :on => @local_parent)
@object_by_parent_author = @local_luke.like(1, :post => @local_parent)
@object_by_recipient = @local_leia.build_like(:positive => 1, :post => @local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.like(0, :on => @remote_parent)
@object_on_remote_parent = @local_luke.like(0, :post => @remote_parent)
end
it_should_behave_like 'it is relayable'
end

View file

@ -119,8 +119,8 @@ describe Notification do
before do
@user3 = bob
@sm = @user3.post(:status_message, :text => "comment!", :to => :all)
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => @sm)).receive_object
Postzord::Receiver.new(@user3, :person => @user.person, :object => @user.comment("hey", :on => @sm)).receive_object
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object
Postzord::Receiver.new(@user3, :person => @user.person, :object => @user.comment("hey", :post => @sm)).receive_object
end
it "updates the notification with a more people if one already exists" do
@ -128,7 +128,7 @@ describe Notification do
end
it 'handles double comments from the same person without raising' do
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => @sm)).receive_object
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object
Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2
end

View file

@ -171,7 +171,7 @@ describe Photo do
context "commenting" do
it "accepts comments if there is no parent status message" do
proc{ @user.comment("big willy style", :on => @photo) }.should change(@photo.comments, :count).by(1)
proc{ @user.comment("big willy style", :post => @photo) }.should change(@photo.comments, :count).by(1)
end
end

View file

@ -13,7 +13,7 @@ describe Post do
describe 'deletion' do
it 'should delete a posts comments on delete' do
post = Factory.create(:status_message, :author => @user.person)
@user.comment "hey", :on => post
@user.comment "hey", :post => post
post.destroy
Post.where(:id => post.id).empty?.should == true
Comment.where(:text => "hey").empty?.should == true

View file

@ -14,7 +14,7 @@ describe RelayableRetraction do
describe '#subscribers' do
before do
@comment= @local_luke.comment("yo", :on => @local_parent)
@comment= @local_luke.comment("yo", :post => @local_parent)
@retraction= @local_luke.retract(@comment)
end
it 'delegates it to target' do
@ -26,7 +26,7 @@ describe RelayableRetraction do
describe '#receive' do
it 'discards a retraction with a nil target' do
@comment= @local_luke.comment("yo", :on => @local_parent)
@comment= @local_luke.comment("yo", :post => @local_parent)
@retraction= @local_luke.retract(@comment)
@retraction.instance_variable_set(:@target, nil)
@ -36,7 +36,7 @@ describe RelayableRetraction do
end
context 'from the downstream author' do
before do
@comment = @local_leia.comment("yo", :on => @local_parent)
@comment = @local_leia.comment("yo", :post => @local_parent)
@retraction = @local_leia.retract(@comment)
@recipient = @local_luke
end
@ -59,7 +59,7 @@ describe RelayableRetraction do
end
context 'from the upstream owner' do
before do
@comment = @local_luke.comment("Yeah, it was great", :on => @remote_parent)
@comment = @local_luke.comment("Yeah, it was great", :post => @remote_parent)
@retraction = RelayableRetraction.allocate
@retraction.sender = @remote_raphael
@retraction.target = @comment
@ -79,7 +79,7 @@ describe RelayableRetraction do
describe 'xml' do
before do
@comment = @local_leia.comment("yo", :on => @local_parent)
@comment = @local_leia.comment("yo", :post => @local_parent)
@retraction = RelayableRetraction.build(@local_leia, @comment)
@retraction.parent_author_signature = 'PARENTSIGNATURE'
@retraction.target_author_signature = 'TARGETSIGNATURE'

View file

@ -562,8 +562,8 @@ describe User do
before do
@message = alice.post(:status_message, :text => "cool", :to => alice.aspects.first)
@message2 = bob.post(:status_message, :text => "uncool", :to => bob.aspects.first)
@like = alice.like(true, :on => @message)
@dislike = bob.like(false, :on => @message)
@like = alice.like(true, :post => @message)
@dislike = bob.like(false, :post => @message)
end
describe '#like_for' do