FIX: topic and category exporters were only exporting users who created the first post
This commit is contained in:
parent
d7657d8e47
commit
f274a5234f
|
@ -75,10 +75,10 @@ module ImportExport
|
|||
end
|
||||
|
||||
user_ids.uniq!
|
||||
return [] if user_ids.empty?
|
||||
return User.none if user_ids.empty?
|
||||
|
||||
users = User.where(id: user_ids)
|
||||
export_users(users.to_a)
|
||||
export_users(users)
|
||||
end
|
||||
|
||||
def export_group_users!
|
||||
|
@ -118,10 +118,9 @@ module ImportExport
|
|||
return if @export_data[:topics].blank?
|
||||
topic_ids = @export_data[:topics].pluck(:id)
|
||||
|
||||
users = User.joins(:topics).where('topics.id IN (?)', topic_ids).to_a
|
||||
users.uniq!
|
||||
users = User.joins(:posts).where('posts.topic_id IN (?)', topic_ids).distinct
|
||||
|
||||
export_users(users.to_a)
|
||||
export_users(users)
|
||||
end
|
||||
|
||||
def export_topic_users!
|
||||
|
@ -132,9 +131,9 @@ module ImportExport
|
|||
|
||||
def export_users(users)
|
||||
data = []
|
||||
users.reject! { |u| u.id == Discourse::SYSTEM_USER_ID }
|
||||
|
||||
users.each do |u|
|
||||
users.find_each do |u|
|
||||
next if u.id == Discourse::SYSTEM_USER_ID
|
||||
x = USER_ATTRS.inject({}) { |h, a| h[a] = u.send(a); h; }
|
||||
x.merge(bio_raw: u.user_profile.bio_raw,
|
||||
website: u.user_profile.website,
|
||||
|
|
|
@ -6,6 +6,8 @@ describe ImportExport::CategoryExporter do
|
|||
let(:category) { Fabricate(:category) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:user2) { Fabricate(:user) }
|
||||
let(:user3) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
STDOUT.stubs(:write)
|
||||
|
@ -38,13 +40,17 @@ describe ImportExport::CategoryExporter do
|
|||
|
||||
it 'export the category with topics and users' do
|
||||
topic1 = Fabricate(:topic, category: category, user_id: -1)
|
||||
Fabricate(:post, topic: topic1, user: User.find(-1), post_number: 1)
|
||||
topic2 = Fabricate(:topic, category: category, user: user)
|
||||
Fabricate(:post, topic: topic2, user: user, post_number: 1)
|
||||
reply1 = Fabricate(:post, topic: topic2, user: user2, post_number: 2)
|
||||
reply2 = Fabricate(:post, topic: topic2, user: user3, post_number: 3)
|
||||
data = ImportExport::CategoryExporter.new([category.id]).perform.export_data
|
||||
|
||||
expect(data[:categories].count).to eq(1)
|
||||
expect(data[:groups].count).to eq(0)
|
||||
expect(data[:topics].count).to eq(2)
|
||||
expect(data[:users].count).to eq(1)
|
||||
expect(data[:users].map { |u| u[:id] }).to match_array([user.id, user2.id, user3.id])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ describe ImportExport::TopicExporter do
|
|||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
let!(:post) { Fabricate(:post, topic: topic, user: user) }
|
||||
|
||||
context '.perform' do
|
||||
it 'export a single topic' do
|
||||
|
@ -22,12 +23,13 @@ describe ImportExport::TopicExporter do
|
|||
|
||||
it 'export multiple topics' do
|
||||
topic2 = Fabricate(:topic, user: user)
|
||||
post2 = Fabricate(:post, user: user, topic: topic2)
|
||||
data = ImportExport::TopicExporter.new([topic.id, topic2.id]).perform.export_data
|
||||
|
||||
expect(data[:categories].blank?).to eq(true)
|
||||
expect(data[:groups].blank?).to eq(true)
|
||||
expect(data[:topics].count).to eq(2)
|
||||
expect(data[:users].count).to eq(1)
|
||||
expect(data[:users].map { |u| u[:id] }).to match_array([user.id])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue