-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(smart-field): set filterable and sortable options at true by def…
…ault on polymorphic smart field (#697)
- Loading branch information
1 parent
b7546ab
commit 7f9de48
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Forest::Address | ||
include ForestLiana::Collection | ||
|
||
collection :Address | ||
|
||
field :addressable_type, type: 'String', polymorphic_key: true, is_filterable: false do | ||
object.addressable_type | ||
end | ||
|
||
field :addressable_id, type: 'String', polymorphic_key: true do | ||
object.addressable_type | ||
end | ||
|
||
field :address_type, type: 'String' do | ||
'delivery' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module ForestLiana | ||
describe Collection do | ||
before do | ||
allow(ForestLiana).to receive(:env_secret).and_return(nil) | ||
end | ||
|
||
let(:collection) { ForestLiana.apimap.select { |collection| collection.name == 'Address' }.first } | ||
|
||
describe 'field' do | ||
it 'add simple smart field' do | ||
field = collection.fields.select { |field| field[:field] == :address_type }.first | ||
|
||
expect(field).not_to be_nil | ||
expect(field).to eq( | ||
{ | ||
type: "String", | ||
is_read_only: true, | ||
is_required: false, | ||
default_value: nil, | ||
integration: nil, | ||
reference: nil, | ||
inverse_of: nil, | ||
relationships: nil, | ||
widget: nil, | ||
validations: [], | ||
is_virtual: true, | ||
field: :address_type, | ||
is_filterable: false, | ||
is_sortable: false | ||
} | ||
) | ||
end | ||
|
||
it 'add polymorphic smart field with default values' do | ||
field = collection.fields.select { |field| field[:field] == :addressable_id }.first | ||
|
||
expect(field).not_to be_nil | ||
expect(field[:is_filterable]).to eq(true) | ||
expect(field[:is_sortable]).to eq(true) | ||
end | ||
|
||
it 'add polymorphic smart field with is_filterable option set to false' do | ||
field = collection.fields.select { |field| field[:field] == :addressable_type }.first | ||
|
||
expect(field).not_to be_nil | ||
expect(field[:is_filterable]).to eq(false) | ||
expect(field[:is_sortable]).to eq(true) | ||
end | ||
end | ||
end | ||
end |