spec/lib/pose/search_spec.rb in pose-3.1.1 vs spec/lib/pose/search_spec.rb in pose-3.2.0
- old
+ new
@@ -118,26 +118,46 @@
end
end
describe :load_classes do
+
context 'when the user wants ids' do
+
it 'does nothing' do
search = Search.new nil, nil, result_type: :ids
result = { PosableOne => [1, 2] }
search.load_classes @result
expect(result[PosableOne]).to eql [1, 2]
end
end
context 'when the user wants classes' do
+
it 'loads the classes' do
object_1 = create :posable_one
object_2 = create :posable_one
result = { PosableOne => [object_1.id, object_2.id] }
search = Search.new nil, nil
search.load_classes result
expect(result[PosableOne]).to eq [object_1, object_2]
+ end
+ end
+
+ context 'when the user specifies a select clause' do
+
+ it 'loads only the specified attributes' do
+ object_1 = create :posable_one
+ object_2 = create :posable_one
+ result = { PosableOne => [object_1.id, object_2.id] }
+ search = Search.new nil, nil, select: 'id'
+ search.load_classes result
+ expect(result[PosableOne][0].id).to eq object_1.id
+ expect(result[PosableOne][0].attribute_present? :text).to be_falsy
+ expect(result[PosableOne][0].attribute_present? :id).to be_truthy
+ expect(result[PosableOne][1].id).to eq object_2.id
+ expect(result[PosableOne][1].attribute_present? :text).to be_falsy
+ expect(result[PosableOne][1].attribute_present? :id).to be_truthy
end
end
end