Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes issues with Ruby 1.8.7, etc... #156

Merged
merged 11 commits into from

2 participants

@johndouthat

Thank you so much for Searchlogic. It's really great. I'm using it in several apps.

  • Fixes an issue with Searchlogic::ActiveRecord::Scope#scopes
  • Fixes a Ruby 1.8.7 compatibility issue in Searchlogic::Search::Conditions#compatct_conditions
  • Adds Appraisal support for testing multiple versions of ActiveRecord at once
  • Backed up AR support from 2.3.11 to 2.3.9. Now the specs pass with ActiveRecord 2.3.9 - 2.3.14 on Ruby 1.9.3-p125, 1.9.2-p318, and 1.8.7-p358
  • Adds some specs for coverage
  • fixes documentation and problem in alias_scope
  • Mucks with the gemfile a little bit. Sorry about that!

I'm going to try to work on Rails 3.2 compatibility in the near future, but for now I hope these changes help.

johndouthat added some commits
@johndouthat johndouthat Switch from Jeweler to bundler/gem_tasks. Remove ruby-debug19 depende…
…ncy.
0c0f017
@johndouthat johndouthat Update bundle. Update rspec development dependency to allow ~> 1.3.1 6295314
@johndouthat johndouthat Remove $LOAD_PATH manipulation. Bundler handles that. Searchlogic req…
…uires active_record.
83db766
@johndouthat johndouthat Add Appraisal development dependency. Support AR back to 2.3.9. 8641923
@johndouthat johndouthat Fix all specs failing in Ruby 1.8.7 046f0c1
@johndouthat johndouthat Fix failing spec in 1.8.7 and potential problem in 1.9...
"should inherit alias scopes from superclasses" creates an anonymous subclass for its test. Anonymous classes return nil for .name by default.
It passed in 1.9 because Searchlogic::ActiveRecord::Scope#scopes's monkey patched `include?` was inadvertantly calling .respond_to?(key) on `result` instead of the AR class. In 1.8.7, it resulted in a syntax error `unexpected '.', expecting kEND` in `.respond_to?(key)` because name was nil. So, instead of looking up the AR class by name, now a reference to the class is passed in.
3958111
@johndouthat johndouthat Fix failing spec in Ruby 1.8.7...
compact_conditions "should remove conditions with blank values". In Ruby 1.9, Hash#select returns a hash, but in 1.8, it returns an array of key/value pair arrays.
a56519f
@johndouthat johndouthat Remove the Jeweler dependency 613a527
@johndouthat johndouthat Tweak alias_scope documentation, add a spec for coverage, and allow a…
…liasing scopes by symbol that have arguments.
0967c91
@johndouthat johndouthat Add specs for OrConditions for coverage 0181025
@johndouthat johndouthat Add specs for ColumnConditions coverage 3b672b7
@oddlyzen oddlyzen merged commit ddfc112 into from
@oddlyzen

@johndouthat Thanks for the work you put into this! We're actually currently working on a fork for Rails 3 compatibility. If you'd like to help out (and get a first look), ping me and we will keep you in the loop during the upgrade process.

@johndouthat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2012
  1. @johndouthat
  2. @johndouthat
  3. @johndouthat
  4. @johndouthat
  5. @johndouthat
  6. @johndouthat

    Fix failing spec in 1.8.7 and potential problem in 1.9...

    johndouthat authored
    "should inherit alias scopes from superclasses" creates an anonymous subclass for its test. Anonymous classes return nil for .name by default.
    It passed in 1.9 because Searchlogic::ActiveRecord::Scope#scopes's monkey patched `include?` was inadvertantly calling .respond_to?(key) on `result` instead of the AR class. In 1.8.7, it resulted in a syntax error `unexpected '.', expecting kEND` in `.respond_to?(key)` because name was nil. So, instead of looking up the AR class by name, now a reference to the class is passed in.
  7. @johndouthat

    Fix failing spec in Ruby 1.8.7...

    johndouthat authored
    compact_conditions "should remove conditions with blank values". In Ruby 1.9, Hash#select returns a hash, but in 1.8, it returns an array of key/value pair arrays.
Commits on Mar 23, 2012
  1. @johndouthat
  2. @johndouthat

    Tweak alias_scope documentation, add a spec for coverage, and allow a…

    johndouthat authored
    …liasing scopes by symbol that have arguments.
  3. @johndouthat
  4. @johndouthat
This page is out of date. Refresh to see the latest.
View
6 Appraisals
@@ -0,0 +1,6 @@
+[9,10,11,12,14].each do |i|
+ appraise "ar2.3.#{i}" do
+ gem 'activerecord', "2.3.#{i}"
+ end
+end
+
View
9 Gemfile
@@ -1,10 +1,3 @@
source :rubygems
-gem 'activerecord', '~> 2.3.12'
-
-group :test do
- gem 'jeweler'
- gem 'ruby-debug19'
- gem 'rspec', '1.3.1'
- gem 'sqlite3'
-end
+gemspec
View
45 Gemfile.lock
@@ -1,38 +1,27 @@
+PATH
+ remote: .
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.8)
+
GEM
remote: http://rubygems.org/
specs:
- activerecord (2.3.12)
- activesupport (= 2.3.12)
- activesupport (2.3.12)
- archive-tar-minitar (0.5.2)
- columnize (0.3.4)
- git (1.2.5)
- jeweler (1.6.4)
- bundler (~> 1.0)
- git (>= 1.2.5)
+ activerecord (2.3.14)
+ activesupport (= 2.3.14)
+ activesupport (2.3.14)
+ appraisal (0.4.1)
+ bundler
rake
- linecache19 (0.5.12)
- ruby_core_source (>= 0.1.4)
- rake (0.9.2)
- rspec (1.3.1)
- ruby-debug-base19 (0.11.25)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby_core_source (>= 0.1.4)
- ruby-debug19 (0.11.6)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby-debug-base19 (>= 0.11.19)
- ruby_core_source (0.1.5)
- archive-tar-minitar (>= 0.5.2)
- sqlite3 (1.3.4)
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ sqlite3 (1.3.5)
PLATFORMS
ruby
DEPENDENCIES
- activerecord (~> 2.3.12)
- jeweler
- rspec (= 1.3.1)
- ruby-debug19
+ appraisal (= 0.4.1)
+ rspec (~> 1.3.1)
+ searchlogic!
sqlite3
View
2  README.rdoc
@@ -2,6 +2,8 @@
Searchlogic makes using ActiveRecord named scopes easier and less repetitive. It helps keep your code DRY, clean, and simple.
+The specs pass with ActiveRecord 2.3.9 - 2.3.14 on Ruby 1.9.3-p125, 1.9.2-p318, and 1.8.7-p358
+
== Helpful links
* <b>Documentation:</b> http://rdoc.info/projects/binarylogic/searchlogic
View
23 Rakefile
@@ -1,24 +1,7 @@
-require 'rubygems'
-require 'rake'
-require 'bundler'
-
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
Bundler.setup
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "searchlogic"
- gem.summary = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
- gem.description = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
- gem.email = "bjohnson@binarylogic.com"
- gem.homepage = "http://github.com/binarylogic/searchlogic"
- gem.authors = ["Ben Johnson of Binary Logic"]
- gem.add_bundler_dependencies
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
-end
+require 'appraisal'
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
View
7 gemfiles/ar2.3.10.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "activerecord", "2.3.10"
+
+gemspec :path=>"../"
View
28 gemfiles/ar2.3.10.gemfile.lock
@@ -0,0 +1,28 @@
+PATH
+ remote: /Users/john/code/searchlogic
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activerecord (2.3.10)
+ activesupport (= 2.3.10)
+ activesupport (2.3.10)
+ appraisal (0.4.1)
+ bundler
+ rake
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ sqlite3 (1.3.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (= 2.3.10)
+ appraisal (= 0.4.1)
+ rspec (~> 1.3.1)
+ searchlogic!
+ sqlite3
View
7 gemfiles/ar2.3.11.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "activerecord", "2.3.11"
+
+gemspec :path=>"../"
View
28 gemfiles/ar2.3.11.gemfile.lock
@@ -0,0 +1,28 @@
+PATH
+ remote: /Users/john/code/searchlogic
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activerecord (2.3.11)
+ activesupport (= 2.3.11)
+ activesupport (2.3.11)
+ appraisal (0.4.1)
+ bundler
+ rake
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ sqlite3 (1.3.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (= 2.3.11)
+ appraisal (= 0.4.1)
+ rspec (~> 1.3.1)
+ searchlogic!
+ sqlite3
View
7 gemfiles/ar2.3.12.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "activerecord", "2.3.12"
+
+gemspec :path=>"../"
View
28 gemfiles/ar2.3.12.gemfile.lock
@@ -0,0 +1,28 @@
+PATH
+ remote: /Users/john/code/searchlogic
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activerecord (2.3.12)
+ activesupport (= 2.3.12)
+ activesupport (2.3.12)
+ appraisal (0.4.1)
+ bundler
+ rake
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ sqlite3 (1.3.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (= 2.3.12)
+ appraisal (= 0.4.1)
+ rspec (~> 1.3.1)
+ searchlogic!
+ sqlite3
View
7 gemfiles/ar2.3.14.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "activerecord", "2.3.14"
+
+gemspec :path=>"../"
View
28 gemfiles/ar2.3.14.gemfile.lock
@@ -0,0 +1,28 @@
+PATH
+ remote: /Users/john/code/searchlogic
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activerecord (2.3.14)
+ activesupport (= 2.3.14)
+ activesupport (2.3.14)
+ appraisal (0.4.1)
+ bundler
+ rake
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ sqlite3 (1.3.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (= 2.3.14)
+ appraisal (= 0.4.1)
+ rspec (~> 1.3.1)
+ searchlogic!
+ sqlite3
View
7 gemfiles/ar2.3.9.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "activerecord", "2.3.9"
+
+gemspec :path=>"../"
View
28 gemfiles/ar2.3.9.gemfile.lock
@@ -0,0 +1,28 @@
+PATH
+ remote: /Users/john/code/searchlogic
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activerecord (2.3.9)
+ activesupport (= 2.3.9)
+ activesupport (2.3.9)
+ appraisal (0.4.1)
+ bundler
+ rake
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ sqlite3 (1.3.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (= 2.3.9)
+ appraisal (= 0.4.1)
+ rspec (~> 1.3.1)
+ searchlogic!
+ sqlite3
View
2  lib/searchlogic.rb
@@ -1,3 +1,5 @@
+require 'active_record'
+require "searchlogic/version"
require "searchlogic/core_ext/proc"
require "searchlogic/core_ext/object"
require "searchlogic/active_record/consistency"
View
9 lib/searchlogic/active_record/scope.rb
@@ -8,14 +8,21 @@ module ActiveRecord
module Scope
def scopes
read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {}.tap do |h|
+
+ class << h
+ attr_accessor :active_record_class
+ end
+ h.active_record_class = self
+
h.instance_eval <<-eval
def include?(key)
result = super
return result if result
- #{name}.respond_to?(key)
+ active_record_class.respond_to?(key)
super
end
eval
+
end)
end
end
View
4 lib/searchlogic/named_scopes/alias_scope.rb
@@ -8,7 +8,7 @@ module AliasScope
# or represents a named scope procedure. Ex:
#
# class User
- # def teenager
+ # def self.teenager
# age_gte(13).age_lte(19)
# end
# end
@@ -37,7 +37,7 @@ def alias_scope(name, options = nil)
define_method name do |*args|
case options
when Symbol
- send(options)
+ send(options, *args)
else
options.call(*args)
end
View
2  lib/searchlogic/search/conditions.rb
@@ -7,7 +7,7 @@ def conditions
end
def compact_conditions
- conditions.select { |k,v| !v.blank? }
+ Hash[conditions.select { |k,v| !v.blank? }]
end
# Accepts a hash of conditions.
View
3  lib/searchlogic/version.rb
@@ -0,0 +1,3 @@
+module Searchlogic
+ VERSION = "2.5.8"
+end
View
100 searchlogic.gemspec
@@ -1,86 +1,30 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/searchlogic/version', __FILE__)
-Gem::Specification.new do |s|
- s.name = %q{searchlogic}
- s.version = "2.5.8"
+Gem::Specification.new do |gem|
+ gem.authors = ["Ben Johnson of Binary Logic"]
+ gem.email = ["bjohnson@binarylogic.com"]
+ gem.description = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
+ gem.summary = gem.description
+ gem.homepage = "http://github.com/binarylogic/searchlogic"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{Ben Johnson of Binary Logic}]
- s.date = %q{2011-08-15}
- s.description = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
- s.email = %q{bjohnson@binarylogic.com}
- s.extra_rdoc_files = [
+ gem.files = `git ls-files`.split($\)
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "searchlogic"
+ gem.require_paths = ["lib"]
+ gem.version = Searchlogic::VERSION
+
+ gem.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
- s.files = [
- "Gemfile",
- "Gemfile.lock",
- "LICENSE",
- "README.rdoc",
- "Rakefile",
- "VERSION.yml",
- "init.rb",
- "lib/searchlogic.rb",
- "lib/searchlogic/active_record/consistency.rb",
- "lib/searchlogic/active_record/named_scope_tools.rb",
- "lib/searchlogic/active_record/scope.rb",
- "lib/searchlogic/core_ext/object.rb",
- "lib/searchlogic/core_ext/proc.rb",
- "lib/searchlogic/named_scopes/alias_scope.rb",
- "lib/searchlogic/named_scopes/association_conditions.rb",
- "lib/searchlogic/named_scopes/association_ordering.rb",
- "lib/searchlogic/named_scopes/base.rb",
- "lib/searchlogic/named_scopes/column_conditions.rb",
- "lib/searchlogic/named_scopes/or_conditions.rb",
- "lib/searchlogic/named_scopes/ordering.rb",
- "lib/searchlogic/rails_helpers.rb",
- "lib/searchlogic/search.rb",
- "lib/searchlogic/search/base.rb",
- "lib/searchlogic/search/conditions.rb",
- "lib/searchlogic/search/date_parts.rb",
- "lib/searchlogic/search/implementation.rb",
- "lib/searchlogic/search/method_missing.rb",
- "lib/searchlogic/search/ordering.rb",
- "lib/searchlogic/search/scopes.rb",
- "lib/searchlogic/search/to_yaml.rb",
- "lib/searchlogic/search/unknown_condition_error.rb",
- "rails/init.rb",
- "searchlogic.gemspec",
- "spec/searchlogic/active_record/association_proxy_spec.rb",
- "spec/searchlogic/active_record/consistency_spec.rb",
- "spec/searchlogic/core_ext/object_spec.rb",
- "spec/searchlogic/core_ext/proc_spec.rb",
- "spec/searchlogic/named_scopes/alias_scope_spec.rb",
- "spec/searchlogic/named_scopes/association_conditions_spec.rb",
- "spec/searchlogic/named_scopes/association_ordering_spec.rb",
- "spec/searchlogic/named_scopes/column_conditions_spec.rb",
- "spec/searchlogic/named_scopes/or_conditions_spec.rb",
- "spec/searchlogic/named_scopes/ordering_spec.rb",
- "spec/searchlogic/search_spec.rb",
- "spec/spec_helper.rb"
- ]
- s.homepage = %q{http://github.com/binarylogic/searchlogic}
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{1.8.6}
- s.summary = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
-
- if s.respond_to? :specification_version then
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.12"])
- s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.12"])
- else
- s.add_dependency(%q<activerecord>, ["~> 2.3.12"])
- s.add_dependency(%q<activerecord>, ["~> 2.3.12"])
- end
- else
- s.add_dependency(%q<activerecord>, ["~> 2.3.12"])
- s.add_dependency(%q<activerecord>, ["~> 2.3.12"])
- end
+ # gem.date = %q{2011-08-15}
+
+
+ gem.add_dependency 'activerecord', '~> 2.3.8'
+ gem.add_development_dependency 'rspec', '~> 1.3.1'
+ gem.add_development_dependency 'sqlite3'
+ gem.add_development_dependency 'appraisal', '0.4.1'
end
View
7 spec/searchlogic/named_scopes/alias_scope_spec.rb
@@ -11,6 +11,13 @@
User.username_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
end
+ it "should allow alias scopes with symbols" do
+ User.alias_scope :login_has, :username_has
+ User.create(:username => "bjohnson")
+ User.create(:username => "thunt")
+ User.login_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
+ end
+
it "should allow alias scopes from the search object" do
search = User.search
search.username_has = "bjohnson"
View
7 spec/searchlogic/named_scopes/column_conditions_spec.rb
@@ -26,6 +26,9 @@
it "should have does not equal" do
(5..7).each { |age| User.create(:age => age) }
User.age_does_not_equal(6).all.should == User.find_all_by_age([5,7])
+
+ User.create!(:age => nil)
+ User.age_does_not_equal(nil).all.size.should == 3
end
it "should have less than" do
@@ -326,4 +329,8 @@
count2 = User.id_ne(10).username_not_like("root").count
count1.should == count2
end
+
+ it "should produce left outer joins" do
+ User.left_outer_joins(:orders).should == [" LEFT OUTER JOIN \"orders\" ON orders.user_id = users.id "]
+ end
end
View
10 spec/searchlogic/named_scopes/or_conditions_spec.rb
@@ -39,6 +39,12 @@
{:conditions => "((users.username LIKE '%ben') OR (users.name LIKE '%ben')) AND ((users.age IS NOT NULL) AND ((users.id > 10) AND (users.username LIKE 'ben%')))"}
end
+ it "should work with boolean conditions" do
+ User.male_or_name_eq("susan").proxy_options.should == {:conditions => %Q{("users"."male" = 't') OR (users.name = 'susan')}}
+ User.not_male_or_name_eq("susan").proxy_options.should == {:conditions => %Q{("users"."male" = 'f') OR (users.name = 'susan')}}
+ lambda { User.male_or_name_eq("susan").all }.should_not raise_error
+ end
+
it "should play nice with scopes on associations" do
lambda { User.name_or_company_name_like("ben") }.should_not raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
User.name_or_company_name_like("ben").proxy_options.should == {:joins => :company, :conditions => "(users.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
@@ -47,6 +53,10 @@
Cart.user_company_name_or_user_company_name_like("ben").proxy_options.should == {:joins => {:user=>:company}, :conditions => "(companies.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
end
+ it "should raise an error on missing condition" do
+ lambda { User.id_or_age(123) }.should raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
+ end
+
it "should not get confused by the 'or' in find_or_create_by_* methods" do
User.create(:name => "Fred")
User.find_or_create_by_name("Fred").should be_a_kind_of User
View
19 spec/spec_helper.rb
@@ -1,7 +1,5 @@
-require 'spec'
-require 'rubygems'
-require 'ruby-debug'
-require "active_record"
+Bundler.setup
+require 'searchlogic'
ENV['TZ'] = 'UTC'
Time.zone = 'Eastern Time (US & Canada)'
@@ -76,9 +74,6 @@
end
end
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'searchlogic'
Spec::Runner.configure do |config|
config.before(:each) do
@@ -130,9 +125,11 @@ class ::LineItem < ActiveRecord::Base
end
config.after(:each) do
- Object.send(:remove_const, :Company)
- Object.send(:remove_const, :User)
- Object.send(:remove_const, :Order)
- Object.send(:remove_const, :LineItem)
+ class ::Object
+ remove_const :Company rescue nil
+ remove_const :User rescue nil
+ remove_const :Order rescue nil
+ remove_const :LineItem rescue nil
+ end
end
end
Something went wrong with that request. Please try again.