From fb8b8ab7fcf740cde5f760705e6144be49aa38ea Mon Sep 17 00:00:00 2001 From: zhitomirskiyi <ilya@joindiaspora.com> Date: Mon, 28 Mar 2011 17:15:54 -0700 Subject: [PATCH] wip holding off until the follow model is done --- .../post_visibilities_controller.rb | 19 ++++++++++ ...8175936_add_hidden_to_post_visibilities.rb | 9 +++++ db/schema.rb | 1 + features/comments.feature | 2 +- features/posts.feature | 17 +++++++++ features/step_definitions/custom_web_steps.rb | 4 +++ .../post_visibilities_controller_spec.rb | 36 +++++++++++++++++++ 7 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/controllers/post_visibilities_controller.rb create mode 100644 db/migrate/20110328175936_add_hidden_to_post_visibilities.rb create mode 100644 spec/controllers/post_visibilities_controller_spec.rb diff --git a/app/controllers/post_visibilities_controller.rb b/app/controllers/post_visibilities_controller.rb new file mode 100644 index 0000000000..572c34cba1 --- /dev/null +++ b/app/controllers/post_visibilities_controller.rb @@ -0,0 +1,19 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. +# + +class PostVisibilitiesController < ApplicationController + before_filter :authenticate_user! + + def destroy + @vis = ConversationVisibility.where(:person_id => current_user.person.id, + :conversation_id => params[:conversation_id]).first + if @vis + if @vis.destroy + flash[:notice] = "Conversation successfully removed" + end + end + redirect_to conversations_path + end +end diff --git a/db/migrate/20110328175936_add_hidden_to_post_visibilities.rb b/db/migrate/20110328175936_add_hidden_to_post_visibilities.rb new file mode 100644 index 0000000000..5ef34a8105 --- /dev/null +++ b/db/migrate/20110328175936_add_hidden_to_post_visibilities.rb @@ -0,0 +1,9 @@ +class AddHiddenToPostVisibilities < ActiveRecord::Migration + def self.up + add_column :post_visibilities, :hidden, :boolean, :defalut => false, :null => false + end + + def self.down + remove_column :post_visibilities, :hidden + end +end diff --git a/db/schema.rb b/db/schema.rb index e484b8f481..6195f73fc0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -215,6 +215,7 @@ ActiveRecord::Schema.define(:version => 20110330230206) do t.integer "post_id", :null => false t.datetime "created_at" t.datetime "updated_at" + t.boolean "hidden", :null => false t.integer "contact_id", :null => false end diff --git a/features/comments.feature b/features/comments.feature index 5b6ad01d4b..ac88ce360a 100644 --- a/features/comments.feature +++ b/features/comments.feature @@ -48,7 +48,7 @@ Feature: commenting Then I should see "hahaha" within "li.comment div.content" And I should see "less than a minute ago" within "li.comment time" - Scenario: delete a post + Scenario: delete a comment When I sign in as "bob@bob.bob" And I am on "alice@alice.alice"'s page Then I should see "Look at this dog" diff --git a/features/posts.feature b/features/posts.feature index ddbeb59b0b..fdb9d31ba6 100644 --- a/features/posts.feature +++ b/features/posts.feature @@ -24,6 +24,23 @@ Feature: posting And I follow "All Aspects" Then I should see "I am eating a yogurt" within ".stream_element" + Scenario: hide a post + Given I expand the publisher + When I fill in "status_message_fake_text" with "I am eating a yogurt" + And I press "Share" + And I wait for the ajax to finish + + And I log out + And I sign in as "alice@alice.alice" + And I am on "bob@bob.bob"'s page + + And I hover over the post + And I preemptively confirm the alert + And I click to hide the first post + And I wait for the ajax to finish + And I follow "All Aspects" + Then I should not see "I am eating a yogurt" + Scenario: delete a post Given I expand the publisher When I fill in "status_message_fake_text" with "I am eating a yogurt" diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 40640a85e9..51212497ba 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -49,6 +49,10 @@ When /^I click to delete the first post$/ do page.execute_script('$(".stream_element").first().find(".stream_element_delete").click()') end +When /^I click to hide the first post$/ do + page.execute_script('$(".stream_element").first().find(".stream_element_hide").click()') +end + When /^I click to delete the first comment$/ do page.execute_script('$(".comment.posted").first().find(".comment_delete").click()') end diff --git a/spec/controllers/post_visibilities_controller_spec.rb b/spec/controllers/post_visibilities_controller_spec.rb new file mode 100644 index 0000000000..0e860bf7bd --- /dev/null +++ b/spec/controllers/post_visibilities_controller_spec.rb @@ -0,0 +1,36 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe PostVisibilitiesController do + render_views + + before do + @user1 = alice + sign_in :user, @user1 + + + status = @user1.post(:status_message, :text => "hello", :public => true, :to => 'all') + @vis = status.post_visibilities.first + pp @vis + @vis.reload.hidden.should == false + end + + describe '#destroy' do + it 'deletes the visibility' do + delete :destroy, :conversation_id => @vis.id + @vis.reload.hidden.should == true + end + + it 'does not let a user destroy a visibility that is not theirs' do + user2 = eve + sign_in :user, user2 + + lambda { + delete :destroy, :conversation_id => @vis.id + }.should_not change(@vis.reload, :hidden).to(true) + end + end +end -- GitLab