Skip to content

Commit d5eff3c

Browse files
authored
fix: sort fields in schema (#561)
1 parent f997659 commit d5eff3c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/services/forest_liana/schema_adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def perform
88
add_columns
99
add_associations
1010

11+
collection.fields.sort_by! { |k| k[:field].to_s }
12+
1113
# NOTICE: Add ActsAsTaggable fields
1214
if @model.try(:taggable?) && @model.respond_to?(:acts_as_taggable) &&
1315
@model.acts_as_taggable.respond_to?(:to_a)

spec/services/forest_liana/schema_adapter_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ module ForestLiana
88
end
99

1010
expect(collection.fields.map { |field| field[:field] }).to eq(
11-
["id", "name", "created_at", "updated_at", "trees", "location"]
11+
["created_at", "id", "location", "name", "trees", "updated_at"]
12+
)
13+
end
14+
end
15+
16+
context 'with standard fields' do
17+
it 'should be sort by alphabetical order' do
18+
collection = ForestLiana.apimap.find do |object|
19+
object.name.to_s == ForestLiana.name_for(Tree)
20+
end
21+
22+
expect(collection.fields.map { |field| field[:field].to_s}).to eq(
23+
["age", "created_at", "cutter", "id", "island", "name", "owner", "updated_at"]
1224
)
1325
end
1426
end

0 commit comments

Comments
 (0)