Skip to content

Commit

Permalink
rename to associations_lookup_list_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoyoussef committed Nov 14, 2024
1 parent f989d91 commit bba4886
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ def destroy_success_action
end

def select_options(query)
query.all.limit(Avo.configuration.associations_query_limit).map do |record|
query.all.limit(Avo.configuration.associations_lookup_list_limit).map do |record|
[@attachment_resource.new(record: record).record_title, record.to_param]
end.tap do |options|
options << t("avo.more_records_available") if options.size == Avo.configuration.associations_query_limit
options << t("avo.more_records_available") if options.size == Avo.configuration.associations_lookup_list_limit
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Configuration
attr_accessor :is_developer_method
attr_accessor :search_results_count
attr_accessor :first_sorting_option
attr_accessor :associations_query_limit
attr_accessor :associations_lookup_list_limit

def initialize
@root_path = "/avo"
Expand Down Expand Up @@ -120,7 +120,7 @@ def initialize
@is_developer_method = :is_developer?
@search_results_count = 8
@first_sorting_option = :desc # :desc or :asc
@associations_query_limit = 1000
@associations_lookup_list_limit = 1000
end

def current_user_method(&block)
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/fields/belongs_to_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def values_for_type(model = nil)
query = Avo::ExecutionContext.new(target: attach_scope, query: query, parent: get_record).handle
end

query.all.limit(Avo.configuration.associations_query_limit).map do |record|
query.all.limit(Avo.configuration.associations_lookup_list_limit).map do |record|
[resource.new(record: record).record_title, record.to_param]
end.tap do |options|
options << t("avo.more_records_available") if options.size == Avo.configuration.associations_query_limit
options << t("avo.more_records_available") if options.size == Avo.configuration.associations_lookup_list_limit
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/avo/templates/initializer/avo.tt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Avo.configure do |config|
## == Number of search results to display ==
# config.search_results_count = 8

## == Associations query limit on select options ==
# config.associations_query_limit = 1000
## == Associations lookup list limit ==
# config.associations_lookup_list_limit = 1000

## == Cache options ==
## Provide a lambda to customize the cache store used by Avo.
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/initializers/avo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

config.alert_dismiss_time = 5000
config.search_results_count = 8
config.associations_query_limit = 1000
config.associations_lookup_list_limit = 1000

## == Menus ==
if Rails.env.test?
Expand Down
6 changes: 3 additions & 3 deletions spec/system/avo/associations_using_fields_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
}.to change(course.links, :count).by(-1)
end

context "when associations options exceeds associations_query_limit" do
context "when associations options exceeds associations_lookup_list_limit" do
let!(:link) { Course::Link.first }

before { Avo.configuration.associations_query_limit = 1 }
after { Avo.configuration.associations_query_limit = 1000 }
before { Avo.configuration.associations_lookup_list_limit = 1 }
after { Avo.configuration.associations_lookup_list_limit = 1000 }

it "limits select options" do
visit avo.resources_course_path(course)
Expand Down
12 changes: 6 additions & 6 deletions spec/system/avo/create_via_belongs_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
expect(Fish.last.user).to eq User.last
end

context "when belongs_to record options exceeds associations_query_limit" do
context "when belongs_to record options exceeds associations_lookup_list_limit" do
let!(:course) { create :course }
let!(:exceeded_course) { create :course }

before { Avo.configuration.associations_query_limit = 1 }
after { Avo.configuration.associations_query_limit = 1000 }
before { Avo.configuration.associations_lookup_list_limit = 1 }
after { Avo.configuration.associations_lookup_list_limit = 1000 }

it "limits select options" do
visit "/admin/resources/course_links/new"
Expand Down Expand Up @@ -139,12 +139,12 @@
)
end

context "when belongs_to record options exceeds associations_query_limit" do
context "when belongs_to record options exceeds associations_lookup_list_limit" do
let!(:user) { User.first }
let!(:exceeded_user) { create :user }

before { Avo.configuration.associations_query_limit = 1 }
after { Avo.configuration.associations_query_limit = 1000 }
before { Avo.configuration.associations_lookup_list_limit = 1 }
after { Avo.configuration.associations_lookup_list_limit = 1000 }

it "limits select options" do
visit "/admin/resources/comments/new"
Expand Down

0 comments on commit bba4886

Please sign in to comment.