remove pending flag from posts
This commit is contained in:
parent
83db0a8f3e
commit
d3edbfd829
10 changed files with 34 additions and 39 deletions
|
|
@ -141,6 +141,6 @@ class Photo < ActiveRecord::Base
|
|||
else
|
||||
Photo.where(author_id: person.id, public: true)
|
||||
end
|
||||
photos.order("created_at desc")
|
||||
photos.where(pending: false).order("created_at DESC")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class Post < ActiveRecord::Base
|
|||
) #note should include root and photos, but i think those are both on status_message
|
||||
}
|
||||
|
||||
scope :all_public, -> { where(public: true) }
|
||||
|
||||
scope :commented_by, ->(person) {
|
||||
select('DISTINCT posts.*')
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ module User::Querying
|
|||
end
|
||||
|
||||
def visible_shareables_query(query, opts)
|
||||
query.with_visibility.where(pending: false).where(
|
||||
query.with_visibility.where(
|
||||
visible_private_shareables(opts).or(opts[:klass].arel_table[:public].eq(true))
|
||||
)
|
||||
end
|
||||
|
|
@ -129,7 +129,7 @@ module User::Querying
|
|||
end
|
||||
|
||||
def construct_shareable_from_self_query(opts)
|
||||
conditions = {pending: false, author_id: person_id}
|
||||
conditions = {author_id: person_id}
|
||||
conditions[:type] = opts[:type] if opts.has_key?(:type)
|
||||
query = opts[:klass].where(conditions)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ class CleanupPostsTable < ActiveRecord::Migration
|
|||
remove_index :posts, column: %i(status_message_guid pending),
|
||||
name: :index_posts_on_status_message_guid_and_pending, length: {status_message_guid: 190}
|
||||
remove_index :posts, column: :status_message_guid, name: :index_posts_on_status_message_guid, length: 191
|
||||
remove_index :posts, column: %i(type pending id), name: :index_posts_on_type_and_pending_and_id
|
||||
|
||||
# from photos?
|
||||
remove_column :posts, :pending, :boolean, default: false, null: false
|
||||
remove_column :posts, :remote_photo_path, :text
|
||||
remove_column :posts, :remote_photo_name, :string
|
||||
remove_column :posts, :random_string, :string
|
||||
|
|
@ -22,5 +24,7 @@ class CleanupPostsTable < ActiveRecord::Migration
|
|||
|
||||
# old single post view templates
|
||||
remove_column :posts, :frame_name, :string
|
||||
|
||||
add_index :posts, %i(id type), name: :index_posts_on_id_and_type
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -450,7 +450,6 @@ ActiveRecord::Schema.define(version: 20160802212635) do
|
|||
t.integer "author_id", limit: 4, null: false
|
||||
t.boolean "public", default: false, null: false
|
||||
t.string "guid", limit: 255, null: false
|
||||
t.boolean "pending", default: false, null: false
|
||||
t.string "type", limit: 40, null: false
|
||||
t.text "text", limit: 65535
|
||||
t.datetime "created_at", null: false
|
||||
|
|
@ -472,9 +471,9 @@ ActiveRecord::Schema.define(version: 20160802212635) do
|
|||
add_index "posts", ["author_id"], name: "index_posts_on_person_id", using: :btree
|
||||
add_index "posts", ["guid"], name: "index_posts_on_guid", unique: true, length: {"guid"=>191}, using: :btree
|
||||
add_index "posts", ["id", "type", "created_at"], name: "index_posts_on_id_and_type_and_created_at", using: :btree
|
||||
add_index "posts", ["id", "type"], name: "index_posts_on_id_and_type", using: :btree
|
||||
add_index "posts", ["root_guid"], name: "index_posts_on_root_guid", length: {"root_guid"=>191}, using: :btree
|
||||
add_index "posts", ["tweet_id"], name: "index_posts_on_tweet_id", length: {"tweet_id"=>191}, using: :btree
|
||||
add_index "posts", ["type", "pending", "id"], name: "index_posts_on_type_and_pending_and_id", using: :btree
|
||||
|
||||
create_table "ppid", force: :cascade do |t|
|
||||
t.integer "o_auth_application_id", limit: 4
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ module Diaspora
|
|||
delegate :id, :name, :first_name, to: :author, prefix: true
|
||||
|
||||
# scopes
|
||||
scope :all_public, -> { where(public: true, pending: false) }
|
||||
|
||||
scope :with_visibility, -> {
|
||||
joins("LEFT OUTER JOIN share_visibilities ON share_visibilities.shareable_id = #{table_name}.id AND "\
|
||||
"share_visibilities.shareable_type = '#{base_class}'")
|
||||
|
|
@ -77,7 +75,7 @@ module Diaspora
|
|||
end
|
||||
|
||||
def owned_by_user(user)
|
||||
user.person.public_send(table_name).where(pending: false)
|
||||
user.person.public_send(table_name)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -2,22 +2,6 @@ require "spec_helper"
|
|||
|
||||
describe Diaspora::Shareable do
|
||||
describe "scopes" do
|
||||
describe ".all_public" do
|
||||
it "includes all public posts" do
|
||||
post1 = FactoryGirl.create(:status_message, author: alice.person, public: true)
|
||||
post2 = FactoryGirl.create(:status_message, author: bob.person, public: true)
|
||||
post3 = FactoryGirl.create(:status_message, author: eve.person, public: true)
|
||||
expect(Post.all_public.map(&:id)).to match_array([post1.id, post2.id, post3.id])
|
||||
end
|
||||
|
||||
it "doesn't include any private posts" do
|
||||
FactoryGirl.create(:status_message, author: alice.person, public: false)
|
||||
FactoryGirl.create(:status_message, author: bob.person, public: false)
|
||||
FactoryGirl.create(:status_message, author: eve.person, public: false)
|
||||
expect(Post.all_public.map(&:id)).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
context "having multiple objects with equal db IDs" do
|
||||
before do
|
||||
# Determine the next database key ID, free on both Photo and StatusMessage
|
||||
|
|
|
|||
|
|
@ -256,6 +256,11 @@ describe Photo, :type => :model do
|
|||
expect(@user).to receive(:photos_from).with(@user.person, limit: :all, max_time: nil).and_call_original
|
||||
Photo.visible(@user, @user.person)
|
||||
end
|
||||
|
||||
it "does not contain pending photos" do
|
||||
pending_photo = @user.post(:photo, pending: true, user_file: File.open(photo_fixture_name), to: @aspect)
|
||||
expect(Photo.visible(@user, @user.person).ids).not_to include(pending_photo.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "without a current user" do
|
||||
|
|
|
|||
|
|
@ -42,6 +42,21 @@ describe Post, :type => :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".all_public" do
|
||||
it "includes all public posts" do
|
||||
post1 = FactoryGirl.create(:status_message, author: alice.person, public: true)
|
||||
post2 = FactoryGirl.create(:status_message, author: bob.person, public: true)
|
||||
post3 = FactoryGirl.create(:status_message, author: eve.person, public: true)
|
||||
expect(Post.all_public.ids).to match_array([post1.id, post2.id, post3.id])
|
||||
end
|
||||
|
||||
it "doesn't include any private posts" do
|
||||
FactoryGirl.create(:status_message, author: alice.person, public: false)
|
||||
FactoryGirl.create(:status_message, author: bob.person, public: false)
|
||||
FactoryGirl.create(:status_message, author: eve.person, public: false)
|
||||
expect(Post.all_public.ids).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe '.for_a_stream' do
|
||||
it 'calls #for_visible_shareable_sql' do
|
||||
|
|
|
|||
|
|
@ -45,22 +45,11 @@ describe User::Querying, :type => :model do
|
|||
expect(alice.visible_shareable_ids(Post)).not_to include(invisible_post.id)
|
||||
end
|
||||
|
||||
it "does not contain pending posts" do
|
||||
pending_post = bob.post(:status_message, :text => "hey", :public => true, :to => @bobs_aspect.id, :pending => true)
|
||||
expect(pending_post).to be_pending
|
||||
expect(alice.visible_shareable_ids(Post)).not_to include pending_post.id
|
||||
end
|
||||
|
||||
it "does not contain pending photos" do
|
||||
pending_photo = bob.post(:photo, :pending => true, :user_file=> File.open(photo_fixture_name), :to => @bobs_aspect)
|
||||
expect(alice.visible_shareable_ids(Photo)).not_to include pending_photo.id
|
||||
end
|
||||
|
||||
it "respects the :type option" do
|
||||
post = bob.post(:status_message, :text => "hey", :public => true, :to => @bobs_aspect.id, :pending => false)
|
||||
reshare = bob.post(:reshare, :pending => false, :root_guid => post.guid, :to => @bobs_aspect)
|
||||
expect(alice.visible_shareable_ids(Post, :type => "Reshare")).to include(reshare.id)
|
||||
expect(alice.visible_shareable_ids(Post, :type => 'StatusMessage')).not_to include(reshare.id)
|
||||
post = bob.post(:status_message, text: "hey", public: true, to: @bobs_aspect.id)
|
||||
reshare = bob.post(:reshare, root_guid: post.guid, to: @bobs_aspect)
|
||||
expect(alice.visible_shareable_ids(Post, type: "Reshare")).to include(reshare.id)
|
||||
expect(alice.visible_shareable_ids(Post, type: "StatusMessage")).not_to include(reshare.id)
|
||||
end
|
||||
|
||||
it "does not contain duplicate posts" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue