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
1 changed files with 6 additions and 5 deletions

View File

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