mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 18:53:47 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe DirectoryItemSerializer do
|
|
fab!(:user)
|
|
|
|
before { DirectoryItem.refresh! }
|
|
|
|
let :serializer do
|
|
directory_item =
|
|
DirectoryItem.find_by(user: user, period_type: DirectoryItem.period_types[:all])
|
|
DirectoryItemSerializer.new(directory_item, { attributes: DirectoryColumn.active_column_names })
|
|
end
|
|
|
|
it "Serializes attributes for enabled directory_columns" do
|
|
DirectoryColumn.update_all(enabled: true)
|
|
|
|
payload = serializer.as_json
|
|
expect(payload[:directory_item].keys).to include(*DirectoryColumn.pluck(:name).map(&:to_sym))
|
|
end
|
|
|
|
it "Doesn't serialize attributes for disabled directory columns" do
|
|
DirectoryColumn.update_all(enabled: false)
|
|
directory_column = DirectoryColumn.first
|
|
directory_column.update(enabled: true)
|
|
|
|
payload = serializer.as_json
|
|
expect(payload[:directory_item].keys.count).to eq(4)
|
|
expect(payload[:directory_item]).to have_key(directory_column.name.to_sym)
|
|
expect(payload[:directory_item]).to have_key(:id)
|
|
expect(payload[:directory_item]).to have_key(:user)
|
|
expect(payload[:directory_item]).to have_key(:time_read)
|
|
end
|
|
end
|