1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Improve test method

- allow different operators & attributes for use with other tests
- replace `send("quoted_#{value}”)` with `quote(value)`
- cache #expected_query to a local var
This commit is contained in:
jonatack 2015-02-03 00:08:21 +01:00
parent 5009eeadb8
commit 3e4b6e34ab

View file

@ -362,9 +362,10 @@ module Ransack
private
def test_boolean_equality_for(boolean_value)
query = expected_query(boolean_value)
test_values_for(boolean_value).each do |value|
s = Search.new(Person, awesome_eq: value)
expect(s.result.to_sql).to match expected_boolean_query(boolean_value)
expect(s.result.to_sql).to match query
end
end
@ -377,10 +378,10 @@ module Ransack
end
end
def expected_boolean_query(boolean_value)
field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}"
condition = ActiveRecord::Base.connection.send("quoted_#{boolean_value}")
/#{field} = #{condition}/
def expected_query(value, attribute = 'awesome', operator = '=')
field = "#{quote_table_name("people")}.#{quote_column_name(attribute)}"
quoted_value = ActiveRecord::Base.connection.quote(value)
/#{field} #{operator} #{quoted_value}/
end
end