Add test for `Exporter#collect_smiles`
This commit is contained in:
parent
f5c0d7b1c6
commit
8e8b5ddb2a
|
@ -227,7 +227,7 @@ class Exporter
|
||||||
end
|
end
|
||||||
|
|
||||||
type = smile.parent.class.name.downcase
|
type = smile.parent.class.name.downcase
|
||||||
sobj[type.to_sym] = send(:"process_#{type}", smile.parent, include_comments: false)
|
sobj[type.to_sym] = send(:"process_#{type}", smile.parent, include_comments: false, include_user: false)
|
||||||
|
|
||||||
sobj
|
sobj
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :smile, class: Appendable::Reaction do
|
factory :smile, class: Appendable::Reaction do
|
||||||
user { FactoryBot.build(:user) }
|
user { FactoryBot.create(:user) }
|
||||||
parent { FactoryBot.build(:answer) }
|
parent { FactoryBot.create(:answer, user: FactoryBot.create(:user)) }
|
||||||
content { "🙂" }
|
content { "🙂" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,4 +64,37 @@ RSpec.describe Exporter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#collect_smiles" do
|
||||||
|
let!(:smiles) { FactoryBot.create_list(:smile, 25, user: user) }
|
||||||
|
|
||||||
|
subject { instance.send(:collect_smiles) }
|
||||||
|
|
||||||
|
context "exporting a user" do
|
||||||
|
it "collects reactions" do
|
||||||
|
subject
|
||||||
|
expect(instance.instance_variable_get(:@obj)[:smiles]).to eq(smiles.map do |s|
|
||||||
|
{
|
||||||
|
id: s.id,
|
||||||
|
created_at: s.created_at,
|
||||||
|
answer: {
|
||||||
|
comment_count: s.parent.comment_count,
|
||||||
|
content: s.parent.content,
|
||||||
|
created_at: s.parent.created_at,
|
||||||
|
id: s.parent.id,
|
||||||
|
question: {
|
||||||
|
answer_count: s.parent.question.answer_count,
|
||||||
|
author_is_anonymous: s.parent.question.author_is_anonymous,
|
||||||
|
content: s.parent.question.content,
|
||||||
|
created_at: s.parent.question.created_at,
|
||||||
|
id: s.parent.question.id,
|
||||||
|
user: nil # we're not populating this in the factory
|
||||||
|
},
|
||||||
|
smile_count: s.parent.smile_count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue