Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bring gem structure up to date

  • Loading branch information...
commit 46b51fca4ac23116d69612cbdc4bea97ea7e3f6c 2 parents a1c2fe5 + ddfc112
@binarylogic authored
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,9 +1,2 @@
source :rubygems
-
-gem 'activerecord', '~> 2.3.12'
-
-group :test do
- gem 'debugger'
- gem 'rspec', '1.3.1'
- gem 'sqlite3'
-end
+gemspec
View
27 Gemfile.lock
@@ -1,25 +1,28 @@
+PATH
+ remote: .
+ specs:
+ searchlogic (2.5.8)
+ activerecord (~> 2.3.12)
+ activesupport (~> 2.3.12)
+
GEM
remote: http://rubygems.org/
specs:
activerecord (2.3.14)
activesupport (= 2.3.14)
activesupport (2.3.14)
- columnize (0.3.6)
- debugger (1.1.3)
- columnize (>= 0.3.1)
- debugger-linecache (~> 1.1.1)
- debugger-ruby_core_source (~> 1.1.2)
- debugger-linecache (1.1.1)
- debugger-ruby_core_source (>= 1.1.1)
- debugger-ruby_core_source (1.1.3)
- rspec (1.3.1)
+ appraisal (0.4.1)
+ bundler
+ rake
+ rake (0.9.2.2)
+ rspec (1.3.2)
sqlite3 (1.3.6)
PLATFORMS
ruby
DEPENDENCIES
- activerecord (~> 2.3.12)
- debugger
- rspec (= 1.3.1)
+ 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
9 Rakefile
@@ -1,10 +1,9 @@
-require 'rubygems'
-require 'rake'
-require 'bundler'
-
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
Bundler.setup
-
+require 'appraisal'
require 'spec/rake/spectask'
+
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
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/named_scopes/column_conditions.rb
@@ -113,7 +113,7 @@ def create_primary_condition(column_name, condition)
column = columns_hash[column_name.to_s]
column_type = column.type
skip_conversion = skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
- match_keyword = ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
+ match_keyword = self.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
scope_options = case condition.to_s
when /^equals/
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
9 searchlogic.gemspec
@@ -1,9 +1,10 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
+require File.expand_path('../lib/searchlogic/version', __FILE__)
Gem::Specification.new do |s|
- s.name = "authlogic"
- s.version = "2.5.8"
+ s.name = "searchlogic"
+ s.version = Searchlogic::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Ben Johnson"]
s.email = ["bjohnson@binarylogic.com"]
@@ -13,6 +14,10 @@ Gem::Specification.new do |s|
s.add_dependency 'activerecord', '~> 2.3.12'
s.add_dependency 'activesupport', '~> 2.3.12'
+ s.add_development_dependency 'rspec', '~> 1.3.1'
+ s.add_development_dependency 'sqlite3'
+ s.add_development_dependency 'appraisal', '0.4.1'
+
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
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
Please sign in to comment.
Something went wrong with that request. Please try again.