Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: labocho/ransack
base: 3542cf4f29
...
head fork: labocho/ransack
compare: faf299429e
Checking mergeability… Don't worry, you can still create the pull request.
  • 18 commits
  • 7 files changed
  • 0 commit comments
  • 5 contributors
Commits on Nov 26, 2012
@labocho Escape wildcard characters in LIKE clause fad3ac9
Commits on Nov 28, 2012
@radar radar Merge pull request #171 from labocho/escape-wildcards
Escape wildcard characters in LIKE clause
aeab6e3
Commits on Nov 29, 2012
@radar radar Add CONTRIBUTING guidelines
Stolen from spree/spree
767675e
Commits on Dec 13, 2012
@radar radar Bump to 0.7.1 bc68626
Commits on Dec 18, 2012
@radar radar Revert escaping of underscore characater from #171
Related to #176
71a3938
@radar radar Bump to 0.7.2 6d8904e
Commits on Jan 30, 2013
@KevinSjoberg KevinSjoberg Fix Predicate spec for wildcard escaping
This fix reflects commit 71a3938.
6a11aac
@KevinSjoberg KevinSjoberg Update Ransack::Constants#escape_wildcards
This updates Ransack::Constants#escape_wildcards to escape dots (.) as
well in order to bypass rails/rails#950.
40ded19
@radar radar Merge pull request #191 from KevinSjoberg/master
Update Ransack::Constants#escape_wildcards
0b55627
Commits on Jan 31, 2013
@westonplatter westonplatter added travis status png e470d99
Commits on Feb 05, 2013
@radar radar Merge pull request #192 from westonplatter/master
added travis ci png status image
7232269
Commits on Feb 06, 2013
@KevinSjoberg KevinSjoberg Fix issue #190 and #195
This resolves issues where an integer column would raise an exception
when handled by Ransack::Constants.escape_wildcards.
53ef01b
@KevinSjoberg KevinSjoberg Change RSpec configuration alias
In RSpec, v2.8, RSpec::Core::Configuration#alias_it_behaves_like_to
does not exist. This method is introduced in later versions. Instead,
use RSpec::Core::Configuration#alias_it_should_behave_like_to.
8501b98
@KevinSjoberg KevinSjoberg Use Object#send to comply with Ruby 1.8.7 3926857
@radar radar Merge pull request #196 from KevinSjoberg/master
Fix issue #190 and #195
4ab1cff
@radar radar Bump to 0.7.3 5cc0595
Commits on Feb 07, 2013
@edulan edulan Fixed lteq spanish translation c98135e
Commits on Feb 12, 2013
@radar radar Merge pull request #197 from edulan/master
Fix for spanish translations
faf2994
View
60 CONTRIBUTING.md
@@ -0,0 +1,60 @@
+Ransack is an open source project and we encourage contributions.
+
+## Filing an issue
+
+When filing an issue on the Ransack project, please provide these details:
+
+* A comprehensive list of steps to reproduce the issue.
+* The version of Ransack *and* the version of Rails.
+* Any relevant stack traces ("Full trace" preferred)
+
+In 99% of cases, this information is enough to determine the cause and solution to the problem that is being described.
+
+Any issue that is open for 14 days without actionable information or activity will be marked as "stalled" and then closed. Stalled issues can be re-opened if the information requested is provided.
+
+## Pull requests
+
+We gladly accept pull requests to fix bugs and, in some circumstances, add new features to Ransack.
+
+Here's a quick guide:
+
+1. Fork the repo.
+
+2. Run the tests. We only take pull requests with passing tests, and it's great
+to know that you have a clean slate:
+
+ $ bundle install
+ $ bundle exec rake test_app
+ $ bundle exec rake
+
+3. Add a test for your change. Only refactoring and documentation changes
+require no new tests. If you are adding functionality or fixing a bug, we need
+a test!
+
+4. Make the test pass.
+
+5. Push to your fork and submit a pull request. If the changes will apply cleanly to the latest stable branches and master branch, you will only need to submit one pull request.
+
+At this point you're waiting on us. We like to at least comment on, if not
+accept, pull requests within three business days (and, typically, one business
+day). We may suggest some changes or improvements or alternatives.
+
+Some things that will increase the chance that your pull request is accepted,
+taken straight from the Ruby on Rails guide:
+
+* Use Rails idioms and helpers
+* Include tests that fail without your code, and pass with it
+* Update the documentation, the surrounding one, examples elsewhere, guides,
+ whatever is affected by your contribution
+
+Syntax:
+
+* Two spaces, no tabs.
+* No trailing whitespace. Blank lines should not have any space.
+* Prefer &&/|| over and/or.
+* `MyClass.my_method(my_arg)` not `my_method( my_arg )` or my_method my_arg.
+* `a = b` and not `a=b`.
+* `a_method { |block| ... }` and not `a_method { | block | ... }`
+* Follow the conventions you see used in the source already.
+
+And in case we didn't emphasize it enough: we love tests!
View
2  README.md
@@ -1,5 +1,7 @@
# Ransack
+[![Build Status](https://travis-ci.org/ernie/ransack.png?branch=master)](https://travis-ci.org/ernie/ransack)
+
Ransack is a rewrite of [MetaSearch](http://metautonomo.us/projects/metasearch). While it
supports many of the same features as MetaSearch, its underlying implementation differs
greatly from MetaSearch, and _backwards compatibility is not a design goal._
View
20 lib/ransack/constants.rb
@@ -6,12 +6,12 @@ module Constants
AREL_PREDICATES = %w(eq not_eq matches does_not_match lt lteq gt gteq in not_in)
DERIVED_PREDICATES = [
- ['cont', {:arel_predicate => 'matches', :formatter => proc {|v| "%#{v}%"}}],
- ['not_cont', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "%#{v}%"}}],
- ['start', {:arel_predicate => 'matches', :formatter => proc {|v| "#{v}%"}}],
- ['not_start', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "#{v}%"}}],
- ['end', {:arel_predicate => 'matches', :formatter => proc {|v| "%#{v}"}}],
- ['not_end', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "%#{v}"}}],
+ ['cont', {:arel_predicate => 'matches', :formatter => proc {|v| "%#{escape_wildcards(v)}%"}}],
+ ['not_cont', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "%#{escape_wildcards(v)}%"}}],
+ ['start', {:arel_predicate => 'matches', :formatter => proc {|v| "#{escape_wildcards(v)}%"}}],
+ ['not_start', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "#{escape_wildcards(v)}%"}}],
+ ['end', {:arel_predicate => 'matches', :formatter => proc {|v| "%#{escape_wildcards(v)}"}}],
+ ['not_end', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "%#{escape_wildcards(v)}"}}],
['true', {:arel_predicate => 'eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}}],
['false', {:arel_predicate => 'eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| !v}}],
['present', {:arel_predicate => 'not_eq_all', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| [nil, '']}}],
@@ -19,5 +19,11 @@ module Constants
['null', {:arel_predicate => 'eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| nil}}],
['not_null', {:arel_predicate => 'not_eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| nil}}]
]
+
+ module_function
+ # replace % \ to \% \\
+ def escape_wildcards(unescaped)
+ unescaped.to_s.gsub(/([\\|\%|.])/, '\\\\\\1')
+ end
end
-end
+end
View
2  lib/ransack/locale/es.yml
@@ -29,7 +29,7 @@ es:
lt: "menor que"
lt_any: "menor que cualquier"
lt_all: "menor o igual a"
- lteq: "less than or equal to"
+ lteq: "menor que o igual a"
lteq_any: "menor o igual a cualquier"
lteq_all: "menor o igual a todos"
gt: "mayor que"
View
2  lib/ransack/version.rb
@@ -1,3 +1,3 @@
module Ransack
- VERSION = "0.7.0"
+ VERSION = "0.7.3"
end
View
19 spec/ransack/predicate_spec.rb
@@ -7,6 +7,17 @@ module Ransack
@s = Search.new(Person)
end
+ shared_examples 'wildcard escaping' do |method, regexp|
+ it 'automatically converts integers to strings' do
+ subject.parent_id_cont = 1
+ expect { subject.result }.to_not raise_error
+ end
+ it "escapes '%', '.' and '\\\\' in value" do
+ subject.send(:"#{method}=", '%._\\')
+ subject.result.to_sql.should match(regexp)
+ end
+ end
+
describe 'eq' do
it 'generates an equality condition for boolean true' do
@s.awesome_eq = true
@@ -25,6 +36,10 @@ module Ransack
end
describe 'cont' do
+ it_has_behavior 'wildcard escaping', :name_cont, /"people"."name" LIKE '%\\%\\._\\\\%'/ do
+ subject { @s }
+ end
+
it 'generates a LIKE query with value surrounded by %' do
@s.name_cont = 'ric'
@s.result.to_sql.should match /"people"."name" LIKE '%ric%'/
@@ -32,6 +47,10 @@ module Ransack
end
describe 'not_cont' do
+ it_has_behavior 'wildcard escaping', :name_not_cont, /"people"."name" NOT LIKE '%\\%\\._\\\\%'/ do
+ subject { @s }
+ end
+
it 'generates a NOT LIKE query with value surrounded by %' do
@s.name_not_cont = 'ric'
@s.result.to_sql.should match /"people"."name" NOT LIKE '%ric%'/
View
2  spec/spec_helper.rb
@@ -20,6 +20,8 @@
end
RSpec.configure do |config|
+ config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior'
+
config.before(:suite) do
puts '=' * 80
puts "Running specs against ActiveRecord #{ActiveRecord::VERSION::STRING} and ARel #{Arel::VERSION}..."

No commit comments for this range

Something went wrong with that request. Please try again.