mirror of
https://github.com/discourse/discourse.git
synced 2026-08-12 05:37:26 +08:00
RSpec setup becomes harder to follow at either extreme: trivial fixture wrappers hide lifecycle and intent, while forcing every named operation inline repeats low-level protocol and configuration details. This change documents and applies a test-setup hierarchy: - use `fab!`, `let`, `let!`, `subject`, and inline `Fabricate` according to lifecycle and role; - use a small example-group method when parameterized behavior gives one spec useful vocabulary; - move helpers into auto-loaded `spec/support` only when they are shared across spec files; - use fabricators and page objects for the data shapes and system-test interfaces they own. Core and plugin support files are loaded centrally by `rails_helper`, so plugin-specific support loaders are unnecessary. The migration specs encountered during the sweep are removed according to repository policy; production migrations are unchanged.
57 lines
1.9 KiB
Ruby
Vendored
57 lines
1.9 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe PostSerializer do
|
|
fab!(:user)
|
|
fab!(:topic)
|
|
fab!(:post) { Fabricate(:post, topic: topic) }
|
|
let(:guardian) { Guardian.new(user) }
|
|
|
|
include_context "with group that is allowed to assign"
|
|
|
|
before do
|
|
SiteSetting.assign_enabled = true
|
|
assign_allowed_group.add(user)
|
|
end
|
|
|
|
it "includes assigned user in serializer" do
|
|
Assigner.new(post, user).assign(user)
|
|
serializer = PostSerializer.new(post, scope: guardian)
|
|
post = serializer.as_json[:post]
|
|
expect(post[:assigned_to_user][:id]).to eq(user.id)
|
|
expect(post[:assigned_to_group]).to be(nil)
|
|
end
|
|
|
|
it "includes assigned group in serializer" do
|
|
Assigner.new(post, user).assign(assign_allowed_group)
|
|
serializer = PostSerializer.new(post, scope: guardian)
|
|
post = serializer.as_json[:post]
|
|
expect(post[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
|
expect(post[:assigned_to_user]).to be(nil)
|
|
end
|
|
|
|
it "includes note in serializer" do
|
|
Assigner.new(post, user).assign(user, note: "tomtom best")
|
|
serializer = PostSerializer.new(post, scope: guardian)
|
|
expect(serializer.as_json[:post][:assignment_note]).to eq("tomtom best")
|
|
end
|
|
|
|
context "when status is enabled" do
|
|
before { SiteSetting.enable_assign_status = true }
|
|
|
|
it "includes status in serializer" do
|
|
Assigner.new(post, user).assign(user, status: "Done")
|
|
serializer = PostSerializer.new(post, scope: guardian)
|
|
expect(serializer.as_json[:post][:assignment_status]).to eq("Done")
|
|
end
|
|
end
|
|
|
|
context "when status is disabled" do
|
|
before { SiteSetting.enable_assign_status = false }
|
|
|
|
it "doesn't include status in serializer" do
|
|
Assigner.new(post, user).assign(user, status: "Done")
|
|
serializer = PostSerializer.new(post, scope: guardian)
|
|
expect(serializer.as_json[:post][:assignment_status]).not_to eq("Done")
|
|
end
|
|
end
|
|
end
|