Use more explicit ActiveRecord::VERSION::MAJOR

This commit is contained in:
jonatack 2013-08-06 00:17:24 +02:00
parent 87ad87abda
commit cb2ff12e34
4 changed files with 6 additions and 6 deletions

View File

@ -23,7 +23,7 @@ module Ransack
module_function
# replace % \ to \% \\
def escape_wildcards(unescaped)
if ActiveRecord::VERSION::STRING =~ /^3/
if ActiveRecord::VERSION::MAJOR == 3
unescaped.to_s.gsub(/([\\|\%|.])/, '\\\\\\1')
else
unescaped.to_s.gsub(/\\/){ "\\\\" }.gsub(/%/, "\\%")

View File

@ -14,7 +14,7 @@ module Ransack
end
it (
if ActiveRecord::VERSION::STRING =~ /^3/
if ActiveRecord::VERSION::MAJOR == 3
"escapes '%', '.' and '\\\\' in value"
else
"escapes % and \\ in value"
@ -45,7 +45,7 @@ module Ransack
describe 'cont' do
it_has_behavior 'wildcard escaping', :name_cont, (
if ActiveRecord::VERSION::STRING =~ /^3/
if ActiveRecord::VERSION::MAJOR == 3
/"people"."name" LIKE '%\\%\\._\\\\%'/
else
/"people"."name" LIKE '%\\%._\\\\%'/
@ -61,7 +61,7 @@ module Ransack
describe 'not_cont' do
it_has_behavior 'wildcard escaping', :name_not_cont, (
if ActiveRecord::VERSION::STRING =~ /^3/
if ActiveRecord::VERSION::MAJOR == 3
/"people"."name" NOT LIKE '%\\%\\._\\\\%'/
else
/"people"."name" NOT LIKE '%\\%._\\\\%'/

View File

@ -167,7 +167,7 @@ module Ransack
it 'returns distinct records when passed :distinct => true' do
search = Search.new(Person, :g => [{:m => 'or', :comments_body_cont => 'e', :articles_comments_body_cont => 'e'}])
if ActiveRecord::VERSION::STRING =~ /^3/
if ActiveRecord::VERSION::MAJOR == 3
all_or_load, uniq_or_distinct = :all, :uniq
else
all_or_load, uniq_or_distinct = :load, :distinct

View File

@ -6,7 +6,7 @@ ActiveRecord::Base.establish_connection(
)
class Person < ActiveRecord::Base
if ActiveRecord::VERSION::STRING =~ /^3/
if ActiveRecord::VERSION::MAJOR == 3
default_scope order('id DESC')
else
default_scope { order(id: :desc) }