Skip to content

Commit

Permalink
ArgumentError: Call `select' with at least one field
Browse files Browse the repository at this point in the history
See:
- https://gist.github.com/dlcmh/9879954ec029162b6788640ef250e216
- #358

Co-authored-by: Ali Ilman <aliilman532@gmail.com>
  • Loading branch information
dlcmh and thealiilman committed May 9, 2020
1 parent dcd987f commit 37d0934
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/mobility/plugins/active_record/query.rb
Expand Up @@ -139,7 +139,9 @@ def order(opts, *rest)

if ::ActiveRecord::VERSION::STRING >= '5.0'
%w[pluck group select].each do |method_name|
define_method method_name do |*attrs|
define_method method_name do |*attrs, &block|
return super(&block) if (method_name == 'select' && block.present?)

return super(*attrs) unless attrs.any?(&@klass.method(:mobility_attribute?))

keys = attrs.dup
Expand Down
6 changes: 6 additions & 0 deletions spec/support/shared_examples/querying_examples.rb
Expand Up @@ -352,6 +352,12 @@
end
end

describe "passing a block to .select" do
it "won't throw any error" do
expect { ordered_results.select {} }.not_to raise_error
end
end

describe "selecting translated attributes" do
it "returns value from attribute methods on results" do
selected = ordered_results.select(a1)
Expand Down

0 comments on commit 37d0934

Please sign in to comment.