Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing Time as value to scope sends time#to_a instead of time #501

Closed
rylwin opened this issue Jan 26, 2015 · 3 comments
Closed

Passing Time as value to scope sends time#to_a instead of time #501

rylwin opened this issue Jan 26, 2015 · 3 comments
Assignees

Comments

@rylwin
Copy link

rylwin commented Jan 26, 2015

Passing a Time value to a scope leads to unexpected behavior. The Time value
appears to be passed as *time_value#to_a. This causes an error as the scope
expects a single Time object and not the 10 elements returned by Time#to_a.
The value should be passed simply as the time object (e.g., time_value).

I've created a failing spec and pasted the error output (since the scope expects a single value) below.

I haven't yet looked into writing a fix for this issue. If there's interest I'm happy to do so and submit a PR.

  1) Ransack::Adapters::ActiveRecord::Base#search with scopes passes Time values to scopes
     Failure/Error: search = Person.ransack('over_age' => time)
     ArgumentError:
       wrong number of arguments (10 for 1)
     # ./spec/support/schema.rb:41:in `block in <class:Person>'
     # ~/.rbenv/.../active_record/scoping/named.rb:155:in `call'
     # ~/.rbenv/.../active_record/scoping/named.rb:155:in `block (2 levels) in scope'
     # ~/.rbenv/.../active_record/relation.rb:302:in `scoping'
     # ~/.rbenv/.../active_record/scoping/named.rb:155:in `block in scope'
     # ~/.rbenv/.../active_record/relation/delegation.rb:70:in `block in over_age'
     # ~/.rbenv/.../active_record/relation.rb:302:in `scoping'
     # ~/.rbenv/.../active_record/relation/delegation.rb:70:in `over_age'
     # ./lib/ransack/context.rb:56:in `public_send'
     # ./lib/ransack/context.rb:56:in `chain_scope'
     # ./lib/ransack/search.rb:138:in `add_scope'
     # ./lib/ransack/search.rb:53:in `block in build'
     # ./lib/ransack/search.rb:47:in `each'
     # ./lib/ransack/search.rb:47:in `build'
     # ./lib/ransack/search.rb:39:in `initialize'
     # ./lib/ransack/adapters/active_record/base.rb:15:in `new'
     # ./lib/ransack/adapters/active_record/base.rb:15:in `ransack'
     # ./spec/ransack/adapters/active_record/base_spec.rb:68:in `block (4 levels) in <module:ActiveRecord>'

P.S. Thanks for a great gem!

@jonatack
Copy link
Contributor

Thanks for the issue and spec!

The README might be referring to this when it says: "scopes with an array as an argument are not easily usable yet, because the array currently needs to be wrapped in an array to function (see #404), which is not compatible with Ransack form helpers. For this use case, it may be better for now to use ransackers instead, where feasible. Pull requests with solutions and tests are welcome!"

What versions of Rails, Ruby and Ransack are you using?

A PR fix would be great.

@jonatack jonatack self-assigned this Aug 20, 2015
@avit
Copy link
Contributor

avit commented Feb 17, 2016

Related to #509. I will make a PR.

@scarroll32
Copy link
Member

Closed by #742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants